warp.inverse_approx#
- warp.inverse_approx(
- a: Matrix[Float, Literal[2], Literal[2]],
Return an approximate inverse of a matrix.
On GPU, this function may be faster than
warp.inverse(), but its result and gradients may be less accurate. For double-precision matrices, even well-conditioned inputs can yield roughly single-precision accuracy. Usewarp.inverse()when double-precision accuracy matters. On CPU, both functions currently use the same inversion method.Nearly singular inputs can amplify rounding errors and produce large gradients. Use a well-conditioned matrix for differentiation, and check that the product of the input and returned matrix is close to the identity before relying on the result.
- Parameters:
a – Matrix to invert. Must be nonsingular.
- Returns:
A matrix whose product with the input approximates the identity.
Example
Invert a matrix in a kernel and inspect the result:
@wp.kernel def approximate_matrix_inverses( matrices: wp.array[wp.mat22], inverses: wp.array[wp.mat22], ): i = wp.tid() inverses[i] = wp.inverse_approx(matrices[i]) matrices = wp.array([wp.mat22(2.0, 1.0, 1.0, 2.0)], dtype=wp.mat22) inverses = wp.empty_like(matrices) wp.launch( approximate_matrix_inverses, dim=1, inputs=[matrices], outputs=[inverses], ) inverse = inverses.numpy()[0] print(np.round(inverse, 3))
[[ 0.667 -0.333] [-0.333 0.667]]
- warp.inverse_approx(
- a: Matrix[Float, Literal[3], Literal[3]],
Return an approximate inverse of a 3x3 matrix.
See the 2x2 overload for device behavior, numerical accuracy, and autodiff guidance.
- Parameters:
a – Matrix to invert. Must be nonsingular.
- Returns:
A matrix whose product with the input approximates the identity.
- warp.inverse_approx(
- a: Matrix[Float, Literal[4], Literal[4]],
Return an approximate inverse of a 4x4 matrix.
See the 2x2 overload for device behavior, numerical accuracy, and autodiff guidance.
- Parameters:
a – Matrix to invert. Must be nonsingular.
- Returns:
A matrix whose product with the input approximates the identity.