Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add lib.Arrayterator
  • Loading branch information
joaosferreira committed Aug 3, 2020
1 parent 57cf4de commit b1e875e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions unumpy/lib/__init__.py
@@ -0,0 +1 @@
from ._multimethods import *
12 changes: 12 additions & 0 deletions unumpy/lib/_multimethods.py
@@ -0,0 +1,12 @@
import functools
import operator
from uarray import create_multimethod, mark_as, all_of_type, Dispatchable
import builtins

create_numpy = functools.partial(create_multimethod, domain="numpy.lib")

from .._multimethods import ClassOverrideMetaWithConstructorAndGetAttr


class Arrayterator(metaclass=ClassOverrideMetaWithConstructorAndGetAttr):
pass
7 changes: 6 additions & 1 deletion unumpy/tests/test_numpy.py
Expand Up @@ -229,6 +229,7 @@ def replace_args_kwargs(method, backend, args, kwargs):
(np.nditer, ([[1, 2, 3]],), {}),
(np.ndenumerate, ([[1, 2], [3, 4]],), {}),
(np.ndindex, (3, 2, 1), {}),
(np.lib.Arrayterator, ([[1, 2], [3, 4]], 2), {}),
],
)
def test_functions_coerce(backend, method, args, kwargs):
Expand Down Expand Up @@ -277,7 +278,7 @@ def test_functions_coerce(backend, method, args, kwargs):
assert isinstance(ret, (bool,) + types)
elif method in {np.place, np.put, np.put_along_axis, np.putmask, np.fill_diagonal}:
assert ret is None
elif method in {np.nditer, np.ndenumerate, np.ndindex}:
elif method in {np.nditer, np.ndenumerate, np.ndindex, np.lib.Arrayterator}:
assert isinstance(ret, collections.abc.Iterator)
else:
assert isinstance(ret, types)
Expand Down Expand Up @@ -379,6 +380,10 @@ def test_multiple_output(backend, method, args, kwargs):
raise pytest.xfail(
reason="Sparse's methods for triangular matrices require an array with zero fill-values as argument."
)
except TypeError:
if backend is CupyBackend and method is np.unravel_index:
pytest.xfail(reason="cupy.unravel_index is broken in version 6.0")
raise
if method is np.nested_iters:
assert all(isinstance(ite, collections.abc.Iterator) for ite in ret)
else:
Expand Down

0 comments on commit b1e875e

Please sign in to comment.