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 nand B has shape... x nfor a vector right-hand side or... x n x nrhsfor 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
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);