diff --git a/cuvec/_common.py b/cuvec/_utils.py similarity index 100% rename from cuvec/_common.py rename to cuvec/_utils.py diff --git a/cuvec/cpython.py b/cuvec/cpython.py index 2f81051..5ae4625 100644 --- a/cuvec/cpython.py +++ b/cuvec/cpython.py @@ -7,7 +7,7 @@ import numpy as np from . import cuvec_cpython as cu -from ._common import Shape, _generate_helpers, typecodes +from ._utils import Shape, _generate_helpers, typecodes __all__ = [ 'CuVec', 'zeros', 'ones', 'zeros_like', 'ones_like', 'copy', 'asarray', 'Shape', 'typecodes'] diff --git a/cuvec/pybind11.py b/cuvec/pybind11.py index 8e186d4..578e206 100644 --- a/cuvec/pybind11.py +++ b/cuvec/pybind11.py @@ -13,7 +13,7 @@ import numpy as np from . import cuvec_pybind11 as cu # type: ignore [attr-defined] # yapf: disable -from ._common import CVector, Shape, _generate_helpers, typecodes +from ._utils import CVector, Shape, _generate_helpers, typecodes __all__ = [ 'CuVec', 'zeros', 'ones', 'zeros_like', 'ones_like', 'copy', 'asarray', 'retarray', 'Shape', @@ -69,14 +69,14 @@ def __new__(cls, arr): if Pybind11Vector.is_instance(arr): log.debug("wrap pyraw %s", type(arr)) obj = np.asarray(arr).view(cls) - obj.pyvec = arr + obj._vec = arr obj.cuvec = arr.cuvec return obj - if isinstance(arr, CuVec) and hasattr(arr, 'pyvec'): + if isinstance(arr, CuVec) and hasattr(arr, '_vec'): log.debug("new view") obj = np.asarray(arr).view(cls) - obj.pyvec = arr.pyvec - obj.cuvec = arr.pyvec.cuvec + obj._vec = arr._vec + obj.cuvec = arr._vec.cuvec return obj if isinstance(arr, np.ndarray): log.debug("copy") @@ -94,11 +94,11 @@ def __cuda_array_interface__(self) -> Dict[str, Any]: dedent("""\ `numpy.ndarray` object has no attribute `cuvec`: try using `cuvec.asarray()` first.""")) - return self.pyvec.__cuda_array_interface__ + return self._vec.__cuda_array_interface__ def resize(self, new_shape: Shape): """Change shape (but not size) of array in-place.""" - self.pyvec.shape = new_shape + self._vec.shape = new_shape super().resize(new_shape, refcheck=False) diff --git a/cuvec/swig.py b/cuvec/swig.py index 912749e..a1c2d02 100644 --- a/cuvec/swig.py +++ b/cuvec/swig.py @@ -13,7 +13,7 @@ import numpy as np from . import swvec as sw # type: ignore [attr-defined] # yapf: disable -from ._common import CVector, Shape, _generate_helpers, typecodes +from ._utils import CVector, Shape, _generate_helpers, typecodes __all__ = [ 'CuVec', 'zeros', 'ones', 'zeros_like', 'ones_like', 'copy', 'asarray', 'retarray', 'Shape', @@ -75,14 +75,14 @@ def __new__(cls, arr): if SWIGVector.is_instance(arr): log.debug("wrap swraw %s", type(arr)) obj = np.asarray(arr).view(cls) - obj.swvec = arr + obj._vec = arr obj.cuvec = arr.cuvec return obj - if isinstance(arr, CuVec) and hasattr(arr, 'swvec'): + if isinstance(arr, CuVec) and hasattr(arr, '_vec'): log.debug("new view") obj = np.asarray(arr).view(cls) - obj.swvec = arr.swvec - obj.cuvec = arr.swvec.cuvec + obj._vec = arr._vec + obj.cuvec = arr._vec.cuvec return obj if isinstance(arr, np.ndarray): log.debug("copy") @@ -100,11 +100,11 @@ def __cuda_array_interface__(self) -> Dict[str, Any]: dedent("""\ `numpy.ndarray` object has no attribute `cuvec`: try using `cuvec.asarray()` first.""")) - return self.swvec.__cuda_array_interface__ + return self._vec.__cuda_array_interface__ def resize(self, new_shape: Shape): """Change shape (but not size) of array in-place.""" - self.swvec.shape = new_shape + self._vec.shape = new_shape super().resize(new_shape, refcheck=False) diff --git a/tests/test_common.py b/tests/test_common.py index 8c23ed5..7ce3c82 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -1,4 +1,30 @@ +"""Common (parameterised) tests for cuvec.{cpython,pybind11,swig}""" +import logging + +import numpy as np +from pytest import importorskip, mark, raises + import cuvec as cu +import cuvec.cpython as cp + +try: + # `cuvec.swig` alternative to `cuvec.cpython` + # `example_swig` is defined in ../cuvec/src/example_swig/ + from cuvec import example_swig # type: ignore # yapf: disable + from cuvec import swig as sw +except ImportError: + sw, example_swig = None, None # type: ignore # yapf: disable + +try: + # `cuvec.pybind11` alternative to `cuvec.cpython` + # `example_pybind11` is defined in ../cuvec/src/example_pybind11/ + from cuvec import example_pybind11 # type: ignore # yapf: disable + from cuvec import pybind11 as py +except ImportError: + py, example_pybind11 = None, None # type: ignore # yapf: disable + + +shape = 127, 344, 344 def test_includes(): @@ -14,3 +40,167 @@ def test_cmake_prefix(): for i in cu.cmake_prefix.iterdir()} == { f'AMYPADcuvec{i}.cmake' for i in ('Config', 'ConfigVersion', 'Targets', 'Targets-release')} + + +@mark.parametrize("cu,CVector", [(py, 'Pybind11Vector'), (sw, 'SWIGVector')]) +def test_CVector_strides(cu, CVector): + v = getattr(cu, CVector)('f', shape) + a = np.asarray(v) + assert a.shape == shape + assert a.strides == (473344, 1376, 4) + + +@mark.parametrize("spec,result", [("i", np.int32), ("d", np.float64)]) +@mark.parametrize("init", ["zeros", "ones"]) +@mark.parametrize("cu", [cp, py, sw]) +def test_create(cu, init, spec, result): + a = np.asarray(getattr(cu, init)(shape, spec)) + assert a.dtype == result + assert a.shape == shape + assert (a == (0 if init == 'zeros' else 1)).all() + + b = getattr(cu, f'{init}_like')(a) + assert b.shape == a.shape + assert b.dtype == a.dtype + + +@mark.parametrize("cu", [cp, py, sw]) +def test_copy(cu): + a = np.random.random(shape) + b = np.asarray(cu.copy(a)) + assert a.shape == b.shape + assert a.dtype == b.dtype + assert (a == b).all() + + +@mark.parametrize("cu,classname", [(cp, "raw "), + (py, "pyraw "), + (sw, "swraw ")]) +def test_CuVec_creation(cu, classname, caplog): + with raises(TypeError): + cu.CuVec() + + with raises(NotImplementedError): + cu.CuVec(shape) + + caplog.set_level(logging.DEBUG) + caplog.clear() + v = cu.CuVec(np.ones(shape, dtype='h')) + assert [i[1:] for i in caplog.record_tuples] == [ + (10, 'copy'), (10, f"wrap {classname}".format(typechar='h'))] + assert v.shape == shape + assert v.dtype.char == 'h' + assert (v == 1).all() + + caplog.clear() + v = cu.zeros(shape, 'd') + assert [i[1:] for i in caplog.record_tuples] == [ + (10, f"wrap {classname}".format(typechar='d'))] + + caplog.clear() + v[0, 0, 0] = 1 + assert not caplog.record_tuples + w = cu.CuVec(v) + assert [i[1:] for i in caplog.record_tuples] == [(10, "new view")] + + caplog.clear() + assert w[0, 0, 0] == 1 + v[0, 0, 0] = 9 + assert w[0, 0, 0] == 9 + assert v.cuvec is w.cuvec + assert v.data == w.data + assert not caplog.record_tuples + + +@mark.parametrize("cu", [py, sw]) +def test_asarray(cu): + v = cu.asarray(np.random.random(shape)) + w = cu.CuVec(v) + assert w.cuvec == v.cuvec + assert (w == v).all() + assert str(w._vec) == str(v._vec) + assert np.asarray(w._vec).data == np.asarray(v._vec).data + x = cu.asarray(w._vec) + assert x.cuvec == v.cuvec + assert (x == v).all() + assert str(x._vec) == str(v._vec) + assert np.asarray(x._vec).data == np.asarray(v._vec).data + y = cu.asarray(x.tolist()) + assert y.cuvec != v.cuvec + assert (y == v).all() + assert str(y._vec) != str(v._vec) + assert np.asarray(y._vec).data == np.asarray(v._vec).data + z = cu.asarray(v[:]) + assert z.cuvec != v.cuvec + assert (z == v[:]).all() + assert str(z._vec) != str(v._vec) + assert np.asarray(z._vec).data == np.asarray(v._vec).data + s = cu.asarray(v[1:]) + assert s.cuvec != v.cuvec + assert (s == v[1:]).all() + assert str(s._vec) != str(v._vec) + assert np.asarray(s._vec).data != np.asarray(v._vec).data + with raises(IOError): + cu.asarray(s._vec.cuvec, ownership='error') + + +@mark.parametrize("cu", [py, sw]) +def test_resize(cu): + v = cu.asarray(np.random.random(shape)) + v.resize(shape[::-1]) + assert v.shape == shape[::-1] + assert v._vec.shape == v.shape + v.resize(v.size) + assert v.shape == (v.size,) + assert v._vec.shape == v.shape + + +@mark.parametrize("cu", [cp, py, sw]) +def test_cuda_array_interface(cu, dev_sync): + cupy = importorskip("cupy") + v = cu.asarray(np.random.random(shape)) + assert hasattr(v, '__cuda_array_interface__') + + c = cupy.asarray(v) + assert (c == v).all() + c[0, 0, 0] = 1 + dev_sync() + assert c[0, 0, 0] == v[0, 0, 0] + c[0, 0, 0] = 0 + dev_sync() + assert c[0, 0, 0] == v[0, 0, 0] + + d = cupy.asarray(v._vec) + d[0, 0, 0] = 1 + dev_sync() + assert d[0, 0, 0] == c[0, 0, 0] == v[0, 0, 0] + d[0, 0, 0] = 0 + dev_sync() + assert d[0, 0, 0] == c[0, 0, 0] == v[0, 0, 0] + + ndarr = v + 1 + assert ndarr.shape == v.shape + assert ndarr.dtype == v.dtype + with raises(AttributeError): + ndarr.__cuda_array_interface__ + + +@mark.parametrize("cu,ex", [(py, example_pybind11), (sw, example_swig)]) +def test_increment(cu, ex): + a = cu.zeros((1337, 42), 'f') + assert (a == 0).all() + ex.increment2d_f(a.cuvec, a.cuvec) + assert (a == 1).all() + + a[:] = 0 + assert (a == 0).all() + + b = cu.retarray(ex.increment2d_f(a.cuvec)) + assert (b == 1).all() + + c = cu.retarray(ex.increment2d_f(b.cuvec, a.cuvec), a) + assert (a == 2).all() + assert c.cuvec == a.cuvec + assert (c == a).all() + assert str(c._vec) == str(a._vec) + assert np.asarray(c._vec).data == np.asarray(a._vec).data diff --git a/tests/test_cpython.py b/tests/test_cpython.py index 1672918..1642f1e 100644 --- a/tests/test_cpython.py +++ b/tests/test_cpython.py @@ -1,7 +1,5 @@ -import logging - import numpy as np -from pytest import importorskip, mark, raises +from pytest import mark, raises import cuvec.cpython as cu from cuvec import cuvec_cpython @@ -23,69 +21,13 @@ def test_PyCuVec_asarray(tp): del a, b, v -def test_PyCuVec_strides(): +def test_CVector_strides(): v = cuvec_cpython.PyCuVec_f(shape) a = np.asarray(v) assert a.shape == shape assert a.strides == (473344, 1376, 4) -@mark.parametrize("spec,result", [("i", np.int32), ("d", np.float64)]) -@mark.parametrize("init", ["zeros", "ones"]) -def test_create(init, spec, result): - a = np.asarray(getattr(cu, init)(shape, spec)) - assert a.dtype == result - assert a.shape == shape - assert (a == (0 if init == 'zeros' else 1)).all() - - b = getattr(cu, f'{init}_like')(a) - assert b.shape == a.shape - assert b.dtype == a.dtype - - -def test_copy(): - a = np.random.random(shape) - b = np.asarray(cu.copy(a)) - assert a.shape == b.shape - assert a.dtype == b.dtype - assert (a == b).all() - - -def test_CuVec_creation(caplog): - with raises(TypeError): - cu.CuVec() - - with raises(NotImplementedError): - cu.CuVec(shape) - - caplog.set_level(logging.DEBUG) - caplog.clear() - v = cu.CuVec(np.ones(shape, dtype='h')) - assert [i[1:] for i in caplog.record_tuples] == [(10, 'copy'), - (10, "wrap raw ")] - assert v.shape == shape - assert v.dtype.char == 'h' - assert (v == 1).all() - - caplog.clear() - v = cu.zeros(shape, 'd') - assert [i[1:] for i in caplog.record_tuples] == [(10, "wrap raw ")] - - caplog.clear() - v[0, 0, 0] = 1 - assert not caplog.record_tuples - w = cu.CuVec(v) - assert [i[1:] for i in caplog.record_tuples] == [(10, "new view")] - - caplog.clear() - assert w[0, 0, 0] == 1 - v[0, 0, 0] = 9 - assert w[0, 0, 0] == 9 - assert v.cuvec is w.cuvec - assert v.data == w.data - assert not caplog.record_tuples - - def test_asarray(): v = cu.asarray(np.random.random(shape)) w = cu.CuVec(v) @@ -110,27 +52,6 @@ def test_asarray(): assert np.asarray(s.cuvec).data != np.asarray(v.cuvec).data -def test_cuda_array_interface(dev_sync): - cupy = importorskip("cupy") - v = cu.asarray(np.random.random(shape)) - assert hasattr(v, '__cuda_array_interface__') - - c = cupy.asarray(v) - assert (c == v).all() - c[0, 0, 0] = 1 - dev_sync() - assert c[0, 0, 0] == v[0, 0, 0] - c[0, 0, 0] = 0 - dev_sync() - assert c[0, 0, 0] == v[0, 0, 0] - - ndarr = v + 1 - assert ndarr.shape == v.shape - assert ndarr.dtype == v.dtype - with raises(AttributeError): - ndarr.__cuda_array_interface__ - - def test_increment(): # `example_mod` is defined in ../cuvec/src/example_mod/ from cuvec.example_mod import increment2d_f diff --git a/tests/test_pybind11.py b/tests/test_pybind11.py index 35bd933..006e9f1 100644 --- a/tests/test_pybind11.py +++ b/tests/test_pybind11.py @@ -1,7 +1,5 @@ -import logging - import numpy as np -from pytest import importorskip, mark, raises +from pytest import importorskip, mark cu = importorskip("cuvec.pybind11") shape = 127, 344, 344 @@ -19,159 +17,3 @@ def test_Pybind11Vector_asarray(tp): assert not b[1:, 1:].any() assert a.dtype == np.dtype(tp) del a, b, v - - -def test_Pybind11Vector_strides(): - v = cu.Pybind11Vector('f', shape) - a = np.asarray(v) - assert a.shape == shape - assert a.strides == (473344, 1376, 4) - - -@mark.parametrize("spec,result", [("i", np.int32), ("d", np.float64)]) -@mark.parametrize("init", ["zeros", "ones"]) -def test_create(init, spec, result): - a = np.asarray(getattr(cu, init)(shape, spec)) - assert a.dtype == result - assert a.shape == shape - assert (a == (0 if init == 'zeros' else 1)).all() - - b = getattr(cu, f'{init}_like')(a) - assert b.shape == a.shape - assert b.dtype == a.dtype - - -def test_copy(): - a = np.random.random(shape) - b = np.asarray(cu.copy(a)) - assert a.shape == b.shape - assert a.dtype == b.dtype - assert (a == b).all() - - -def test_CuVec_creation(caplog): - with raises(TypeError): - cu.CuVec() - - with raises(NotImplementedError): - cu.CuVec(shape) - - caplog.set_level(logging.DEBUG) - caplog.clear() - v = cu.CuVec(np.ones(shape, dtype='h')) - assert [i[1:] for i in caplog.record_tuples] == [ - (10, 'copy'), (10, "wrap pyraw ")] - assert v.shape == shape - assert v.dtype.char == 'h' - assert (v == 1).all() - - caplog.clear() - v = cu.zeros(shape, 'd') - assert [i[1:] for i in caplog.record_tuples] == [ - (10, "wrap pyraw ")] - - caplog.clear() - v[0, 0, 0] = 1 - assert not caplog.record_tuples - w = cu.CuVec(v) - assert [i[1:] for i in caplog.record_tuples] == [(10, "new view")] - - caplog.clear() - assert w[0, 0, 0] == 1 - v[0, 0, 0] = 9 - assert w[0, 0, 0] == 9 - assert v.cuvec is w.cuvec - assert v.data == w.data - assert not caplog.record_tuples - - -def test_asarray(): - v = cu.asarray(np.random.random(shape)) - w = cu.CuVec(v) - assert w.cuvec == v.cuvec - assert (w == v).all() - assert str(w.pyvec) == str(v.pyvec) - assert np.asarray(w.pyvec).data == np.asarray(v.pyvec).data - x = cu.asarray(w.pyvec) - assert x.cuvec == v.cuvec - assert (x == v).all() - assert str(x.pyvec) == str(v.pyvec) - assert np.asarray(x.pyvec).data == np.asarray(v.pyvec).data - y = cu.asarray(x.tolist()) - assert y.cuvec != v.cuvec - assert (y == v).all() - assert str(y.pyvec) != str(v.pyvec) - assert np.asarray(y.pyvec).data == np.asarray(v.pyvec).data - z = cu.asarray(v[:]) - assert z.cuvec != v.cuvec - assert (z == v[:]).all() - assert str(z.pyvec) != str(v.pyvec) - assert np.asarray(z.pyvec).data == np.asarray(v.pyvec).data - s = cu.asarray(v[1:]) - assert s.cuvec != v.cuvec - assert (s == v[1:]).all() - assert str(s.pyvec) != str(v.pyvec) - assert np.asarray(s.pyvec).data != np.asarray(v.pyvec).data - with raises(IOError): - cu.asarray(s.pyvec.cuvec, ownership='error') - - -def test_resize(): - v = cu.asarray(np.random.random(shape)) - v.resize(shape[::-1]) - assert v.shape == shape[::-1] - assert v.pyvec.shape == v.shape - v.resize(v.size) - assert v.shape == (v.size,) - assert v.pyvec.shape == v.shape - - -def test_cuda_array_interface(dev_sync): - cupy = importorskip("cupy") - v = cu.asarray(np.random.random(shape)) - assert hasattr(v, '__cuda_array_interface__') - - c = cupy.asarray(v) - assert (c == v).all() - c[0, 0, 0] = 1 - dev_sync() - assert c[0, 0, 0] == v[0, 0, 0] - c[0, 0, 0] = 0 - dev_sync() - assert c[0, 0, 0] == v[0, 0, 0] - - d = cupy.asarray(v.pyvec) - d[0, 0, 0] = 1 - dev_sync() - assert d[0, 0, 0] == v[0, 0, 0] - d[0, 0, 0] = 0 - dev_sync() - assert d[0, 0, 0] == v[0, 0, 0] - - ndarr = v + 1 - assert ndarr.shape == v.shape - assert ndarr.dtype == v.dtype - with raises(AttributeError): - ndarr.__cuda_array_interface__ - - -def test_increment(): - # `example_pybind11` is defined in ../cuvec/src/example_pybind11/ - from cuvec.example_pybind11 import increment2d_f - a = cu.zeros((1337, 42), 'f') - assert (a == 0).all() - increment2d_f(a.cuvec, a.cuvec) - assert (a == 1).all() - - a[:] = 0 - assert (a == 0).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.pyvec) == str(a.pyvec) - assert np.asarray(c.pyvec).data == np.asarray(a.pyvec).data diff --git a/tests/test_swig.py b/tests/test_swig.py index ce4446f..efebc34 100644 --- a/tests/test_swig.py +++ b/tests/test_swig.py @@ -1,7 +1,5 @@ -import logging - import numpy as np -from pytest import importorskip, mark, raises +from pytest import importorskip, mark cu = importorskip("cuvec.swig") shape = 127, 344, 344 @@ -19,159 +17,3 @@ def test_SWIGVector_asarray(tp): assert not b[1:, 1:].any() assert a.dtype == np.dtype(tp) del a, b, v - - -def test_PyCuVec_strides(): - v = cu.SWIGVector('f', shape) - a = np.asarray(v) - assert a.shape == shape - assert a.strides == (473344, 1376, 4) - - -@mark.parametrize("spec,result", [("i", np.int32), ("d", np.float64)]) -@mark.parametrize("init", ["zeros", "ones"]) -def test_create(init, spec, result): - a = np.asarray(getattr(cu, init)(shape, spec)) - assert a.dtype == result - assert a.shape == shape - assert (a == (0 if init == 'zeros' else 1)).all() - - b = getattr(cu, f'{init}_like')(a) - assert b.shape == a.shape - assert b.dtype == a.dtype - - -def test_copy(): - a = np.random.random(shape) - b = np.asarray(cu.copy(a)) - assert a.shape == b.shape - assert a.dtype == b.dtype - assert (a == b).all() - - -def test_CuVec_creation(caplog): - with raises(TypeError): - cu.CuVec() - - with raises(NotImplementedError): - cu.CuVec(shape) - - caplog.set_level(logging.DEBUG) - caplog.clear() - v = cu.CuVec(np.ones(shape, dtype='h')) - assert [i[1:] for i in caplog.record_tuples] == [ - (10, 'copy'), (10, "wrap swraw ")] - assert v.shape == shape - assert v.dtype.char == 'h' - assert (v == 1).all() - - caplog.clear() - v = cu.zeros(shape, 'd') - assert [i[1:] for i in caplog.record_tuples] == [ - (10, "wrap swraw ")] - - caplog.clear() - v[0, 0, 0] = 1 - assert not caplog.record_tuples - w = cu.CuVec(v) - assert [i[1:] for i in caplog.record_tuples] == [(10, "new view")] - - caplog.clear() - assert w[0, 0, 0] == 1 - v[0, 0, 0] = 9 - assert w[0, 0, 0] == 9 - assert v.cuvec is w.cuvec - assert v.data == w.data - assert not caplog.record_tuples - - -def test_asarray(): - v = cu.asarray(np.random.random(shape)) - w = cu.CuVec(v) - assert w.cuvec == v.cuvec - assert (w == v).all() - assert str(w.swvec) == str(v.swvec) - assert np.asarray(w.swvec).data == np.asarray(v.swvec).data - x = cu.asarray(w.swvec) - assert x.cuvec == v.cuvec - assert (x == v).all() - assert str(x.swvec) == str(v.swvec) - assert np.asarray(x.swvec).data == np.asarray(v.swvec).data - y = cu.asarray(x.tolist()) - assert y.cuvec != v.cuvec - assert (y == v).all() - assert str(y.swvec) != str(v.swvec) - assert np.asarray(y.swvec).data == np.asarray(v.swvec).data - z = cu.asarray(v[:]) - assert z.cuvec != v.cuvec - assert (z == v[:]).all() - assert str(z.swvec) != str(v.swvec) - assert np.asarray(z.swvec).data == np.asarray(v.swvec).data - s = cu.asarray(v[1:]) - assert s.cuvec != v.cuvec - assert (s == v[1:]).all() - assert str(s.swvec) != str(v.swvec) - assert np.asarray(s.swvec).data != np.asarray(v.swvec).data - with raises(IOError): - cu.asarray(s.swvec.cuvec, ownership='error') - - -def test_resize(): - v = cu.asarray(np.random.random(shape)) - v.resize(shape[::-1]) - assert v.shape == shape[::-1] - assert v.swvec.shape == v.shape - v.resize(v.size) - assert v.shape == (v.size,) - assert v.swvec.shape == v.shape - - -def test_cuda_array_interface(dev_sync): - cupy = importorskip("cupy") - v = cu.asarray(np.random.random(shape)) - assert hasattr(v, '__cuda_array_interface__') - - c = cupy.asarray(v) - assert (c == v).all() - c[0, 0, 0] = 1 - dev_sync() - assert c[0, 0, 0] == v[0, 0, 0] - c[0, 0, 0] = 0 - dev_sync() - assert c[0, 0, 0] == v[0, 0, 0] - - d = cupy.asarray(v.swvec) - d[0, 0, 0] = 1 - dev_sync() - assert d[0, 0, 0] == v[0, 0, 0] - d[0, 0, 0] = 0 - dev_sync() - assert d[0, 0, 0] == v[0, 0, 0] - - ndarr = v + 1 - assert ndarr.shape == v.shape - assert ndarr.dtype == v.dtype - with raises(AttributeError): - ndarr.__cuda_array_interface__ - - -def test_increment(): - # `example_swig` is defined in ../cuvec/src/example_swig/ - from cuvec.example_swig import increment2d_f - a = cu.zeros((1337, 42), 'f') - assert (a == 0).all() - increment2d_f(a.cuvec, a.cuvec) - assert (a == 1).all() - - a[:] = 0 - assert (a == 0).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