Skip to content

Commit

Permalink
Fix upsampling of multichannel textures
Browse files Browse the repository at this point in the history
  • Loading branch information
dvicini committed Jul 19, 2022
1 parent 8ca30da commit 53dd605
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drjit/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ def upsample(t, shape=None, scale_factor=None):

# Concatenate output values to a flatten buffer
channels = len(values)
width = _dr.width(values[0]) * channels
index = _dr.arange(_dr.uint32_array_t(value_type), width) // channels
data = _dr.zeros(value_type, width)
width = _dr.width(values[0])
index = _dr.arange(_dr.uint32_array_t(value_type), width)
data = _dr.zeros(value_type, width * channels)
for c in range(channels):
_dr.scatter(data, values[c], index + c)
_dr.scatter(data, values[c], channels * index + c)

# Create the up-sampled texture
texture = type(t)(shape[:-1], channels,
Expand Down
6 changes: 6 additions & 0 deletions tests/python/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,9 @@ def test14_upsampling_texture(pkg):
assert dr.allclose(b.tensor().array, [1.0, 1.5, 2.0,
2.0, 2.5, 3.0,
3.0, 3.5, 4.0])

a = tex_t(t([1, 1, 5, 2, 2, 6, 3, 3, 7, 4, 4, 8], shape=(2, 2, 3)), filter_mode=dr.FilterMode.Linear)
b = dr.upsample(a, shape=[3, 3])
assert dr.allclose(b.tensor().array, [1.0, 1.0, 5.0, 1.5, 1.5, 5.5, 2.0, 2.0, 6.0,
2.0, 2.0, 6.0, 2.5, 2.5, 6.5, 3.0, 3.0, 7.0,
3.0, 3.0, 7.0, 3.5, 3.5, 7.5, 4.0, 4.0, 8.0])

0 comments on commit 53dd605

Please sign in to comment.