Skip to content

Commit 19f1fc7

Browse files
Merge a23719b into 75b13c5
2 parents 75b13c5 + a23719b commit 19f1fc7

File tree

12 files changed

+63
-34
lines changed

12 files changed

+63
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum
4343

4444
* `dpnp.asfarray` is deprecated. Use `dpnp.asarray` with an appropriate dtype instead [#2650](https://github.com/IntelPython/dpnp/pull/2650)
4545
* Passing the output array ``out`` positionally to `dpnp.minimum` and `dpnp.maximum` is deprecated. Pass the output with the keyword form, e.g. ``dpnp.minimum(a, b, out=c)`` [#2659](https://github.com/IntelPython/dpnp/pull/2659)
46+
* Using the `.T` property on non-2D `dpnp.ndarray` is deprecated. Use `self.transpose()` or `self.mT` instead [#2681](https://github.com/IntelPython/dpnp/pull/2681)
4647

4748
### Removed
4849

dpnp/dpnp_array.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
# pylint: disable=invalid-name
3636
# pylint: disable=protected-access
3737

38+
import warnings
39+
3840
import dpctl.tensor as dpt
3941
import dpctl.tensor._type_utils as dtu
4042
from dpctl.tensor._numpy_helper import AxisError
@@ -1925,7 +1927,8 @@ def T(self):
19251927
"""
19261928
View of the transposed array.
19271929
1928-
Same as ``self.transpose()``.
1930+
Same as ``self.transpose()`` except that it requires
1931+
the array to be 2-dimensional.
19291932
19301933
See Also
19311934
--------
@@ -1942,14 +1945,17 @@ def T(self):
19421945
array([[1, 3],
19431946
[2, 4]])
19441947
1945-
>>> a = np.array([1, 2, 3, 4])
1946-
>>> a
1947-
array([1, 2, 3, 4])
1948-
>>> a.T
1949-
array([1, 2, 3, 4])
1950-
19511948
"""
19521949

1950+
if self.ndim != 2:
1951+
warnings.warn(
1952+
"`.T` is deprecated for non-2D dpnp.ndarray "
1953+
"and will raise an error in a future release. "
1954+
"Either `self.transpose()` or `self.mT` (which swaps "
1955+
"the last two axes only) should be used instead.",
1956+
DeprecationWarning,
1957+
stacklevel=2,
1958+
)
19531959
return self.transpose()
19541960

19551961
def take(self, indices, axis=None, *, out=None, mode="wrap"):

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_arraymanipulation.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,12 @@ def test_concatenate_3d(self, dtype):
503503
dp_res = dpnp.concatenate((dp_a0, dp_a1, dp_a2), axis=axis)
504504
assert_array_equal(dp_res, np_res)
505505

506-
np_res = numpy.concatenate((np_a0.T, np_a1.T, np_a2.T), axis=0)
507-
dp_res = dpnp.concatenate((dp_a0.T, dp_a1.T, dp_a2.T), axis=0)
506+
np_res = numpy.concatenate(
507+
(np_a0.transpose(), np_a1.transpose(), np_a2.transpose()), axis=0
508+
)
509+
dp_res = dpnp.concatenate(
510+
(dp_a0.transpose(), dp_a1.transpose(), dp_a2.transpose()), axis=0
511+
)
508512
assert_array_equal(dp_res, np_res)
509513

510514
@pytest.mark.parametrize(
@@ -1164,3 +1168,13 @@ def test_can_cast():
11641168
assert dpnp.can_cast(X, "float32") == numpy.can_cast(X_np, "float32")
11651169
assert dpnp.can_cast(X, dpnp.int32) == numpy.can_cast(X_np, numpy.int32)
11661170
assert dpnp.can_cast(X, dpnp.int64) == numpy.can_cast(X_np, numpy.int64)
1171+
1172+
1173+
def test_depr_T_non_2d():
1174+
x = dpnp.arange(8)
1175+
with pytest.warns(DeprecationWarning, match="deprecated"):
1176+
_ = x.T
1177+
1178+
x_3d = x.reshape(2, 2, 2)
1179+
with pytest.warns(DeprecationWarning, match="deprecated"):
1180+
_ = x_3d.T

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)

0 commit comments

Comments
 (0)