Table of Contents

Class LinAlgError

Namespace
NumSharp
Assembly
NumSharp.dll

NumPy-compatible numpy.linalg.LinAlgError. Raised by np.linalg when a matrix is unsuitable for the requested factorisation — the wrong rank, not square, singular, or not positive definite.

public class LinAlgError : ValueError, ISerializable, INumSharpException
Inheritance
LinAlgError
Implements
Inherited Members

Remarks

Mirrors numpy.linalg.LinAlgError, which derives from Python's ValueError — so this derives from ValueError and a catch (ValueError) sees it, exactly as except ValueError does upstream.

The messages NumPy 2.4.2 raises verbatim (probed):

  • {n}-dimensional array given. Array must be at least two-dimensional
  • {n}-dimensional array given. Array must be two-dimensional
  • Last 2 dimensions of the array must be square
  • Singular matrix
  • Matrix is not positive definite
  • Array must not contain infs or NaNs

Constructors

LinAlgError()

Creates the error with Python's text for a bare raise LinAlgError: an empty Message, as str(np.linalg.LinAlgError()) is ''.

public LinAlgError()

Remarks

ToString() then starts with the class name alone, as Python's traceback prints a bare LinAlgError; prefer one of NumPy's texts listed on the class.

LinAlgError(string)

Creates the error with NumPy's message.

public LinAlgError(string message)

Parameters

message string

The text NumPy raises, verbatim (Singular matrix).

LinAlgError(string, Exception)

Creates the error with NumPy's message and the exception that caused it: Python's raise LinAlgError(message) from innerException, the cause kept in InnerException.

public LinAlgError(string message, Exception innerException)

Parameters

message string

The text NumPy raises, verbatim.

innerException Exception

The exception that led to this one (a backend's own failure), or null for none.