You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Actually, we don't always set the right contiguous flag when constructing PyArrayInterface. For example, Vector should be both C and F contiguous when converted to ndarray, but we set the flag is_c_style to false when constructing a DynamicArray, but after casting it to ndarray, numpy seems to reset this flag to true, which is correct. Not sure if numpy could always do this check in all situation, need to check carefully.
a =rand(3)
ad = CPython.DynamicArray(a)
ad.is_c_style # false
pya =py_cast(Py, a)
pya.flags
# Py( C_CONTIGUOUS : True# F_CONTIGUOUS : True# ...# another example with subarray
b =@viewrand(3,3)[2:3, :]
bd = CPython.DynamicArray(y)
bd.is_c_style # false
bd.is_f_style # false# reconstruct a DynamicArray with wrong flag
bd_wrong = CPython.DynamicArray(bd.arr, bd.eltype, bd.shape, bd.strides, bd.ptr, bd.ndim, bd.itemsize, bd.typekind, true, true, false, bd.perm)
pyb =py_coerce(Py, bd_wrong)
pyb.flags
# Py( C_CONTIGUOUS : False# F_CONTIGUOUS : False# ...
The text was updated successfully, but these errors were encountered:
If it's true that numpy could set contiguous flag automatically, the next questions is could we just wrap every StridedArray without copy?
normalized_x =if x isa StridedArray
x
elsecollect(x)
end
It seems numpy could work correctly if the data pointer, strides, shape and ndims are correct, so it should support all StridedArray. But let me check the mechanism behind numpy first.
Actually, we don't always set the right contiguous flag when constructing
PyArrayInterface
. For example,Vector
should be both C and F contiguous when converted to ndarray, but we set the flagis_c_style
tofalse
when constructing aDynamicArray
, but after casting it to ndarray, numpy seems to reset this flag to true, which is correct. Not sure if numpy could always do this check in all situation, need to check carefully.The text was updated successfully, but these errors were encountered: