warp.qr3#

warp.qr3(
A: Matrix[Float, Literal[3], Literal[3]],
) tuple[Matrix[Float, Literal[3], Literal[3]], Matrix[Float, Literal[3], Literal[3]]]#
  • Kernel: true
  • Python: true
  • Differentiable: true

Compute the QR decomposition of a 3x3 matrix.

For rank-deficient A, more than one pair of Q and R may satisfy A = Q * R.

Autodiff requires A to have full rank. Gradients involve the inverse of R and may be numerically unstable when a diagonal entry of R is small relative to the others.

The decomposition is a finite-precision approximation. Check the orthogonality of Q, triangularity of R, and reconstruction error when accuracy is critical.

Parameters:

A – Matrix to decompose.

Returns:

A tuple (Q, R) such that A = Q * R. Q is an orthogonal matrix with determinant +1. R is upper triangular. Because Q has determinant +1, R may contain a negative diagonal entry when A has negative determinant.

Example

Orthonormalize the columns of a left-handed coordinate frame while recording the reflection in R:

@wp.kernel
def orthonormalize_frames(
    frames: wp.array[wp.mat33],
    orthonormal_frames: wp.array[wp.mat33],
    coefficients: wp.array[wp.mat33],
):
    i = wp.tid()
    Q, R = wp.qr3(frames[i])
    orthonormal_frames[i] = Q
    coefficients[i] = R

frames = wp.array(
    [
        wp.mat33(
            1.0, 1.0, 0.0,
            1.0, 0.0, 1.0,
            0.0, 1.0, 1.0,
        )
    ],
    dtype=wp.mat33,
)
orthonormal_frames = wp.empty(1, dtype=wp.mat33)
coefficients = wp.empty(1, dtype=wp.mat33)

wp.launch(
    orthonormalize_frames,
    dim=1,
    inputs=[frames],
    outputs=[orthonormal_frames, coefficients],
)

print(f"Orthonormal frame:\n{np.round(orthonormal_frames.numpy()[0], 3)}")
print(f"R diagonal: {np.round(np.diag(coefficients.numpy()[0]), 3)}")
Orthonormal frame:
[[ 0.707  0.408  0.577]
 [ 0.707 -0.408 -0.577]
 [ 0.     0.816 -0.577]]
R diagonal: [ 1.414  1.225 -1.155]
warp.qr3(
A: Matrix[Float, Literal[3], Literal[3]],
Q: Matrix[Float, Literal[3], Literal[3]],
R: Matrix[Float, Literal[3], Literal[3]],
) None
  • Kernel: true
  • Python: false
  • Differentiable: true

Compute the QR decomposition of a 3x3 matrix and store the factors in caller-provided output arguments.

See the return-value overload for the factorization convention, numerical behavior, and autodiff guidance.

Parameters:
  • A – Matrix to decompose.

  • Q – Output orthogonal matrix.

  • R – Output upper-triangular matrix.

Example

Store the QR decomposition of A in Q and R:

@wp.kernel
def compute_qr3(A: wp.mat33):
    Q = wp.mat33()
    R = wp.mat33()

    wp.qr3(A, Q, R)