Beispiel #1
0
def test_broadcast_function():
    expr =  Pow(Add(x, Mult(2, y)), 2)  # (x + (2 * y)) ** 2
    b = broadcast(expr, [x, y])
    xx, yy = b._scalars
    assert b._scalar_expr.isidentical((xx + (2 * yy)) ** 2)

    # A different set of leaves
    b = broadcast(expr, [x, Mult(2, y)])
    xx, yy = b._scalars
    assert b._scalar_expr.isidentical((xx + yy) ** 2)
Beispiel #2
0
def test_broadcast_function():
    expr = Pow(Add(x, Mult(2, y)), 2)  # (x + (2 * y)) ** 2
    b = broadcast(expr, [x, y])
    xx, yy = b._scalars
    assert b._scalar_expr.isidentical((xx + (2 * yy))**2)

    # A different set of leaves
    b = broadcast(expr, [x, Mult(2, y)])
    xx, yy = b._scalars
    assert b._scalar_expr.isidentical((xx + yy)**2)
Beispiel #3
0
def test_broadcast():
    from blaze.expr.arithmetic import Add, Eq, Mult, Le
    t = TableSymbol('t', '{x: int, y: int, z: int}')
    t2 = TableSymbol('t', '{a: int, b: int, c: int}')
    x = t['x']
    y = t['y']
    z = t['z']
    a = t2['a']
    b = t2['b']
    c = t2['c']

    assert str(broadcast(Add, x, y).expr) == 'x + y'
    assert broadcast(Add, x, y)._child.isidentical(t)

    c1 = broadcast(Add, x, y)
    c2 = broadcast(Mult, x, z)

    assert eval_str(broadcast(Eq, c1, c2).expr) == '(x + y) == (x * z)'
    assert broadcast(Eq, c1, c2)._child.isidentical(t)

    assert str(broadcast(Add, x, 1).expr) == 'x + 1'

    assert str(x <= y) == "t['x'] <= t['y']"
    assert str(x >= y) == "t['x'] >= t['y']"
    assert str(x | y) == "t['x'] | t['y']"
    assert str(x.__ror__(y)) == "t['y'] | t['x']"
    assert str(x.__rand__(y)) == "t['y'] & t['x']"

    with pytest.raises(ValueError):
        broadcast(Add, x, a)
Beispiel #4
0
def test_broadcast():
    from blaze.expr.arithmetic import Add, Eq, Mult, Le
    t = TableSymbol('t', '{x: int, y: int, z: int}')
    t2 = TableSymbol('t', '{a: int, b: int, c: int}')
    x = t['x']
    y = t['y']
    z = t['z']
    a = t2['a']
    b = t2['b']
    c = t2['c']

    assert str(broadcast(Add, x, y)._expr) == 'x + y'
    assert broadcast(Add, x, y)._child.isidentical(t)

    c1 = broadcast(Add, x, y)
    c2 = broadcast(Mult, x, z)

    assert eval_str(broadcast(Eq, c1, c2)._expr) == '(x + y) == (x * z)'
    assert broadcast(Eq, c1, c2)._child.isidentical(t)

    assert str(broadcast(Add, x, 1)._expr) == 'x + 1'

    assert str(x <= y) == "t.x <= t.y"
    assert str(x >= y) == "t.x >= t.y"
    assert str(x | y) == "t.x | t.y"
    assert str(x.__ror__(y)) == "t.y | t.x"
    assert str(x.__rand__(y)) == "t.y & t.x"

    with pytest.raises(ValueError):
        broadcast(Add, x, a)
Beispiel #5
0
def test_table_broadcast():
    t = symbol('t', 'var * {x: int, y: int, z: int}')

    expr = t.distinct()
    expr = (2 * expr.x + expr.y + 1).distinct()

    expected = t.distinct()
    expected = broadcast(2 * expected.x + expected.y + 1, [expected]).distinct()
    assert broadcast_collect(expr).isidentical(expected)

    expr = (t.x + t.y).sum()
    result = broadcast_collect(expr)
    expected = broadcast(t.x + t.y, [t]).sum()
    assert result.isidentical(expected)
Beispiel #6
0
def test_table_broadcast():
    t = Symbol('t', 'var * {x: int, y: int, z: int}')

    expr = t.distinct()
    expr = (2 * expr.x + expr.y + 1).distinct()

    expected = t.distinct()
    expected = broadcast(2 * expected.x + expected.y + 1, [t]).distinct()
    assert broadcast_collect(expr).isidentical(expected)

    expr = (t.x + t.y).sum()
    result = broadcast_collect(expr)
    expected = broadcast(t.x + t.y, [t]).sum()
    assert result.isidentical(expected)
Beispiel #7
0
def test_tabular_case():
    expr = t.x + t.y * 2

    b = broadcast(expr, [t])
    tt, = b._scalars

    assert b._scalar_expr.isidentical(tt.x + tt.y * 2)
Beispiel #8
0
def test_tabular_case():
    expr = Add(x, Mult(y, 2))

    b = broadcast(expr, [t])
    tt, = b._scalars

    assert b._scalar_expr.isidentical(tt.x + tt.y * 2)
Beispiel #9
0
def test_optimize_broadcast():
    expr = (t.distinct().x + 1).distinct()

    expected = broadcast(t.distinct().x + 1, [t.distinct()]).distinct()
    result = broadcast_collect(expr, broadcastable=(Field, Arithmetic), want_to_broadcast=(Field, Arithmetic))

    assert result.isidentical(expected)
Beispiel #10
0
def test_tabular_case():
    expr = t.x + t.y * 2

    b = broadcast(expr, [t])
    tt, = b._scalars

    assert b._scalar_expr.isidentical(tt.x + tt.y * 2)
Beispiel #11
0
def test_optimize_broadcast():
    expr = (t.distinct().x + 1).distinct()

    expected = broadcast(t.distinct().x + 1, [t.distinct()]).distinct()
    result = broadcast_collect(expr,
                               Broadcastable=(Field, Arithmetic),
                               WantToBroadcast=(Field, Arithmetic))

    assert result.isidentical(expected)
Beispiel #12
0
def test_broadcast_naming():
    t = symbol('t', 'var * {x: int, y: int, z: int}')

    for expr in [t.x, t.x + 1]:
        assert broadcast(expr, [t])._name == 'x'
Beispiel #13
0
def test_broadcast_naming():
    t = TableSymbol('t', '{x: int, y: int, z: int}')

    for expr in [t.x, t.x + 1]:
        assert broadcast(expr, [t])._name == 'x'
Beispiel #14
0
def test_broadcast_naming():
    t = symbol("t", "var * {x: int, y: int, z: int}")

    for expr in [t.x, t.x + 1]:
        assert broadcast(expr, [t])._name == "x"