How to use transonic - 10 common examples

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_testing / for_test_justintime.py View on Github external
    @jit
    def myfunc1(self):
        return self.attr0

    def check(self):
        assert self.myfunc(1) == 3


# FIXME support multilevel imported jitted function call in a jitted function
from .for_test_exterior_import_jit import foo, func_import, func_import2
from numpy import pi

const = 1

jitted_func_import = jit(func_import)
jitted_func_import2 = jit(func_import2)


@jit
def main(add: int):
    return (
        add
        + foo
        + pi
        - pi
        - jitted_func_import()
        + func_import2()
        + func0_jitted(1 / 2)
        + const
    )
github fluiddyn / transonic / data_tests / subpackages.py View on Github external
@boost
def test_sp_special(v: int, x: float):
    return jv(v, x)
github fluiddyn / transonic / data_tests / subpackages.py View on Github external
@boost
def test_np_fft(u: "float[]"):
    u_fft = rfft(u)
    return u_fft
github fluiddyn / transonic / _transonic_testing / for_test_init.py View on Github external
def func0(a, b):
    return a + b


func0_boosted = boost(func0)

A = Union[int, Array[int, "1d", "C"]]


@boost
def func2(a: A, b: float):
    return a - func_tmp(b)


A1 = Array[int, "1d", "C", "memview"]


@boost
def func3(c: const(A1)):
    return c[0] + 1


ts = Transonic()


def func1(a, b):
    n = 10

    if ts.is_transpiled:
        result = ts.use_block("block0")
    else:
github fluiddyn / transonic / transonic / backends / test_cython.py View on Github external
def compare(result, dtype, ndim, memview, mem_layout=None, positive_indices=None):
    A = Array[dtype, ndim, memview, mem_layout, positive_indices]
    assert A.format_as_backend_type(type_formatter) == result
github fluiddyn / transonic / data_tests / type_hint.py View on Github external
import numpy as np
import transonic as ts
from transonic import Type, NDim, Array, Union

T = Type("T")
T1 = Type("T1")
N = NDim("N")

A = Array[T, N]
A1 = Array[T1, N + 1]

# for coverage
assert repr(N - 1) == "N - 1"
print(repr(A1))


repr(Union[A, A1])


@ts.boost
def compute(a: A, b: A1, c: T, d: A, e: str):
    print(e)
    tmp = a + b
    return tmp
github fluiddyn / transonic / _transonic_testing / for_test_justintime.py View on Github external
@jit
def main(add: int):
    return (
        add
        + foo
        + pi
        - pi
        - jitted_func_import()
        + func_import2()
        + func0_jitted(1 / 2)
        + const
    )
github fluiddyn / transonic / _transonic_testing / for_test_justintime.py View on Github external
@jit
def func_dict(d: "str: float dict"):
    return d.popitem()