File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 1
1
import importlib
2
2
3
+ from numba import njit
4
+
3
5
from stumpy import config
4
6
5
7
8
+ @njit (fastmath = True )
9
+ def _add_assoc (x , y ): # pragma: no cover
10
+ """
11
+ A dummy function to test the fastmath module
12
+
13
+ Parameters
14
+ ----------
15
+ x : float
16
+ A float value
17
+
18
+ y : floatf
19
+ A float value
20
+
21
+ Returns
22
+ -------
23
+ out : float
24
+ The ouput valus
25
+
26
+ Notes
27
+ -----
28
+ This is taken from the following link:
29
+ https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath
30
+ """
31
+ return (x - y ) + y
32
+
33
+
6
34
def _set (module_name , func_name , flag ):
7
35
"""
8
36
Set fastmath flag for a given function
Original file line number Diff line number Diff line change
1
+ import numpy as np
2
+
3
+ from stumpy import fastmath
4
+
5
+
6
+ def test_fastmath ():
7
+ # Test the _set and _reset function in fastmath.py
8
+ # The test is done by changing the value of fastmath flag for
9
+ # the fastmath._add_assoc function
10
+ # See: https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath
11
+
12
+ x , y = 0.0 , np .inf
13
+
14
+ # fastmath=False
15
+ fastmath ._set ("fastmath" , "_add_assoc" , False )
16
+ out = fastmath ._add_assoc (x , y )
17
+ assert np .isnan (out )
18
+
19
+ # fastmath={'reassoc', 'nsz'}
20
+ fastmath ._set ("fastmath" , "_add_assoc" , {"reassoc" , "nsz" })
21
+ out = fastmath ._add_assoc (x , y )
22
+ assert out == 0.0
23
+
24
+ # fastmath={'reassoc'}
25
+ fastmath ._set ("fastmath" , "_add_assoc" , {"reassoc" })
26
+ out = fastmath ._add_assoc (x , y )
27
+ assert np .isnan (out )
28
+
29
+ # fastmath={'nsz'}
30
+ fastmath ._set ("fastmath" , "_add_assoc" , {"nsz" })
31
+ out = fastmath ._add_assoc (x , y )
32
+ assert np .isnan (out )
33
+
34
+ # reset value of fastmath (default is True)
35
+ fastmath ._reset ("fastmath" , "_add_assoc" )
36
+ out = fastmath ._add_assoc (x , y )
37
+ assert out == 0.0
You can’t perform that action at this time.
0 commit comments