FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
docker-python/tests/test_numba.py at main · ZahidSQLDBA/docker-python · GitHub
ZahidSQLDBA
/
docker-python
Public
forked from
Kaggle/docker-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
docker-python
/
tests
/
test_numba.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (27 loc) · 1.08 KB
Breadcrumbs
docker-python
/
tests
/
test_numba.py
Copy path
File metadata and controls
35 lines (27 loc) · 1.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import
unittest
import
numpy
as
np
from
numba
import
jit
,
cuda
from
common
import
gpu_test
class
TestNumba
(
unittest
.
TestCase
):
def
test_jit
(
self
):
x
=
np
.
arange
(
100
).
reshape
(
10
,
10
)
@
jit
(
nopython
=
True
)
# Set "nopython" mode for best performance, equivalent to @njit
def
go_fast
(
a
):
# Function is compiled to machine code when called the first time
trace
=
0.0
for
i
in
range
(
a
.
shape
[
0
]):
# Numba likes loops
trace
+=
np
.
tanh
(
a
[
i
,
i
])
# Numba likes NumPy functions
return
a
+
trace
# Numba likes NumPy broadcasting
self
.
assertEqual
(
10
,
go_fast
(
x
).
shape
[
0
])
@
gpu_test
def
test_cuda_jit
(
self
):
x
=
np
.
arange
(
10
)
@
cuda
.
jit
def
increment_by_one
(
an_array
):
pos
=
cuda
.
grid
(
1
)
if
pos
<
an_array
.
size
:
an_array
[
pos
]
+=
1
threadsperblock
=
32
blockspergrid
=
(
x
.
size
+
(
threadsperblock
-
1
))
self
.
assertEqual
(
0
,
x
[
0
])
increment_by_one
[
blockspergrid
,
threadsperblock
](
x
)
self
.
assertEqual
(
1
,
x
[
0
])
Back
|
FazBrowse Home
|
New Git URL