- java.lang.Object
-
- com.powsybl.math.matrix.AbstractMatrix
-
- com.powsybl.math.matrix.DenseMatrix
-
- All Implemented Interfaces:
Matrix
public class DenseMatrix extends AbstractMatrix
Dense matrix implementation based on an array ofrowCount
*columnCount
double values.- Author:
- Geoffroy Jamgotchian
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.powsybl.math.matrix.Matrix
Matrix.Element, Matrix.ElementHandler
-
-
Constructor Summary
Constructors Constructor Description DenseMatrix(int rowCount, int columnCount)
DenseMatrix(int rowCount, int columnCount, double[] values)
DenseMatrix(int rowCount, int columnCount, Supplier<ByteBuffer> bufferSupplier)
DenseMatrix(Jama.Matrix matrix)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(int i, int j, double value)
Add value at rowi
and columnj
.DenseMatrix
add(DenseMatrix other, double alpha, double beta)
Matrix
add(Matrix other, double alpha, double beta)
Addition the matrix with another one (alpha * this + beta * other).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)
double
get(int i, int j)
Get value at rowi
and columnj
.int
getColumnCount()
Get column count.protected int
getEstimatedNonZeroValueCount()
Get an estimation of non zero value count.int
getRowCount()
Get row count.double
getValue(int i, int j)
Deprecated.Useget(int, int)
instead.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.DenseMatrix
times(DenseMatrix other)
DenseMatrix
times(DenseMatrix other, double scalar)
Matrix
times(Matrix other, double scalar)
Multiply the matrix by another one and by a scalar (this*other*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.DenseMatrix
transpose()
Calculate the transposed matrix.-
Methods inherited from class com.powsybl.math.matrix.AbstractMatrix
add, checkBounds, copy, times
-
-
-
-
Constructor Detail
-
DenseMatrix
public DenseMatrix(int rowCount, int columnCount, double[] values)
-
DenseMatrix
public DenseMatrix(int rowCount, int columnCount)
-
DenseMatrix
public DenseMatrix(int rowCount, int columnCount, Supplier<ByteBuffer> bufferSupplier)
-
DenseMatrix
public DenseMatrix(Jama.Matrix matrix)
-
-
Method Detail
-
get
public double get(int i, int j)
Get value at rowi
and columnj
.- Parameters:
i
- row indexj
- column index- Returns:
- value at row
i
and columnj
-
getValue
@Deprecated public double getValue(int i, int j)
Deprecated.Useget(int, int)
instead.
-
set
public void set(int i, int j, double value)
Description copied from interface:Matrix
Set value at rowi
and columnj
.- Parameters:
i
- row indexj
- column indexvalue
- the value to set at rowi
and columnj
-
add
public void add(int i, int j, double value)
Description copied from interface:Matrix
Add value at rowi
and columnj
.- Parameters:
i
- row indexj
- column indexvalue
- the value to add at rowi
and columnj
-
addAndGetElement
public Matrix.Element addAndGetElement(int i, int j, double value)
Description copied from interface:Matrix
Add value at rowi
and columnj
and get an#Element
to later update the element.- Parameters:
i
- row indexj
- column indexvalue
- the value to add at rowi
and columnj
- Returns:
- an element at row
i
and columnj
-
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.
-
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
-
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 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
-
times
public DenseMatrix times(DenseMatrix other, double scalar)
-
times
public DenseMatrix times(DenseMatrix other)
-
add
public DenseMatrix add(DenseMatrix 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 DenseMatrix 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
-
-