How to index ArrayXf using index of type UInt32 #1421
-
Is there any way to implement the code below? from drjit.cuda import ArrayXf, UInt32, Float
A = ArrayXf([1,2],[2,3],[3,4],[4,5])
idx= UInt32(1, 3)
value = Float(99, 100)
A[idx] = value # Exception occured: Complex slicing operations are currently only supported on tensors. |
Beta Was this translation helpful? Give feedback.
Answered by
rtabbara
Dec 2, 2024
Replies: 1 comment 4 replies
-
Hi @XiaoXinyyx , I think the most concise way is to use import drjit as dr
from drjit.cuda import TensorXf, UInt32, Float, ArrayXf
A = TensorXf([[1,2],[2,3],[3,4],[4,5]])
idx= UInt32(1, 3)
value = Float([99, 100] * dr.width(idx))
A[idx, :] = value
print(A)
'''
[[1, 2],
[99, 100],
[3, 4],
[99, 100]]
''' But I would recommend reading the Dr.Jit section on tensor limitations here and why you may encounter issues if you're inside a symbolic loop. If you still wanted to stick to an B = ArrayXf([1,2,3,4],[2,3,4,5])
idx= UInt32(1, 3)
value = ArrayXf([99], [100])
dr.scatter(B, value, idx)
print(B)
'''
[[1, 2],
[99, 100],
[3, 4],
[99, 100]]
''' |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure. The documentation on local memory is quite detailed and includes an example usage, so that should give a good idea whether or not it's suitable for your needs.
I'm sorry, I'm not sure I can provide any further advice beyond my previous suggestions. As a general comment, if you want to concisely express more complex tensor slicing operations, as the documentation mentions, Dr.Jit may be ill-suited for your needs and you might be better off considering tensor libraries such as PyTorch.