Package org.apache.commons.math.linear
Class OpenMapRealMatrix
- java.lang.Object
-
- org.apache.commons.math.linear.AbstractRealMatrix
-
- org.apache.commons.math.linear.OpenMapRealMatrix
-
- All Implemented Interfaces:
java.io.Serializable
,AnyMatrix
,RealMatrix
,SparseRealMatrix
public class OpenMapRealMatrix extends AbstractRealMatrix implements SparseRealMatrix, java.io.Serializable
Sparse matrix implementation based on an open addressed map.- Since:
- 2.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description OpenMapRealMatrix(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OpenMapRealMatrix
add(OpenMapRealMatrix m)
Compute the sum of this andm
.OpenMapRealMatrix
add(RealMatrix m)
Compute the sum of this and m.void
addToEntry(int row, int column, double increment)
Change an entry in the specified row and column.OpenMapRealMatrix
copy()
Returns a (deep) copy of this.OpenMapRealMatrix
createMatrix(int rowDimension, int columnDimension)
Create a new RealMatrix of the same type as the instance with the supplied row and column dimensions.int
getColumnDimension()
Returns the number of columns in the matrix.double
getEntry(int row, int column)
Returns the entry in the specified row and column.int
getRowDimension()
Returns the number of rows in the matrix.OpenMapRealMatrix
multiply(OpenMapRealMatrix m)
Returns the result of postmultiplying this by m.RealMatrix
multiply(RealMatrix m)
Returns the result of postmultiplying this by m.void
multiplyEntry(int row, int column, double factor)
Change an entry in the specified row and column.void
setEntry(int row, int column, double value)
Set the entry in the specified row and column.OpenMapRealMatrix
subtract(OpenMapRealMatrix m)
Compute this minusm
.OpenMapRealMatrix
subtract(RealMatrix m)
Compute this minus m.-
Methods inherited from class org.apache.commons.math.linear.AbstractRealMatrix
copySubMatrix, copySubMatrix, equals, getColumn, getColumnMatrix, getColumnVector, getData, getDeterminant, getFrobeniusNorm, getNorm, getRow, getRowMatrix, getRowVector, getSubMatrix, getSubMatrix, getTrace, hashCode, inverse, isSingular, isSquare, luDecompose, operate, operate, preMultiply, preMultiply, preMultiply, scalarAdd, scalarMultiply, setColumn, setColumnMatrix, setColumnVector, setRow, setRowMatrix, setRowVector, setSubMatrix, solve, solve, toString, transpose, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder
-
Methods inherited from interface org.apache.commons.math.linear.RealMatrix
copySubMatrix, copySubMatrix, getColumn, getColumnMatrix, getColumnVector, getData, getDeterminant, getFrobeniusNorm, getNorm, getRow, getRowMatrix, getRowVector, getSubMatrix, getSubMatrix, getTrace, inverse, isSingular, operate, operate, preMultiply, preMultiply, preMultiply, scalarAdd, scalarMultiply, setColumn, setColumnMatrix, setColumnVector, setRow, setRowMatrix, setRowVector, setSubMatrix, solve, solve, transpose, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder
-
-
-
-
Constructor Detail
-
OpenMapRealMatrix
public OpenMapRealMatrix(int rowDimension, int columnDimension)
Build a sparse matrix with the supplied row and column dimensions.- Parameters:
rowDimension
- number of rows of the matrixcolumnDimension
- number of columns of the matrix
-
OpenMapRealMatrix
public OpenMapRealMatrix(OpenMapRealMatrix matrix)
Build a matrix by copying another one.- Parameters:
matrix
- matrix to copy
-
-
Method Detail
-
copy
public OpenMapRealMatrix 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 java.lang.IllegalArgumentException
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:
java.lang.IllegalArgumentException
- if row or column dimension is not positive
-
getColumnDimension
public int getColumnDimension()
Returns the number of columns in the matrix.- Specified by:
getColumnDimension
in interfaceAnyMatrix
- Specified by:
getColumnDimension
in classAbstractRealMatrix
- Returns:
- columnDimension
-
add
public OpenMapRealMatrix add(RealMatrix m) throws java.lang.IllegalArgumentException
Compute the sum of this and m.- Specified by:
add
in interfaceRealMatrix
- Overrides:
add
in classAbstractRealMatrix
- Parameters:
m
- matrix to be added- Returns:
- this + m
- Throws:
java.lang.IllegalArgumentException
- if m is not the same size as this
-
add
public OpenMapRealMatrix add(OpenMapRealMatrix m) throws java.lang.IllegalArgumentException
Compute the sum of this andm
.- Parameters:
m
- matrix to be added- Returns:
- this + m
- Throws:
java.lang.IllegalArgumentException
- if m is not the same size as this
-
subtract
public OpenMapRealMatrix subtract(RealMatrix m) throws java.lang.IllegalArgumentException
Compute this minus m.- Specified by:
subtract
in interfaceRealMatrix
- Overrides:
subtract
in classAbstractRealMatrix
- Parameters:
m
- matrix to be subtracted- Returns:
- this - m
- Throws:
java.lang.IllegalArgumentException
- if m is not the same size as this
-
subtract
public OpenMapRealMatrix subtract(OpenMapRealMatrix m) throws java.lang.IllegalArgumentException
Compute this minusm
.- Parameters:
m
- matrix to be subtracted- Returns:
- this - m
- Throws:
java.lang.IllegalArgumentException
- if m is not the same size as this
-
multiply
public RealMatrix multiply(RealMatrix m) throws java.lang.IllegalArgumentException
Returns the result of postmultiplying this by m.- Specified by:
multiply
in interfaceRealMatrix
- Overrides:
multiply
in classAbstractRealMatrix
- Parameters:
m
- matrix to postmultiply by- Returns:
- this * m
- Throws:
java.lang.IllegalArgumentException
- if columnDimension(this) != rowDimension(m)
-
multiply
public OpenMapRealMatrix multiply(OpenMapRealMatrix m) throws java.lang.IllegalArgumentException
Returns the result of postmultiplying this by m.- Parameters:
m
- matrix to postmultiply by- Returns:
- this * m
- Throws:
java.lang.IllegalArgumentException
- if columnDimension(this) != rowDimension(m)
-
getEntry
public double getEntry(int row, int column) throws MatrixIndexException
Returns the entry in the specified row and column.Row and column indices start at 0 and must satisfy
0 <= row < rowDimension
0 <= column < columnDimension
MatrixIndexException
is thrown.- Specified by:
getEntry
in interfaceRealMatrix
- Specified by:
getEntry
in classAbstractRealMatrix
- Parameters:
row
- row location of entry to be fetchedcolumn
- column location of entry to be fetched- Returns:
- matrix entry in row,column
- Throws:
MatrixIndexException
- if the row or column index is not valid
-
getRowDimension
public int getRowDimension()
Returns the number of rows in the matrix.- Specified by:
getRowDimension
in interfaceAnyMatrix
- Specified by:
getRowDimension
in classAbstractRealMatrix
- Returns:
- rowDimension
-
setEntry
public void setEntry(int row, int column, double value) throws MatrixIndexException
Set the entry in the specified row and column.Row and column indices start at 0 and must satisfy
0 <= row < rowDimension
0 <= column < columnDimension
MatrixIndexException
is thrown.- Specified by:
setEntry
in interfaceRealMatrix
- Specified by:
setEntry
in classAbstractRealMatrix
- Parameters:
row
- row location of entry to be setcolumn
- column location of entry to be setvalue
- matrix entry to be set in row,column- Throws:
MatrixIndexException
- if the row or column index is not valid
-
addToEntry
public void addToEntry(int row, int column, double increment) throws MatrixIndexException
Change an entry in the specified row and column.Row and column indices start at 0 and must satisfy
0 <= row < rowDimension
0 <= column < columnDimension
MatrixIndexException
is thrown.- Specified by:
addToEntry
in interfaceRealMatrix
- Specified by:
addToEntry
in classAbstractRealMatrix
- Parameters:
row
- row location of entry to be setcolumn
- column location of entry to be setincrement
- value to add to the current matrix entry in row,column- Throws:
MatrixIndexException
- if the row or column index is not valid
-
multiplyEntry
public void multiplyEntry(int row, int column, double factor) throws MatrixIndexException
Change an entry in the specified row and column.Row and column indices start at 0 and must satisfy
0 <= row < rowDimension
0 <= column < columnDimension
MatrixIndexException
is thrown.- Specified by:
multiplyEntry
in interfaceRealMatrix
- Specified by:
multiplyEntry
in classAbstractRealMatrix
- Parameters:
row
- row location of entry to be setcolumn
- column location of entry to be setfactor
- multiplication factor for the current matrix entry in row,column- Throws:
MatrixIndexException
- if the row or column index is not valid
-
-