solve

solve#

Solves the system of equations AX=Y, where X is the unknown.

Added in version 0.9.1.

template<typename OpA, typename OpB>
__MATX_INLINE__ auto matx::solve(const OpA &A, const OpB &B)#

Running X = solve(A, B) solves the system A X = B for dense A, where A has shape ... x n x n and B has shape ... x n for a vector right-hand side or ... x n x nrhs for one or more matrix right-hand sides. Dense batch dimensions must match exactly and are not broadcast.

For sparse A, solve preserves the legacy sparse API: B and X stack different right-hand sides by row and the operation solves A X^T = B^T.

Template Parameters:
  • OpA – Data type of A tensor

  • OpB – Data type of B tensor

Parameters:
  • A – A tensor with system coefficients

  • B – B Dense tensor of known values

Returns:

Operator that produces the output tensor X with the solution

template<typename OpA, typename OpB>
__MATX_INLINE__ auto matx::solve(const OpA &A, const OpB &B, const SolverStatus &status)#

Solve A X = B for dense A, reporting per-matrix errors through a solver status.

Same as solve(A, B) for dense A, except each system’s factorization info value is written to stage 0 of status and its solve info value to stage 1, and, on CUDA executors, the call does not synchronize the stream (see the Solver Status docs for when it can). A positive stage 0 value i means U(i,i) is exactly zero, so A is singular and that system’s X is not valid; the solve still runs. Check the result after synchronizing, as for qr_solver(a, status). Sparse A is not supported.

Template Parameters:
  • OpA – Data type of A tensor

  • OpB – Data type of B tensor

Parameters:
  • A – Dense A tensor with system coefficients, of shape ... x n x n

  • B – B Dense tensor of known values

  • status – Solver status with at least two stages, created with make_solver_status() for an input shaped like A

Returns:

Operator that produces the output tensor X with the solution

Note

The overload that takes a solver status writes each system’s factorization info value into stage 0 and its solve info value into stage 1, instead of synchronizing the stream to check them. The status needs at least two stages. It supports dense A only.

For dense A, A must have shape ... x n x n. B may have shape ... x n for a vector right-hand side or ... x n x nrhs for one or more matrix right-hand sides. Dense batch dimensions must match exactly; they are not broadcast. The output shape matches B. Dense solve uses cuSolver/cuBLAS with CUDA executors and LAPACK with host executors when CPU solver support is configured.

For sparse A, solve preserves the legacy sparse solve layout where right-hand sides are stacked by row and the operation solves A X^T = B^T. Sparse direct solve support depends on the sparse format and may require cuDSS; please see Sparse Tensor Type.

Examples#

Dense vector right-hand side

// Solve A(n x n) X = B(n) for vector X(n).
(X = solve(A, B)).run(this->exec);

Dense matrix right-hand side

// Solve A(n x n) X = B(n x nrhs) for matrix X(n x nrhs).
(X = solve(A, B)).run(this->exec);

In an expression

// solve(A, B) may be used in a larger expression.
(X = solve(A, B) * C).run(this->exec);

Batched vector right-hand side

// Solve a batch of independent systems with vector right-hand sides.
(X = solve(A, B)).run(this->exec);

Batched matrix right-hand side

// Solve a batch of independent systems with matrix right-hand sides.
(X = solve(A, B)).run(this->exec);

In-place right-hand side

// The right-hand side can be overwritten with the solution.
(B = solve(A, B)).run(this->exec);