@@ -3543,6 +3543,10 @@ Tensor numpy_T(const Tensor &self) {
35433543 " or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse the dimensions of a tensor."
35443544 );
35453545 }
3546+ if (n == 0 ) {
3547+ // Added in PyTorch 2.0
3548+ TORCH_WARN_ONCE (" Tensor.T is deprecated on 0-D tensors. This function is the identity in these cases." );
3549+ }
35463550 DimVector transpose_dims;
35473551 for (int64_t i = n - 1 ; i >= 0 ; --i) {
35483552 transpose_dims.push_back (i);
@@ -3552,6 +3556,10 @@ Tensor numpy_T(const Tensor &self) {
35523556
35533557Tensor matrix_H (const Tensor &self) {
35543558 const auto ndim = self.dim ();
3559+ if (ndim == 0 ) {
3560+ // Added in PyTorch 2.0
3561+ TORCH_WARN_ONCE (" Tensor.H is deprecated on 0-D tensors. Consider using x.conj()." );
3562+ }
35553563 TORCH_CHECK (ndim == 2 || ndim == 0 ,
35563564 " tensor.H is only supported on matrices (2-D tensors). Got " , ndim, " -D tensor." ,
35573565 ndim > 2 ? " For batches of matrices, consider using tensor.mH" : " " );
@@ -3576,14 +3584,25 @@ Tensor _adjoint(const Tensor &self, const bool transpose, const char* const name
35763584} // anonymous namespace
35773585
35783586Tensor mT (const Tensor &self) {
3587+ if (self.dim () == 0 ) {
3588+ // Added in PyTorch 2.0
3589+ TORCH_WARN_ONCE (" Tensor.mT is deprecated on 0-D tensors. This function is the identity in these cases." );
3590+ }
35793591 return _adjoint (self, /* transpose=*/ true , " mT" );
35803592}
35813593
35823594Tensor mH (const Tensor &self) {
3595+ if (self.dim () == 0 ) {
3596+ // Added in PyTorch 2.0
3597+ TORCH_WARN_ONCE (" Tensor.mH is deprecated on 0-D tensors. Consider using x.conj()." );
3598+ }
35833599 return _adjoint (self, /* transpose=*/ false , " mH" );
35843600}
35853601
35863602Tensor adjoint (const Tensor &self) {
3603+ if (self.dim () == 0 ) {
3604+ TORCH_WARN_ONCE (" adjoint() is deprecated on 0-D tensors. Consider using x.conj()." );
3605+ }
35873606 return _adjoint (self, /* transpose=*/ false , " adjoint()" );
35883607}
35893608
0 commit comments