Quansight-Labs / numpy.net

A port of NumPy to .Net
BSD 3-Clause "New" or "Revised" License
128 stars 14 forks source link

Rotating an array, then attempting to update with advanced indexing causes an index out of bound error #52

Closed Taz145 closed 1 year ago

Taz145 commented 1 year ago
ndarray arr1 = np.arange(24).reshape((2, 3, 4));
ndarray arr2 = np.arange(24).reshape((2, 3, 4));

arr2 = np.rot90(arr2, k: 2, axes: new int[] {0, 2});
arr2[arr1 > 0] = 0;

The above section should rotate arr2 180 degrees and then set all indexes from the indexing mask to 0 but instead throws

Message: 
System.IndexOutOfRangeException : Index was outside the bounds of the array.

  Stack Trace: 
CopyHelper`1.SetMap(NpyArrayMapIterObject destIter, NpyArrayIterObject srcIter, Boolean swap)
numpyinternal.NpyArray_SetMap(NpyArrayMapIterObject mit, NpyArray arr)
numpyinternal.NpyArray_IndexFancyAssign(NpyArray self, NpyIndex[] indexes, Int32 n, NpyArray value)
numpyAPI.NpyArray_IndexFancyAssign(NpyArray self, NpyIndex[] indexes, Int32 n, NpyArray value)
NpyCoreApi.IndexFancyAssign(ndarray dest, NpyIndexes indexes, ndarray values)
ndarray.set_Item(Object[] args, Object value)
KevinBaselinesw commented 1 year ago

arr2 = arr2.Copy(); arr2[arr1 > 0] = 0;

As a temporary fix, if you Copy() the array, you should get the expected results.

I will try to debug it. It is complicated.

KevinBaselinesw commented 1 year ago

the new release 0.9.85 should fix this problem

Taz145 commented 1 year ago

Awesome! Thanks for the quick response and fix