Skip to content

Commit d8c670a

Browse files
Added tests for T, real, imag methods of the object inspired by #649
1 parent b1a1b50 commit d8c670a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

dpctl/tests/test_usm_ndarray_ctor.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,3 +841,25 @@ def test_reshape():
841841
dpt.reshape(Z, Z.shape, order="invalid")
842842
W = dpt.reshape(Z, (-1,), order="C")
843843
assert W.shape == (Z.size,)
844+
845+
846+
def test_transpose():
847+
n, m = 2, 3
848+
X = dpt.usm_ndarray((n, m), "f4")
849+
Xnp = np.arange(n * m, dtype="f4").reshape((n, m))
850+
X[:] = Xnp
851+
assert np.array_equal(dpt.to_numpy(X.T), Xnp.T)
852+
assert np.array_equal(dpt.to_numpy(X[1:].T), Xnp[1:].T)
853+
854+
855+
def test_real_imag_views():
856+
n, m = 2, 3
857+
X = dpt.usm_ndarray((n, m), "c8")
858+
Xnp_r = np.arange(n * m, dtype="f4").reshape((n, m))
859+
Xnp_i = np.arange(n * m, 2 * n * m, dtype="f4").reshape((n, m))
860+
Xnp = Xnp_r + 1j * Xnp_i
861+
X[:] = Xnp
862+
assert np.array_equal(dpt.to_numpy(X.real), Xnp.real)
863+
assert np.array_equal(dpt.to_numpy(X.imag), Xnp.imag)
864+
assert np.array_equal(dpt.to_numpy(X[1:].real), Xnp[1:].real)
865+
assert np.array_equal(dpt.to_numpy(X[1:].imag), Xnp[1:].imag)

0 commit comments

Comments
 (0)