Skip to content

Commit 2f5a453

Browse files
Improved efficiency of complex NumPy array construction
1 parent 3e14436 commit 2f5a453

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

dpctl/tests/elementwise/test_hyperbolic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_hyper_complex_contig(np_call, dpt_call, dtype):
100100
high = 9.0
101101
x1 = np.random.uniform(low=low, high=high, size=n_seq)
102102
x2 = np.random.uniform(low=low, high=high, size=n_seq)
103-
Xnp = np.array([complex(v1, v2) for v1, v2 in zip(x1, x2)], dtype=dtype)
103+
Xnp = x1 + 1j * x2
104104

105105
X = dpt.asarray(np.repeat(Xnp, n_rep), dtype=dtype, sycl_queue=q)
106106
Y = dpt_call(X)

dpctl/tests/elementwise/test_trigonometric.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,20 @@ def test_trig_complex_contig(np_call, dpt_call, dtype):
100100
high = 9.0
101101
x1 = np.random.uniform(low=low, high=high, size=n_seq)
102102
x2 = np.random.uniform(low=low, high=high, size=n_seq)
103-
Xnp = np.array([complex(v1, v2) for v1, v2 in zip(x1, x2)], dtype=dtype)
103+
Xnp = x1 + 1j * x2
104104

105105
X = dpt.asarray(np.repeat(Xnp, n_rep), dtype=dtype, sycl_queue=q)
106106
Y = dpt_call(X)
107107

108+
expected = np.repeat(np_call(Xnp), n_rep)
109+
108110
tol = 50 * dpt.finfo(dtype).resolution
109-
assert_allclose(
110-
dpt.asnumpy(Y), np.repeat(np_call(Xnp), n_rep), atol=tol, rtol=tol
111-
)
111+
assert_allclose(dpt.asnumpy(Y), expected, atol=tol, rtol=tol)
112112

113113
Z = dpt.empty_like(X, dtype=dtype)
114114
dpt_call(X, out=Z)
115115

116-
assert_allclose(
117-
dpt.asnumpy(Z), np.repeat(np_call(Xnp), n_rep), atol=tol, rtol=tol
118-
)
116+
assert_allclose(dpt.asnumpy(Z), expected, atol=tol, rtol=tol)
119117

120118

121119
@pytest.mark.parametrize("np_call, dpt_call", _all_funcs)

0 commit comments

Comments
 (0)