inv#

Matrix inverse#

Compute the inverse of a square matrix.

Note

This function is currently not supported with host-based executors (CPU)

Note

CUDA JIT kernel fusion is supported by cuSolverDx if -DMATX_EN_MATHDX=ON is enabled. The current JIT path supports rank 2 through 4 square matrices with float, double, complex<float>, and complex<double> values. Unsupported ranks, shapes, or data types should use a normal executor and will be rejected by CUDAJITExecutor.

Note

The default inverse uses LU/GETRF-style factorization for general square matrices. For Hermitian positive-definite inputs, inv<MAT_INVERSE_ALGO_POSV>(A) enables a cuSolverDx POSV JIT path that solves A * X = I directly and can fuse with other compatible JIT operators such as cuBLASDx matmul. POSV is currently a MathDx/CUDAJITExecutor-only inverse algorithm, and callers must ensure the input satisfies the positive-definite contract.

Added in version 0.6.0.

template<MatInverseAlgo_t ALGO = MAT_INVERSE_ALGO_LU, typename OpA>
__MATX_INLINE__ auto matx::inv(const OpA &a)#

Performs a matrix inverse on a square matrix. The inverse API currently uses cuBLAS as a backend with the cublas<t>matinvBatched() family of functions for N <= 32 and getri/getrf functions otherwise.

If rank > 2, operations are batched.

The CUDAJITExecutor MathDx path also supports MAT_INVERSE_ALGO_POSV, which uses cuSolverDx POSV to invert Hermitian positive-definite matrices by solving A * X = I. The caller is responsible for only using POSV with positive-definite inputs; normal CUDA executor paths currently support the LU algorithm only.

Template Parameters:
  • ALGO – Algorithm to use for matrix inversion. MAT_INVERSE_ALGO_LU supports normal CUDA execution and MathDx JIT. MAT_INVERSE_ALGO_POSV supports MathDx JIT for Hermitian positive-definite inputs.

  • OpA – Data type of input a tensor or operator

Parameters:

a – Input tensor or operator of shape ... x n x n

Returns:

Operator that produces the inverse tensor of shape ... x n x n.

Examples#

// Perform an inverse on matrix "A" and store the output in "Ainv"
(Ainv = inv(A)).run(this->exec);