mlx.core.linalg.qr#

qr(a: array, *, stream: None | Stream | Device = None)#

The QR factorization of the input matrix.

This function supports arrays with at least 2 dimensions. The matrices which are factorized are assumed to be in the last two dimensions of the input.

Parameters:
  • a (array) – Input array.

  • stream (Stream, optional) – Stream or device. Defaults to None in which case the default stream of the default device is used.

Returns:

The Q and R matrices.

Return type:

tuple(array, array)

Example

>>> A = mx.array([[2., 3.], [1., 2.]])
>>> Q, R = mx.linalg.qr(A, stream=mx.cpu)
>>> Q
array([[-0.894427, -0.447214],
       [-0.447214, 0.894427]], dtype=float32)
>>> R
array([[-2.23607, -3.57771],
       [0, 0.447214]], dtype=float32)