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
When a SimpleArray is constructed through the "array" argument in Python and the numpy array passed to this argument is a subset using ndarray accessor, the SimpleArray is constructed with wrong section of data from the original ndarray. Following code is a demonstration.
from modmesh import SimpleArrayFloat64
import numpy as np
a = np.array([[1,2,3,4,5], [10,20,30,40,50],[100,200,300,400,500]])
The SimpleArray constructor expects a contiguous memory buffer and disregard the strides set in ndarray. Before SimpleArray supports the same stride as ndarray, it should throw an exception when the input ndarray is not contiguous.
For now, please use b = SimpleArrayFloat64(array=a[:,4].copy()) to work around.
Thanks @yungyuc, I already used that workaround in my code.
yungyuc
changed the title
Cannot correctly construct SimpleArray from a subset of numpy array using its accessor
Incorrect construction of SimpleArray from a discontiguous slice of ndarray
Oct 19, 2024
When a SimpleArray is constructed through the "array" argument in Python and the numpy array passed to this argument is a subset using ndarray accessor, the SimpleArray is constructed with wrong section of data from the original ndarray. Following code is a demonstration.
Now we have
If we construct a SimpleArray with
The print result is [ 5., 10., 20.].
We should expect a SimpleArray contains [5, 50, 500] instead of [ 5., 10., 20.]
The text was updated successfully, but these errors were encountered: