Learn R Programming

torch (version 0.0.2)

torch_qr: Qr

Description

Qr

Arguments

input

(Tensor) the input tensor of size \((*, m, n)\) where * is zero or more batch dimensions consisting of matrices of dimension \(m \times n\).

some

(bool, optional) Set to True for reduced QR decomposition and False for complete QR decomposition.

out

(tuple, optional) tuple of Q and R tensors satisfying input = torch.matmul(Q, R). The dimensions of Q and R are \((*, m, k)\) and \((*, k, n)\) respectively, where \(k = \min(m, n)\) if some: is True and \(k = m\) otherwise.

qr(input, some=True, out=None) -> (Tensor, Tensor)

Computes the QR decomposition of a matrix or a batch of matrices input, and returns a namedtuple (Q, R) of tensors such that \(\mbox{input} = Q R\) with \(Q\) being an orthogonal matrix or batch of orthogonal matrices and \(R\) being an upper triangular matrix or batch of upper triangular matrices.

If some is True, then this function returns the thin (reduced) QR factorization. Otherwise, if some is False, this function returns the complete QR factorization.

Examples

Run this code
# NOT RUN {
if (torch_is_installed()) {

a = torch_tensor(matrix(c(12., -51, 4, 6, 167, -68, -4, 24, -41), ncol = 3, byrow = TRUE))
out = torch_qr(a)
q = out[[1]]
r = out[[2]]
torch_mm(q, r)$round()
torch_mm(q$t(), q)$round()
}
# }

Run the code above in your browser using DataLab