Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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
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
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
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)
tmp = a + b + myconst
return tmp
"""
Not yet implemented...
Many things can be expressed in Pythran specifications (see
https://pythran.readthedocs.io/en/latest/MANUAL.html#concerning-pythran-specifications),
in particular stride arrays and partial shapes...
We could also express these concepts in strings, mainly following Pythran...
"""
from transonic import boost, Type, NDim, Shape, Array
T = Type(int, float)
# here the shape of the array is only defined with the ShapeVar
A = Array[T, Shape("[3, :]", "[3, :, :]", "[::, ::]", "[::, ::, ::]")]
@boost
def compute(a: A, b: A, c: T):
return a + b
# if there is a NDimVar, we can use the ellipsis
A1 = Array[T, NDim(1, 3), Shape("[3, ...]", "[::, ...]")]
@boost
def compute1(a: A1, b: A1, c: T):
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.
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
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