Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
fluiddyn
transonic
Commits
9d9122ba93d3
Commit
3e2a4f54
authored
Feb 02, 2021
by
Pierre Augier
Browse files
Numba @njit(cache=True, fastmath=True)
parent
93a9ad7a1394
Pipeline
#17466
passed with stage
in 10 minutes and 50 seconds
Changes
20
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
CHANGES.rst
View file @
9d9122ba
...
...
@@ -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
-----
...
...
data_tests/saved__backend__/numba/add_inline.py
View file @
9d9122ba
# __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
"
,)
data_tests/saved__backend__/numba/assign_func_boost.py
View file @
9d9122ba
# __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
"
,)
data_tests/saved__backend__/numba/block_fluidsim.py
View file @
9d9122ba
# __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
"
,)
data_tests/saved__backend__/numba/blocks_type_hints.py
View file @
9d9122ba
# __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
"
,)
data_tests/saved__backend__/numba/boosted_class_use_import.py
View file @
9d9122ba
...
...
@@ -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\n
def new_method(self, arg):
\n
return backend_func(self.attr0, self.attr1, arg)
\n\n
"
__transonic__
=
(
"0.
3.0.post0
"
,)
__transonic__
=
(
"0.
4.7
"
,)
data_tests/saved__backend__/numba/boosted_func_use_import.py
View file @
9d9122ba
...
...
@@ -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
"
,)
data_tests/saved__backend__/numba/class_blocks.py
View file @
9d9122ba
# __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
"
,)
data_tests/saved__backend__/numba/class_rec_calls.py
View file @
9d9122ba
# __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\n
def new_method(self, arg):
\n
return backend_func(self.attr, self.attr2, arg)
\n\n
"
__transonic__
=
(
"0.
3.0.post0
"
,)
__transonic__
=
(
"0.
4.7
"
,)
data_tests/saved__backend__/numba/classic.py
View file @
9d9122ba
# __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
"
,)
data_tests/saved__backend__/numba/default_params.py
View file @
9d9122ba
# __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
"
,)
data_tests/saved__backend__/numba/methods.py
View file @
9d9122ba
# __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\n
def new_method(self, inp):
\n
return backend_func(self.arr, self.freq, inp)
\n\n
"
__transonic__
=
(
"0.
3.0.post0
"
,)
__transonic__
=
(
"0.
4.7
"
,)
data_tests/saved__backend__/numba/mixed_classic_type_hint.py
View file @
9d9122ba
# __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
"
,)
data_tests/saved__backend__/numba/no_arg.py
View file @
9d9122ba
# __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
"
,)
data_tests/saved__backend__/numba/row_sum_boost.py
View file @
9d9122ba
# __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
"
,)
data_tests/saved__backend__/numba/subpackages.py
View file @
9d9122ba
...
...
@@ -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
"
,)
data_tests/saved__backend__/numba/type_hint_notemplate.py
View file @
9d9122ba
# __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
"
,)
transonic/backends/numba.py
View file @
9d9122ba
...
...
@@ -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
...
...
transonic/test_typing.py
View file @
9d9122ba
...
...
@@ -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
...
...
transonic/typing.py
View file @
9d9122ba
...
...
@@ -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
})
...
...
Pierre Augier
@paugier
mentioned in commit
632d68cbded1
·
Feb 02, 2021
mentioned in commit
632d68cbded1
mentioned in commit e93540d298deb608ecd0518251fdd8c6201bcd70
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment