warp.qr3#
- warp.qr3(
- A: Matrix[Float, Literal[3], Literal[3]],
Compute the QR decomposition of a 3x3 matrix.
For rank-deficient
A, more than one pair ofQandRmay satisfyA = Q * R.Autodiff requires
Ato have full rank. Gradients involve the inverse ofRand may be numerically unstable when a diagonal entry ofRis small relative to the others.The decomposition is a finite-precision approximation. Check the orthogonality of
Q, triangularity ofR, and reconstruction error when accuracy is critical.- Parameters:
A – Matrix to decompose.
- Returns:
A tuple
(Q, R)such thatA = Q * R.Qis an orthogonal matrix with determinant+1.Ris upper triangular. BecauseQhas determinant+1,Rmay contain a negative diagonal entry whenAhas 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]],
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
AinQandR:@wp.kernel def compute_qr3(A: wp.mat33): Q = wp.mat33() R = wp.mat33() wp.qr3(A, Q, R)