-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtimingtests.py
More file actions
49 lines (43 loc) · 1.68 KB
/
timingtests.py
File metadata and controls
49 lines (43 loc) · 1.68 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 2 13:16:52 2019
@author: talon
"""
from timeit import timeit as t
import numba as nb
import numpy as np
@nb.jit(nopython = True)
def roundinfty(array):
a = array.copy()
f=np.modf(a)[0] #get decimal values from data
if (a.ndim == 1): #for 1D array
for i in range(len(array)):
if((f[i]<0.0 and f[i] <=-0.5) or (f[i]>=0.0 and f[i]<0.5)):
a[i]=np.floor(a[i])
else:
a[i]=np.ceil(a[i])
elif(a.ndim==2): #for 2D array
for i in range(array.shape[0]):
for j in range(array.shape[1]):
if((f[i,j]<0.0 and f[i,j] <=-0.5) or (f[i,j]>=0.0
and f[i,j]<0.5)):
a[i,j]=np.floor(a[i,j])
else:
a[i,j]=np.ceil(a[i,j])
elif(a.ndim==3): #for 3D array
for i in range(array.shape[0]):
for j in range(array.shape[1]):
for k in range(array.shape[2]):
if((f[i,j,k]<0.0 and f[i,j,k] <=-0.5) or
(f[i,j,k]>=0.0 and f[i,j,k]<0.5)):
a[i,j,k]=np.floor(a[i,j,k])
else:
a[i,j,k]=np.ceil(a[i,j,k])
return a
upset = '''from pfb_floating_numba import FloatPFB
import numpy as np
data = np.ones(8*2**13)
pfbflt = FloatPFB(2**13,8, chan_acc = True)'''
code = '''pfbflt.run(data)'''
print(t(stmt=code,setup=upset,number=1000))