示例#1
0
        solutions.append(values_one_step)
    return solutions


def bench(n_sleds, n_time):
    x_init = np.zeros(n_sleds)
    y_init = np.random.rand(n_sleds)
    v_init = np.zeros(n_sleds)
    u_init = np.zeros(n_sleds) + 3.5

    solver(board, x_init, y_init, u_init, v_init, 0.01, n_time)


# end code functions (don't remove this line)

bench_pythran = jit(bench)
# Numba does not support this code...
# bench_numba = jit(backend="numba")(bench)
from transonic import wait_for_all_extensions

# warmup (compilation of the Pythran extension)
bench_pythran(1, 1)
wait_for_all_extensions()

if __name__ == "__main__":

    from transonic.util import timeit_verbose as timeit

    n_sleds = 10
    n_time = 200
import numpy as np
from scipy.integrate import odeint

from transonic.util import timeit_verbose as timeit
import numba

from transonic import jit, wait_for_all_extensions


def lorenz(u, t):
    x, y, z = u
    return 10.0 * (y - x), x * (28.0 - z) - y, x * y - 2.66 * z


lorenz_pythran = jit(native=True, xsimd=True)(lorenz)
lorenz_numba = numba.jit(lorenz)

u0 = (1.0, 0.0, 0.0)

lorenz_pythran(u0, 0)
lorenz_numba(u0, 0)
wait_for_all_extensions()

# tspan = (0.0, 100.0)
t = np.linspace(0, 100, 1001)
sol = odeint(lorenz, u0, t)

norm = timeit("odeint(lorenz, u0, t, rtol = 1e-8, atol=1e-8)", globals=locals())
timeit(
    "odeint(lorenz_pythran, u0, t, rtol = 1e-8, atol=1e-8)",
    globals=locals(),
示例#3
0
    return solutions


def bench():
    n_sleds = 10
    n_time = 1000
    x_init = np.zeros(n_sleds)
    y_init = np.random.rand(n_sleds)
    v_init = np.zeros(n_sleds)
    u_init = np.zeros(n_sleds) + 3.5

    solver(board, x_init, y_init, v_init, u_init, 0.01, n_time, n_sleds)


bench_pythran = jit(bench)
bench_numba = jit(backend="numba")(bench)

if __name__ == "__main__":

    from transonic.util import timeit_verbose as timeit

    g = locals()
    norm = timeit("bench()", globals=g)
    timeit("bench_pythran()", globals=g, norm=norm)
    timeit("bench_numba()", globals=g, norm=norm)
"""
bench                            : 1.000 * norm
norm = 8.35e-01 s
bench_pythran                    : 0.007 * norm
bench_numba                      : 0.009 * norm
示例#4
0
from transonic import jit

# from .base import identity
# FIXME: The above import works but creating an alias does not
from .base import identity as base_identity

identity_jit = jit(native=True)(base_identity)
    pisum_vec,
    parse_int,
    parse_int_rand,
    parse_int_randomgen,
    printfd,
    # abs2,
    # mandel,
    mandelperf,
    mandelperf2,
    broadcast,
    broadcast_inplace,
)

args_jit = dict(native=True, xsimd=True)

fib = jit(fib, **args_jit)

qsort_kernel = jit(qsort_kernel, **args_jit)

matrix_statistics_rand = jit(matrix_statistics_rand, **args_jit)
matrix_statistics_ones = jit(matrix_statistics_ones, **args_jit)

matrix_multiply_rand = jit(matrix_multiply_rand, **args_jit)
matrix_multiply_ones = jit(matrix_multiply_ones, **args_jit)
broadcast = jit(broadcast, **args_jit)
broadcast_inplace = jit(broadcast_inplace, **args_jit)
bench_random = jit(bench_random, **args_jit)

pisum = jit(pisum, **args_jit)
pisum_vec = jit(pisum_vec, **args_jit)
示例#6
0
import numpy as np

from transonic import jit, boost
from transonic.mpi import Path


def func0(a):
    return 2 * a


def func():
    return 1


func0_jitted = jit(func0)


@jit
def func1(a: "int[][] or float[]", l: "int list"):
    tmp = np.exp(sum(l))
    result = tmp * a * func0(a) + func()
    return result


@jit
def func_identity(a):
    return a


# weird but done on purpose for a better coverage
Path(__file__).touch()
示例#7
0
from transonic import jit
import numba

from pure_numpy import laplace_numpy, laplace_loops

laplace_transonic_pythran = jit(native=True, xsimd=True)(laplace_numpy)
laplace_transonic_python = jit(backend="python")(laplace_numpy)
laplace_transonic_numba = jit(backend="numba")(laplace_numpy)
laplace_numba = numba.njit(laplace_numpy)

laplace_transonic_pythran_loops = jit(native=True, xsimd=True)(laplace_loops)
laplace_transonic_python_loops = jit(backend="python")(laplace_loops)
laplace_transonic_numba_loops = jit(backend="numba")(laplace_loops)
laplace_numba_loops = numba.njit(laplace_loops)

if __name__ == "__main__":
    from transonic import wait_for_all_extensions

    from skimage.data import astronaut
    from skimage.color import rgb2gray

    image = astronaut()
    image = rgb2gray(image)

    # warm the functions
    laplace_transonic_python(image)
    laplace_transonic_pythran(image)
    laplace_transonic_pythran_loops(image)
    laplace_transonic_numba(image)
    laplace_transonic_numba_loops(image)
    laplace_numba(image)
示例#8
0
from scipy.integrate import quad

from scipy import LowLevelCallable

import numba
from transonic.util import timeit_verbose as timeit
from transonic import jit, boost, wait_for_all_extensions

from util import integrand as integrand_capsule


def integrand(x):
    return np.exp(10.0 * x * np.cos(x))


integrand_transonic_jit = jit(native=True)(integrand)

integrand_transonic_jit(0.0)
wait_for_all_extensions()

# transonic bug (should work)!
# integrand_transonic_boost = boost(integrand)


@boost
def integrand_transonic_boost(x: float):
    return np.exp(10.0 * x * np.cos(x))


integrand_numba = numba.njit(integrand)
integrand_numba_cfunc = numba.cfunc("float64(float64)")(integrand)
示例#9
0
from transonic import jit


def func(x):
    return x**2


def func2(x):
    return x**2


func_jitted = jit(func)