mirror of
https://github.com/pytorch/pytorch.git
synced 2025-11-04 16:04:58 +08:00
Remove deprecated torch.lstsq (#70980)
The time has come to remove deprecated linear algebra related functions. This PR removes `torch.lstsq`.
There's a note in `tools/codegen/gen.py` about `lstsq` schema in `native_function.yaml` that I will not remove:
87139d8532/tools/codegen/gen.py (L734-L770)
cc @jianyuh @nikitaved @pearu @mruberry @walterddr @IvanYashchuk @xwang233 @Lezcano
Pull Request resolved: https://github.com/pytorch/pytorch/pull/70980
Approved by: https://github.com/lezcano, https://github.com/kit1980
This commit is contained in:
committed by
PyTorch MergeBot
parent
6380016bdd
commit
539076e2c2
@ -6352,96 +6352,6 @@ Example::
|
||||
),
|
||||
)
|
||||
|
||||
add_docstr(
|
||||
torch.lstsq,
|
||||
r"""
|
||||
lstsq(input, A, *, out=None) -> (Tensor, Tensor)
|
||||
|
||||
Computes the solution to the least squares and least norm problems for a full
|
||||
rank matrix :math:`A` of size :math:`(m \times n)` and a matrix :math:`B` of
|
||||
size :math:`(m \times k)`.
|
||||
|
||||
If :math:`m \geq n`, :func:`lstsq` solves the least-squares problem:
|
||||
|
||||
.. math::
|
||||
|
||||
\begin{array}{ll}
|
||||
\min_X & \|AX-B\|_2.
|
||||
\end{array}
|
||||
|
||||
If :math:`m < n`, :func:`lstsq` solves the least-norm problem:
|
||||
|
||||
.. math::
|
||||
|
||||
\begin{array}{llll}
|
||||
\min_X & \|X\|_2 & \text{subject to} & AX = B.
|
||||
\end{array}
|
||||
|
||||
Returned tensor :math:`X` has shape :math:`(\max(m, n) \times k)`. The first :math:`n`
|
||||
rows of :math:`X` contains the solution. If :math:`m \geq n`, the residual sum of squares
|
||||
for the solution in each column is given by the sum of squares of elements in the
|
||||
remaining :math:`m - n` rows of that column.
|
||||
|
||||
.. warning::
|
||||
|
||||
:func:`torch.lstsq` is deprecated in favor of :func:`torch.linalg.lstsq`
|
||||
and will be removed in a future PyTorch release. :func:`torch.linalg.lstsq`
|
||||
has reversed arguments and does not return the QR decomposition in the returned tuple,
|
||||
(it returns other information about the problem).
|
||||
The returned `solution` in :func:`torch.lstsq` stores the residuals of the solution in the
|
||||
last `m - n` columns in the case `m > n`. In :func:`torch.linalg.lstsq`, the residuals
|
||||
are in the field 'residuals' of the returned named tuple.
|
||||
|
||||
Unpacking the solution as ``X = torch.lstsq(B, A).solution[:A.size(1)]`` should be replaced with
|
||||
|
||||
.. code:: python
|
||||
|
||||
X = torch.linalg.lstsq(A, B).solution
|
||||
|
||||
.. note::
|
||||
The case when :math:`m < n` is not supported on the GPU.
|
||||
|
||||
Args:
|
||||
input (Tensor): the matrix :math:`B`
|
||||
A (Tensor): the :math:`m` by :math:`n` matrix :math:`A`
|
||||
|
||||
Keyword args:
|
||||
out (tuple, optional): the optional destination tensor
|
||||
|
||||
Returns:
|
||||
(Tensor, Tensor): A namedtuple (solution, QR) containing:
|
||||
|
||||
- **solution** (*Tensor*): the least squares solution
|
||||
- **QR** (*Tensor*): the details of the QR factorization
|
||||
|
||||
.. note::
|
||||
|
||||
The returned matrices will always be transposed, irrespective of the strides
|
||||
of the input matrices. That is, they will have stride `(1, m)` instead of
|
||||
`(m, 1)`.
|
||||
|
||||
Example::
|
||||
|
||||
>>> A = torch.tensor([[1., 1, 1],
|
||||
... [2, 3, 4],
|
||||
... [3, 5, 2],
|
||||
... [4, 2, 5],
|
||||
... [5, 4, 3]])
|
||||
>>> B = torch.tensor([[-10., -3],
|
||||
... [ 12, 14],
|
||||
... [ 14, 12],
|
||||
... [ 16, 16],
|
||||
... [ 18, 16]])
|
||||
>>> X, _ = torch.lstsq(B, A)
|
||||
>>> X
|
||||
tensor([[ 2.0000, 1.0000],
|
||||
[ 1.0000, 1.0000],
|
||||
[ 1.0000, 2.0000],
|
||||
[ 10.9635, 4.8501],
|
||||
[ 8.9332, 5.2418]])
|
||||
""",
|
||||
)
|
||||
|
||||
add_docstr(
|
||||
torch.lt,
|
||||
r"""
|
||||
|
||||
Reference in New Issue
Block a user