Linear Algebra module

codpy.lalg.VanDerMonde(x: ndarray, y: ndarray) ndarray[source]

Compute the inverse of the Vandermonde system for a given input array x and specified orders. Useful for Lagrange polynomial interpolations to design higher order numerical schemes

The Vandermonde system consists in solving \(A x = y\), where \(A=(x_i)^j\). If x is a one-dimensional array, the function directly computes the Vandermonde matrix. If x is a multi-dimensional array, the function computes the Vandermonde matrix for each row.

Parameters:
  • x (array_like) – Input one-dimensional matrix, optionally a facility is provided to matrix.

  • y (array_like) – Input matrix.

Returns:

\(A^{-1} y\), if x is one-dimensional. \([A_i^{-1} y]\), for \(i=1,\cdots,N\), \(N\) being the number of row of \(x\) , if x is a matrix.

Return type:

ndarray

Examples

For a one-dimensional input:

>>> vdm = VanDerMonde(np.array([1, 2, 3]), 3)
>>> print(vdm)
# Output:
[[1 1 1]
 [1 2 4]
 [1 3 9]]

For a two-dimensional input:

>>> vdm = VanDerMonde(np.array([[1, 2], [3, 4]]), 3)
>>> print(vdm)
# Output:
[[[1 1 1]
  [1 2 4]]
 [[1 1 1]
  [1 4 16]]]
class codpy.lalg.lalg[source]

Bases: object

A namespace to grant access to linear algebra tools, using Intel(R) Math Kernel Library (MKL) as backend. MKL is a parallelized, highly optimized library for linear algebra and other math tools.

prod(y)[source]

Compute the product of two matrices.

This method computes the matrix product of two input matrices, x and y.

Parameters:
  • x – The first matrix.

  • y – The second matrix.

Returns:

The product of the two matrices.

transpose()[source]

Transpose a matrix.

This method computes the transpose of a given matrix x.

Parameters:

x – The matrix to transpose.

Returns:

The transposed matrix.

scalar_product(y)[source]

Compute the scalar product of two vectors.

This method calculates the scalar (dot) product of two vectors, x and y.

Parameters:
  • x – The first vector.

  • y – The second vector.

Returns:

The scalar product of the two vectors.

cholesky(eps=0)[source]

Compute the inverse of a square symetrical matrix using Cholesky decomposition.

This method performs the Cholesky decomposition on a given matrix x. It optionally uses a small value eps for numerical stability.

Parameters:
  • x – The matrix to decompose.

  • eps (float, optional) – A small value added for numerical stability. Default is 0.

Returns:

The inverse of the regularized matrix.

inverse()[source]

Compute the inverse of a square matrix using LU decomposition.

This method performs the LU decomposition on a given matrix x to compute itrs inverse.

Parameters:

x – The matrix to decompose.

Returns:

The inverse of the matrix.

polar(eps=0)[source]

Compute the polar decomposition of a matrix.

This method calculates the polar decomposition of a given matrix x. It optionally uses a small value eps for numerical stability.

Parameters:
  • x – The matrix to decompose.

  • eps (float, optional) – A small value added for numerical stability. Default is 0.

Returns:

The polar decomposition of the matrix.

svd(eps=0)[source]

Compute the singular value decomposition (SVD) of a matrix.

This method performs the singular value decomposition on a given matrix x. It optionally uses a small value eps for numerical stability.

Parameters:
  • x – The matrix to decompose.

  • eps (float, optional) – A small value added for numerical stability. Default is 0.

Returns: The singular value decomposition of the matrix.

lstsq(b=[], eps=1e-08)[source]

Compute the inverse of a rectangular matrix using the least square method. This method performs a safe matrix invertion, computing \((A^T A + \epsilon I)^{-1}A^T b\), the inversion relying on a fast cholesky decomposition. For semi-definite matrix and without regularization \(\epsilon=0\), the cholesky decomposition might fail, in which case the algorithm rely on SVD decomposition to perform the invertion, a safer, but computationally intensive procedure.

Parameters:
  • A – The matrix to invert.

  • b – an optional matrix as second member.

  • eps (float, optional) – A small value added for numerical stability. Default is 1e-9 to cope with numerical error.

Returns: \((A^T A + \epsilon I)^{-1}A^T b\) .

SelfAdjointEigenDecomposition()[source]

Compute the self adjoint Eigen decomposition \(A = U D U^T\).

fix_nonpositive_semidefinite(eps=1e-08)[source]