|
24 | 24 | import importlib.util |
25 | 25 | import textwrap |
26 | 26 |
|
27 | | -import numpy as np |
28 | 27 | import pytest |
29 | 28 |
|
30 | 29 | from typedpython import cbuild, cgen, frontend, ir, verify |
31 | 30 |
|
32 | 31 | SOURCE = textwrap.dedent(''' |
33 | 32 | # typedpython: compiled |
34 | 33 | import array |
35 | | - import numpy as np |
36 | | - import numpy.typing as npt |
37 | 34 |
|
38 | 35 |
|
39 | 36 | def sum_ad(a: array.array[float]) -> float: |
@@ -119,22 +116,13 @@ def rebind_view(a: array.array[float]) -> None: |
119 | 116 | y[0] = 5.0 |
120 | 117 |
|
121 | 118 |
|
122 | | - def nd_first(x: npt.NDArray[np.float64]) -> object: |
123 | | - return x[0] |
124 | | -
|
125 | | -
|
126 | | - def nd_sum(x: npt.NDArray[np.float64]) -> object: |
127 | | - s = 0.0 |
128 | | - for i in range(len(x)): |
129 | | - s += x[i] |
130 | | - return s |
131 | 119 | ''') |
132 | 120 |
|
133 | 121 | COMPILED = { |
134 | 122 | "sum_ad", "sum_aq", "get_ad", "get_aq", "set_ad", "set_aq", "length_ad", "scale_ad", "iota_aq", |
135 | 123 | "copy_ad", "cascade_ad", "fill_n", "mixed", "four", "div_ad", |
136 | 124 | } |
137 | | -SKIPPED = {"open_ad", "rebind_view", "nd_first", "nd_sum"} |
| 125 | +SKIPPED = {"open_ad", "rebind_view"} |
138 | 126 |
|
139 | 127 |
|
140 | 128 | def build_source(d, source, name="bufmod"): |
@@ -252,23 +240,6 @@ def wrapper_text(c, name): |
252 | 240 | return c[start:c.index("\n}\n", start)] |
253 | 241 |
|
254 | 242 |
|
255 | | -# --- numpy is not supported (#220): an ordinary object parameter ---------------------------------- |
256 | | - |
257 | | -def test_numpy_parameter_is_an_ordinary_object_and_keeps_numpy_results(built): |
258 | | - for f in built.proved.functions: |
259 | | - assert all(not isinstance(p, ir.ArrayParam) or p.buffer == "array" or p.buffer is None |
260 | | - for p in f.params) |
261 | | - assert not (f.name.startswith("nd_") and any(isinstance(p, ir.ArrayParam) for p in f.params)) |
262 | | - x = np.array(F, dtype=np.float64) |
263 | | - r = built.module.nd_first(x) |
264 | | - assert type(r) is np.float64 and r == F[0] |
265 | | - r = built.module.nd_sum(x) # never compiled: the module's plain function |
266 | | - ref = 0.0 |
267 | | - for v in x: |
268 | | - ref += v |
269 | | - assert type(r) is np.float64 and r == ref |
270 | | - |
271 | | - |
272 | 243 | # --- reads, writes, len --------------------------------------------------------------------------- |
273 | 244 |
|
274 | 245 | @pytest.mark.parametrize("name,make", [ |
@@ -375,7 +346,6 @@ class SubArray(array.array): |
375 | 346 | ("sum_ad", lambda: (array.array("f", [1.0, 2.0]),)), |
376 | 347 | ("sum_ad", lambda: (SubArray("d", F),)), |
377 | 348 | ("sum_ad", lambda: (list(F),)), |
378 | | - ("sum_ad", lambda: (np.array(F),)), |
379 | 349 | ("sum_ad", lambda: (memoryview(AD()),)), |
380 | 350 | ("sum_ad", lambda: (None,)), |
381 | 351 | ]) |
|
0 commit comments