enoki icon indicating copy to clipboard operation
enoki copied to clipboard

Dynamic Array of a fixed sized Matrix

Open chkone opened this issue 5 years ago • 2 comments

Could you help me to clarify this behavior:

using Mat22f = enoki::Matrix< f32, 2 >;
using Mat22fBuffer = enoki::DynamicArray< enoki::Packet< Mat22f, 2 > >; // With 2
Mat22fBuffer x, y;
y = x;

// Compile time error:
array_generic.h(464,59): error C2440: '<function-style-cast>': cannot convert from 'enoki::Array<eMV::f32,2>' to 'enoki::Matrix<eMV::f32,2>'
array_generic.h(414,1): message : No constructor could take the source type, or constructor overload resolution was ambiguous
array_generic.h(344): message : see reference to function template instantiation 'void enoki::StaticArrayImpl<Value_,2,false,enoki::Packet<Value_,2>,int>::assign_<eMV::Mat22f&,0,1>(T,std::integer_sequence<size_t,0,1>)' being compiled
1>        with
1>        [
1>            Value_=eMV::Mat22f,
1>            T=eMV::Mat22f &
1>        ]

With:

using Mat22f = enoki::Matrix< f32, 2 >;
using Mat22fBuffer = enoki::DynamicArray< enoki::Packet< Mat22f, 2 > >; // With 1
Mat22fBuffer x, y;
y = x;

Compile with no problem.

chkone avatar May 18 '20 06:05 chkone

What will be the use of this Mat22Buffer type?

To perform operations on an "array" of matrices, what you want is:

using MyMat22 = enoki::Matrix<enoki::DynamicArray<enoki::Packet<float, PACKET_WIDTH>>, 2>;

here using a Structure of Arrays (SoA) instead of an Array of Structures (AoS).

Speierers avatar May 18 '20 08:05 Speierers

This is from a code generation. From "Basic type" & enoki types {int32_t, int64_t, float, enoki::Array<float, 2>, enoki::Array<float, 3>, ..., } based on the context I generate a dynamic version of it. Like

template < typename Type >
constexpr size_t PacketSize = enoki::max_packet_size/sizeof( Type );

Generated: using TypeBuffer = enoki::DynamicArray<enoki::Packet<Type, PacketSize< Type > == 0 ? 1 : PacketSize< Type > >;

My understanding was, that will be flatten internally and keeping the type for operation during the unroll of the template expression (for example multiplication). I will rewrite the code-gen if it's "as design".

chkone avatar May 18 '20 10:05 chkone