How to use the transonic.config.backend_default function in transonic

To help you get started, we’ve selected a few transonic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fluiddyn / transonic / transonic / test_build_ext.py View on Github external
def teardown_module():
    os.chdir(cwd)
    for namedir in ("build", f"__{backend_default}__", "__pycache__"):
        with suppress(FileNotFoundError):
            shutil.rmtree(setup_dir / namedir)

    to_remove = list(setup_dir.glob("*.h")) + list(setup_dir.glob("*.so"))
    for path in to_remove:
        os.remove(path)
github fluiddyn / transonic / transonic / test_dist.py View on Github external
def test_detect_backend_extensions():

    shutil.rmtree(path_data_tests / f"__{backend_default}__", ignore_errors=True)

    names = [
        "assign_func_boost.py",
        "assign_func_jit.py",
        "block_fluidsim.py",
        "blocks_type_hints.py",
        "boosted_func_use_import.py",
        # "boosted_class_use_import.py",  # was forgotten...
        "class_blocks.py",
        "classic.py",
        # "class_rec_calls.py",
        # "methods.py",
        "mixed_classic_type_hint.py",
        # "no_arg.py",
        "type_hint_notemplate.py",
        "no_pythran_.py",
github fluiddyn / transonic / transonic / test_init_transonified.py View on Github external
def setUpClass(cls):
        cls.path_for_test = (
            mpi.Path(__file__).parent.parent
            / "_transonic_testing/for_test_init.py"
        )

        assert cls.path_for_test.exists()

        cls.path_backend = path_backend = (
            cls.path_for_test.parent
            / f"__{backend_default}__"
            / cls.path_for_test.name
        )

        cls.path_ext = path_backend.with_name(
            backend.name_ext_from_path_backend(path_backend)
        )
github fluiddyn / transonic / transonic / test_init.py View on Github external
def test_not_transonified():

    path_for_test = (
        Path(__file__).parent.parent / "_transonic_testing/for_test_init.py"
    )
    path_output = path_for_test.parent / f"__{backend_default}__"

    if path_output.exists() and mpi.rank == 0:
        rmtree(path_output)
    mpi.barrier()

    from _transonic_testing import for_test_init

    importlib.reload(for_test_init)

    from _transonic_testing.for_test_init import func, func1, check_class

    func(1, 3.14)
    func1(1.1, 2.2)
    check_class()
github fluiddyn / transonic / transonic / justintime.py View on Github external
from transonic.util import (
    get_module_name,
    has_to_build,
    path_root,
    get_info_from_ipython,
    make_hex,
    has_to_compile_at_import,
    import_from_path,
    is_method,
    write_if_has_to_write,
    can_import_accelerator,
    format_str,
)

modules_backends = {backend_name: {} for backend_name in backends.keys()}
modules = modules_backends[backend_default]

_COMPILE_JIT = strtobool(os.environ.get("TRANSONIC_COMPILE_JIT", "True"))


def set_compile_jit(value):
    global _COMPILE_JIT
    _COMPILE_JIT = value


class ModuleJIT:
    """Representation of a module using jit"""

    def __init__(self, backend_name: str, frame=None):

        self.backend_name = backend_name
        if frame is None:
github fluiddyn / transonic / doc / examples / bench_row_sum / util.py View on Github external
def bench(functions, arr, columns):
    print(backend_default.capitalize())
    for func in functions:
        result = timeit("func(arr, columns)", globals=locals())
        print(f"{func.__name__:20s} {result:.3e} s")
    print()
github fluiddyn / transonic / transonic / run.py View on Github external
help="proceed even if the files seem up-to-date",
        action="store_true",
    )

    parser.add_argument(
        "-V", "--version", help="print version and exit", action="store_true"
    )

    parser.add_argument("-v", "--verbose", help="verbose mode", action="count")

    parser.add_argument(
        "-b",
        "--backend",
        help=("Backend (pythran, cython, numba or python)"),
        type=str,
        default=backend_default,
    )

    parser.add_argument(
        "-nc",
        "--no-compile",
        help="do not compile the Pythran/Cython/... files",
        action="store_true",
    )

    parser.add_argument(
        "-nb",
        "--no-blocking",
        help="launch the compilation in the background and return",
        action="store_true",
    )
github fluiddyn / transonic / transonic / aheadoftime.py View on Github external
has_to_compile_at_import,
    import_from_path,
    has_to_build,
    modification_date,
    is_method,
    write_if_has_to_write,
    find_module_name_from_path,
)

if mpi.nb_proc == 1:
    mpi.has_to_build = has_to_build
    mpi.modification_date = modification_date

is_transpiling = False
modules_backends = {backend_name: {} for backend_name in backends.keys()}
modules = modules_backends[backend_default]


def _get_transonic_calling_module(backend_name: str = None, index_frame: int = 2):
    """Get the Transonic instance corresponding to the calling module

    Parameters
    ----------

    index_frame : int

      Index (in :code:`inspect.stack()`) of the frame to be selected

    """

    try:
        frame = inspect.stack()[index_frame]
github fluiddyn / transonic / transonic / dist.py View on Github external
def init_transonic_extensions(
    name_package: str,
    backend: str = backend_default,
    include_dirs: Iterable[str] = (),
    compile_args: Iterable[str] = (),
    exclude_exts: Iterable[str] = (),
    logger=None,
    inplace=None,
    annotate=False,
):
    """Detects pythran extensions under a package and returns a list of
    Extension instances ready to be passed into the ``setup()`` function.

    Parameters
    ----------
    name_package:

        Package to be recursively scanned for Pythran extensions.
github fluiddyn / transonic / transonic / backends / __init__.py View on Github external
def get_backend_name_module(module_name):
    return backend_default_modules.get(module_name, backend_default)