When calling dr.trace on an array of matrices, the current implementation accumulates the diagonal entries into an array that is a reference to the first diagonal entry. As a consequence, the first entry of the matrix is modified after running this operation.
This issue concerns all vectorized variants.
This PR fixes this by accumulating the result in a new array.
Reproducer
import drjit as dr
M = dr.cuda.Matrix3f(1.)
print(M)
#[[[1.0, 0.0, 0.0],
# [0.0, 1.0, 0.0],
# [0.0, 0.0, 1.0]]]
t = dr.trace(M)
print(M)
#[[[3.0, 0.0, 0.0],
# [0.0, 1.0, 0.0],
# [0.0, 0.0, 1.0]]]
Issue
When calling
dr.trace
on an array of matrices, the current implementation accumulates the diagonal entries into an array that is a reference to the first diagonal entry. As a consequence, the first entry of the matrix is modified after running this operation.This issue concerns all vectorized variants.
This PR fixes this by accumulating the result in a new array.
Reproducer