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')
示例#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))
示例#3
0
 def test_coercion_transitivity(self):
     a, b, c = dshapes('int8', 'complex128', 'float64')
     self.assertGreater(coerce(a, b), coerce(a, c))
示例#4
0
 def test_coerce_numeric(self):
     a, b = dshapes('float32', 'float64')
     self.assertEqual(coerce(a, b), 1)
示例#5
0
 def test_coerce_ctype(self):
     a, b = dshapes('float32', 'float32')
     self.assertEqual(coerce(a, b), 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))
 def test_coerce_numeric(self):
     a, b = dshapes("float32", "float64")
     self.assertEqual(coerce(a, b), 1)
示例#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))
 def test_coerce_ctype(self):
     a, b, c = dshapes('float32', 'float32', 'float64')
     self.assertLess(coercion_cost(a, b), coercion_cost(a, c))
示例#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))
示例#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))
示例#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))
示例#13
0
 def test_coercion_transitivity(self):
     a, b, c = dshapes("int8", "complex128", "float64")
     self.assertGreater(coerce(a, b), coerce(a, c))
示例#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))
示例#15
0
 def test_coerce_numeric(self):
     a, b = dshapes('float32', 'float64')
     self.assertGreater(coercion_cost(a, b), 0)
示例#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))
示例#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))
示例#18
0
 def test_downcast(self):
     a, b = dshapes('float32', 'int32')
     self.assertRaises(error.CoercionError, coerce, a, b)
示例#19
0
 def test_coerce_ctype(self):
     a, b = dshapes("float32", "float32")
     self.assertEqual(coerce(a, b), 0)