Ejemplo n.º 1
0
def test_not_compat():
    with assert_raises(NotNumpyCompatible):
        to_numpy(dshape('x, int32'))

    with assert_raises(NotNumpyCompatible):
        to_numpy(dshape('{1}, int32'))

    with assert_raises(NotNumpyCompatible):
        to_numpy(dshape('Range(0, 3), int32'))
Ejemplo n.º 2
0
def test_dot_shape_exception():
    '''Dot product with wrong inner dimensions should raise exception.'''
    a = blaze.ones(blaze.dshape('20, 20, float64'))
    b = blaze.ones(blaze.dshape('30, 30, float64'))

    with assert_raises(ValueError):
        out = dot(a, b, outname=None)
Ejemplo n.º 3
0
def test_dot_not2d_exception():
    '''Dot product of arrays other than 2D should raise exception.'''
    a = blaze.ones(blaze.dshape('20, 20, 20, float64'))
    b = blaze.ones(blaze.dshape('20, 20, 20, float64'))

    with assert_raises(ValueError):
        out = dot(a, b, outname=None)
Ejemplo n.º 4
0
def test_dot_out_exception():
    '''Output array of wrong size should raise exception.'''
    a = blaze.ones(blaze.dshape('20, 20, float64'))
    b = blaze.ones(blaze.dshape('20, 30, float64'))
    out = blaze.zeros(blaze.dshape('20, 20, float64'))

    with assert_raises(ValueError):
        dot(a, b, out=out)
Ejemplo n.º 5
0
def test_reconstruct():
    var1 = var()
    var2 = var()

    product_t = con("x", (var1, var2), infix=True)
    sum_t = con("+", (var1, var2), infix=True)
    dynamic_t = con("?", [])

    # Example Env
    #------------

    env = {
        "?": dynamic_t,
        "product": Function(var1, Function(var2, product_t)),
        "sum": Function(var1, Function(var2, sum_t)),
        "true": Bool,
        "false": Bool,
        "boolfunc": Function(Bool, Bool),
    }

    # -- Example 1 --

    x = lam(['x', 'y'], product(atom('x'), atom('y')))
    inferred = infer(env, x, debug=DEBUG)
    assert pprint(inferred) == '(a -> (b -> (b x a)))'

    # -- Example 2 --

    x = app(lam(['x', 'y', 'z'], product(atom('x'), atom('z'))), [atom('1')])
    inferred = infer(env, x, debug=DEBUG)
    assert pprint(inferred) == '(a -> (b -> (b x int)))'

    # -- Example 3 --

    x = app(lam(['x', 'y', 'z'], product(atom('x'), atom('z'))),
            [atom('1'), atom('2'), atom('3')])
    inferred = infer(env, x, debug=DEBUG)
    assert pprint(inferred) == '(int x int)'

    # -- Example 4 --

    x = app(atom("product"), [atom("?"), atom("1")])
    inferred = infer(env, x, debug=DEBUG)
    assert pprint(inferred) == '(? x int)'

    # -- Example 5 --

    x = app(atom("sum"), [atom("?"), atom("1")])
    inferred = infer(env, x, debug=DEBUG)
    assert pprint(inferred) == '(? + int)'

    # -- Example 6 --

    x = app(atom("boolfunc"), [atom('1')])
    with assert_raises(TypeError):
        infer(env, x, debug=DEBUG)
Ejemplo n.º 6
0
def test_reconstruct():
    var1 = var()
    var2 = var()

    product_t = con("x", (var1, var2), infix=True)
    sum_t     = con("+", (var1, var2), infix=True)
    dynamic_t = con("?", [])

    # Example Env
    #------------

    env = {
        "?"        : dynamic_t,
        "product"  : Function(var1, Function(var2, product_t)),
        "sum"      : Function(var1, Function(var2, sum_t)),
        "true"     : Bool,
        "false"    : Bool,
        "boolfunc" : Function(Bool, Bool),
    }

    # -- Example 1 --

    x = lam(['x', 'y'], product(atom('x'), atom('y')))
    inferred = infer(env,x, debug=DEBUG)
    assert pprint(inferred) == '(a -> (b -> (b x a)))'

    # -- Example 2 --

    x = app(
        lam(['x', 'y', 'z'], product(atom('x'), atom('z'))),
        [atom('1')]
    )
    inferred = infer(env,x, debug=DEBUG)
    assert pprint(inferred) == '(a -> (b -> (b x int)))'

    # -- Example 3 --

    x = app(
        lam(['x', 'y', 'z'], product(atom('x'), atom('z'))),
        [atom('1'), atom('2'), atom('3')]
    )
    inferred = infer(env,x, debug=DEBUG)
    assert pprint(inferred) == '(int x int)'

    # -- Example 4 --

    x = app(atom("product"), [atom("?"), atom("1")])
    inferred = infer(env, x, debug=DEBUG)
    assert pprint(inferred) == '(? x int)'

    # -- Example 5 --

    x = app(atom("sum"), [atom("?"), atom("1")])
    inferred = infer(env, x, debug=DEBUG)
    assert pprint(inferred) == '(? + int)'

    # -- Example 6 --

    x = app(atom("boolfunc"), [atom('1')])
    with assert_raises(TypeError):
        infer(env, x, debug=DEBUG)
Ejemplo n.º 7
0
 def test_not_compat(self):
     with assert_raises(NotNumpyCompatible):
         to_numpy(dshape('Range(0, 3), int32'))