예제 #1
0
    def _ensure_global_state(self):
        """Ensure global PhySL session has been initialized"""

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

        if not self.is_compiled:

            # compile all functions that have so far been collected without an
            # initialized session object
            PhySLFunction.compile()
예제 #2
0
def global_compiler_state(file_name=None):

    global _compiler_state
    if _compiler_state is None:
        from phylanx import PhylanxSession
        if not PhylanxSession.is_initialized:
            PhylanxSession.init(1)

        if file_name is None:
            file_name = _name_of_importing_file

        _compiler_state = compiler_state(file_name)

    return _compiler_state
예제 #3
0
파일: physl.py 프로젝트: lfsmariz/phylanx
    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)
예제 #4
0
    def lazy(self, args=()):
        """Compile a given function, return wrapper binding the 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 = phylanx.execution_tree.compiler_state(
                    self.file_name)

            phylanx.execution_tree.compile(
                PhySL.compiler_state, self.file_name,
                self.wrapped_function.__name__, self.__src__)

            self.is_compiled = True

        return self.eval_wrapper(self, tuple(map(self.map_wrapped, args)))
예제 #5
0
#  Copyright (c) 2019 Bita Hasheminezhad
#
#  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)

# #874: Shape for 0D arrays

import numpy as np
from phylanx import execution_tree, PhylanxSession


PhylanxSession.init(1)


def variable(value):
    return execution_tree.var(np.float64(value))


val = variable(42.0).eval()
assert isinstance(val, np.float64)
assert val.shape == ()
예제 #6
0
#  Copyright (c) 2019 Bita Hasheminezhad
#
#  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 numpy as np
from phylanx import Phylanx, PhylanxSession, execution_tree

PhylanxSession.init()


def variable(value, dtype=None):
    return execution_tree.var(np.array(value, dtype))


@Phylanx
def dot_eager(x, y):
    return np.dot(x, y)


def dot(x, y):
    return dot_eager.lazy(x, y)


def eval(func):
    return func.eval()


def parse_shape_or_val(shape_or_val):
    return shape_or_val, np.random.random(shape_or_val).astype(
        np.float32) - 0.5