Commit 3e2a4f54 authored by Pierre Augier's avatar Pierre Augier
Browse files

Numba @njit(cache=True, fastmath=True)

parent 93a9ad7a1394
Pipeline #17466 passed with stage
in 10 minutes and 50 seconds
......@@ -4,6 +4,13 @@ Future
See the `ROADMAP.rst file
<https://transonic.readthedocs.io/en/latest/roadmap.html>`_.
0.4.7
-----
- Numba backend: using by default ``@njit(cache=True, fastmath=True)``
- Better logging with rich
- Support Pythran code using the omp module provided by Pythran
0.4.6
-----
......
# __protected__ from numba import njit
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def add(a, b):
return a + b
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def use_add(n=10000):
......@@ -16,4 +16,4 @@ def use_add(n=10000):
return tmp
__transonic__ = ("0.3.2",)
__transonic__ = ("0.4.7",)
# __protected__ from numba import njit
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def func(x):
return x ** 2
__transonic__ = ("0.3.0.post0",)
__transonic__ = ("0.4.7",)
# __protected__ from numba import njit
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def rk2_step0(state_spect_n12, state_spect, tendencies_n, diss2, dt):
......@@ -15,4 +15,4 @@ def rk2_step0(state_spect_n12, state_spect, tendencies_n, diss2, dt):
arguments_blocks = {
"rk2_step0": ["state_spect_n12", "state_spect", "tendencies_n", "diss2", "dt"]
}
__transonic__ = ("0.3.0.post0",)
__transonic__ = ("0.4.7",)
# __protected__ from numba import njit
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def block0(a, b, n):
......@@ -16,4 +16,4 @@ def block0(a, b, n):
arguments_blocks = {"block0": ["a", "b", "n"]}
__transonic__ = ("0.4.2",)
__transonic__ = ("0.4.7",)
......@@ -2,7 +2,7 @@
import numpy as np
from exterior_import_boost import func_import
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def __for_method__MyClass2__myfunc(self_attr0, self_attr1, arg):
......@@ -10,4 +10,4 @@ def __for_method__MyClass2__myfunc(self_attr0, self_attr1, arg):
__code_new_method__MyClass2__myfunc = "\n\ndef new_method(self, arg):\n return backend_func(self.attr0, self.attr1, arg)\n\n"
__transonic__ = ("0.3.0.post0",)
__transonic__ = ("0.4.7",)
......@@ -2,11 +2,11 @@
import numpy as np
from exterior_import_boost import func_import
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def func(a, b):
return (a * np.log(b)).max() + func_import()
__transonic__ = ("0.3.0.post0",)
__transonic__ = ("0.4.7",)
# __protected__ from numba import njit
import numpy as np
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def block0(a, b, n):
......@@ -22,7 +22,7 @@ def block0(a, b, n):
return result
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def block1(a, b, n):
......@@ -41,4 +41,4 @@ def block1(a, b, n):
arguments_blocks = {"block0": ["a", "b", "n"], "block1": ["a", "b", "n"]}
__transonic__ = ("0.4.2",)
__transonic__ = ("0.4.7",)
# __protected__ from numba import njit
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def __for_method__Myclass__func(self_attr, self_attr2, arg):
......@@ -15,4 +15,4 @@ def __for_method__Myclass__func(self_attr, self_attr2, arg):
__code_new_method__Myclass__func = "\n\ndef new_method(self, arg):\n return backend_func(self.attr, self.attr2, arg)\n\n"
__transonic__ = ("0.3.0.post0",)
__transonic__ = ("0.4.7",)
# __protected__ from numba import njit
import numpy as np
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def func(a, b):
return (a * np.log(b)).max()
__transonic__ = ("0.3.0.post0",)
__transonic__ = ("0.4.7",)
# __protected__ from numba import njit
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def func(a=1, b=None, c=1.0):
......@@ -7,4 +7,4 @@ def func(a=1, b=None, c=1.0):
return a + c
__transonic__ = ("0.4.0",)
__transonic__ = ("0.4.7",)
# __protected__ from numba import njit
import numpy as np
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def __for_method__Transmitter____call__(self_arr, self_freq, inp):
......@@ -10,4 +10,4 @@ def __for_method__Transmitter____call__(self_arr, self_freq, inp):
__code_new_method__Transmitter____call__ = "\n\ndef new_method(self, inp):\n return backend_func(self.arr, self.freq, inp)\n\n"
__transonic__ = ("0.3.0.post0",)
__transonic__ = ("0.4.7",)
# __protected__ from numba import njit
import numpy as np
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def func(a, b):
return (a * np.log(b)).max()
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def func1(a, b):
return a * np.cos(b)
__transonic__ = ("0.3.0.post0",)
__transonic__ = ("0.4.7",)
# __protected__ from numba import njit
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def func():
return 1
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def func2():
return 1
__transonic__ = ("0.3.0.post0",)
__transonic__ = ("0.4.7",)
# __protected__ from numba import njit
import numpy as np
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def row_sum(arr, columns):
return arr.T[columns].sum(0)
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def row_sum_loops(arr, columns):
......@@ -24,4 +24,4 @@ def row_sum_loops(arr, columns):
return res
__transonic__ = ("0.3.3.post0",)
__transonic__ = ("0.4.7",)
......@@ -4,7 +4,7 @@ from numpy.random import randn
from numpy.linalg import matrix_power
from scipy.special import jv
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def test_np_fft(u):
......@@ -12,7 +12,7 @@ def test_np_fft(u):
return u_fft
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def test_np_linalg_random(u):
......@@ -23,11 +23,11 @@ def test_np_linalg_random(u):
return u4
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def test_sp_special(v, x):
return jv(v, x)
__transonic__ = ("0.4.2",)
__transonic__ = ("0.4.7",)
# __protected__ from numba import njit
# __protected__ @njit
# __protected__ @njit(cache=True, fastmath=True)
def compute(a, b, c, d, e):
......@@ -10,4 +10,4 @@ def compute(a, b, c, d, e):
return tmp
__transonic__ = ("0.3.0.post0",)
__transonic__ = ("0.4.7",)
......@@ -29,7 +29,7 @@ def add_numba_comments(code):
for node in mod.body:
if isinstance(node, gast.FunctionDef):
new_body.append(CommentLine("# __protected__ @njit"))
new_body.append(CommentLine("# __protected__ @njit(cache=True, fastmath=True)"))
new_body.append(node)
mod.body = new_body
......
......@@ -41,8 +41,8 @@ def test_NDim():
def test_str2type_simple():
assert str2type("int") == np.int
assert str2type("float") == np.float
assert str2type("int") == int
assert str2type("float") == float
assert str2type("uint32") == np.uint32
......
......@@ -890,15 +890,16 @@ def str2type(str_type):
# not a simple type
pass
# could be a numpy type
try:
if not str_type.startswith("np."):
dtype = "np." + str_type
else:
dtype = str_type
return eval(dtype, {"np": np})
except (TypeError, SyntaxError, AttributeError):
pass
if "[" not in str_type:
# could be a numpy type
try:
if not str_type.startswith("np."):
dtype = "np." + str_type
else:
dtype = str_type
return eval(dtype, {"np": np})
except (TypeError, SyntaxError, AttributeError):
pass
if str_type.startswith("(") and str_type.endswith(")"):
re_comma = re.compile(r",(?![^\[]*\])(?![^\(]*\))")
......@@ -931,7 +932,8 @@ def str2type(str_type):
raise ValueError(f"Can't determine the Transonic type from '{str_type}'")
dtype, str_shape = str_type.split("[", 1)
if not dtype.startswith("np."):
dtype = dtype.strip()
if not dtype.startswith("np.") and dtype not in ("int", "float"):
dtype = "np." + dtype
str_shape = "[" + str_shape
dtype = eval(dtype, {"np": np})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment