qr

paddle.linalg. qr ( x, mode='reduced', name=None ) [source]

Computes the QR decomposition of one matrix or batches of matrices (backward is unsupported now).

Parameters
  • x (Tensor) – The input tensor. Its shape should be […, M, N], where … is zero or more batch dimensions. M and N can be arbitrary positive number. The data type of x should be float32 or float64.

  • mode (str, optional) – A flag to control the behavior of qr. Suppose x’s shape is […, M, N] and denoting K = min(M, N): If mode = “reduced”, qr op will return reduced Q and R matrices, which means Q’s shape is […, M, K] and R’s shape is […, K, N]. If mode = “complete”, qr op will return complete Q and R matrices, which means Q’s shape is […, M, M] and R’s shape is […, M, N]. If mode = “r”, qr op will only return reduced R matrix, which means R’s shape is […, K, N]. Default: “reduced”.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

If mode = “reduced” or mode = “complete”, qr will return a two tensor-tuple, which represents Q and R. If mode = “r”, qr will return a tensor which represents R.

Examples

>>> import paddle

>>> x = paddle.to_tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]).astype('float64')
>>> q, r = paddle.linalg.qr(x)
>>> print (q)
Tensor(shape=[3, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
[[-0.16903085,  0.89708523],
 [-0.50709255,  0.27602622],
 [-0.84515425, -0.34503278]])
>>> print (r)
Tensor(shape=[2, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
[[-5.91607978, -7.43735744],
 [ 0.        ,  0.82807867]])

>>> # one can verify : X = Q * R ;