Commits

Maciej Fijalkowski committed 0c2425c

rename shards to strides

Comments (0)

Files changed (2)

pypy/module/micronumpy/interp_numarray.py

         for i in range(shape_len - 1, -1, -1):
             if self.indices[i] < self.arr.shape[i] - 1:
                 self.indices[i] += 1
-                self.offset += self.arr.shards[i]
+                self.offset += self.arr.strides[i]
                 break
             else:
                 self.indices[i] = 0
-                self.offset -= self.arr.backshards[i]
+                self.offset -= self.arr.backstrides[i]
         else:
             self._done = True
 
     def __init__(self, arr, res_shape):
         self.indices = [0] * len(res_shape)
         self.offset  = arr.start
-        #shards are 0 where original shape==1
-        self.shards = []
-        self.backshards = []
+        #strides are 0 where original shape==1
+        self.strides = []
+        self.backstrides = []
         for i in range(len(arr.shape)):
             if arr.shape[i]==1:
-                self.shards.append(0)
-                self.backshards.append(0)
+                self.strides.append(0)
+                self.backstrides.append(0)
             else:
-                self.shards.append(arr.shards[i])
-                self.backshards.append(arr.backshards[i])
+                self.strides.append(arr.strides[i])
+                self.backstrides.append(arr.backstrides[i])
         self.shape_len = len(res_shape)
         self.res_shape = res_shape
-        self.shards = [0] * (len(res_shape) - len(arr.shape)) + self.shards
-        self.backshards = [0] * (len(res_shape) - len(arr.shape)) + self.backshards
+        self.strides = [0] * (len(res_shape) - len(arr.shape)) + self.strides
+        self.backstrides = [0] * (len(res_shape) - len(arr.shape)) + self.backstrides
         self._done = False
         self.arr = arr
 
         for i in range(shape_len - 1, -1, -1):
             if self.indices[i] < self.res_shape[i] - 1:
                 self.indices[i] += 1
-                self.offset += self.shards[i]
+                self.offset += self.strides[i]
                 break
             else:
                 self.indices[i] = 0
-                self.offset -= self.backshards[i]
+                self.offset -= self.backstrides[i]
         else:
             self._done = True
 
         return 0
 
 class BaseArray(Wrappable):
-    _attrs_ = ["invalidates", "signature", "shape", "shards", "backshards",
+    _attrs_ = ["invalidates", "signature", "shape", "strides", "backstrides",
                "start", 'order']
 
-    _immutable_fields_ = ['shape[*]', "shards[*]", "backshards[*]", 'start',
+    _immutable_fields_ = ['shape[*]', "strides[*]", "backstrides[*]", 'start',
                           "order"]
 
-    shards = None
+    strides = None
     start = 0
 
     def __init__(self, shape, order):
         self.invalidates = []
         self.shape = shape
         self.order = order
-        if self.shards is None:
-            shards = []
-            backshards = []
+        if self.strides is None:
+            strides = []
+            backstrides = []
             s = 1
             shape_rev = shape[:]
             if order == 'C':
                 shape_rev.reverse()
             for sh in shape_rev:
-                shards.append(s)
-                backshards.append(s * (sh - 1))
+                strides.append(s)
+                backstrides.append(s * (sh - 1))
                 s *= sh
             if order == 'C':
-                shards.reverse()
-                backshards.reverse()
-            self.shards = shards[:]
-            self.backshards = backshards[:]
+                strides.reverse()
+                backstrides.reverse()
+            self.strides = strides[:]
+            self.backstrides = backstrides[:]
 
     def invalidated(self):
         if self.invalidates:
                     else:
                         builder.append(spacer)
                     builder.append(dtype.str_format(self.getitem(item)))
-                    item += self.shards[0]
+                    item += self.strides[0]
                 #Add a comma only if comma is False - this prevents adding two commas
                 builder.append(spacer + '...' + ',' * (1 - comma))
                 #Ugly, but can this be done with an iterator?
-                item = self.start + self.backshards[0] - 2 * self.shards[0]
+                item = self.start + self.backstrides[0] - 2 * self.strides[0]
                 i = self.shape[0] - 3
             while i < self.shape[0]:
                 if start:
                 else:
                     builder.append(spacer)
                 builder.append(dtype.str_format(self.getitem(item)))
-                item += self.shards[0]
+                item += self.strides[0]
                 i += 1
         else:
             builder.append('[')
             if idx < 0 or idx >= self.shape[0]:
                 raise OperationError(space.w_IndexError,
                                      space.wrap("index out of range"))
-            return self.start + idx * self.shards[0]
+            return self.start + idx * self.strides[0]
         index = [space.int_w(w_item)
                  for w_item in space.fixedview(w_idx)]
         item = self.start
             if v < 0 or v >= self.shape[i]:
                 raise OperationError(space.w_IndexError,
                                      space.wrap("index (%d) out of range (0<=index<%d" % (i, self.shape[i])))
-            item += v * self.shards[i]
+            item += v * self.strides[i]
         return item
 
     def get_root_shape(self):
             start, stop, step, lgt = chunks[0]
             if step == 0:
                 shape = self.shape[1:]
-                shards = self.shards[1:]
-                backshards = self.backshards[1:]
+                strides = self.strides[1:]
+                backstrides = self.backstrides[1:]
             else:
                 shape = [lgt] + self.shape[1:]
-                shards = [self.shards[0] * step] + self.shards[1:]
-                backshards = [(lgt - 1) * self.shards[0] * step] + self.backshards[1:]
-            start *= self.shards[0]
+                strides = [self.strides[0] * step] + self.strides[1:]
+                backstrides = [(lgt - 1) * self.strides[0] * step] + self.backstrides[1:]
+            start *= self.strides[0]
             start += self.start
         else:
             shape = []
-            shards = []
-            backshards = []
+            strides = []
+            backstrides = []
             start = self.start
             i = -1
             for i, (start_, stop, step, lgt) in enumerate(chunks):
                 if step != 0:
                     shape.append(lgt)
-                    shards.append(self.shards[i] * step)
-                    backshards.append(self.shards[i] * (lgt - 1) * step)
-                start += self.shards[i] * start_
+                    strides.append(self.strides[i] * step)
+                    backstrides.append(self.strides[i] * (lgt - 1) * step)
+                start += self.strides[i] * start_
             # add a reminder
             s = i + 1
             assert s >= 0
             shape += self.shape[s:]
-            shards += self.shards[s:]
-            backshards += self.backshards[s:]
-        return NDimSlice(self, new_sig, start, shards[:], backshards[:],
+            strides += self.strides[s:]
+            backstrides += self.backstrides[s:]
+        return NDimSlice(self, new_sig, start, strides[:], backstrides[:],
                          shape[:])
 
     def descr_mean(self, space):
     def compute_index(self, space, offset):
         offset -= self.start
         if len(self.shape) == 1:
-            return space.wrap(offset // self.shards[0])
+            return space.wrap(offset // self.strides[0])
         indices_w = []
-        for shard in self.shards:
+        for shard in self.strides:
             r = offset // shard
             indices_w.append(space.wrap(r))
             offset -= shard * r
     Class for representing views of arrays, they will reflect changes of parent
     arrays. Example: slices
     """
-    def __init__(self, parent, signature, shards, backshards, shape):
-        self.shards = shards
-        self.backshards = backshards
+    def __init__(self, parent, signature, strides, backstrides, shape):
+        self.strides = strides
+        self.backstrides = backstrides
         BaseArray.__init__(self, shape, parent.order)
         self.signature = signature
         self.parent = parent
 class NDimSlice(ViewArray):
     signature = signature.BaseSignature()
 
-    def __init__(self, parent, signature, start, shards, backshards,
+    def __init__(self, parent, signature, start, strides, backstrides,
                  shape):
         if isinstance(parent, NDimSlice):
             parent = parent.parent
-        ViewArray.__init__(self, parent, signature, shards, backshards, shape)
+        ViewArray.__init__(self, parent, signature, strides, backstrides, shape)
         self.start = start
         self.size = 1
         for sh in shape:

pypy/module/micronumpy/test/test_numarray.py

                 args_w.append(arg)
         return self.space.newtuple(args_w)
 
-    def test_shards_f(self):
+    def test_strides_f(self):
         a = NDimArray(100, [10, 5, 3], MockDtype(), 'F')
-        assert a.shards == [1, 10, 50]
-        assert a.backshards == [9, 40, 100]
+        assert a.strides == [1, 10, 50]
+        assert a.backstrides == [9, 40, 100]
 
-    def test_shards_c(self):
+    def test_strides_c(self):
         a = NDimArray(100, [10, 5, 3], MockDtype(), 'C')
-        assert a.shards == [15, 3, 1]
-        assert a.backshards == [135, 12, 2]
+        assert a.strides == [15, 3, 1]
+        assert a.backstrides == [135, 12, 2]
 
     def test_create_slice_f(self):
         space = self.space
         a = NDimArray(10 * 5 * 3, [10, 5, 3], MockDtype(), 'F')
         s = a.create_slice(space, [(3, 0, 0, 1)])
         assert s.start == 3
-        assert s.shards == [10, 50]
-        assert s.backshards == [40, 100]
+        assert s.strides == [10, 50]
+        assert s.backstrides == [40, 100]
         s = a.create_slice(space, [(1, 9, 2, 4)])
         assert s.start == 1
-        assert s.shards == [2, 10, 50]
-        assert s.backshards == [6, 40, 100]
+        assert s.strides == [2, 10, 50]
+        assert s.backstrides == [6, 40, 100]
         s = a.create_slice(space, [(1, 5, 3, 2), (1, 2, 1, 1), (1, 0, 0, 1)])
         assert s.shape == [2, 1]
-        assert s.shards == [3, 10]
-        assert s.backshards == [3, 0]
+        assert s.strides == [3, 10]
+        assert s.backstrides == [3, 0]
         s = a.create_slice(space, [(0, 10, 1, 10), (2, 0, 0, 1)])
         assert s.start == 20
         assert s.shape == [10, 3]
         a = NDimArray(10 * 5 * 3, [10, 5, 3], MockDtype(), 'C')
         s = a.create_slice(space, [(3, 0, 0, 1)])
         assert s.start == 45
-        assert s.shards == [3, 1]
-        assert s.backshards == [12, 2]
+        assert s.strides == [3, 1]
+        assert s.backstrides == [12, 2]
         s = a.create_slice(space, [(1, 9, 2, 4)])
         assert s.start == 15
-        assert s.shards == [30, 3, 1]
-        assert s.backshards == [90, 12, 2]
+        assert s.strides == [30, 3, 1]
+        assert s.backstrides == [90, 12, 2]
         s = a.create_slice(space, [(1, 5, 3, 2), (1, 2, 1, 1), (1, 0, 0, 1)])
         assert s.start == 19
         assert s.shape == [2, 1]
-        assert s.shards == [45, 3]
-        assert s.backshards == [45, 0]
+        assert s.strides == [45, 3]
+        assert s.backstrides == [45, 0]
         s = a.create_slice(space, [(0, 10, 1, 10), (2, 0, 0, 1)])
         assert s.start == 6
         assert s.shape == [10, 3]
         assert s.start == 5
         s2 = s.create_slice(space, [(3, 0, 0, 1)])
         assert s2.shape == [3]
-        assert s2.shards == [50]
+        assert s2.strides == [50]
         assert s2.parent is a
-        assert s2.backshards == [100]
+        assert s2.backstrides == [100]
         assert s2.start == 35
         s = a.create_slice(space, [(1, 5, 3, 2)])
         s2 = s.create_slice(space, [(0, 2, 1, 2), (2, 0, 0, 1)])
         assert s2.shape == [2, 3]
-        assert s2.shards == [3, 50]
-        assert s2.backshards == [3, 100]
+        assert s2.strides == [3, 50]
+        assert s2.backstrides == [3, 100]
         assert s2.start == 1 * 15 + 2 * 3
 
     def test_slice_of_slice_c(self):
         assert s.start == 15 * 5
         s2 = s.create_slice(space, [(3, 0, 0, 1)])
         assert s2.shape == [3]
-        assert s2.shards == [1]
+        assert s2.strides == [1]
         assert s2.parent is a
-        assert s2.backshards == [2]
+        assert s2.backstrides == [2]
         assert s2.start == 5 * 15 + 3 * 3
         s = a.create_slice(space, [(1, 5, 3, 2)])
         s2 = s.create_slice(space, [(0, 2, 1, 2), (2, 0, 0, 1)])
         assert s2.shape == [2, 3]
-        assert s2.shards == [45, 1]
-        assert s2.backshards == [45, 2]
+        assert s2.strides == [45, 1]
+        assert s2.backstrides == [45, 2]
         assert s2.start == 1 * 15 + 2 * 3
 
     def test_negative_step_f(self):
         a = NDimArray(10 * 5 * 3, [10, 5, 3], MockDtype(), 'F')
         s = a.create_slice(space, [(9, -1, -2, 5)])
         assert s.start == 9
-        assert s.shards == [-2, 10, 50]
-        assert s.backshards == [-8, 40, 100]
+        assert s.strides == [-2, 10, 50]
+        assert s.backstrides == [-8, 40, 100]
 
     def test_negative_step_c(self):
         space = self.space
         a = NDimArray(10 * 5 * 3, [10, 5, 3], MockDtype(), order='C')
         s = a.create_slice(space, [(9, -1, -2, 5)])
         assert s.start == 135
-        assert s.shards == [-30, 3, 1]
-        assert s.backshards == [-120, 12, 2]
+        assert s.strides == [-30, 3, 1]
+        assert s.backstrides == [-120, 12, 2]
 
     def test_index_of_single_item_f(self):
         a = NDimArray(10 * 5 * 3, [10, 5, 3], MockDtype(), 'F')