Exemple #1
0
    def _Op(self, term):
        spine = term.spine
        args = term.args

        # visit the innermost arguments, push those arguments on
        # the instruction list first
        self.visit(term.args)

        fn, cost = lookup(term)
        fargs = [self._vartable[a] for a in args]

        # push the temporary for the result in the vartable
        key = self.var(term)

        # build the instruction & push it on the stack
        inst = Instruction(str(fn.fn), fargs, lhs=key)
        self._instructions.append(inst)
Exemple #2
0
    def _Arithmetic(self, term):
        # All the function signatures are of the form
        #
        #     Add(a,b)
        #
        # But the aterm expression for LLVM is expected to be
        #
        #     Arithmetic(Add, ...)
        #
        # so we do this ugly hack to get the signature back to
        # standard form

        # -- hack --
        op   = term.args[0]
        args = term.args[1:]
        normal_term = AAppl(ATerm(op), args)
        # --

        assert isinstance(op, ATerm)
        label = op.label

        # Find us implementation for execution
        # Returns either a ExternalF ( reference to a external C
        # library ) or a PythonF, a Python callable. These can be
        # anything, numpy ufuncs, numexpr, pandas, cmath whatever
        from blaze.rts.funcs import lookup

        # visit the innermost arguments, push those arguments on
        # the instruction list first
        self.visit(args)

        fn, cost = lookup(normal_term)
        fargs = [self._vartable[a] for a in args]

        # push the temporary for the result in the vartable
        key = self.var(term)

        # build the instruction & push it on the stack
        inst = Instruction(str(fn.fn), get_datashape(term), fargs, lhs=key)
        self._instructions.append(inst)
Exemple #3
0
    def _Arithmetic(self, term):
        # All the function signatures are of the form
        #
        #     Add(a,b)
        #
        # But the aterm expression for LLVM is expected to be
        #
        #     Arithmetic(Add, ...)
        #
        # so we do this ugly hack to get the signature back to
        # standard form

        # -- hack --
        op = term.args[0]
        args = term.args[1:]
        normal_term = AAppl(ATerm(op), args)
        # --

        assert isinstance(op, ATerm)
        label = op.label

        # Find us implementation for execution
        # Returns either a ExternalF ( reference to a external C
        # library ) or a PythonF, a Python callable. These can be
        # anything, numpy ufuncs, numexpr, pandas, cmath whatever
        from blaze.rts.funcs import lookup

        # visit the innermost arguments, push those arguments on
        # the instruction list first
        self.visit(args)

        fn, cost = lookup(normal_term)
        fargs = [self._vartable[a] for a in args]

        # push the temporary for the result in the vartable
        key = self.var(term)

        # build the instruction & push it on the stack
        inst = Instruction(str(fn.fn), get_datashape(term), fargs, lhs=key)
        self._instructions.append(inst)
Exemple #4
0
def test_match1():
    expr = AAppl(ATerm('Add'), [AInt(1), AInt(2)])
    fn, cost = lookup(expr)

    assert fn.fn == add.fn.im_func
Exemple #5
0
def test_match2():
    expr = AAppl(ATerm('Mul'), [ATerm('Array'), ATerm('Array')])
    fn, cost = lookup(expr)

    assert fn.fn == multiply.fn.im_func
Exemple #6
0
def test_match1():
    expr = parse('Add(1,2)')
    fn, cost = lookup(expr)
Exemple #7
0
def test_match2():
    expr = parse('Mul(1,2)')
    fn, cost = lookup(expr)
Exemple #8
0
def test_match2():
    expr = AAppl(ATerm('Mul'), [ATerm('Array'), ATerm('Array')])
    fn, cost = lookup(expr)

    assert fn.fn == multiply.fn.im_func
Exemple #9
0
def test_match1():
    expr = AAppl(ATerm('Add'), [AInt(1), AInt(2)])
    fn, cost = lookup(expr)

    assert fn.fn == add.fn.im_func