Пример #1
0
def test_binary_ops():
    a = IntNode(1)
    b = IntNode(2)

    x = a + b

    if DEBUG:
        dump(x, filename='binary')
Пример #2
0
def test_scalars():
    a = IntNode(1)
    b = IntNode(1)
    c = IntNode(2)

    x = abs((a + b + c + 3) * 4)

    if DEBUG:
        dump(x, filename='scalars')
Пример #3
0
def test_unary_ops():
    a = IntNode(1)

    x = abs(a)

    if DEBUG:
        dump(x, filename='unary')
Пример #4
0
def test_binary_mixed():
    a = IntNode(1)

    x = a + 2

    if DEBUG:
        dump(x, filename='binarymixed')
Пример #5
0
def test_preserve_types():
    a = IntNode(1)
    b = FloatNode(1.0)

    x = a + b
    assert isinstance(x, App)
    assert x.dom == [float64, float64]
    assert x.cod == float64
Пример #6
0
def test_promote():
    from blaze.expr.graph import IntNode, FloatNode

    # ----------------------------------
    x, y = IntNode(1), FloatNode(1.)
    res = promote(x, y)

    ## TODO: check if this is platform specific
    assert res == blaze.float64
    ## ----------------------------------
    x, y = IntNode(1), IntNode(1)
    res = promote(x, y)

    assert res == blaze.int32
    # ----------------------------------
    x = NDArray([1, 2, 3], dshape('3, int32'))
    y = NDArray([1, 2, 3], dshape('3, int32'))
    res = promote(x, y)
    assert res == blaze.int32
Пример #7
0
def test_op_dtype2():
    a = IntNode(1)
    b = FloatNode(1.)

    x = (a + b)
    x.simple_type() == dshape('float')
Пример #8
0
def test_op_dtype():
    a = IntNode(1)
    b = IntNode(1)

    x = (a + b)
    x.simple_type() == dshape('int')
Пример #9
0
 def FloatNode(self, node):
     return IntNode(3)
Пример #10
0
from blaze.expr.graph import IntNode, FloatNode
from blaze import visitor

#------------------------------------------------------------------------
# Sample Graph
#------------------------------------------------------------------------

a = IntNode(1)
b = IntNode(2)
c = FloatNode(3.0)

x = a + (b + c)
y = a + b + c

#------------------------------------------------------------------------
# Visitors
#------------------------------------------------------------------------


class Visitor(visitor.BasicGraphVisitor):
    def App(self, tree):
        return self.visit(tree.children)

    def IntNode(self, tree):
        return int

    def FloatNode(self, tree):
        return float

    def Add(self, tree):
        return self.visit(tree.children)