- java.lang.Object
-
- com.powsybl.math.matrix.AbstractMatrix
-
- com.powsybl.math.matrix.SparseMatrix
-
- All Implemented Interfaces:
Matrix
public class SparseMatrix extends AbstractMatrix
Sparse matrix implementation in CSC format. This implementation rely on a native library which is a wrapper around KLU module of SuiteSparse project.- Author:
- Geoffroy Jamgotchian
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.powsybl.math.matrix.Matrix
Matrix.Element, Matrix.ElementHandler
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int i, int j, double value)
Add value at rowi
and columnj
.Matrix
add(Matrix other, double alpha, double beta)
Addition the matrix with another one (alpha * this + beta * other).SparseMatrix
add(SparseMatrix other, double alpha, double beta)
Matrix.Element
addAndGetElement(int i, int j, double value)
Add value at rowi
and columnj
and get an#Element
to later update the element.int
addAndGetIndex(int i, int j, double value)
Add value at rowi
and columnj
and get an element index to later update the element.void
addAtIndex(int index, double value)
Add value at element indexindex
.void
addQuickAtIndex(int index, double value)
Add value at element indexindex
without doing any bound checking.LUDecomposition
decomposeLU()
Get LU decomposition utility class for this matrix.boolean
equals(Object obj)
int
getColumnCount()
Get column count.protected int
getEstimatedNonZeroValueCount()
Get an estimation of non zero value count.double
getRgrowthThreshold()
int
getRowCount()
Get row count.int
hashCode()
void
iterateNonZeroValue(Matrix.ElementHandler handler)
Iterate over non zero values of the matrix.void
iterateNonZeroValueOfColumn(int j, Matrix.ElementHandler handler)
Iterate over non zero values of thej
column of the matrix.void
print(PrintStream out)
Print the matrix to a stream.void
print(PrintStream out, List<String> rowNames, List<String> columnNames)
Print the matrix to a stream.void
reset()
Fill matrix with zeros.void
set(int i, int j, double value)
Set value at rowi
and columnj
.void
setAtIndex(int index, double value)
Set value at element indexindex
.void
setQuickAtIndex(int index, double value)
Set value at element indexindex
without doing any bound checking.void
setRgrowthThreshold(double rgrowthThreshold)
Matrix
times(Matrix other, double scalar)
Multiply the matrix by another one and by a scalar (this*other*scalar).SparseMatrix
times(SparseMatrix other)
SparseMatrix
times(SparseMatrix other, double scalar)
Matrix
to(MatrixFactory factory)
Copy this matrix using another implementation.DenseMatrix
toDense()
Copy this matrix using a dense implementation.SparseMatrix
toSparse()
Copy this matrix using a sparse implementation.SparseMatrix
transpose()
Calculate the transposed matrix.-
Methods inherited from class com.powsybl.math.matrix.AbstractMatrix
add, checkBounds, copy, times
-
-
-
-
Method Detail
-
getRgrowthThreshold
public double getRgrowthThreshold()
-
setRgrowthThreshold
public void setRgrowthThreshold(double rgrowthThreshold)
-
getRowCount
public int getRowCount()
Description copied from interface:Matrix
Get row count.- Returns:
- row count
-
getColumnCount
public int getColumnCount()
Description copied from interface:Matrix
Get column count.- Returns:
- column count
-
set
public void set(int i, int j, double value)
Set value at rowi
and columnj
.As sparse matrix is stored in CSC format. Columns must be filled in ascending order but values inside a column may be filled in any order.
- Parameters:
i
- row indexj
- column indexvalue
- the value to set at rowi
and columnj
- Throws:
MatrixException
- if values are filled in wrong order.
-
add
public void add(int i, int j, double value)
Add value at rowi
and columnj
.As sparse matrix is stored in CSC format. Columns must be filled in ascending order but values inside a column may be filled in any order.
- Parameters:
i
- row indexj
- column indexvalue
- the value to add at rowi
and columnj
- Throws:
MatrixException
- if values are filled in wrong order.
-
addAndGetElement
public Matrix.Element addAndGetElement(int i, int j, double value)
Add value at rowi
and columnj
and get an#Element
to later update the element.As sparse matrix is stored in CSC format. Columns must be filled in ascending order but values inside a column may be filled in any order.
- Parameters:
i
- row indexj
- column indexvalue
- the value to add at rowi
and columnj
- Returns:
- an element at row
i
and columnj
- Throws:
MatrixException
- if values are filled in wrong order.
-
addAndGetIndex
public int addAndGetIndex(int i, int j, double value)
Description copied from interface:Matrix
Add value at rowi
and columnj
and get an element index to later update the element.- Parameters:
i
- row indexj
- column indexvalue
- the value to add at rowi
and columnj
- Returns:
- an element index corresponding to row
i
and columnj
-
setAtIndex
public void setAtIndex(int index, double value)
Description copied from interface:Matrix
Set value at element indexindex
.- Parameters:
index
- element indexvalue
- the value to set at element indexindex
-
setQuickAtIndex
public void setQuickAtIndex(int index, double value)
Description copied from interface:Matrix
Set value at element indexindex
without doing any bound checking.- Parameters:
index
- element indexvalue
- the value to set at element indexindex
-
addAtIndex
public void addAtIndex(int index, double value)
Description copied from interface:Matrix
Add value at element indexindex
.- Parameters:
index
- element indexvalue
- the value to add at element indexindex
-
addQuickAtIndex
public void addQuickAtIndex(int index, double value)
Description copied from interface:Matrix
Add value at element indexindex
without doing any bound checking.- Parameters:
index
- element indexvalue
- the value to add at element indexindex
-
reset
public void reset()
Description copied from interface:Matrix
Fill matrix with zeros.
-
decomposeLU
public LUDecomposition decomposeLU()
Description copied from interface:Matrix
Get LU decomposition utility class for this matrix.- Returns:
- LU decomposition utility class for this matrix
-
times
public SparseMatrix times(SparseMatrix other)
-
times
public SparseMatrix times(SparseMatrix other, double scalar)
-
times
public Matrix times(Matrix other, double scalar)
Description copied from interface:Matrix
Multiply the matrix by another one and by a scalar (this*other*scalar). The resulting matrix has the same implementation as this matrix.- Parameters:
other
- the other matrixscalar
- a scalar to multiply the result matrix- Returns:
- the result of the multiplication of this matrix by the other one
-
add
public SparseMatrix add(SparseMatrix other, double alpha, double beta)
-
add
public Matrix add(Matrix other, double alpha, double beta)
Description copied from interface:Matrix
Addition the matrix with another one (alpha * this + beta * other). The resulting matrix has the same implementation as this matrix.- Parameters:
other
- the other matrixalpha
- a scalar to multiply this matrixbeta
- a scalar to multiply other matrix- Returns:
- the result of the addition of this matrix and the other one
-
iterateNonZeroValue
public void iterateNonZeroValue(Matrix.ElementHandler handler)
Description copied from interface:Matrix
Iterate over non zero values of the matrix. At each non zero valueMatrix.ElementHandler.onElement(int, int, double)
is called.- Parameters:
handler
- the element handler
-
iterateNonZeroValueOfColumn
public void iterateNonZeroValueOfColumn(int j, Matrix.ElementHandler handler)
Description copied from interface:Matrix
Iterate over non zero values of thej
column of the matrix. At each non zero valueMatrix.ElementHandler.onElement(int, int, double)
is called.- Parameters:
j
- column indexhandler
- the element handler
-
toDense
public DenseMatrix toDense()
Description copied from interface:Matrix
Copy this matrix using a dense implementation. If already a dense matrix, this method is allowed to return this.- Returns:
- a copy of the matrix with a dense implementation.
-
toSparse
public SparseMatrix toSparse()
Description copied from interface:Matrix
Copy this matrix using a sparse implementation. If already a sparse matrix, this method is allowed to return this.- Returns:
- a copy of the matrix with a sparse implementation.
-
to
public Matrix to(MatrixFactory factory)
Description copied from interface:Matrix
Copy this matrix using another implementation. If already with the right implementation, this method is allowed to return this.- Parameters:
factory
- a matrix factory to create the copy.- Returns:
- a copy of the matrix
-
getEstimatedNonZeroValueCount
protected int getEstimatedNonZeroValueCount()
Description copied from class:AbstractMatrix
Get an estimation of non zero value count.- Specified by:
getEstimatedNonZeroValueCount
in classAbstractMatrix
- Returns:
- an estimation of non zero value count
-
transpose
public SparseMatrix transpose()
Description copied from interface:Matrix
Calculate the transposed matrix.- Returns:
- the transposed matrix
-
print
public void print(PrintStream out)
Description copied from interface:Matrix
Print the matrix to a stream.- Parameters:
out
- the stream
-
print
public void print(PrintStream out, List<String> rowNames, List<String> columnNames)
Description copied from interface:Matrix
Print the matrix to a stream. Row and column names are also printed to facilitate debugging.- Parameters:
out
- the streamrowNames
- row namescolumnNames
- column names
-
-