Move dunder methods to top of class definition.
@@ -50,9 +50,21 @@ class SparseArray(object):
self._idx = idx
self._data = data
else:
- self._idx = np.zeros(0, dtype=int)
+ self._idx = np.zeros(0, dtype=np.int64)
self._data = np.zeros(0, dtype=dtype)
+ def __getitem__(self, slices):
+
+ idx = slices_to_idxs(slices, self.shape, self.ndim)
+ idx = np.broadcast_arrays(*idx)
+ return self.get(idx)
+
+ def __setitem__(self, slices, vals):
+
+ idx = slices_to_idxs(slices, self.shape, self.ndim)
+ idx = np.broadcast_arrays(*idx)
+ return self.set(idx, vals)
+
@property
def size(self):
"""Return current number of elements."""
@@ -155,15 +167,3 @@ class SparseArray(object):
del shape[axis]
out = SparseArray(shape)
return out
-
- def __getitem__(self, slices):
-
- idx = slices_to_idxs(slices, self.shape, self.ndim)
- idx = np.broadcast_arrays(*idx)
- return self.get(idx)
-
- def __setitem__(self, slices, vals):
-
- idx = slices_to_idxs(slices, self.shape, self.ndim)
- idx = np.broadcast_arrays(*idx)
- return self.set(idx, vals)
