def test_jit_array_bool():
    from _transonic_testing.for_test_justintime import func_identity

    a = np.zeros(2, dtype=bool)
    func_identity(a)
    wait_for_all_extensions()
    assert np.allclose(a, func_identity(a))
def test_jit_dict():
    from _transonic_testing.for_test_justintime import func_dict

    d = dict(a=1, b=2)
    func_dict(d)

    if not can_import_accelerator():
        return

    mod = modules[module_name]
    cjit = mod.jit_functions["func_dict"]

    d = dict(a=1, b=2)
    func_dict(d)

    wait_for_all_extensions()

    for _ in range(100):
        d = dict(a=1, b=2)
        func_dict(d)
        sleep(0.1)
        if not cjit.compiling:
            sleep(0.1)
            func_dict(d)
            break
def test_func0():
    from _transonic_testing.for_test_justintime import func0, func0_jitted

    func02 = func0(2.1)
    result = func0_jitted(2.1)
    wait_for_all_extensions()
    assert func02 == func0(2.1)
    assert result == func0(2.1)
Exemple #4
0
def test_assign_boosted_func():
    from _transonic_testing.for_test_init import func0, func0_boosted

    func02 = func0(2, 6)
    result = func0_boosted(2, 6)
    wait_for_all_extensions()
    assert func02 == func0(2, 6)
    assert result == func0(2, 6)
def test_jit_imported():
    from _transonic_testing.for_test_justintime import (
        jitted_func_import,
        func_import,
    )

    result = jitted_func_import()
    wait_for_all_extensions()
    assert result == jitted_func_import() == func_import()
def test_fib():
    from _transonic_testing.for_test_justintime import fib, use_fib

    fib2 = fib(2)
    result = use_fib()
    wait_for_all_extensions()
    assert fib2 == fib(2)
    assert result == use_fib()

    fib15 = fib(1.5)
    wait_for_all_extensions()
    assert fib15 == fib(1.5)
def test_jit():
    from _transonic_testing.for_test_justintime import func1

    a = np.arange(2)
    b = [1, 2]

    for _ in range(2):
        func1(a, b)
        sleep(0.1)

    wait_for_all_extensions()
    func1(a, b)
def test_jit_method2():
    from _transonic_testing.for_test_justintime import MyClass2

    obj = MyClass2()
    obj.check()

    if not can_import_accelerator():
        return

    obj = MyClass2()
    obj.check()

    wait_for_all_extensions()

    obj.check()
def test_main():
    from _transonic_testing.for_test_justintime import main

    main_res = main(2)
    wait_for_all_extensions()
    assert main_res == 5
Exemple #10
0
def run():
    """Run the transonic commandline

    See :code:`transonic -h`
    """
    args = parse_args()

    if args.version:
        print(__version__)
        return

    if not args.path and not args.clear_cache:
        logger.warning("No python files given. Nothing to do! ✨ 🍰 ✨.")
        return

    if args.clear_cache:
        clear_cached_extensions(args.clear_cache, args.force, args.backend)
        return

    if args.verbose is None:
        logger.set_level(None)
    elif args.verbose == 1:
        logger.set_level("info")
    elif args.verbose > 1:
        logger.set_level("debug")
    logger.info(args)

    path = args.path

    if isinstance(path, list) and len(path) == 1:
        path = path[0]

    if isinstance(path, list):
        paths = path
    else:
        path = Path(path)
        if path.is_file():
            paths = (path, )
        elif path.is_dir():
            paths = path.glob("*.py")
        else:
            paths = glob(str(path))

    if not paths:
        logger.error(f"No input file found (args.path = {args.path})")
        sys.exit(1)

    backend = backends[args.backend]
    backend.make_backend_files(paths, force=args.force)

    if args.no_compile:
        return

    if not can_import_accelerator(backend.name):
        logger.warning(f"Since {backend.name_capitalized} is not importable, "
                       "Transonic cannot properly compile a file.")
        return

    # find pythran files not already compiled
    backends_paths = []

    for path in paths:
        path = Path(path)
        backend_path = path.parent / str(f"__{backend.name}__") / path.name
        ext_path = backend_path.with_name(
            backend.name_ext_from_path_backend(backend_path))
        if backend_path.exists() and has_to_build(ext_path, backend_path):
            backends_paths.append(backend_path)

    with scheduler.progress:
        backend.compile_extensions(
            backends_paths,
            str_accelerator_flags=args.accelerator_flags,
            parallel=True,
            force=args.force,
        )

        if not args.no_blocking:
            wait_for_all_extensions()