Exemplo n.º 1
0
    def test_unify_datashape_promotion2(self):
        # LHS
        s1 = 'A, B, int32'
        s2 = 'B, 10, float32'

        # RHS
        s3 = 'X, Y, int16'
        s4 = 'X, X, Z'

        # Create proper equation
        d1, d2, d3, d4 = dshapes(s1, s2, s3, s4)
        constraints = [(d1, d3), (d2, d4)]

        # What we know from the above equations is:
        #   1) A coerces to X
        #   2) B coerces to Y
        #   3) 10 coerces to X
        #
        # From this we determine that X must be Fixed(10). We must retain
        # type variable B for Y, since we can only say that B must unify with
        # Fixed(10), but not whether it is actually Fixed(10) (it may also be
        # Fixed(1))

        [arg1, arg2], remaining_constraints = unify(constraints, [True, True])
        self.assertEqual(str(arg1), '10, B, int16')
        self.assertEqual(str(arg2), '10, 10, float32')
Exemplo n.º 2
0
 def test_coerce_constrained_typevars(self):
     a, b, c = dshapes('10, 10, float32', 'X, Y, float64', 'X, X, float64')
     self.assertGreater(coerce(a, b), coerce(a, c))
Exemplo n.º 3
0
 def test_coercion_transitivity(self):
     a, b, c = dshapes('int8', 'complex128', 'float64')
     self.assertGreater(coerce(a, b), coerce(a, c))
Exemplo n.º 4
0
 def test_coerce_numeric(self):
     a, b = dshapes('float32', 'float64')
     self.assertEqual(coerce(a, b), 1)
Exemplo n.º 5
0
 def test_coerce_ctype(self):
     a, b = dshapes('float32', 'float32')
     self.assertEqual(coerce(a, b), 0)
Exemplo n.º 6
0
 def test_coerce_broadcasting(self):
     a, b, c = dshapes('10, 10, float32', '10, Y, Z, float64', 'X, Y, float64')
     self.assertGreater(coercion_cost(a, b), coercion_cost(a, c))
Exemplo n.º 7
0
 def test_coerce_numeric(self):
     a, b = dshapes("float32", "float64")
     self.assertEqual(coerce(a, b), 1)
Exemplo n.º 8
0
 def test_coerce_src_ellipsis(self):
     a, b, c = dshapes('10, ..., float32', 'X, Y, float64', 'X, ..., float64')
     self.assertGreater(coerce(a, b), coerce(a, c))
Exemplo n.º 9
0
 def test_coerce_ctype(self):
     a, b, c = dshapes('float32', 'float32', 'float64')
     self.assertLess(coercion_cost(a, b), coercion_cost(a, c))
Exemplo n.º 10
0
 def test_coerce_src_ellipsis(self):
     a, b, c = dshapes("10, ..., float32", "X, Y, float64", "X, ..., float64")
     self.assertGreater(coerce(a, b), coerce(a, c))
Exemplo n.º 11
0
 def test_coerce_broadcasting2(self):
     a, b, c = dshapes("10, 10, float32", "1, 10, 10, float32", "10, 10, float32")
     self.assertGreater(coerce(a, b), coerce(a, c))
Exemplo n.º 12
0
 def test_coerce_typevars(self):
     a, b, c = dshapes("10, 11, float32", "X, Y, float64", "10, Y, float64")
     self.assertGreater(coerce(a, b), coerce(a, c))
Exemplo n.º 13
0
 def test_coercion_transitivity(self):
     a, b, c = dshapes("int8", "complex128", "float64")
     self.assertGreater(coerce(a, b), coerce(a, c))
Exemplo n.º 14
0
 def test_coerce_broadcasting3(self):
     a, b, c = dshapes('10, 10, float32', '10, 10, 10, float32', '1, 10, 10, float32')
     self.assertGreater(coerce(a, b), coerce(a, c))
Exemplo n.º 15
0
 def test_coerce_numeric(self):
     a, b = dshapes('float32', 'float64')
     self.assertGreater(coercion_cost(a, b), 0)
Exemplo n.º 16
0
 def test_coerce_traits(self):
     a, b, c = dshapes('10, 10, float32', '10, X, A : floating', '10, X, float32')
     self.assertGreater(coerce(a, b), coerce(a, c))
Exemplo n.º 17
0
 def test_coerce_typevars(self):
     a, b, c = dshapes('10, 11, float32', 'X, Y, float64', '10, Y, float64')
     self.assertGreater(coercion_cost(a, b), coercion_cost(a, c))
Exemplo n.º 18
0
 def test_downcast(self):
     a, b = dshapes('float32', 'int32')
     self.assertRaises(error.CoercionError, coerce, a, b)
Exemplo n.º 19
0
 def test_coerce_ctype(self):
     a, b = dshapes("float32", "float32")
     self.assertEqual(coerce(a, b), 0)