-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
94 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
import re | ||
|
||
import numpy as np | ||
from pytest import importorskip, mark | ||
from pytest import importorskip, mark, raises | ||
|
||
cu = importorskip("cuvec.pybind11") | ||
cuvec_pybind11 = importorskip("cuvec.cuvec_pybind11") | ||
ex = importorskip("cuvec.example_pybind11") | ||
|
||
|
||
@mark.parametrize("tp", list(cu.typecodes)) | ||
def test_Pybind11Vector_asarray(tp): | ||
v = cu.Pybind11Vector(tp, (1, 2, 3)) | ||
assert repr(v) == f"Pybind11Vector('{tp}', (1, 2, 3))" | ||
def test_NDCuVec_asarray(tp): | ||
v = getattr(cuvec_pybind11, f"NDCuVec_{tp}")((1, 2, 3)) | ||
assert re.match(f"<cuvec.cuvec_pybind11.NDCuVec_{tp} object at 0x[0-9a-f]+>", str(v)) | ||
a = np.asarray(v) | ||
assert not a.any() | ||
a[0, 0] = 42 | ||
b = np.asarray(v) | ||
assert (b[0, 0] == 42).all() | ||
assert not b[1:, 1:].any() | ||
assert a.dtype == np.dtype(tp) | ||
assert a.dtype.char == tp | ||
del a, b, v | ||
|
||
|
||
def test_np_types(): | ||
f = cu.zeros((1337, 42), 'f') | ||
d = cu.zeros((1337, 42), 'd') | ||
cu.asarray(ex.increment2d_f(f.cuvec)) | ||
cu.asarray(ex.increment2d_f(f.cuvec, f.cuvec)) | ||
with raises(TypeError): | ||
cu.asarray(ex.increment2d_f(d.cuvec)) | ||
with raises(TypeError): | ||
cu.asarray(ex.increment2d_f(f.cuvec, d.cuvec)) |