Example #1
0
    def __init__(self, func, tree, kwargs):
        self.defined = set()
        self.numpy_aliases = {'numpy'}
        self.wrapped_function = func
        self.fglobals = kwargs['fglobals']
        for key, val in self.fglobals.items():
            if type(val).__name__ == 'module' and val.__name__ == 'numpy':
                self.numpy_aliases.add(key)
        self.file_name = self.fglobals['__file__']

        # Add arguments of the function to the list of discovered variables.
        if inspect.isfunction(tree.body[0]):
            for arg in tree.body[0].args.args:
                self.defined.add(arg.arg)
        else:
            PhySL.defined_classes = {}

        self.ir = self.apply_rule(tree.body[0])
        self.__src__ = self.generate_physl(self.ir)

        if kwargs.get("debug"):
            print_physl_src(self.__src__)
            print(end="", flush="")

        if "compiler_state" in kwargs:
            PhySL.compiler_state = kwargs['compiler_state']
        # the static method compiler_state is constructed only once
        elif PhySL.compiler_state is None:
            PhySL.compiler_state = compiler_state()

        phylanx.execution_tree.compile(self.file_name, self.__src__,
                                       PhySL.compiler_state)
Example #2
0
    def lazy(self, args):
        """compile a given function, return wrapper binding function to
           arguments"""

        if not PhylanxSession.is_initialized:
            PhylanxSession.init(1)

        if not self.is_compiled:
            if "compiler_state" in self.kwargs:
                PhySL.compiler_state = self.kwargs['compiler_state']
            elif PhySL.compiler_state is None:
                PhySL.compiler_state = compiler_state()

            phylanx.execution_tree.compile(self.file_name, self.__src__,
                                           PhySL.compiler_state)
            self.is_compiled = True

        return self.eval_wrapper(self, args)
Example #3
0
    def __init__(self, func, tree, kwargs):
        self.defined = set()
        self.numpy_aliases = {'numpy'}
        self.wrapped_function = func
        self.kwargs = kwargs
        self.fglobals = self.kwargs['fglobals']
        self.is_compiled = False
        for key, val in self.fglobals.items():
            if type(val).__name__ == 'module' and val.__name__ == 'numpy':
                self.numpy_aliases.add(key)
        self.file_name = self.fglobals.get('__file__')
        if not self.file_name:
            self.file_name = "<none>"

        self.performance = self.kwargs.get('performance', False)
        self.localities = self.kwargs.get('localities')
        self.__perfdata__ = (None, None, None)

        # Add arguments of the function to the list of discovered variables.
        if inspect.isfunction(tree.body[0]):
            for arg in tree.body[0].args.args:
                self.defined.add(arg.arg)
        else:
            PhySL.defined_classes = {}

        self.ir = self.apply_rule(tree.body[0])
        check_return(self.ir)
        self.__src__ = self.generate_physl(self.ir)

        if self.kwargs.get("debug"):
            print_physl_src(self.__src__)
            print(end="", flush="")

        if PhylanxSession.is_initialized:
            if "compiler_state" in self.kwargs:
                PhySL.compiler_state = self.kwargs['compiler_state']
            # the static method compiler_state is constructed only once
            elif PhySL.compiler_state is None:
                PhySL.compiler_state = compiler_state()

            phylanx.execution_tree.compile(self.file_name, self.__src__,
                                           PhySL.compiler_state)
            self.is_compiled = True
Example #4
0
#  Copyright (c) 2017-2018 Hartmut Kaiser
#  Copyright (c) 2018 Steven R. Brandt
#  Copyright (c) 2018 R. Tohid
#
#  Distributed under the Boost Software License, Version 1.0. (See accompanying
#  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

import phylanx
from phylanx import Phylanx
import numpy as np

et = phylanx.execution_tree
cs = phylanx.compiler_state()

fib10 = et.eval(
    """
block(
    define(fib,n,
    if(n<2,n,
        fib(n-1)+fib(n-2))),
    fib)""", cs, 10)

assert fib10 == 55.0

sum10 = et.eval(
    """
block(
    define(sum10,
        block(
            define(i,0),
            define(n,0),