siconos.kernel.SimpleMatrix (Python class)

class siconos.kernel.SimpleMatrix(*args)[source]

Bases: siconos.kernel.SiconosMatrix

Matrix (embedded various types of Boost matrices of double)

SimpleMatrix is used in the platform to store matrices (mathematical object) of double.

Possible types: Siconos::DENSE (default), TRIANGULAR, SYMMETRIC, SPARSE, BANDED, ZERO, Siconos::IDENTITY.

See Linear Algebra in Siconos in Users guide.

Generated class (swig), based on C++ header Program listing for file kernel/src/utils/SiconosAlgebra/SimpleMatrix.hpp.

Constructors

SimpleMatrix()

Default constructor.

SimpleMatrix(int i)
SimpleMatrix(int row, int col, int typ=DENSE, int upper=1, int lower=1)

constructor with the type and the dimension of the Boost matrix

Parameters:
  • row – number of rows.
  • col – number of columns.
  • typ – the type of matrix
  • upper – if Siconos::UBLAS_TYPE==SPARSE, number of non-zero terms, if Siconos::UBLAS_TYPE == BANDED, number of diags. under the main diagonal
  • lower – if Siconos::UBLAS_TYPE == BANDED, number of diags. over the main diagonal
SimpleMatrix(int row, int col, double inputValue, int typ=DENSE, int upper=1, int lower=1)

constructor with the the dimensions of the Boost matrix, a default value and the type.

Parameters:
  • row – number of rows.
  • col – number of columns.
  • inputValue – double a, so that *this = [a a a …]
  • typ – the type of matrix
  • upper – if Siconos::UBLAS_TYPE==SPARSE, number of non-zero terms, if Siconos::UBLAS_TYPE == BANDED, number of diags. under the main diagonal
  • lower – if Siconos::UBLAS_TYPE == BANDED, number of diags. over the main diagonal
SimpleMatrix(array_like (np.float64, 2D) smat)

copy constructor

Parameters:smat – the matrix to copy
SimpleMatrix(array_like (np.float64, 2D) A, array_like (int, 1D) coord)

copy constructor of a block given by the coord = [r0A r1A c0A c1A]

Parameters:
  • A – the matrix which contains the block to extract
  • coord – positions of the block to be extracted (row:start, row:end, col:start, col:end)
SimpleMatrix(array_like (np.float64, 2D) m)

copy constructor

Parameters:m – the matrix to copy
SimpleMatrix(DenseMat m)

constructor with a DenseMat matrix (see SiconosMatrix.h for details)

Parameters:m – a DenseMat
SimpleMatrix(TriangMat m)

constructor with a TriangMat matrix (see SiconosMatrix.h for details)

Parameters:m – a TriangMat
SimpleMatrix(SymMat m)

constructor with a SymMat matrix (see SiconosMatrix.h for details)

Parameters:m – a SymMat
SimpleMatrix(BandedMat m)

constructor with a BandedMat matrix (see SiconosMatrix.h for details)

Parameters:m – a BandedMat
SimpleMatrix(SparseMat m)

constructor with a SparseMat matrix (see SiconosMatrix.h for details)

Parameters:m – a SparseMat
SimpleMatrix(ZeroMat m)

constructor with a ZeroMat matrix (see SiconosMatrix.h for details)

Parameters:m – a ZeroMat
SimpleMatrix(IdentityMat m)

constructor with a IdentityMat matrix (see SiconosMatrix.h for details)

Parameters:m – a IdentityMat
SimpleMatrix(str file, bool ascii=True)

constructor with an input file

Parameters:
  • file – the input file path
  • ascii – a boolean to indicate if the file is in ascii
PLUFactorizationInPlace() → None[source]

computes an LU factorization of a general M-by-N matrix using partial pivoting with row interchanges.

The result is returned in this (InPlace). Based on Blas dgetrf function.

PLUForwardBackwardInPlace(*args)[source]

Warning - Overloaded function : multiple signatures available, check prototypes below.

PLUForwardBackwardInPlace(array_like (np.float64, 2D) B) → None[source]

solves a system of linear equations A * X = B (A=this) with a general N-by-N matrix A using the LU factorization computed by PLUFactorizationInPlace.

Based on Blas dgetrs function.

Parameters:B – on input the RHS matrix b; on output the result x
PLUForwardBackwardInPlace(array_like (np.float64, 1D) B) → None[source]

solves a system of linear equations A * X = B (A=this) with a general N-by-N matrix A using the LU factorization computed by PLUFactorizationInPlace.

Based on Blas dgetrs function.

Parameters:B – on input the RHS matrix b; on output the result x
PLUInverseInPlace() → None[source]

compute inverse of this thanks to LU factorization with Partial pivoting.

This method inverts U and then computes inv(A) by solving the system inv(A)*L = inv(U) for inv(A). The result is returned in this (InPlace). Based on Blas dgetri function.

SolveByLeastSquares(*args)[source]

Warning - Overloaded function : multiple signatures available, check prototypes below.

SolveByLeastSquares(array_like (np.float64, 2D) B) → None[source]

solves a system of linear equations A * X = B (A=this) with a general N-by-N matrix A using the Least squares method

Parameters:B – on input the RHS matrix b; on output the result x
SolveByLeastSquares(array_like (np.float64, 1D) B) → None[source]

solves a system of linear equations A * X = B (A=this) with a general N-by-N matrix A using the Least squares method

Parameters:B – on input the RHS matrix b; on output the result x
addBlock(int i, int j, array_like (np.float64, 2D) m) → None[source]

add the input matrix to the elements starting from position i (row) and j (col).

Parameters:
  • i – an unsigned int
  • j – an unsigned int
  • m – a SiconosMatrix
banded(int row=0, int col=0) → BandedMat *[source]

get a pointer on BandedMat matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

a BandedMat*

block(*args)[source]

Warning - Overloaded function : multiple signatures available, check prototypes below.

block(int row=0, int col=0) -> array_like (np.float64, 2D)[source]

get block at position row-col, (current matrix in SimpleMatrix case)

Parameters:
  • row – row index
  • col – column index
Returns:

a sub-matrix

block(int row=0, int col=0) -> SPC::array_like (np.float64, 2D)[source]

get block at position row-col, (current matrix in SimpleMatrix case)

Parameters:
  • row – row index
  • col – column index
Returns:

a sub-matrix

copyData(array_like (np.float64, 1D)data)[source]

copy the matrix data to the array given in parameter’ Works only for dense matrices !

Parameters:data – array where the matrix is copied
Returns:the size of the matrix
dense(int row=0, int col=0) → DenseMat *[source]

get a pointer on DenseMat matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

a DenseMat*

det() → double[source]

compute the determinant of the matrix (use LU factorization)

Returns:a double
display() → None[source]

display data on standard output

eye() → None[source]

set an identity matrix

getArray(int row=0, int col=0) -> array_like (np.float64, 1D)[source]

return the address of the array of double values of the matrix

Parameters:
  • row – position for the required block ->useless for SimpleMatrix
  • col – position for the required block ->useless for SimpleMatrix
Returns:

double* (the pointer on the double array)

getBanded(int row=0, int col=0) → BandedMat[source]

get BandedMat matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

a BandedMat

getCol(int col, array_like (np.float64, 1D) vOut) → None[source]

get column index of current matrix and save it into vOut

Parameters:
  • col – index column we want to get
  • vOut – SiconosVector that will contain the desired column
getDense(int row=0, int col=0) → DenseMat[source]

get DenseMat matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

a DenseMat

getIdentity(int row=0, int col=0) → IdentityMat[source]

get getIdentity matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

an IdentityMat

getRow(int row, array_like (np.float64, 1D) vOut) → None[source]

get row index of current matrix and save it into vOut

Parameters:
  • row – index row we want to get
  • vOut – SiconosVector that will contain the desired row
getSparse(int row=0, int col=0) → SparseMat[source]

get SparseMat matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

a SparseMat

getSubCol(int index, int pos, array_like (np.float64, 1D) vOut) → None[source]

get column number index of current matrix, starting from element at position pos and save it into vOut

Parameters:
  • index – index of required column
  • pos – index of the first required element in the column
  • vOut – a SP::SiconosVector
getSubRow(int index, int pos, array_like (np.float64, 1D) vOut) → None[source]

get row number index of current matrix, starting from element at position pos and save it into vOut

Parameters:
  • index – index of the required row
  • pos – index of the first required element in the row
  • vOut – a SP::SiconosVector that will contain the sub row
getSym(int row=0, int col=0) → SymMat[source]

get SymMat matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

a SymMat

getTriang(int row=0, int col=0) → TriangMat[source]

get TriangMat matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

a TriangMat

getValue(int i, int j) → double[source]

return the element matrix[i,j]

Parameters:
  • i – an unsigned int
  • j – an unsigned int
Returns:

a double

getZero(int row=0, int col=0) → ZeroMat[source]

get ZeroMat matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

a ZeroMat

identity(int row=0, int col=0) → IdentityMat *[source]

get a pointer on Identity matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

an IdentityMat*

ipiv() → VInt[source]
isPLUFactorized() → bool[source]

determines if the matrix has been factorized

Returns:true if the matrix is factorized
isPLUInversed() → bool[source]

determines if the matrix has been inversed

Returns:true if the matrix is inversed
isQRFactorized() → bool[source]

determines if the matrix has been factorized

Returns:true if the matrix is factorized
isSymmetric(double tol) → bool[source]
normInf() → double[source]

compute the infinite norm of the matrix

Returns:a double
normInfByColumn(array_like (np.float64, 1D) vIn) → None[source]

Compute the normInf for each column.

Parameters:vIn – column
randomize() → None[source]

Initialize the matrix with random values.

randomize_sym() → None[source]

Initialize a symmetric matrix with random values.

resetLU() → None[source]

set to false all LU indicators.

Useful in case of assignment for example.

resetQR() → None[source]

set to false all QR indicators.

Useful in case of assignment for example.

resize(int row, int col, int lower=0, int upper=0, bool preserve=True) → None[source]

resize the matrix with nbrow rows and nbcol columns The existing elements of the matrix are preseved when specified.

Parameters:
  • row – the new number of rows
  • col – the mew number of columns
  • lower – (only for Banded)
  • upper – (only for Banded)
  • preserve – preserve existing elements
setCol(int col, array_like (np.float64, 1D) vIn) → None[source]

set column col of the current matrix with vector v

Parameters:
  • col – index column we want to set
  • vIn – a SiconosVector containing the new column
setRow(int row, array_like (np.float64, 1D) vIn) → None[source]

set line row of the current matrix with vector v

Parameters:
  • row – index row we want to set
  • vIn – SiconosVector containing the new row
setSubCol(int index, int pos, array_like (np.float64, 1D) vIn) → None[source]

set column number index of current matrix, starting from element at position pos, with vIn

Parameters:
  • index – index of required column
  • pos – index of the first required element in the column
  • vIn – a vector
setSubRow(int index, int pos, array_like (np.float64, 1D) vIn) → None[source]

set row number index of current matrix, starting from element at position pos, with vIn

Parameters:
  • index – index of required row
  • pos – index of the first required element in the row
  • vIn – a vector
setValue(int i, int j, double value) → None[source]

set the element matrix[i,j]

Parameters:
  • i – an unsigned int
  • j – an unsigned int
  • value
size(int index) → int[source]

get the number of rows or columns of the matrix

Parameters:index – 0 for rows, 1 for columns
Returns:the size
sparse(int row=0, int col=0) → SparseMat *[source]

get a pointer on SparseMat matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

a SparseMat*

subBlock(int i, int j, array_like (np.float64, 2D) m) → None[source]

subtract the input matrix to the elements starting from position i (row) and j (col).

Parameters:
  • i – an unsigned int
  • j – an unsigned int
  • m – a SiconosMatrix
sym(int row=0, int col=0) → SymMat *[source]

get a pointer on SymMat matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

a SymMat*

toString() → str[source]

put data of the matrix into a std::string

Returns:std::string
trans(*args)[source]

Warning - Overloaded function : multiple signatures available, check prototypes below.

trans() → None[source]

transpose in place: x->trans() is x = transpose of x.

trans(array_like (np.float64, 2D) mat) → None[source]

transpose a matrix: x->trans(m) is x = transpose of m.

Parameters:mat – the matrix to be transposed.
triang(int row=0, int col=0) → TriangMat *[source]

get a pointer on TriangMat matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

a TriangMat*

zero() → None[source]

sets all the values of the matrix to 0.0

zero_mat(int row=0, int col=0) → ZeroMat *[source]

get a pointer on ZeroMat matrix

Parameters:
  • row – an unsigned int, position of the block - Useless for SimpleMatrix
  • col – an unsigned int, position of the block - Useless for SimpleMatrix
Returns:

a ZeroMat*