@@ -742,6 +742,42 @@ def test05_char_multidim(self):
742742 for i , v in enumerate (("s1" , "s23" , "s456" )):
743743 assert len (ns .str_array [i ]) == 7
744744 assert ns .str_array [i ].as_string () == v
745+
746+ def test06_fixed_multidim_array_itemsize (self ):
747+ """conversion of fixed-length array low level views into NumPy arrays"""
748+ import cppyy
749+ try :
750+ import numpy as np
751+ except ImportError :
752+ skip ('numpy is not installed' )
753+
754+ cases = [
755+ ('float' , np .float32 , (3 , 5 )),
756+ ('int' , np .intc , (2 , 6 )),
757+ ('short' , np .short , (5 , 3 )),
758+ ('unsigned char' , np .ubyte , (4 , 4 )),
759+ ('int32_t' , np .int32 , (2 , 8 )),
760+ ('uint16_t' , np .uint16 , (7 , 3 )),
761+ ]
762+
763+ for cpp_type , np_dtype , (rows , cols ) in cases :
764+ tag = cpp_type .replace (' ' , '_' )
765+ cppyy .cppdef (f"""
766+ struct LLVFixed2D_{ tag } {{
767+ { cpp_type } a[{ rows } ][{ cols } ];
768+ }};
769+ """ )
770+ s = getattr (cppyy .gbl , f'LLVFixed2D_{ tag } ' )()
771+
772+ itemsize = np .dtype (np_dtype ).itemsize
773+ mv = memoryview (s .a )
774+ assert mv .ndim == 2
775+ assert mv .shape == (rows , cols )
776+ assert mv .itemsize == itemsize
777+ assert mv .strides == (cols * itemsize , itemsize )
778+
779+ arr = np .array (s .a , dtype = np_dtype )
780+ assert arr .shape == (rows , cols )
745781
746782
747783if __name__ == "__main__" :
0 commit comments