Skip to content

Commit

Permalink
fix asarray not copying on CuVec views
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Jan 24, 2021
1 parent d366923 commit 335d3cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cuvec/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __new__(cls, arr):
obj = np.asarray(arr).view(cls)
obj.cuvec = arr
return obj
if isinstance(arr, CuVec):
if isinstance(arr, CuVec) and hasattr(arr, 'cuvec'):
log.debug("new view")
obj = np.asarray(arr).view(cls)
obj.cuvec = arr.cuvec
Expand Down
8 changes: 8 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@ def test_asarray():
assert y.cuvec != v.cuvec
assert (y == v).all()
assert np.asarray(y.cuvec).data == np.asarray(v.cuvec).data
z = cu.asarray(v[:])
assert z.cuvec != v.cuvec
assert (z == v[:]).all()
assert np.asarray(z.cuvec).data == np.asarray(v.cuvec).data
s = cu.asarray(v[1:])
assert s.cuvec != v.cuvec
assert (s == v[1:]).all()
assert np.asarray(s.cuvec).data != np.asarray(v.cuvec).data

0 comments on commit 335d3cd

Please sign in to comment.