Skip to content
fn

solve_op

→TensorImplPtr
int solve_op(const int & a, const int & b)

Python wrappers

Public Python APIs implemented by this engine symbol.

Solve the linear system AX=BAX = B for XX.

Shape

  • a: (*, N, N).
  • b: (*, N, K), (N,), or a.shape[:-1] (vector RHS).
  • Output: the broadcast batch followed by (N, K), or by (N,) for a vector RHS.

References

Giles, "Collected Matrix Derivative Results" (Oxford, 2008), §2.4. LAPACK sgesv/dgesv; LAPACK Users' Guide §2.5.

See Also

[[lu_factor_op]] : Standalone LU factorisation (no autograd). [[lu_solve_op]] : Apply pre-computed LU factors. [[matmul_op]] : Used in the backward outer product −dB X⊤-dB\, X^\top.

Parameters

aconst TensorImplPtr&
Square float tensor of shape (..., N, N). Must share dtype and device with b.
bconst TensorImplPtr&
Right-hand side of shape (..., N) or (..., N, K).

Returns

TensorImplPtr

Solution tensor X=A−1BX = A^{-1} B with the same shape as b. When grad mode is active, the result has [[SolveBackward]] wired into the autograd graph with AA saved as input and XX saved as output.

Raises

ShapeMismatch
When b is none of the shapes above, or the batch axes of a and b do not broadcast — before any backend call.
LinAlgError
When a is not square, not float-typed, when dtypes/devices mismatch between a and b, or when AA is singular (zero pivot detected by LU).

Examples

Single RHS solve::
    auto x = solve_op(a, b);  // a: (n, n), b: (n,) → x: (n,)
Batched multi-RHS solve::
    auto x = solve_op(a, b);  // a: (B, n, n), b: (B, n, k)