linalg_qr {torch} | R Documentation |
Computes the QR decomposition of a matrix.
Description
Letting \mathbb{K}
be \mathbb{R}
or \mathbb{C}
,
the full QR decomposition of a matrix
A \in \mathbb{K}^{m \times n}
is defined as
Usage
linalg_qr(A, mode = "reduced")
Arguments
A |
(Tensor): tensor of shape |
mode |
(str, optional): one of |
Details
Math could not be displayed. Please visit the package website.
where Q
is orthogonal in the real case and unitary in the complex case, and R
is upper triangular.
When m > n
(tall matrix), as R
is upper triangular, its last m - n
rows are zero.
In this case, we can drop the last m - n
columns of Q
to form the
reduced QR decomposition:
Math could not be displayed. Please visit the package website.
The reduced QR decomposition agrees with the full QR decomposition when n >= m
(wide matrix).
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if A
is a batch of matrices then
the output has the same batch dimensions.
The parameter mode
chooses between the full and reduced QR decomposition.
If A
has shape (*, m, n)
, denoting k = min(m, n)
-
mode = 'reduced'
(default): Returns(Q, R)
of shapes(*, m, k)
,(*, k, n)
respectively. -
mode = 'complete'
: Returns(Q, R)
of shapes(*, m, m)
,(*, m, n)
respectively. -
mode = 'r'
: Computes only the reducedR
. Returns(Q, R)
withQ
empty andR
of shape(*, k, n)
.
Value
A list (Q, R)
.
See Also
Other linalg:
linalg_cholesky_ex()
,
linalg_cholesky()
,
linalg_det()
,
linalg_eigh()
,
linalg_eigvalsh()
,
linalg_eigvals()
,
linalg_eig()
,
linalg_householder_product()
,
linalg_inv_ex()
,
linalg_inv()
,
linalg_lstsq()
,
linalg_matrix_norm()
,
linalg_matrix_power()
,
linalg_matrix_rank()
,
linalg_multi_dot()
,
linalg_norm()
,
linalg_pinv()
,
linalg_slogdet()
,
linalg_solve_triangular()
,
linalg_solve()
,
linalg_svdvals()
,
linalg_svd()
,
linalg_tensorinv()
,
linalg_tensorsolve()
,
linalg_vector_norm()
Examples
if (torch_is_installed()) {
a <- torch_tensor(rbind(c(12., -51, 4), c(6, 167, -68), c(-4, 24, -41)))
qr <- linalg_qr(a)
torch_mm(qr[[1]], qr[[2]])$round()
torch_mm(qr[[1]]$t(), qr[[1]])$round()
}