Example #1
0
def test_unify_Type():
    t1 = TensorType(np.float64, (True, False))
    t2 = TensorType(np.float64, (True, False))

    # `Type`, `Type`
    s = unify(t1, t2)
    assert s == {}

    # `Type`, `ExpressionTuple`
    s = unify(t1, etuple(TensorType, "float64", (1, None)))
    assert s == {}

    from aesara.scalar.basic import Scalar

    st1 = Scalar(np.float64)
    st2 = Scalar(np.float64)

    s = unify(st1, st2)
    assert s == {}
Example #2
0
    def test_true_div(self):
        # true_div's upcast policy is not exactly "upgrade_to_float",
        # so the test is a little bit different
        x_range = list(range(-127, 128))
        y_range = list(range(-127, 0)) + list(range(1, 127))

        xi = int8("xi")
        yi = int8("yi")
        xf = Scalar(aesara.config.floatX)("xf")
        yf = Scalar(aesara.config.floatX)("yf")

        ei = true_div(xi, yi)
        fi = aesara.function([xi, yi], ei)

        ef = true_div(xf, yf)
        ff = aesara.function([xf, yf], ef)

        for x_val in x_range:
            for y_val in y_range:
                outi = fi(x_val, y_val)
                outf = ff(x_val, y_val)

                assert outi.dtype == outf.dtype, "incorrect dtype"
                assert np.allclose(outi, outf), "insufficient precision"
Example #3
0
def test_MatrixSlice():
    from aesara.graph.basic import Constant

    cache = {}

    n = sy.Symbol('n', integer=True)
    X = sy.MatrixSymbol('X', n, n)

    Y = X[1:2:3, 4:5:6]
    Yt = aesara_code_(Y, cache=cache)

    s = Scalar('int64')
    assert tuple(Yt.owner.op.idx_list) == (slice(s, s, s), slice(s, s, s))
    assert Yt.owner.inputs[0] == aesara_code_(X, cache=cache)
    # == doesn't work in Aesara like it does in SymPy. You have to use
    # equals.
    assert all(Yt.owner.inputs[i].equals(Constant(s, i)) for i in range(1, 7))

    k = sy.Symbol('k')
    aesara_code_(k, dtypes={k: 'int32'})
    start, stop, step = 4, k, 2
    Y = X[start:stop:step]
    Yt = aesara_code_(Y, dtypes={n: 'int32', k: 'int32'})
Example #4
0
def test_filter_float_subclass():
    """Make sure `Scalar.filter` can handle `float` subclasses."""
    with config.change_flags(floatX="float64"):
        test_type = Scalar("float64")

        nan = np.array([np.nan], dtype="float64")[0]
        assert isinstance(nan, float)

        filtered_nan = test_type.filter(nan)
        assert isinstance(filtered_nan, float)

    with config.change_flags(floatX="float32"):
        # Try again, except this time `nan` isn't a `float`
        test_type = Scalar("float32")

        nan = np.array([np.nan], dtype="float32")[0]
        assert isinstance(nan, np.floating)

        filtered_nan = test_type.filter(nan)
        assert isinstance(filtered_nan, np.floating)
Example #5
0
def test_clone():
    st = Scalar("int64")
    assert st == st.clone()
    assert st.clone("float64").dtype == "float64"
Example #6
0
def test_numpy_dtype():
    test_type = Scalar(np.int32)
    assert test_type.dtype == "int32"