-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_numpy2.py
85 lines (72 loc) · 2.55 KB
/
test_numpy2.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import unittest
import numpy as np
import fake_numpy as fnp
#This test module is a temporary hack
class TestNdarrayNdarray(unittest.TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def test_emptyShape(self):
shape = ()
self.assertEqual(np.ndarray(shape).shape, fnp.ndarray(shape).shape)
# Test overflows
class TestArray(unittest.TestCase):
def __init__(self, *args, **kwargs):
self.scalar = 25
super().__init__(*args, **kwargs)
def arrayCalls(self, a, dtype, copy):
return (np.array(a, dtype=dtype, copy=copy), fnp.array(a, dtype=dtype, copy=copy))
def arrayShapes(self, a, dtype = None, copy = True):
return (arr.shape for arr in self.arrayCalls(a, dtype, copy))
def arrayStrides(self, a, dtype = None, copy = True):
return (arr.strides for arr in self.arrayCalls(a, dtype, copy))
def arrayTobytes(self, a, dtype = None, copy = True):
return (arr.tobytes() for arr in self.arrayCalls(a, dtype, copy))
def arraySize(self, a, dtype = None, copy = True):
return (arr.size for arr in self.arrayCalls(a, dtype, copy))
def arrayNdim(self, a, dtype=None, copy = True):
return (arr.ndim for arr in self.arrayCalls(a, dtype, copy))
def arrayItemsize(self, a, dtype=None, copy = True):
return (arr.itemsize for arr in self.arrayCalls(a, dtype, copy))
def test_scalarCopy(self):
#arr_old = fnp.array()
pass
def generateArrayTests():
dtypes = [
"int8",
"int16",
"int32",
"int64",
"uint8",
"uint16",
"uint32",
"uint64",
"float16",
"float32",
"float64",
"complex64",
"complex128"
]
functions = {
#"Shapes" : TestArray.arrayShapes,
"Strides": TestArray.arrayStrides,
#"Tobytes": TestArray.arrayTobytes,
#"Size": TestArray.arraySize,
#"Ndim": TestArray.arrayNdim,
#"Itemsize": TestArray.arrayItemsize
}
data = {
"scalar": 25,
#"empty": [],
}
for dtype in dtypes:
for func_name, func in functions.items():
for name, obj in data.items():
def test_func(self):
self.assertEqual(*func(self, obj, dtype=dtype))
setattr(TestArray,
f"test_{name}{func_name}{dtype[0].upper() + dtype[1:]}",
test_func
)
if __name__ == "__main__":
generateArrayTests()
unittest.main()