Exemple #1
0
 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.strides == [-30, 3, 1]
     assert s.backstrides == [-120, 12, 2]
Exemple #2
0
 def test_negative_step_f(self):
     space = self.space
     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.strides == [-2, 10, 50]
     assert s.backstrides == [-8, 40, 100]
Exemple #3
0
 def test_index_of_single_item_c(self):
     a = NDimArray(10 * 5 * 3, [10, 5, 3], MockDtype(), 'C')
     r = a._index_of_single_item(self.space, self.newtuple(1, 2, 2))
     assert r == 1 * 3 * 5 + 2 * 3 + 2
     s = a.create_slice(self.space, [(0, 10, 1, 10), (2, 0, 0, 1)])
     r = s._index_of_single_item(self.space, self.newtuple(1, 0))
     assert r == a._index_of_single_item(self.space, self.newtuple(1, 2, 0))
     r = s._index_of_single_item(self.space, self.newtuple(1, 1))
     assert r == a._index_of_single_item(self.space, self.newtuple(1, 2, 1))
Exemple #4
0
    def test_slice_signature(self, space):
        ar = NDimArray(10, [10], dtype=space.fromcache(interp_dtype.W_Float64Dtype))
        v1 = ar.descr_getitem(space, space.wrap(slice(1, 3, 1)))
        v2 = ar.descr_getitem(space, space.wrap(slice(4, 6, 1)))
        assert v1.signature is v2.signature

        v3 = v2.descr_add(space, v1)
        v4 = v1.descr_add(space, v2)
        assert v3.signature is v4.signature
Exemple #5
0
 def f(n):
     if NonConstant(False):
         dtype = float64_dtype
     else:
         dtype = int32_dtype
     ar = NDimArray(n, [n], dtype=dtype)
     i = 0
     while i < n:
         ar.get_concrete().setitem(i, int32_dtype.box(7))
         i += 1
     v = ar.descr_add(space, ar).descr_sum(space)
     assert isinstance(v, IntObject)
     return v.intval
Exemple #6
0
 def test_slice_of_slice_c(self):
     space = self.space
     a = NDimArray(10 * 5 * 3, [10, 5, 3], MockDtype(), order='C')
     s = a.create_slice(space, [(5, 0, 0, 1)])
     assert s.start == 15 * 5
     s2 = s.create_slice(space, [(3, 0, 0, 1)])
     assert s2.shape == [3]
     assert s2.strides == [1]
     assert s2.parent is a
     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.strides == [45, 1]
     assert s2.backstrides == [45, 2]
     assert s2.start == 1 * 15 + 2 * 3
Exemple #7
0
 def test_slice_of_slice_f(self):
     space = self.space
     a = NDimArray(10 * 5 * 3, [10, 5, 3], MockDtype(), 'F')
     s = a.create_slice(space, [(5, 0, 0, 1)])
     assert s.start == 5
     s2 = s.create_slice(space, [(3, 0, 0, 1)])
     assert s2.shape == [3]
     assert s2.strides == [50]
     assert s2.parent is a
     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.strides == [3, 50]
     assert s2.backstrides == [3, 100]
     assert s2.start == 1 * 15 + 2 * 3
Exemple #8
0
 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.strides == [10, 50]
     assert s.backstrides == [40, 100]
     s = a.create_slice(space, [(1, 9, 2, 4)])
     assert s.start == 1
     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.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]
Exemple #9
0
 def test_create_slice_c(self):
     space = self.space
     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.strides == [3, 1]
     assert s.backstrides == [12, 2]
     s = a.create_slice(space, [(1, 9, 2, 4)])
     assert s.start == 15
     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.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]
Exemple #10
0
    def test_binop_signature(self, space):
        float64_dtype = space.fromcache(interp_dtype.W_Float64Dtype)

        ar = NDimArray(10, [10], dtype=float64_dtype)
        v1 = ar.descr_add(space, ar)
        v2 = ar.descr_add(space, Scalar(float64_dtype, 2.0))
        assert v1.signature is not v2.signature
        v3 = ar.descr_add(space, Scalar(float64_dtype, 1.0))
        assert v2.signature is v3.signature
        v4 = ar.descr_add(space, ar)
        assert v1.signature is v4.signature

        bool_ar = NDimArray(10, [10], dtype=space.fromcache(interp_dtype.W_BoolDtype))
        v5 = ar.descr_add(space, bool_ar)
        assert v5.signature is not v1.signature
        assert v5.signature is not v2.signature
        v6 = ar.descr_add(space, bool_ar)
        assert v5.signature is v6.signature