warp.inverse\_approx ==================== .. currentmodule:: warp._src.lang .. function:: inverse_approx(a: Matrix[Float, Literal[2], Literal[2]]) -> Matrix[Float, Any, Any] .. wp-function-tags:: :kernel: true :python: false :differentiable: true Return an approximate inverse of a matrix. On GPU, this function may be faster than :func:`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. Use :func:`warp.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. :param a: Matrix to invert. Must be nonsingular. :returns: A matrix whose product with the input approximates the identity. .. rubric:: Example Invert a matrix in a kernel and inspect the result: .. testcode:: @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)) .. testoutput:: [[ 0.667 -0.333] [-0.333 0.667]] .. function:: inverse_approx(a: Matrix[Float, Literal[3], Literal[3]]) -> Matrix[Float, Any, Any] :noindex: .. wp-function-tags:: :kernel: true :python: false :differentiable: true Return an approximate inverse of a 3x3 matrix. See the 2x2 overload for device behavior, numerical accuracy, and autodiff guidance. :param a: Matrix to invert. Must be nonsingular. :returns: A matrix whose product with the input approximates the identity. .. function:: inverse_approx(a: Matrix[Float, Literal[4], Literal[4]]) -> Matrix[Float, Any, Any] :noindex: .. wp-function-tags:: :kernel: true :python: false :differentiable: true Return an approximate inverse of a 4x4 matrix. See the 2x2 overload for device behavior, numerical accuracy, and autodiff guidance. :param a: Matrix to invert. Must be nonsingular. :returns: A matrix whose product with the input approximates the identity.