Package org.hipparchus.linear
Class OpenMapRealMatrix
java.lang.Object
org.hipparchus.linear.AbstractRealMatrix
org.hipparchus.linear.OpenMapRealMatrix
- All Implemented Interfaces:
Serializable
,AnyMatrix
,RealLinearOperator
,RealMatrix
,SparseRealMatrix
,Blendable<RealMatrix>
Sparse matrix implementation based on an open addressed map.
Caveat: This implementation assumes that, for any x
,
the equality x * 0d == 0d
holds. But it is is not true for
NaN
. Moreover, zero entries will lose their sign.
Some operations (that involve NaN
and/or infinities) may
thus give incorrect results.
- See Also:
-
Constructor Summary
ConstructorDescriptionOpenMapRealMatrix
(int rowDimension, int columnDimension) Build a sparse matrix with the supplied row and column dimensions.OpenMapRealMatrix
(OpenMapRealMatrix matrix) Build a matrix by copying another one. -
Method Summary
Modifier and TypeMethodDescriptionCompute the sum of this matrix andm
.void
addToEntry
(int row, int column, double increment) Adds (in place) the specified value to the specified entry ofthis
matrix.copy()
Returns a (deep) copy of this.createMatrix
(int rowDimension, int columnDimension) Create a new RealMatrix of the same type as the instance with the supplied row and column dimensions.int
Returns the number of columns of this matrix.double
getEntry
(int row, int column) Get the entry in the specified row and column.int
Returns the number of rows of this matrix.Postmultiply this matrix bym
.Returns the result of postmultiplyingthis
bym
.void
multiplyEntry
(int row, int column, double factor) Multiplies (in place) the specified entry ofthis
matrix by the specified value.Returns the result of postmultiplyingthis
bym^T
.void
setEntry
(int row, int column, double value) Set the entry in the specified row and column.Subtractm
from this matrix.Returnsthis
minusm
.Returns the result of postmultiplyingthis^T
bym
.Methods inherited from class org.hipparchus.linear.AbstractRealMatrix
add, copySubMatrix, copySubMatrix, equals, getColumn, getColumnMatrix, getColumnVector, getData, getFrobeniusNorm, getRow, getRowMatrix, getRowVector, getSubMatrix, getSubMatrix, getTrace, hashCode, isSquare, operate, operate, power, preMultiply, preMultiply, preMultiply, scalarAdd, scalarMultiply, setColumn, setColumnMatrix, setColumnVector, setRow, setRowMatrix, setRowVector, setSubMatrix, toString, transpose, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.hipparchus.linear.RealLinearOperator
isTransposable, operateTranspose
Methods inherited from interface org.hipparchus.linear.RealMatrix
add, blendArithmeticallyWith, copySubMatrix, copySubMatrix, getColumn, getColumnMatrix, getColumnVector, getData, getFrobeniusNorm, getNorm1, getNormInfty, getRow, getRowMatrix, getRowVector, getSubMatrix, getSubMatrix, getTrace, map, mapToSelf, operate, operate, power, preMultiply, preMultiply, preMultiply, scalarAdd, scalarMultiply, setColumn, setColumnMatrix, setColumnVector, setRow, setRowMatrix, setRowVector, setSubMatrix, transpose, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder
-
Constructor Details
-
OpenMapRealMatrix
Build a sparse matrix with the supplied row and column dimensions.- Parameters:
rowDimension
- Number of rows of the matrix.columnDimension
- Number of columns of the matrix.- Throws:
MathIllegalArgumentException
- if row or column dimension is not positive.MathIllegalArgumentException
- if the total number of entries of the matrix is larger thanInteger.MAX_VALUE
.
-
OpenMapRealMatrix
Build a matrix by copying another one.- Parameters:
matrix
- matrix to copy.
-
-
Method Details
-
copy
Returns a (deep) copy of this.- Specified by:
copy
in interfaceRealMatrix
- Specified by:
copy
in classAbstractRealMatrix
- Returns:
- matrix copy
-
createMatrix
public OpenMapRealMatrix createMatrix(int rowDimension, int columnDimension) throws MathIllegalArgumentException Create a new RealMatrix of the same type as the instance with the supplied row and column dimensions.- Specified by:
createMatrix
in interfaceRealMatrix
- Specified by:
createMatrix
in classAbstractRealMatrix
- Parameters:
rowDimension
- the number of rows in the new matrixcolumnDimension
- the number of columns in the new matrix- Returns:
- a new matrix of the same type as the instance
- Throws:
MathIllegalArgumentException
- if the total number of entries of the matrix is larger thanInteger.MAX_VALUE
.
-
getColumnDimension
public int getColumnDimension()Returns the number of columns of this matrix.- Specified by:
getColumnDimension
in interfaceAnyMatrix
- Specified by:
getColumnDimension
in interfaceRealLinearOperator
- Specified by:
getColumnDimension
in classAbstractRealMatrix
- Returns:
- the number of columns.
-
add
Compute the sum of this matrix andm
.- Parameters:
m
- Matrix to be added.- Returns:
this
+m
.- Throws:
MathIllegalArgumentException
- ifm
is not the same size asthis
.
-
subtract
Returnsthis
minusm
.- Specified by:
subtract
in interfaceRealMatrix
- Overrides:
subtract
in classAbstractRealMatrix
- Parameters:
m
- matrix to be subtracted- Returns:
this - m
- Throws:
MathIllegalArgumentException
- ifm
is not the same size asthis
.
-
subtract
Subtractm
from this matrix.- Parameters:
m
- Matrix to be subtracted.- Returns:
this
-m
.- Throws:
MathIllegalArgumentException
- ifm
is not the same size asthis
.
-
multiply
Returns the result of postmultiplyingthis
bym
.- Specified by:
multiply
in interfaceRealMatrix
- Overrides:
multiply
in classAbstractRealMatrix
- Parameters:
m
- matrix to postmultiply by- Returns:
this * m
- Throws:
MathIllegalArgumentException
- ifm
is anOpenMapRealMatrix
, and the total number of entries of the product is larger thanInteger.MAX_VALUE
.
-
multiplyTransposed
Returns the result of postmultiplyingthis
bym^T
.This is equivalent to call
multiply
(m.RealMatrix.transpose()
), but some implementations may avoid building the intermediate transposed matrix.- Specified by:
multiplyTransposed
in interfaceRealMatrix
- Parameters:
m
- matrix to first transpose and second postmultiply by- Returns:
this * m^T
- Throws:
MathIllegalArgumentException
- ifm
is anOpenMapRealMatrix
, and the total number of entries of the product is larger thanInteger.MAX_VALUE
.
-
transposeMultiply
Returns the result of postmultiplyingthis^T
bym
.This is equivalent to call
RealMatrix.transpose()
.multiply(m)
, but some implementations may avoid building the intermediate transposed matrix.- Specified by:
transposeMultiply
in interfaceRealMatrix
- Parameters:
m
- matrix to postmultiply by- Returns:
this^T * m
- Throws:
MathIllegalArgumentException
- ifm
is anOpenMapRealMatrix
, and the total number of entries of the product is larger thanInteger.MAX_VALUE
.
-
multiply
Postmultiply this matrix bym
.- Parameters:
m
- Matrix to postmultiply by.- Returns:
this
*m
.- Throws:
MathIllegalArgumentException
- if the number of rows ofm
differ from the number of columns ofthis
matrix.MathIllegalArgumentException
- if the total number of entries of the product is larger thanInteger.MAX_VALUE
.
-
getEntry
Get the entry in the specified row and column. Row and column indices start at 0.- Specified by:
getEntry
in interfaceRealMatrix
- Specified by:
getEntry
in classAbstractRealMatrix
- Parameters:
row
- Row index of entry to be fetched.column
- Column index of entry to be fetched.- Returns:
- the matrix entry at
(row, column)
. - Throws:
MathIllegalArgumentException
- if the row or column index is not valid.
-
getRowDimension
public int getRowDimension()Returns the number of rows of this matrix.- Specified by:
getRowDimension
in interfaceAnyMatrix
- Specified by:
getRowDimension
in interfaceRealLinearOperator
- Specified by:
getRowDimension
in classAbstractRealMatrix
- Returns:
- the number of rows.
-
setEntry
Set the entry in the specified row and column. Row and column indices start at 0.- Specified by:
setEntry
in interfaceRealMatrix
- Specified by:
setEntry
in classAbstractRealMatrix
- Parameters:
row
- Row index of entry to be set.column
- Column index of entry to be set.value
- the new value of the entry.- Throws:
MathIllegalArgumentException
- if the row or column index is not valid
-
addToEntry
Adds (in place) the specified value to the specified entry ofthis
matrix. Row and column indices start at 0.- Specified by:
addToEntry
in interfaceRealMatrix
- Overrides:
addToEntry
in classAbstractRealMatrix
- Parameters:
row
- Row index of the entry to be modified.column
- Column index of the entry to be modified.increment
- value to add to the matrix entry.- Throws:
MathIllegalArgumentException
- if the row or column index is not valid.
-
multiplyEntry
Multiplies (in place) the specified entry ofthis
matrix by the specified value. Row and column indices start at 0.- Specified by:
multiplyEntry
in interfaceRealMatrix
- Overrides:
multiplyEntry
in classAbstractRealMatrix
- Parameters:
row
- Row index of the entry to be modified.column
- Column index of the entry to be modified.factor
- Multiplication factor for the matrix entry.- Throws:
MathIllegalArgumentException
- if the row or column index is not valid.
-