Package com.powsybl.math.matrix
Class SparseMatrix
java.lang.Object
com.powsybl.math.AbstractMathNative
com.powsybl.math.matrix.AbstractMatrix
com.powsybl.math.matrix.SparseMatrix
- All Implemented Interfaces:
Matrix
,Serializable
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 <geoffroy.jamgotchian at rte-france.com>
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.powsybl.math.matrix.Matrix
Matrix.Element, Matrix.ElementHandler
-
Constructor Summary
ConstructorDescriptionSparseMatrix
(int rowCount, int columnCount, int[] columnStart, int[] rowIndices, double[] values) Create a sparse matrix from its internal structure vectors. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int i, int j, double value) Add value at rowi
and columnj
.Addition the matrix with another one (alpha * this + beta * other).add
(SparseMatrix other, double alpha, double beta) 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.Get LU decomposition utility class for this matrix.boolean
int
Get column count.int[]
Get columm start index vector.double
int
Get row count.int[]
Get row index vector.int
Get value count.double[]
Get non zero value vector.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 the matrix to a stream.static SparseMatrix
read
(InputStream inputStream) static SparseMatrix
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) Multiply the matrix by another one and by a scalar (this*other*scalar).times
(SparseMatrix other) times
(SparseMatrix other, double scalar) to
(MatrixFactory factory) Copy this matrix using another implementation.toDense()
Copy this matrix using a dense implementation.toSparse()
Copy this matrix using a sparse implementation.Calculate the transposed matrix.void
write
(OutputStream outputStream) void
Methods inherited from class com.powsybl.math.matrix.AbstractMatrix
add, checkBounds, copy, times
-
Constructor Details
-
SparseMatrix
public SparseMatrix(int rowCount, int columnCount, int[] columnStart, int[] rowIndices, double[] values) Create a sparse matrix from its internal structure vectors. This constructor is only called on C++ side.- Parameters:
rowCount
- row countcolumnCount
- column countcolumnStart
- column start vectorrowIndices
- row indices vectorvalues
- value vector
-
-
Method Details
-
getRgrowthThreshold
public double getRgrowthThreshold() -
setRgrowthThreshold
public void setRgrowthThreshold(double rgrowthThreshold) -
getColumnStart
public int[] getColumnStart()Get columm start index vector.- Returns:
- columm start index vector
-
getRowIndices
public int[] getRowIndices()Get row index vector.- Returns:
- row index vector
-
getValues
public double[] getValues()Get non zero value vector.- Returns:
- non zero value vector
-
getRowCount
public int getRowCount()Description copied from interface:Matrix
Get row count.- Specified by:
getRowCount
in interfaceMatrix
- Returns:
- row count
-
getColumnCount
public int getColumnCount()Description copied from interface:Matrix
Get column count.- Specified by:
getColumnCount
in interfaceMatrix
- 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.
- Specified by:
set
in interfaceMatrix
- 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.
- Specified by:
add
in interfaceMatrix
- Parameters:
i
- row indexj
- column indexvalue
- the value to add at rowi
and columnj
- Throws:
MatrixException
- if values are filled in wrong order.
-
addAndGetElement
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.
- Specified by:
addAndGetElement
in interfaceMatrix
- 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.- Specified by:
addAndGetIndex
in interfaceMatrix
- 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
.- Specified by:
setAtIndex
in interfaceMatrix
- 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.- Specified by:
setQuickAtIndex
in interfaceMatrix
- 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
.- Specified by:
addAtIndex
in interfaceMatrix
- 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.- Specified by:
addQuickAtIndex
in interfaceMatrix
- 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
Description copied from interface:Matrix
Get LU decomposition utility class for this matrix.- Specified by:
decomposeLU
in interfaceMatrix
- Returns:
- LU decomposition utility class for this matrix
-
times
-
times
-
times
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. -
add
-
add
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. -
iterateNonZeroValue
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.- Specified by:
iterateNonZeroValue
in interfaceMatrix
- Parameters:
handler
- the element handler
-
iterateNonZeroValueOfColumn
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.- Specified by:
iterateNonZeroValueOfColumn
in interfaceMatrix
- Parameters:
j
- column indexhandler
- the element handler
-
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. -
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. -
to
Description copied from interface:Matrix
Copy this matrix using another implementation. If already with the right implementation, this method is allowed to return this. -
getValueCount
public int getValueCount()Description copied from class:AbstractMatrix
Get value count.- Specified by:
getValueCount
in classAbstractMatrix
- Returns:
- the value count
-
transpose
Description copied from interface:Matrix
Calculate the transposed matrix. -
print
Description copied from interface:Matrix
Print the matrix to a stream. -
print
Description copied from interface:Matrix
Print the matrix to a stream. Row and column names are also printed to facilitate debugging. -
hashCode
public int hashCode() -
equals
-
write
-
read
-
write
-
read
-