Skip to content

Commit

Permalink
tests: increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed May 16, 2023
1 parent 8331390 commit 4d64963
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cuvec/swigcuvec.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def asarray(arr, dtype=None, order=None, ownership: str = 'warning') -> CuVec:
Instead, use the `retarray` helper:
>>> raw = some_swig_api_func(..., output=getattr(out, 'cuvec', None))
>>> res = retarray(raw, out)
NB: `asarray()` is safe if the raw cuvec was created in C++/SWIG, e.g.:
>>> res = asarray(some_swig_api_func(..., output=None), ownership='debug')
NB: `asarray()`/`retarray()` are safe if the raw cuvec was created in C++/SWIG, e.g.:
>>> res = retarray(some_swig_api_func(..., output=None))
"""
if is_raw_cuvec(arr):
ownership = ownership.lower()
Expand Down
11 changes: 9 additions & 2 deletions tests/test_swigcuvec.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,12 @@ def test_increment():
a[:] = 0
assert (a == 0).all()

res = cu.asarray(increment2d_f(a.cuvec), ownership='debug')
assert (res == 1).all()
b = cu.retarray(increment2d_f(a.cuvec))
assert (b == 1).all()

c = cu.retarray(increment2d_f(b.cuvec, a.cuvec), a)
assert (a == 2).all()
assert c.cuvec == a.cuvec
assert (c == a).all()
assert str(c.swvec) == str(a.swvec)
assert np.asarray(c.swvec).data == np.asarray(a.swvec).data

0 comments on commit 4d64963

Please sign in to comment.