Package org.apache.commons.math3.linear
Class OpenMapRealMatrix
java.lang.Object
org.apache.commons.math3.linear.RealLinearOperator
org.apache.commons.math3.linear.AbstractRealMatrix
org.apache.commons.math3.linear.OpenMapRealMatrix
- All Implemented Interfaces:
Serializable,AnyMatrix,RealMatrix,SparseRealMatrix
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.
- Since:
- 2.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionOpenMapRealMatrix(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.voidaddToEntry(int row, int column, double increment) Adds (in place) the specified value to the specified entry ofthismatrix.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.intReturns the number of columns of this matrix.doublegetEntry(int row, int column) Get the entry in the specified row and column.intReturns the number of rows of this matrix.Postmultiply this matrix bym.Returns the result of postmultiplyingthisbym.voidmultiplyEntry(int row, int column, double factor) Multiplies (in place) the specified entry ofthismatrix by the specified value.voidsetEntry(int row, int column, double value) Set the entry in the specified row and column.Subtractmfrom this matrix.Returnsthisminusm.Methods inherited from class org.apache.commons.math3.linear.AbstractRealMatrix
add, copySubMatrix, copySubMatrix, equals, getColumn, getColumnMatrix, getColumnVector, getData, getFrobeniusNorm, getNorm, 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, walkInRowOrderMethods inherited from class org.apache.commons.math3.linear.RealLinearOperator
isTransposable, operateTransposeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.math3.linear.RealMatrix
add, copySubMatrix, copySubMatrix, getColumn, getColumnMatrix, getColumnVector, getData, getFrobeniusNorm, getNorm, getRow, getRowMatrix, getRowVector, getSubMatrix, getSubMatrix, getTrace, 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
public OpenMapRealMatrix(int rowDimension, int columnDimension) throws NotStrictlyPositiveException, NumberIsTooLargeException 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:
NotStrictlyPositiveException- if row or column dimension is not positive.NumberIsTooLargeException- 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:
copyin interfaceRealMatrix- Specified by:
copyin classAbstractRealMatrix- Returns:
- matrix copy
-
createMatrix
public OpenMapRealMatrix createMatrix(int rowDimension, int columnDimension) throws NotStrictlyPositiveException, NumberIsTooLargeException Create a new RealMatrix of the same type as the instance with the supplied row and column dimensions.- Specified by:
createMatrixin interfaceRealMatrix- Specified by:
createMatrixin 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:
NumberIsTooLargeException- if the total number of entries of the matrix is larger thanInteger.MAX_VALUE.NotStrictlyPositiveException- if row or column dimension is not positive.
-
getColumnDimension
public int getColumnDimension()Returns the number of columns of this matrix.- Specified by:
getColumnDimensionin interfaceAnyMatrix- Specified by:
getColumnDimensionin classAbstractRealMatrix- Returns:
- the number of columns.
-
add
Compute the sum of this matrix andm.- Parameters:
m- Matrix to be added.- Returns:
this+m.- Throws:
MatrixDimensionMismatchException- ifmis not the same size asthis.
-
subtract
Returnsthisminusm.- Specified by:
subtractin interfaceRealMatrix- Overrides:
subtractin classAbstractRealMatrix- Parameters:
m- matrix to be subtracted- Returns:
this - m- Throws:
MatrixDimensionMismatchException- ifmis not the same size asthis.
-
subtract
Subtractmfrom this matrix.- Parameters:
m- Matrix to be subtracted.- Returns:
this-m.- Throws:
MatrixDimensionMismatchException- ifmis not the same size asthis.
-
multiply
public RealMatrix multiply(RealMatrix m) throws DimensionMismatchException, NumberIsTooLargeException Returns the result of postmultiplyingthisbym.- Specified by:
multiplyin interfaceRealMatrix- Overrides:
multiplyin classAbstractRealMatrix- Parameters:
m- matrix to postmultiply by- Returns:
this * m- Throws:
NumberIsTooLargeException- ifmis anOpenMapRealMatrix, and the total number of entries of the product is larger thanInteger.MAX_VALUE.DimensionMismatchException- ifcolumnDimension(this) != rowDimension(m)
-
multiply
public OpenMapRealMatrix multiply(OpenMapRealMatrix m) throws DimensionMismatchException, NumberIsTooLargeException Postmultiply this matrix bym.- Parameters:
m- Matrix to postmultiply by.- Returns:
this*m.- Throws:
DimensionMismatchException- if the number of rows ofmdiffer from the number of columns ofthismatrix.NumberIsTooLargeException- 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:
getEntryin interfaceRealMatrix- Specified by:
getEntryin 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:
OutOfRangeException- if the row or column index is not valid.
-
getRowDimension
public int getRowDimension()Returns the number of rows of this matrix.- Specified by:
getRowDimensionin interfaceAnyMatrix- Specified by:
getRowDimensionin 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:
setEntryin interfaceRealMatrix- Specified by:
setEntryin 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:
OutOfRangeException- if the row or column index is not valid
-
addToEntry
Adds (in place) the specified value to the specified entry ofthismatrix. Row and column indices start at 0.- Specified by:
addToEntryin interfaceRealMatrix- Overrides:
addToEntryin 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:
OutOfRangeException- if the row or column index is not valid.
-
multiplyEntry
Multiplies (in place) the specified entry ofthismatrix by the specified value. Row and column indices start at 0.- Specified by:
multiplyEntryin interfaceRealMatrix- Overrides:
multiplyEntryin 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:
OutOfRangeException- if the row or column index is not valid.
-