mitsuba-renderer / drjit

Dr.Jit — A Just-In-Time-Compiler for Differentiable Rendering
BSD 3-Clause "New" or "Revised" License
563 stars 40 forks source link

dr.trace: Avoid modifying the matrix entries #199

Closed bathal1 closed 9 months ago

bathal1 commented 9 months ago

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

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]]]