copapy.solve#

copapy.solve(a, b, pivot=True)#

Solve the linear system a x = b for x (like numpy.linalg.solve).

Overloads:

Tensors with more than 16 copapy values in the matrix a are solved by a single array stencil: Gaussian elimination with partial pivoting. Otherwise the elimination is unrolled into scalar operations, where operations with constant zeros are eliminated and pivot elements that are constants are selected without generating code. A tensor created with packed=True is always solved by the array stencil, a matrix created with packed=False is always unrolled.

In both cases the execution time only depends on the size of the system, not on the values. A singular matrix results in inf or nan values.

Parameters:
  • a (Any) – Square matrix (2D tensor)

  • b (Any) – Right-hand side: a vector or 1D tensor with n elements or a 2D tensor with n rows (one system per column)

  • pivot (bool) – Partial pivoting for the unrolled elimination. It can be disabled to reduce the number of operations for matrices that do not require it, like symmetric positive definite or diagonally dominant matrices. The array stencil does always pivot.

Returns:

a vector if b is a vector, otherwise a tensor

Return type:

Solution x with the shape of b