Esempio n. 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()
Esempio n. 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
Esempio n. 3
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)
Esempio n. 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)))
Esempio n. 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 == ()
Esempio n. 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
Esempio n. 7
0
#  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)

from phylanx import Phylanx, PhylanxSession

cfg = [
    "hpx.run_hpx_main!=1", "hpx.commandline.allow_unknown!=1",
    "hpx.commandline.aliasing!=0", "hpx.os_threads!=4",
    "hpx.diagnostics_on_terminate!=0", "hpx.parcel.tcp.enable!=0"
]


@Phylanx
def foo():
    a = 2
    return a


def main():
    assert (foo() == 2)


if __name__ == "__main__":
    PhylanxSession.config(cfg)
    main()