Esempio n. 1
0
 def __init__(self, data, nrows, ncols, dtype):
     self.data = data
     self._nrows = nrows if isinstance(nrows, ShapeElement) else ShapeElement(nrows)
     self._ncols = ncols if isinstance(ncols, ShapeElement) else ShapeElement(ncols)
     self.dtype = dtype
     self.device_id = 0
     self.last_modif_context = None
     self.last_usage_context = None
Esempio n. 2
0
 def test_index(self):
     r = []
     for _ in xrange(self.N):
         a = 1 + self.rng.randint(self.max_int)
         a_se = ShapeElement(a)
         l = [42] * 2 * a
         r.append(l[a_se] == l[a])
         with self.assertRaises(ValueError):
             a_se = ShapeElement(float(a))
             r.append(l[a_se] == l[a])
     self.assertTrue(all(r))
Esempio n. 3
0
    def test_ge(self):
        r = []
        for _ in xrange(self.N):
            a = self.rng.randint(self.max_int)
            a_se = ShapeElement(a)
            b = self.rng.randint(self.max_int)
            b_se = ShapeElement(b)

            r.append((a >= a_se) == (a >= a))
            r.append((a_se >= a) == (a >= a))
            r.append((a_se >= a_se) == (a >= a))
            r.append((a_se >= b) == (a >= b))
            r.append((a_se >= b_se) == (a >= b))
            r.append((a >= b_se) == (a >= b))
        self.assertTrue(all(r))
Esempio n. 4
0
 def test_float(self):
     r = []
     for _ in xrange(self.N):
         a = self.rng.randint(self.max_int)
         a_se = ShapeElement(a)
         r.append(float(a_se) == float(a))
     self.assertTrue(all(r))
Esempio n. 5
0
    def test_div(self):
        r = []
        for _ in xrange(self.N):
            a = 1 + self.rng.randint(self.max_int)
            a_se = ShapeElement(a)
            b = 1 + self.rng.randint(self.max_int)
            b_se = ShapeElement(b)
            delta = 1 + self.rng.randint(self.max_int)

            c_se = a_se / b
            r.append(c_se.value == a / b)
            a_se[:] = a * delta
            r.append(c_se.value == a * delta / b)
            a_se[:] = a
            c_se = a_se / b_se
            r.append(c_se.value == a / b)
            a_se[:] = a + delta
            b_se[:] = b + delta
            r.append(c_se.value == (a + delta) / (b + delta))
        self.assertTrue(all(r))
Esempio n. 6
0
    def test_mul(self):
        r = []
        for _ in xrange(self.N):
            a = self.rng.randint(self.max_int)
            a_se = ShapeElement(a)
            b = self.rng.randint(self.max_int)
            b_se = ShapeElement(b)
            delta = self.rng.randint(self.max_int)

            c_se = a_se * b
            r.append(c_se.value == a * b)
            a_se[:] = a * delta
            r.append(c_se.value == a * b * delta)
            a_se[:] = a
            c_se = a_se * b_se
            r.append(c_se.value == a * b)
            a_se[:] = a * delta
            b_se[:] = b * delta
            r.append(c_se.value == a * b * delta * delta)
        self.assertTrue(all(r))
Esempio n. 7
0
    def test_sub(self):
        r = []
        for _ in xrange(self.N):
            a = self.rng.randint(self.max_int)
            a_se = ShapeElement(a)
            b = self.rng.randint(self.max_int)
            b_se = ShapeElement(b)
            delta = self.rng.randint(self.max_int)

            c_se = a_se - b
            r.append(c_se.value == a - b)
            a_se[:] = a + delta
            r.append(c_se.value == a - b + delta)
            a_se[:] = a
            c_se = a_se - b_se
            r.append(c_se.value == a - b)
            a_se[:] = a + delta
            b_se[:] = b - delta
            r.append(c_se.value == a - b + 2 * delta)
        self.assertTrue(all(r))
Esempio n. 8
0
    def test_rsub(self):
        r = []
        for _ in xrange(self.N):
            a = self.rng.randint(self.max_int)
            a_se = ShapeElement(a)
            b = self.rng.randint(self.max_int)
            delta = self.rng.randint(self.max_int)

            c_se = b - a_se
            r.append(c_se.value == b - a)
            a_se[:] = a + delta
            r.append(c_se.value == b - a - delta)
        self.assertTrue(all(r))
Esempio n. 9
0
    def test_rdiv(self):
        r = []
        for _ in xrange(self.N):
            a = 1 + self.rng.randint(self.max_int)
            a_se = ShapeElement(a)
            b = self.rng.randint(self.max_int)
            delta = 1 + self.rng.randint(self.max_int)

            c_se = b / a_se
            r.append(c_se.value == b / a)
            try:
                a_se[:] = a - delta + (a - delta == 0)
                r.append(c_se.value == b / (a - delta + (a - delta == 0)))
            except:
                pass
        self.assertTrue(all(r))
Esempio n. 10
0
 def __init__(self, elements, length=None):
     self.elements = elements
     length = length if length is not None else len(elements)
     self._length = length if isinstance(
         length, ShapeElement) else ShapeElement(length)