Skip to content

Commit

Permalink
minor test import alias
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Jan 18, 2021
1 parent 4d75600 commit 9830fd0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,53 @@
import numpy as np
from pytest import mark, raises

import cuvec
import cuvec as cu

shape = 127, 344, 344


@mark.parametrize("spec,result", [("i", np.int32), ("d", np.float64)])
def test_zeros(spec, result):
a = np.asarray(cuvec.zeros(shape, spec))
a = np.asarray(cu.zeros(shape, spec))
assert a.dtype == result
assert a.shape == shape
assert not a.any()


def test_copy():
a = np.random.random(shape)
b = np.asarray(cuvec.copy(a))
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):
cuvec.CuVec()
cu.CuVec()

with raises(NotImplementedError):
cuvec.CuVec(shape)
cu.CuVec(shape)

caplog.set_level(logging.DEBUG)
caplog.clear()
v = cuvec.CuVec(np.ones(shape, dtype='h'))
v = cu.CuVec(np.ones(shape, dtype='h'))
assert [i[1:] for i in caplog.record_tuples] == [(10, 'copy'),
(10, "wrap raw <class 'Vector_h'>")]
assert v.shape == shape
assert v.dtype.char == 'h'
assert (v == 1).all()

caplog.clear()
v = cuvec.zeros(shape, 'd')
v = cu.zeros(shape, 'd')
assert [i[1:] for i in caplog.record_tuples] == [(10, "wrap raw <class 'Vector_d'>")]

caplog.clear()
v[0, 0, 0] = 1
assert not caplog.record_tuples
w = cuvec.CuVec(v)
w = cu.CuVec(v)
assert [i[1:] for i in caplog.record_tuples] == [(10, "new view")]
assert cuvec.asarray(w.cuvec).cuvec == w.cuvec
assert cu.asarray(w.cuvec).cuvec == w.cuvec

caplog.clear()
assert w[0, 0, 0] == 1
Expand Down
8 changes: 4 additions & 4 deletions tests/test_pycuvec.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import numpy as np
from pytest import mark

import cuvec
import cuvec as cu


@mark.parametrize("tp", list(cuvec.typecodes))
@mark.parametrize("tp", list(cu.typecodes))
def test_Vector_asarray(tp):
"""tp(char): any of bBhHiIqQfd"""
v = getattr(cuvec.cuvec, f"Vector_{tp}")((1, 2, 3))
v = getattr(cu.cuvec, f"Vector_{tp}")((1, 2, 3))
assert str(v) == f"Vector_{tp}((1, 2, 3))"
a = np.asarray(v)
assert not a.any()
Expand All @@ -21,7 +21,7 @@ def test_Vector_asarray(tp):

def test_Vector_strides():
shape = 127, 344, 344
v = cuvec.cuvec.Vector_f(shape)
v = cu.cuvec.Vector_f(shape)
a = np.asarray(v)
assert a.shape == shape
assert a.strides == (473344, 1376, 4)

0 comments on commit 9830fd0

Please sign in to comment.