示例#1
0
    def test_bug_complext_10_august_09(self):
        v0 = dmatrix()
        v1 = _convert_to_complex128(v0)

        f = function([v0], v1)
        i = np.zeros((2, 2))
        assert np.array_equal(f(i), i)
示例#2
0
    def test_bug_complext_10_august_09(self):
        v0 = dmatrix()
        v1 = basic._convert_to_complex128(v0)

        inputs = [v0]
        outputs = [v1]
        f = function(inputs, outputs)
        i = np.zeros((2, 2))
        assert (f(i) == np.zeros((2, 2))).all()
示例#3
0
    def test_convert_to_complex(self):
        val64 = np.ones(3, dtype="complex64") + 0.5j
        val128 = np.ones(3, dtype="complex128") + 0.5j

        vec64 = TensorType("complex64", (False, ))()
        vec128 = TensorType("complex128", (False, ))()

        f = function([vec64], basic._convert_to_complex128(vec64))
        # we need to compare with the same type.
        assert vec64.type.values_eq_approx(val128, f(val64))

        f = function([vec128], basic._convert_to_complex128(vec128))
        assert vec64.type.values_eq_approx(val128, f(val128))

        f = function([vec64], basic._convert_to_complex64(vec64))
        assert vec64.type.values_eq_approx(val64, f(val64))

        f = function([vec128], basic._convert_to_complex64(vec128))
        assert vec128.type.values_eq_approx(val64, f(val128))

        # upcasting to complex128
        for t in ["int8", "int16", "int32", "int64", "float32", "float64"]:
            a = aesara.shared(np.ones(3, dtype=t))
            b = aesara.shared(np.ones(3, dtype="complex128"))
            f = function([], basic._convert_to_complex128(a))
            assert a.type.values_eq_approx(b.get_value(), f())

        # upcasting to complex64
        for t in ["int8", "int16", "int32", "int64", "float32"]:
            a = aesara.shared(np.ones(3, dtype=t))
            b = aesara.shared(np.ones(3, dtype="complex64"))
            f = function([], basic._convert_to_complex64(a))
            assert a.type.values_eq_approx(b.get_value(), f())

        # downcast to complex64
        for t in ["float64"]:
            a = aesara.shared(np.ones(3, dtype=t))
            b = aesara.shared(np.ones(3, dtype="complex64"))
            f = function([], basic._convert_to_complex64(a))
            assert a.type.values_eq_approx(b.get_value(), f())