Skip to content

Commit 4a20615

Browse files
Use .transpose instead of .T to avoid DeprecationWarning
1 parent 178c014 commit 4a20615

File tree

9 files changed

+33
-25
lines changed

9 files changed

+33
-25
lines changed

dpnp/linalg/dpnp_utils_linalg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,14 +2210,14 @@ def dpnp_lstsq(a, b, rcond=None):
22102210

22112211
# Solve the least-squares solution
22122212
# x = vh.T.conj() @ diag(s1) @ u.T.conj() @ b
2213-
z = (dpnp.dot(b.T, u.conj()) * s1).T
2214-
x = dpnp.dot(vh.T.conj(), z)
2213+
z = (dpnp.dot(b.transpose(), u.conj()) * s1).transpose()
2214+
x = dpnp.dot(vh.transpose().conj(), z)
22152215
# Calculate squared Euclidean 2-norm for each column in b - a*x
22162216
if m <= n or rank != n:
22172217
resids = dpnp.empty_like(s, shape=(0,))
22182218
else:
22192219
e = b - a.dot(x)
2220-
resids = dpnp.atleast_1d(_nrm2_last_axis(e.T))
2220+
resids = dpnp.atleast_1d(_nrm2_last_axis(e.transpose()))
22212221

22222222
return x, resids, rank, s
22232223

dpnp/tests/test_linalg.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -879,25 +879,33 @@ def check_einsum_sums(self, dtype, do_opt=False):
879879
b = numpy.arange(n, dtype=dtype)
880880
a_dp = dpnp.array(a)
881881
b_dp = dpnp.array(b)
882-
expected = numpy.einsum("ji,j", a.T, b.T, optimize=do_opt)
883-
result = dpnp.einsum("ji,j", a_dp.T, b_dp.T, optimize=do_opt)
882+
expected = numpy.einsum(
883+
"ji,j", a.transpose(), b.transpose(), optimize=do_opt
884+
)
885+
result = dpnp.einsum(
886+
"ji,j", a_dp.transpose(), b_dp.transpose(), optimize=do_opt
887+
)
884888
assert_dtype_allclose(result, expected)
885889

886890
result = dpnp.einsum(
887-
a_dp.T, [1, 0], b_dp.T, [1], optimize=do_opt
891+
a_dp.transpose(),
892+
[1, 0],
893+
b_dp.transpose(),
894+
[1],
895+
optimize=do_opt,
888896
)
889897
assert_dtype_allclose(result, expected)
890898

891899
c = dpnp.arange(4, dtype=a_dp.dtype)
892-
args = ["ji,j", a_dp.T, b_dp.T]
900+
args = ["ji,j", a_dp.transpose(), b_dp.transpose()]
893901
result = dpnp.einsum(
894902
*args, out=c, dtype="f4", casting="unsafe", optimize=do_opt
895903
)
896904
assert result is c
897905
assert_dtype_allclose(result, expected)
898906

899907
c[...] = 0
900-
args = [a_dp.T, [1, 0], b_dp.T, [1]]
908+
args = [a_dp.transpose(), [1, 0], b_dp.transpose(), [1]]
901909
result = dpnp.einsum(
902910
*args, out=c, dtype="f4", casting="unsafe", optimize=do_opt
903911
)

dpnp/tests/test_strides.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ def test_2args_in_out(func, dtype):
316316
b = numpy.full(sh, fill_value=0.7, dtype=dtype)
317317
ia, ib = dpnp.array(a), dpnp.array(b)
318318

319-
a, b = a[::2], b[::2].T
320-
ia, ib = ia[::2], ib[::2].T
319+
a, b = a[::2], b[::2].transpose()
320+
ia, ib = ia[::2], ib[::2].transpose()
321321

322322
expected = getattr(numpy, func)(a, b, out=out)
323323
result = getattr(dpnp, func)(ia, ib, out=iout)

dpnp/tests/test_sum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def test_sum(shape, dtype_in, dtype_out, transpose, keepdims, order):
4141
a = dpnp.asarray(a_np)
4242

4343
if transpose:
44-
a_np = a_np.T
45-
a = a.T
44+
a_np = a_np.transpose()
45+
a = a.transpose()
4646

4747
axes_range = list(numpy.arange(len(shape)))
4848
axes = [None]

dpnp/tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_view_non_contiguous_raise(self, dtype):
6666
def test_view_f_contiguous(self, dtype):
6767
for xp in (numpy, cupy):
6868
a = testing.shaped_arange((2, 2, 2), xp, dtype=numpy.float32)
69-
a = a.T
69+
a = a.transpose()
7070
with pytest.raises(ValueError):
7171
a.view(dtype=dtype)
7272

dpnp/tests/third_party/cupy/core_tests/test_ndarray_indexing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,12 @@ def test_setitem_partial_copy(self, xp, dtype):
252252
@testing.numpy_cupy_array_equal()
253253
def test_T(self, xp):
254254
a = testing.shaped_arange((2, 3, 4), xp)
255-
return a.T
255+
return a.transpose()
256256

257257
@testing.numpy_cupy_array_equal()
258258
def test_T_vector(self, xp):
259259
a = testing.shaped_arange((4,), xp)
260-
return a.T
260+
return a.transpose()
261261

262262

263263
class TestSetItemCompatBroadcast:

dpnp/tests/third_party/cupy/linalg_tests/test_product.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ class TestDot(unittest.TestCase):
4646
def test_dot(self, xp, dtype_a, dtype_b):
4747
shape_a, shape_b = self.shape
4848
if self.trans_a:
49-
a = testing.shaped_arange(shape_a[::-1], xp, dtype_a).T
49+
a = testing.shaped_arange(shape_a[::-1], xp, dtype_a).transpose()
5050
else:
5151
a = testing.shaped_arange(shape_a, xp, dtype_a)
5252
if self.trans_b:
53-
b = testing.shaped_arange(shape_b[::-1], xp, dtype_b).T
53+
b = testing.shaped_arange(shape_b[::-1], xp, dtype_b).transpose()
5454
else:
5555
b = testing.shaped_arange(shape_b, xp, dtype_b)
5656
return xp.dot(a, b)
@@ -62,11 +62,11 @@ def test_dot(self, xp, dtype_a, dtype_b):
6262
def test_dot_with_out(self, xp, dtype_a, dtype_b, dtype_c):
6363
shape_a, shape_b = self.shape
6464
if self.trans_a:
65-
a = testing.shaped_arange(shape_a[::-1], xp, dtype_a).T
65+
a = testing.shaped_arange(shape_a[::-1], xp, dtype_a).transpose()
6666
else:
6767
a = testing.shaped_arange(shape_a, xp, dtype_a)
6868
if self.trans_b:
69-
b = testing.shaped_arange(shape_b[::-1], xp, dtype_b).T
69+
b = testing.shaped_arange(shape_b[::-1], xp, dtype_b).transpose()
7070
else:
7171
b = testing.shaped_arange(shape_b, xp, dtype_b)
7272
if a.ndim == 0 or b.ndim == 0:
@@ -206,11 +206,11 @@ class TestDotFor0Dim(unittest.TestCase):
206206
def test_dot(self, xp, dtype_a, dtype_b):
207207
shape_a, shape_b = self.shape
208208
if self.trans_a:
209-
a = testing.shaped_arange(shape_a[::-1], xp, dtype_a).T
209+
a = testing.shaped_arange(shape_a[::-1], xp, dtype_a).transpose()
210210
else:
211211
a = testing.shaped_arange(shape_a, xp, dtype_a)
212212
if self.trans_b:
213-
b = testing.shaped_arange(shape_b[::-1], xp, dtype_b).T
213+
b = testing.shaped_arange(shape_b[::-1], xp, dtype_b).transpose()
214214
else:
215215
b = testing.shaped_arange(shape_b, xp, dtype_b)
216216
return xp.dot(a, b)

dpnp/tests/third_party/cupy/manipulation_tests/test_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_copyto(self, xp, dtype):
2626
@testing.for_all_dtypes()
2727
@testing.numpy_cupy_array_equal()
2828
def test_copyto_different_contiguity(self, xp, dtype):
29-
a = testing.shaped_arange((2, 3, 2), xp, dtype).T
29+
a = testing.shaped_arange((2, 3, 2), xp, dtype).transpose()
3030
b = xp.empty((2, 3, 2), dtype=dtype)
3131
xp.copyto(b, a)
3232
return b

dpnp/tests/third_party/cupy/manipulation_tests/test_join.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,17 @@ def test_concatenate_large_different_devices(self):
113113
@testing.numpy_cupy_array_equal()
114114
def test_concatenate_f_contiguous(self, xp, dtype):
115115
a = testing.shaped_arange((2, 3, 4), xp, dtype)
116-
b = testing.shaped_arange((2, 3, 2), xp, dtype).T
116+
b = testing.shaped_arange((2, 3, 2), xp, dtype).transpose()
117117
c = testing.shaped_arange((2, 3, 3), xp, dtype)
118118
return xp.concatenate((a, b, c), axis=-1)
119119

120120
@testing.for_all_dtypes(name="dtype")
121121
@testing.numpy_cupy_array_equal()
122122
def test_concatenate_large_f_contiguous(self, xp, dtype):
123123
a = testing.shaped_arange((2, 3, 4), xp, dtype)
124-
b = testing.shaped_arange((2, 3, 2), xp, dtype).T
124+
b = testing.shaped_arange((2, 3, 2), xp, dtype).transpose()
125125
c = testing.shaped_arange((2, 3, 3), xp, dtype)
126-
d = testing.shaped_arange((2, 3, 2), xp, dtype).T
126+
d = testing.shaped_arange((2, 3, 2), xp, dtype).transpose()
127127
e = testing.shaped_arange((2, 3, 2), xp, dtype)
128128
return xp.concatenate((a, b, c, d, e) * 2, axis=-1)
129129

0 commit comments

Comments
 (0)