Top Description Fields Constructors Methods
org.apache.commons.math3.linear

public Class OpenMapRealMatrix

extends AbstractRealMatrix
implements SparseRealMatrix, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.math3.linear.SparseRealMatrix, org.apache.commons.math3.linear.RealMatrix, org.apache.commons.math3.linear.AnyMatrix
Imports
java.io.Serializable, org.apache.commons.math3.exception.DimensionMismatchException, .NotStrictlyPositiveException, .NumberIsTooLargeException, .OutOfRangeException, org.apache.commons.math3.util.OpenIntToDoubleHashMap

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

Field Summary

Modifier and TypeField and Description
private final int
columns

Number of columns of the matrix.

private final OpenIntToDoubleHashMap
entries

Storage for (sparse) matrix elements.

private final int
rows

Number of rows of the matrix.

private static final long
serialVersionUID

Serializable version identifier.

Constructor Summary

AccessConstructor and Description
public
OpenMapRealMatrix(int
Number of rows of the matrix.
rowDimension
,
int
Number of columns of the matrix.
columnDimension
)

Build a sparse matrix with the supplied row and column dimensions.

public
OpenMapRealMatrix(OpenMapRealMatrix
matrix to copy.
matrix
)

Build a matrix by copying another one.

Method Summary

Modifier and TypeMethod and Description
public OpenMapRealMatrix

Returns:

this + m.
add
(OpenMapRealMatrix
Matrix to be added.
m
)

Compute the sum of this matrix and m.

public void
addToEntry(int
Row index of the entry to be modified.
row
,
int
Column index of the entry to be modified.
column
,
double
value to add to the matrix entry.
increment
)

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.addToEntry.

Implements org.apache.commons.math3.linear.RealMatrix.addToEntry.

Adds (in place) the specified value to the specified entry of this matrix.

private int

Returns:

key within the map to access the matrix element
computeKey
(int
row index of the matrix element
row
,
int
column index of the matrix element
column
)

Compute the key to access a matrix element

public OpenMapRealMatrix
public OpenMapRealMatrix
createMatrix(int
the number of rows in the new matrix
rowDimension
,
int
the number of columns in the new matrix
columnDimension
)

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.createMatrix.

Implements org.apache.commons.math3.linear.RealMatrix.createMatrix.

Create a new RealMatrix of the same type as the instance with the supplied row and column dimensions.

public int
public double
getEntry(int
Row index of entry to be fetched.
row
,
int
Column index of entry to be fetched.
column
)

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.getEntry.

Implements org.apache.commons.math3.linear.RealMatrix.getEntry.

Get the entry in the specified row and column.

public int
public RealMatrix
multiply(final RealMatrix
matrix to postmultiply by
m
)

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.multiply.

Implements org.apache.commons.math3.linear.RealMatrix.multiply.

Returns the result of postmultiplying this by m.

public OpenMapRealMatrix

Returns:

this * m.
multiply
(OpenMapRealMatrix
Matrix to postmultiply by.
m
)

Postmultiply this matrix by m.

public void
multiplyEntry(int
Row index of the entry to be modified.
row
,
int
Column index of the entry to be modified.
column
,
double
Multiplication factor for the matrix entry.
factor
)

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.multiplyEntry.

Implements org.apache.commons.math3.linear.RealMatrix.multiplyEntry.

Multiplies (in place) the specified entry of this matrix by the specified value.

public void
setEntry(int
Row index of entry to be set.
row
,
int
Column index of entry to be set.
column
,
double
the new value of the entry.
value
)

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.setEntry.

Implements org.apache.commons.math3.linear.RealMatrix.setEntry.

Set the entry in the specified row and column.

public OpenMapRealMatrix
public OpenMapRealMatrix

Returns:

this - m.
subtract
(OpenMapRealMatrix
Matrix to be subtracted.
m
)

Subtract m from this matrix.

Inherited from org.apache.commons.math3.linear.AbstractRealMatrix:
addcopySubMatrixcopySubMatrixequalsgetColumngetColumnMatrixgetColumnVectorgetDatagetFrobeniusNormgetNormgetRowgetRowMatrixgetRowVectorgetSubMatrixgetSubMatrixgetTracehashCodeisSquareoperateoperatepowerpreMultiplypreMultiplypreMultiplyscalarAddscalarMultiplysetColumnsetColumnMatrixsetColumnVectorsetRowsetRowMatrixsetRowVectorsetSubMatrixtoStringtransposewalkInColumnOrderwalkInColumnOrderwalkInColumnOrderwalkInColumnOrderwalkInOptimizedOrderwalkInOptimizedOrderwalkInOptimizedOrderwalkInOptimizedOrderwalkInRowOrderwalkInRowOrderwalkInRowOrderwalkInRowOrder

Field Detail

columnsback to summary
private final int columns

Number of columns of the matrix.

entriesback to summary
private final OpenIntToDoubleHashMap entries

Storage for (sparse) matrix elements.

rowsback to summary
private final int rows

Number of rows of the matrix.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier.

Constructor Detail

OpenMapRealMatrixback to summary
public OpenMapRealMatrix(int rowDimension, int columnDimension) throws NotStrictlyPositiveException, NumberIsTooLargeException

Build a sparse matrix with the supplied row and column dimensions.

Parameters
rowDimension:int

Number of rows of the matrix.

columnDimension:int

Number of columns of the matrix.

Exceptions
NotStrictlyPositiveException:
if row or column dimension is not positive.
NumberIsTooLargeException:
if the total number of entries of the matrix is larger than Integer.MAX_VALUE.
OpenMapRealMatrixback to summary
public OpenMapRealMatrix(OpenMapRealMatrix matrix)

Build a matrix by copying another one.

Parameters
matrix:OpenMapRealMatrix

matrix to copy.

Method Detail

addback to summary
public OpenMapRealMatrix add(OpenMapRealMatrix m) throws MatrixDimensionMismatchException

Compute the sum of this matrix and m.

Parameters
m:OpenMapRealMatrix

Matrix to be added.

Returns:OpenMapRealMatrix

this + m.

Exceptions
MatrixDimensionMismatchException:
if m is not the same size as this.
addToEntryback to summary
public void addToEntry(int row, int column, double increment) throws OutOfRangeException

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.addToEntry.

Implements org.apache.commons.math3.linear.RealMatrix.addToEntry.

Doc from org.apache.commons.math3.linear.RealMatrix.addToEntry.

Adds (in place) the specified value to the specified entry of this matrix. Row and column indices start at 0.

Parameters
row:int

Row index of the entry to be modified.

column:int

Column index of the entry to be modified.

increment:double

value to add to the matrix entry.

Annotations
@Override
Exceptions
OutOfRangeException:
if the row or column index is not valid.
computeKeyback to summary
private int computeKey(int row, int column)

Compute the key to access a matrix element

Parameters
row:int

row index of the matrix element

column:int

column index of the matrix element

Returns:int

key within the map to access the matrix element

copyback to summary
public OpenMapRealMatrix copy()

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.copy.

Implements org.apache.commons.math3.linear.RealMatrix.copy.

Doc from org.apache.commons.math3.linear.RealMatrix.copy.

Returns a (deep) copy of this.

Returns:OpenMapRealMatrix

matrix copy

Annotations
@Override
createMatrixback to summary
public OpenMapRealMatrix createMatrix(int rowDimension, int columnDimension) throws NotStrictlyPositiveException, NumberIsTooLargeException

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.createMatrix.

Implements org.apache.commons.math3.linear.RealMatrix.createMatrix.

Doc from org.apache.commons.math3.linear.RealMatrix.createMatrix.

Create a new RealMatrix of the same type as the instance with the supplied row and column dimensions.

Parameters
rowDimension:int

the number of rows in the new matrix

columnDimension:int

the number of columns in the new matrix

Returns:OpenMapRealMatrix

a new matrix of the same type as the instance

Annotations
@Override
Exceptions
NotStrictlyPositiveException:
if row or column dimension is not positive.
NumberIsTooLargeException:
if the total number of entries of the matrix is larger than Integer.MAX_VALUE.
getColumnDimensionback to summary
public int getColumnDimension()

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.getColumnDimension.

Implements org.apache.commons.math3.linear.AnyMatrix.getColumnDimension.

Doc from org.apache.commons.math3.linear.AnyMatrix.getColumnDimension.

Returns the number of columns in the matrix.

Returns:int

columnDimension

Annotations
@Override
getEntryback to summary
public double getEntry(int row, int column) throws OutOfRangeException

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.getEntry.

Implements org.apache.commons.math3.linear.RealMatrix.getEntry.

Doc from org.apache.commons.math3.linear.RealMatrix.getEntry.

Get the entry in the specified row and column. Row and column indices start at 0.

Parameters
row:int

Row index of entry to be fetched.

column:int

Column index of entry to be fetched.

Returns:double

the matrix entry at (row, column).

Annotations
@Override
Exceptions
OutOfRangeException:
if the row or column index is not valid.
getRowDimensionback to summary
public int getRowDimension()

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.getRowDimension.

Implements org.apache.commons.math3.linear.AnyMatrix.getRowDimension.

Doc from org.apache.commons.math3.linear.AnyMatrix.getRowDimension.

Returns the number of rows in the matrix.

Returns:int

rowDimension

Annotations
@Override
multiplyback to summary
public RealMatrix multiply(final RealMatrix m) throws DimensionMismatchException, NumberIsTooLargeException

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.multiply.

Implements org.apache.commons.math3.linear.RealMatrix.multiply.

Doc from org.apache.commons.math3.linear.RealMatrix.multiply.

Returns the result of postmultiplying this by m.

Parameters
m:RealMatrix

matrix to postmultiply by

Returns:RealMatrix

this * m

Annotations
@Override
Exceptions
DimensionMismatchException:
if columnDimension(this) != rowDimension(m)
NumberIsTooLargeException:
if m is an OpenMapRealMatrix, and the total number of entries of the product is larger than Integer.MAX_VALUE.
multiplyback to summary
public OpenMapRealMatrix multiply(OpenMapRealMatrix m) throws DimensionMismatchException, NumberIsTooLargeException

Postmultiply this matrix by m.

Parameters
m:OpenMapRealMatrix

Matrix to postmultiply by.

Returns:OpenMapRealMatrix

this * m.

Exceptions
DimensionMismatchException:
if the number of rows of m differ from the number of columns of this matrix.
NumberIsTooLargeException:
if the total number of entries of the product is larger than Integer.MAX_VALUE.
multiplyEntryback to summary
public void multiplyEntry(int row, int column, double factor) throws OutOfRangeException

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.multiplyEntry.

Implements org.apache.commons.math3.linear.RealMatrix.multiplyEntry.

Doc from org.apache.commons.math3.linear.RealMatrix.multiplyEntry.

Multiplies (in place) the specified entry of this matrix by the specified value. Row and column indices start at 0.

Parameters
row:int

Row index of the entry to be modified.

column:int

Column index of the entry to be modified.

factor:double

Multiplication factor for the matrix entry.

Annotations
@Override
Exceptions
OutOfRangeException:
if the row or column index is not valid.
setEntryback to summary
public void setEntry(int row, int column, double value) throws OutOfRangeException

Implements abstract org.apache.commons.math3.linear.AbstractRealMatrix.setEntry.

Implements org.apache.commons.math3.linear.RealMatrix.setEntry.

Doc from org.apache.commons.math3.linear.RealMatrix.setEntry.

Set the entry in the specified row and column. Row and column indices start at 0.

Parameters
row:int

Row index of entry to be set.

column:int

Column index of entry to be set.

value:double

the new value of the entry.

Annotations
@Override
Exceptions
OutOfRangeException:
if the row or column index is not valid
subtractback to summary
public OpenMapRealMatrix subtract(final RealMatrix m) throws MatrixDimensionMismatchException

Overrides org.apache.commons.math3.linear.AbstractRealMatrix.subtract.

Implements org.apache.commons.math3.linear.RealMatrix.subtract.

Doc from org.apache.commons.math3.linear.RealMatrix.subtract.

Returns this minus m.

Parameters
m:RealMatrix

matrix to be subtracted

Returns:OpenMapRealMatrix

this - m

Annotations
@Override
Exceptions
MatrixDimensionMismatchException:
if m is not the same size as this.
subtractback to summary
public OpenMapRealMatrix subtract(OpenMapRealMatrix m) throws MatrixDimensionMismatchException

Subtract m from this matrix.

Parameters
m:OpenMapRealMatrix

Matrix to be subtracted.

Returns:OpenMapRealMatrix

this - m.

Exceptions
MatrixDimensionMismatchException:
if m is not the same size as this.