Exemplo n.º 1
0
import transonic as ts
from transonic import Type, NDim, Array, Union

import numpy as np
import skimage

T = Type(int, np.complex128)

dim = 2
dim += 1

N = NDim(1, dim)

A = Array[T, N]
A1 = Array[np.float32, N + 1]

A3d = Array[np.float32, "3d"]
N1 = NDim(4, 5)
N1 = NDim(4, 5)

T = Type(int, np.complex128)

a_type_var = "hello"
myconst = 0

cdict = skimage.color.color_dict


@ts.boost
def compute(a: A, b: A, c: T, d: Union[A, A1], e: str):
    print(e)
Exemplo n.º 2
0
import numpy as np

import foo

from transonic import Transonic, Type, NDim, Array

T = Type(float, complex)
N = NDim(1, 2)
A = Array[T, N]
A1 = Array[T, N + 1]

ts = Transonic()


class MyClass:
    def __init__(self, a, b):
        self.a = a
        self.b = b

    def compute(self, n):

        a = self.a
        b = self.b

        if ts.is_transpiled:
            result = ts.use_block("block0")
        else:
            # transonic block (
            #     A a; A1 b;
            #     float n
            # )
Exemplo n.º 3
0
import numpy as np
import matplotlib.pyplot as plt

from transonic import boost, Type

T = Type(float, int)


@boost
def func(a: T):
    b = 1
    return a * np.sin(b)
Exemplo n.º 4
0
import numpy as np

from transonic import Type, NDim, Array, boost

T = Type(np.float64, np.complex128)
N = NDim(1)
A = Array[T, N]


@boost
def func(a: A):
    i: int
    n: int = a.shape[0]

    for i in range(n):
        a[i] = a[i] + 1.
Exemplo n.º 5
0
import numpy as np

from transonic import boost, Type, Array, NDim


T = Type(np.int32, np.float64, np.float32)
A = Array[T, NDim(2)]


@boost
def laplace(image: A):
    """Laplace operator in NumPy for 2D images."""
    laplacian = (
        image[:-2, 1:-1]
        + image[2:, 1:-1]
        + image[1:-1, :-2]
        + image[1:-1, 2:]
        - 4 * image[1:-1, 1:-1]
    )
    thresh = np.abs(laplacian) > 0.05
    return thresh
Exemplo n.º 6
0
import numpy as np
from transonic import boost, Array, Type

A = Array[Type(np.float64, np.complex128), "3d"]
Af = "float[:,:,:]"
A = Af  # issue fused type with Cython


def proj(vx: A, vy: A, vz: A, kx: Af, ky: Af, kz: Af, inv_k_square_nozero: Af):
    tmp = (kx * vx + ky * vy + kz * vz) * inv_k_square_nozero
    vx -= kx * tmp
    vy -= ky * tmp
    vz -= kz * tmp


def proj_loop(vx: A, vy: A, vz: A, kx: Af, ky: Af, kz: Af,
              inv_k_square_nozero: Af):

    # type annotations only useful for Cython
    n0: int
    n1: int
    n2: int
    i0: int
    i1: int
    i2: int
    tmp: float

    n0, n1, n2 = kx.shape[0], kx.shape[1], kx.shape[2]

    for i0 in range(n0):
        for i1 in range(n1):
Exemplo n.º 7
0
from transonic import jit, Type

T = Type(int, float)


@jit()
def func(a: T, b: T):
    return a * b


if __name__ == "__main__":

    from time import sleep

    a_i = b_i = 1
    a_f = b_f = 1.0

    for _ in range(10):
        print(_, end=",", flush=True)
        func(a_i, b_i)
        sleep(1)

    print()

    for _ in range(10):
        print(_, end=",", flush=True)
        func(a_f, b_f)
        sleep(1)