@@ -29,10 +29,10 @@ def _fc_to_af_array(in_ptr, in_shape, in_dtype, is_device=False, copy = True):
2929 """
3030 res = Array (in_ptr , in_shape , in_dtype , is_device = is_device )
3131
32- if is_device :
33- lock_array (res )
34- pass
32+ if not is_device :
33+ return res
3534
35+ lock_array (res )
3636 return res .copy () if copy else res
3737
3838def _cc_to_af_array (in_ptr , ndim , in_shape , in_dtype , is_device = False , copy = True ):
@@ -41,24 +41,11 @@ def _cc_to_af_array(in_ptr, ndim, in_shape, in_dtype, is_device=False, copy = Tr
4141 """
4242 if ndim == 1 :
4343 return _fc_to_af_array (in_ptr , in_shape , in_dtype , is_device , copy )
44- elif ndim == 2 :
45- shape = (in_shape [1 ], in_shape [0 ])
46- res = Array (in_ptr , shape , in_dtype , is_device = is_device )
47- if is_device : lock_array (res )
48- return reorder (res , 1 , 0 )
49- elif ndim == 3 :
50- shape = (in_shape [2 ], in_shape [1 ], in_shape [0 ])
51- res = Array (in_ptr , shape , in_dtype , is_device = is_device )
52- if is_device : lock_array (res )
53- return reorder (res , 2 , 1 , 0 )
54- elif ndim == 4 :
55- shape = (in_shape [3 ], in_shape [2 ], in_shape [1 ], in_shape [0 ])
44+ else :
45+ shape = tuple (reversed (in_shape ))
5646 res = Array (in_ptr , shape , in_dtype , is_device = is_device )
5747 if is_device : lock_array (res )
58- return reorder (res , 3 , 2 , 1 , 0 )
59- else :
60- raise RuntimeError ("Unsupported ndim" )
61-
48+ return res ._reorder ()
6249
6350_nptype_to_aftype = {'b1' : Dtype .b8 ,
6451 'u1' : Dtype .u8 ,
0 commit comments