@@ -27,6 +27,17 @@ def test_output():
27
27
assert res .output .out == 5
28
28
29
29
30
+ def test_numpy ():
31
+ """ checking if mark.task works for numpy functions"""
32
+ np = pytest .importorskip ("numpy" )
33
+ fft = mark .annotate ({"a" : np .ndarray , "return" : float })(np .fft .fft )
34
+ fft = mark .task (fft )()
35
+ arr = np .array ([[1 , 10 ], [2 , 20 ]])
36
+ fft .inputs .a = arr
37
+ res = fft ()
38
+ assert np .allclose (np .fft .fft (arr ), res .output .out )
39
+
40
+
30
41
@pytest .mark .xfail (reason = "cp.dumps(func) depends on the system/setup, TODO!!" )
31
42
def test_checksum ():
32
43
nn = funaddtwo (a = 3 )
@@ -38,7 +49,9 @@ def test_checksum():
38
49
39
50
def test_annotated_func ():
40
51
@mark .task
41
- def testfunc (a : int , b : float = 0.1 ) -> ty .NamedTuple ("Output" , [("out1" , float )]):
52
+ def testfunc (
53
+ a : int , b : float = 0.1
54
+ ) -> ty .NamedTuple ("Output" , [("out_out" , float )]):
42
55
return a + b
43
56
44
57
funky = testfunc (a = 1 )
@@ -48,14 +61,14 @@ def testfunc(a: int, b: float = 0.1) -> ty.NamedTuple("Output", [("out1", float)
48
61
assert getattr (funky .inputs , "a" ) == 1
49
62
assert getattr (funky .inputs , "b" ) == 0.1
50
63
assert getattr (funky .inputs , "_func" ) is not None
51
- assert set (funky .output_names ) == set (["out1 " ])
64
+ assert set (funky .output_names ) == set (["out_out " ])
52
65
# assert funky.inputs.hash == '17772c3aec9540a8dd3e187eecd2301a09c9a25c6e371ddd86e31e3a1ecfeefa'
53
66
assert funky .__class__ .__name__ + "_" + funky .inputs .hash == funky .checksum
54
67
55
68
result = funky ()
56
69
assert hasattr (result , "output" )
57
- assert hasattr (result .output , "out1 " )
58
- assert result .output .out1 == 1.1
70
+ assert hasattr (result .output , "out_out " )
71
+ assert result .output .out_out == 1.1
59
72
60
73
assert os .path .exists (funky .cache_dir / funky .checksum / "_result.pklz" )
61
74
funky .result () # should not recompute
@@ -64,7 +77,7 @@ def testfunc(a: int, b: float = 0.1) -> ty.NamedTuple("Output", [("out1", float)
64
77
assert funky .result () is None
65
78
funky ()
66
79
result = funky .result ()
67
- assert result .output .out1 == 2.1
80
+ assert result .output .out_out == 2.1
68
81
69
82
help = funky .help (returnhelp = True )
70
83
assert help == [
@@ -74,7 +87,7 @@ def testfunc(a: int, b: float = 0.1) -> ty.NamedTuple("Output", [("out1", float)
74
87
"- b: float (default: 0.1)" ,
75
88
"- _func: str" ,
76
89
"Output Parameters:" ,
77
- "- out1 : float" ,
90
+ "- out_out : float" ,
78
91
]
79
92
80
93
@@ -150,13 +163,13 @@ def testfunc(a, b) -> int:
150
163
assert getattr (funky .inputs , "a" ) == 10
151
164
assert getattr (funky .inputs , "b" ) == 20
152
165
assert getattr (funky .inputs , "_func" ) is not None
153
- assert set (funky .output_names ) == set (["out1 " ])
166
+ assert set (funky .output_names ) == set (["out " ])
154
167
assert funky .__class__ .__name__ + "_" + funky .inputs .hash == funky .checksum
155
168
156
169
result = funky ()
157
170
assert hasattr (result , "output" )
158
- assert hasattr (result .output , "out1 " )
159
- assert result .output .out1 == 30
171
+ assert hasattr (result .output , "out " )
172
+ assert result .output .out == 30
160
173
161
174
assert os .path .exists (funky .cache_dir / funky .checksum / "_result.pklz" )
162
175
@@ -165,7 +178,7 @@ def testfunc(a, b) -> int:
165
178
assert funky .result () is None
166
179
funky ()
167
180
result = funky .result ()
168
- assert result .output .out1 == 31
181
+ assert result .output .out == 31
169
182
help = funky .help (returnhelp = True )
170
183
171
184
assert help == [
@@ -175,7 +188,7 @@ def testfunc(a, b) -> int:
175
188
"- b: _empty" ,
176
189
"- _func: str" ,
177
190
"Output Parameters:" ,
178
- "- out1 : int" ,
191
+ "- out : int" ,
179
192
]
180
193
181
194
0 commit comments