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

How to implement the join operation of two arrays in Drjit #205

Closed linxxcad closed 9 months ago

linxxcad commented 9 months ago

I want to realize merge multiple arrays in type of Array3f.

A=Array3f( [0,1,2] )
B=Array3f( [3,4,5] )
C=Array3f( [6,7,8] )

How to get D=Array3f( [ [0,1,2] , [3,4,5] , [6,7,8] ])

It can be done in numpy by append or stack. Is this operation differentiable?

I would appreciate it if anyone could help me

rtabbara commented 9 months ago

Hi @linxxcad,

I think one approach could be to use dr.ravel/dr.unravel

# Flatten the input
z = Float(dr.ravel([A,B,C]))

# Use row-major ordering to repackage the Array3f
D = dr.unravel(Array3f, z, order='C')

And yes, this will still be differentiable

linxxcad commented 9 months ago

你好@linxxcad,

我认为一种方法可能是使用dr.ravel/dr.unravel

# Flatten the input
z = Float(dr.ravel([A,B,C]))

# Use row-major ordering to repackage the Array3f
D = dr.unravel(Array3f, z, order='C')

是的,这仍然是可微的

Thanks for your help!