drjit icon indicating copy to clipboard operation
drjit copied to clipboard

Swizzle and implicit binding predicate fixes

Open rtabbara opened this issue 1 year ago • 4 comments

dr.cross : Cast return type back to original type

  • Use of swizzle operator will return a dr.jit array type. This means for example swizzling a mi.Vector3f returns a dr.*.Array3f

For implicit conversion predicate from dr.jit types, also check dimensions are compatible

  • Previously types such as Array4f -> Matrix4<Color3f> would return true as we're just simply checking that the first dimension aligns

rtabbara avatar Aug 20 '24 12:08 rtabbara

Also addresses Mitsuba issue 1280

rtabbara avatar Aug 20 '24 14:08 rtabbara

Wouldn't it be preferable to fix this by changing swizzling so that it preserves the type when the number of array dimensions remains the same?

wjakob avatar Aug 21 '24 02:08 wjakob

Somehow this patch prevents casting a Matrix<4, Float> into a Matrix<4, Color<3, Float>> as in the following example:

import mitsuba as mi
mi.set_variant('llvm_ad_rgb_polarized')

print(mi.Spectrum(mi.mueller.depolarizer(1)))

Speierers avatar Aug 21 '24 08:08 Speierers

@wjakob I've updated the PR so that instead the swizzle operation returns the original type if the swizzle size is compatible

@Speierers I think I've fixed this now and added some corresponding tests related to this

rtabbara avatar Aug 21 '24 11:08 rtabbara

There will always be a tradeoff between an "excessive" check in the implicit cast predicate, and letting it fail during the actual construction attempt. These change are fair for now, in my opinion.

njroussel avatar Aug 27 '24 12:08 njroussel