mitsuba-renderer / mitsuba3

Mitsuba 3: A Retargetable Forward and Inverse Renderer
https://www.mitsuba-renderer.org/
Other
2.1k stars 246 forks source link

`dr.diag` no longer accepts `mi.Vector3f` #1250

Closed dvicini closed 3 months ago

dvicini commented 3 months ago

The following code used to create a diagonal matrix:

import mitsuba as mi
import drjit as dr 
mi.set_variant('llvm_ad_rgb')
dr.diag(mi.Vector3f(1,2,3))

but now raises Exception: drjit.diag(): unsupported type!.

It works if I use the raw Dr.Jit array type:

import drjit as dr 
dr.diag(dr.llvm.ad.Array3f(1,2,3))

So the issue seems to somehow relate to the way Mitsuba exposes Vector3f, hence I am opening this here and not in the Dr.Jit repo.

dvicini commented 3 months ago

I think the issue is the logic in Dr.Jit's diag function:

    elif is_array_v(arg) and 'Array' in tp.__name__:
        import sys
        mat_tp = getattr(sys.modules[tp.__module__], tp.__name__.replace('Array', 'Matrix'), None)

This does not seem to work for mi.Vector3f, since the type name here does not contain Array

wjakob commented 3 months ago

The more stable way to fix this would be to add a type trait to drjit/src/python/traits.cpp, which produces a matrix type from a vector type of a given size.

njroussel commented 3 months ago

Fixed in https://github.com/mitsuba-renderer/drjit/pull/254