Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pub
pi
Commits
0fc7307c
Commit
0fc7307c
authored
Feb 06, 2020
by
Neil Gershenfeld
Browse files
add Numba
parent
50e2f2e7
Pipeline
#4914
passed with stage
in 1 second
Changes
1
Pipelines
1
Show whitespace changes
Inline
Sidebyside
Python/numbapi.py
0 → 100755
View file @
0fc7307c
#
# numbapi.py
# Neil Gershenfeld 2/6/20
# calculation of pi by a Numba sum
# pi = 3.14159265358979323846
#
import
time
from
numba
import
jit
NPTS
=
100000000
@
jit
(
nopython
=
True
)
def
calc
():
a
=
0.5
b
=
0.75
c
=
0.25
pi
=
0
for
i
in
range
(
1
,(
NPTS
+
1
)):
pi
+=
a
/
((
i

b
)
*
(
i

c
))
return
pi
start_time
=
time
.
time
()
pi
=
calc
()
end_time
=
time
.
time
()
mflops
=
NPTS
*
5.0
/
(
1.0e6
*
(
end_time

start_time
))
print
(
"NPTS = %d, pi = %f"
%
(
NPTS
,
pi
))
print
(
"time = %f, estimated MFlops = %f"
%
(
end_time

start_time
,
mflops
))
Write
Preview
Markdown
is supported
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