I think the behavior of == being a reduction and <= being performed element-wise is at least to me unexpected. Especially in the context where <= is used for an interval because (idx<=0) & (idx>=0) and idx==0 are not the same thing, as the second expression evaluates to either True/False.
If you want, I could send a PR that either adapts the documentation of dr.eq or adds a section to the First steps in Python?
Code
import drjit as dr
from drjit.cuda import UInt, Float
import numpy as np
n = 2
rng = np.random.default_rng(0)
idx = dr.arange(UInt, 0, n)
arr = Float(rng.uniform(size=[n]))
print(r1 := dr.gather(Float, arr, idx, active=idx==0))
print(r2 := dr.gather(Float, arr, idx, active=dr.eq(idx, 0)))
print(r3 := dr.gather(Float, arr, idx, active=(idx<=0) & (idx>=0)))
assert not np.array_equal(r1, r2)
assert np.array_equal(r2, r3)
print([type(m) for m in [idx==0, dr.eq(idx, 0), (idx<=0) & (idx>=0)]])
I think the behavior of
==
being a reduction and<=
being performed element-wise is at least to me unexpected. Especially in the context where<=
is used for an interval because(idx<=0) & (idx>=0)
andidx==0
are not the same thing, as the second expression evaluates to eitherTrue/False
.If you want, I could send a PR that either adapts the documentation of dr.eq or adds a section to the First steps in Python?
Code
Output