inaos / iron-array

2 stars 0 forks source link

Getting a second index twice fails #427

Closed FrancescAlted closed 3 years ago

FrancescAlted commented 3 years ago

The next script shows the behaviour:

import numpy as np
import iarray as ia

iarr = ia.zeros((3, 2), dtype=np.float32)
print("iarr.shape->", iarr.shape)
print("first time:", iarr[1])
print("second time:", iarr[1])  # this fails with iarr[0] too
aleixalcacer commented 3 years ago

This patch will fix it:

diff --git a/iarray/iarray_ext.pyx b/iarray/iarray_ext.pyx
index 4da3c20..19b3ae8 100644
--- a/iarray/iarray_ext.pyx
+++ b/iarray/iarray_ext.pyx
@@ -26,6 +26,8 @@ from cpython cimport (
     PyBUF_SIMPLE, PyBUF_WRITABLE, Py_buffer,
     PyBytes_FromStringAndSize
 )
+from dataclasses import asdict
+

 def compress_squeeze(data, selectors):
     return tuple(d for d, s in zip(data, selectors) if not s)
@@ -685,7 +687,12 @@ def get_slice(ctx, data, start, stop, squeeze_mask, view, storage):

     cdef ciarray.iarray_storage_t store_
     cdef ciarray.iarray_container_t *c
-    cfg = ctx.cfg
+
+    # A deep copy of the cfg is needed, but can not be used copy.deepcopy().
+    kwargs = asdict(ctx.cfg)
+    kwargs["store"] = ia.Store(**kwargs["store"])
+    cfg = ia.Config(**kwargs)
+
     if view:
         if cfg.blocks and cfg.chunks:
             shape = tuple(sp - st for sp, st in zip(stop, start))

But I think we need to check why get_slice and set_slice in .pyx file use a ctx instead of a cfg.

FrancescAlted commented 3 years ago

Fixed in https://github.com/inaos/iron-array-python/pull/97