Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
val_int = randint(100)
val_float = rand()*100
f_int_int = epyccel(create_full_val_int_int)
assert( f_int_int(val_int) == create_full_val_int_int(val_int))
assert(type(f_int_int(val_int)) == type(create_full_val_int_int(val_int).item())) # pylint: disable=unidiomatic-typecheck
f_int_float = epyccel(create_full_val_int_float)
assert(isclose( f_int_float(val_int) , create_full_val_int_float(val_int), rtol=1e-15, atol=1e-15))
assert(type(f_int_float(val_int)) == type(create_full_val_int_float(val_int).item())) # pylint: disable=unidiomatic-typecheck
f_int_complex = epyccel(create_full_val_int_complex)
assert(isclose( f_int_complex(val_int) , create_full_val_int_complex(val_int), rtol=1e-15, atol=1e-15))
assert(type(f_int_complex(val_int)) == type(create_full_val_int_complex(val_int).item())) # pylint: disable=unidiomatic-typecheck
f_real_int32 = epyccel(create_full_val_real_int32)
assert( f_real_int32(val_float) == create_full_val_real_int32(val_float))
assert(type(f_real_int32(val_float)) == type(create_full_val_real_int32(val_float).item())) # pylint: disable=unidiomatic-typecheck
f_real_float32 = epyccel(create_full_val_real_float32)
assert(isclose( f_real_float32(val_float) , create_full_val_real_float32(val_float), rtol=1e-15, atol=1e-15))
assert(type(f_real_float32(val_float)) == type(create_full_val_real_float32(val_float).item())) # pylint: disable=unidiomatic-typecheck
f_real_float64 = epyccel(create_full_val_real_float64)
assert(isclose( f_real_float64(val_float) , create_full_val_real_float64(val_float), rtol=1e-15, atol=1e-15))
assert(type(f_real_float64(val_float)) == type(create_full_val_real_float64(val_float).item())) # pylint: disable=unidiomatic-typecheck
f_real_complex64 = epyccel(create_full_val_real_complex64)
assert(isclose( f_real_complex64(val_float) , create_full_val_real_complex64(val_float), rtol=1e-15, atol=1e-15))
assert(type(f_real_complex64(val_float)) == type(create_full_val_real_complex64(val_float).item())) # pylint: disable=unidiomatic-typecheck
f_real_complex128 = epyccel(create_full_val_real_complex128)
s = shape(a)
return len(s),s[0], s[1]
@types('int','int')
def create_empty_shape_F(n,m):
from numpy import empty, shape
a = empty((n,m), order = 'F')
s = shape(a)
return len(s),s[0], s[1]
size_1 = randint(10)
size_2 = randint(10)
f_shape_C = epyccel(create_empty_shape_C)
assert( f_shape_C(size_1,size_2) == create_empty_shape_C(size_1,size_2))
f_shape_F = epyccel(create_empty_shape_F)
assert( f_shape_F(size_1,size_2) == create_empty_shape_F(size_1,size_2))
def test_pointers(test_func):
f1 = test_func
f2 = epyccel( f1 )
python_out = f1()
pyccel_out = f2()
compare_python_pyccel(python_out, pyccel_out)
def test_array_real_2d_2d_matmul_C_C_F_F():
f1 = arrays.array_real_2d_2d_matmul
f2 = epyccel( f1 )
A1 = np.ones([3, 2], order='F')
A1[1, 0] = 2
A2 = np.copy(A1)
B1 = np.ones([2, 3], order='F')
B2 = np.copy(B1)
C1 = np.empty([3,3])
C2 = np.empty([3,3])
f1(A1, B1, C1)
f2(A2, B2, C2)
assert np.array_equal(C1, C2)
def test_array_int_1d_scalar_idiv():
f1 = arrays.array_int_1d_scalar_idiv
f2 = epyccel( f1 )
x1 = np.array( [1,2,3] )
x2 = np.copy(x1)
a = 5
f1(x1, a)
f2(x2, a)
assert np.array_equal( x1, x2 )
def test_asin_call():
@types('real')
def asin_call(x):
from math import asin
return asin(x)
f1 = epyccel(asin_call)
x = rand()
assert(isclose(f1(x) , asin_call(x), rtol=1e-15, atol=1e-15))
def test_f1():
@types('int')
def f1(x = 1):
y = x - 1
return y
f = epyccel(f1)
# ...
assert f(2) == f1(2)
assert f() == f1()
# ...
def test_log_phrase():
@types('real','real')
def log_phrase(x,y):
from math import log
a = log(x)+log(y)
return a
f2 = epyccel(log_phrase)
x = rand()
y = rand()
assert(isclose(f2(x,y) , log_phrase(x,y), rtol=1e-15, atol=1e-15))
from math import floor
a = floor(x)
return a
@types('real')
def floor_return_type_real(x):
from math import floor
a = floor(x)
return a
f1 = epyccel(floor_return_type_int)
x = randint(100)
assert(isclose(f1(x) , floor_return_type_int(x), rtol=1e-15, atol=1e-15))
assert(type(f1(x)) == type(floor_return_type_int(x))) # pylint: disable=unidiomatic-typecheck
f1 = epyccel(floor_return_type_real)
x = randint(100)
assert(isclose(f1(x) , floor_return_type_real(x), rtol=1e-15, atol=1e-15))
assert(type(f1(x)) == type(floor_return_type_real(x))) # pylint: disable=unidiomatic-typecheck
def test_shape_bool():
@types('bool[:]')
def test_shape_1d(f):
from numpy import shape
b = shape(f)
return b[0]
@types('bool[:,:]')
def test_shape_2d(f):
from numpy import shape
a = shape(f)
return a[0], a[1]
from numpy import empty
f1 = epyccel(test_shape_1d)
f2 = epyccel(test_shape_2d)
n1 = randint(20)
n2 = randint(20)
n3 = randint(20)
x1 = empty(n1,dtype = bool)
x2 = empty((n2,n3), dtype = bool)
assert(f1(x1) == test_shape_1d(x1))
assert(f2(x2) == test_shape_2d(x2))