Closed ShnitzelKiller closed 1 year ago
Hi @ShnitzelKiller
I believe this is a bug. When using numpy
the behaviour for 1-deep vectorized types is as you expected here.
Let me transfer this issue to the appropriate repository.
I have pushed a fix: https://github.com/mitsuba-renderer/drjit/commit/16b388292b5cb1e532b43a8800f1cca95a17c513
This DLPack
protocol is surprisingly "brittle", there's a lot of room let to interpretation and practically every framework seems to differ from another ever so slightly in their implementation. I would not be surprised if there are still some conversions that we do not handle correctly.
Anyway, this particular fix will be available in our next release.
Summary
I would like to use a torch tensor to control transforms of objects in the scene. Instantiating mitsuba vector/matrix types using pytorch tensors exhibits inconsistent behavior (cannot only seem to create batches greater than 1) and I get errors attempting to make Matrix4f or Point3f objects from TensorXf or torch tensors in any way.
System configuration
Description
I cannot instantiate a
Matrix4f
from a corresponding 4x4 torch tensor. I have tried all manner of input shapes, and it appears thatndim
must be 3. I can create a batched set ofMatrix4f
as long as the input tensor has shape(N, 4, 4)
where N is greater than 1. If it is equal to 1, for some reason I end up with 16 4x4 matrices, all with identical elements (though different from one another).The result:
Meanwhile, if I create a (2, 4, 4) tensor, I will get 2
Matrix4f
as expected:The result:
The same thing happens with
Point3f
objects; I need a (N, 3) tensor with N > 1 or face the same unpredictable behavior. Am I misunderstanding how vectorization works? I cannot pass a tensor with only 2 dimensions, as it immediately raises an error.What I am trying to do is use a torch tensor (from the output of a neural network) to control the transform of an object in a scene. Is this the right approach at all? I have even tried setting individual elements of the matrix to elements of the tensor to no avail (I get the
Refusing to do an extremely inefficient element-by-element array conversion from type <class 'drjit.cuda.ad.TensorXf'> to <class 'drjit.cuda.ad.Float'>
error). Basically I have not seen any example code using Torch tensors in place of matrices/points in Mitsuba code; there is only the one example here which replaces a TensorXf texture with a Torch tensor.