Esempio n. 1
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
            # )
Esempio n. 2
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.
Esempio n. 3
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)
Esempio n. 4
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
Esempio n. 5
0
import numpy as np

from transonic import Transonic, Type, NDim, Array

T = Type(float, complex)
N = NDim(2, 3)
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, b; A1 c; int n)
            # transonic block (int a, b, c; float n)

            result = np.zeros_like(a)
            for _ in range(n):
                result += a**2 + b**3
import numpy as np
from transonic import Type, NDim, Array, boost

T = Type(int, np.complex128)
N = NDim(1, 3)

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


@boost
def compute(a: A, b: A, c: T, d: A1, e: str):
    print(e)
    tmp = a + b
    return tmp
Esempio n. 7
0
  - Adams-Bashforth (leapfrog) + phase-shifting

  For a theoretical presentation of phase-shifting see
  https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19810022965.pdf.

"""

import numpy as np

from transonic import Transonic, Type, NDim, Array

from .base import TimeSteppingBase

ts = Transonic()

N = NDim(3, 4)
A = Array[np.complex128, N]

T = Type(np.float64, np.complex128)
A1 = Array[T, N]
A2 = Array[T, N - 1]


class ExactLinearCoefs:
    """Handle the computation of the exact coefficient for the RK4."""
    def __init__(self, time_stepping):
        self.time_stepping = time_stepping
        sim = time_stepping.sim
        self.shapeK_loc = sim.oper.shapeK_loc
        self.freq_lin = time_stepping.freq_lin
Esempio n. 8
0
from functools import partial

import numpy as np

import transonic as ts
from transonic import Type, NDim, Array, Union

T = Type(int, np.complex128)
N = NDim(1, 3)

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)


@ts.boost
def compute(a: A, b: A, c: T, d: Union[A, A1], e: str):
    print(e)
    tmp = a + b
    if 1 and 2:
        tmp *= 2
    return tmp


main = partial(lambda x: x, lambda x: x)