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

public Class SparseFieldMatrix<T extends FieldElement<T>>

extends AbstractFieldMatrix<T extends FieldElement<T>>
Class Inheritance
Type Parameters
<T>
the type of the field elements
Imports
org.apache.commons.math3.Field, .FieldElement, org.apache.commons.math3.util.OpenIntToFieldHashMap

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

Column dimension.

private final OpenIntToFieldHashMap<T>
entries

Storage for (sparse) matrix elements.

private final int
rows

Row dimension.

Constructor Summary

AccessConstructor and Description
public
SparseFieldMatrix(final Field<T>
Field to which the elements belong.
field
)

Create a matrix with no data.

public
SparseFieldMatrix(final Field<T>
Field to which the elements belong.
field
,
final int
Number of rows in the new matrix.
rowDimension
,
final int
Number of columns in the new matrix.
columnDimension
)

Create a new SparseFieldMatrix<t> with the supplied row and column dimensions.

public
SparseFieldMatrix(SparseFieldMatrix<T>
Instance to copy.
other
)

Copy constructor.

public
SparseFieldMatrix(FieldMatrix<T>
Instance to copy.
other
)

Generic copy constructor.

Method Summary

Modifier and TypeMethod and Description
public void
addToEntry(int
Row location of entry to be set.
row
,
int
Column location of entry to be set.
column
,
T
Value to add to the current matrix entry in (row, column).
increment
)

Implements abstract org.apache.commons.math3.linear.AbstractFieldMatrix.addToEntry.

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

Change an entry in the specified row and column.

private int

Returns:

the 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 FieldMatrix<T>
public FieldMatrix<T>
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.AbstractFieldMatrix.createMatrix.

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

Create a new FieldMatrix<t> of the same type as the instance with the supplied row and column dimensions.

public int
public T
getEntry(int
row location of entry to be fetched
row
,
int
column location of entry to be fetched
column
)

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

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

Returns the entry in the specified row and column.

public int
public void
multiplyEntry(int
Row location of entry to be set.
row
,
int
Column location of entry to be set.
column
,
T
Multiplication factor for the current matrix entry in (row,column)
factor
)

Implements abstract org.apache.commons.math3.linear.AbstractFieldMatrix.multiplyEntry.

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

Change an entry in the specified row and column.

public void
setEntry(int
row location of entry to be set
row
,
int
column location of entry to be set
column
,
T
matrix entry to be set in row,column
value
)

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

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

Set the entry in the specified row and column.

Inherited from org.apache.commons.math3.linear.AbstractFieldMatrix:
addbuildArraybuildArraycheckAdditionCompatiblecheckColumnIndexcheckMultiplicationCompatiblecheckRowIndexcheckSubMatrixIndexcheckSubMatrixIndexcheckSubtractionCompatiblecopySubMatrixcopySubMatrixequalsextractFieldextractFieldgetColumngetColumnMatrixgetColumnVectorgetDatagetFieldgetRowgetRowMatrixgetRowVectorgetSubMatrixgetSubMatrixgetTracehashCodeisSquaremultiplyoperateoperatepowerpreMultiplypreMultiplypreMultiplyscalarAddscalarMultiplysetColumnsetColumnMatrixsetColumnVectorsetRowsetRowMatrixsetRowVectorsetSubMatrixsubtracttoStringtransposewalkInColumnOrderwalkInColumnOrderwalkInColumnOrderwalkInColumnOrderwalkInOptimizedOrderwalkInOptimizedOrderwalkInOptimizedOrderwalkInOptimizedOrderwalkInRowOrderwalkInRowOrderwalkInRowOrderwalkInRowOrder

Field Detail

columnsback to summary
private final int columns

Column dimension.

entriesback to summary
private final OpenIntToFieldHashMap<T> entries

Storage for (sparse) matrix elements.

rowsback to summary
private final int rows

Row dimension.

Constructor Detail

SparseFieldMatrixback to summary
public SparseFieldMatrix(final Field<T> field)

Create a matrix with no data.

Parameters
field:Field<T>

Field to which the elements belong.

SparseFieldMatrixback to summary
public SparseFieldMatrix(final Field<T> field, final int rowDimension, final int columnDimension)

Create a new SparseFieldMatrix with the supplied row and column dimensions.

Parameters
field:Field<T>

Field to which the elements belong.

rowDimension:int

Number of rows in the new matrix.

columnDimension:int

Number of columns in the new matrix.

Exceptions
NotStrictlyPositiveException:
if row or column dimension is not positive.
SparseFieldMatrixback to summary
public SparseFieldMatrix(SparseFieldMatrix<T> other)

Copy constructor.

Parameters
other:SparseFieldMatrix<T>

Instance to copy.

SparseFieldMatrixback to summary
public SparseFieldMatrix(FieldMatrix<T> other)

Generic copy constructor.

Parameters
other:FieldMatrix<T>

Instance to copy.

Method Detail

addToEntryback to summary
public void addToEntry(int row, int column, T increment)

Implements abstract org.apache.commons.math3.linear.AbstractFieldMatrix.addToEntry.

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

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

Change an entry in the specified row and column.

Parameters
row:int

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

Row location of entry to be set.

column:int

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

Column location of entry to be set.

increment:T

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

Value to add to the current matrix entry in (row, column).

Annotations
@Override
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

the key within the map to access the matrix element.

copyback to summary
public FieldMatrix<T> copy()

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

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

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

Make a (deep) copy of this.

Returns:FieldMatrix<T>

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

a copy of this matrix.

Annotations
@Override
createMatrixback to summary
public FieldMatrix<T> createMatrix(int rowDimension, int columnDimension)

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

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

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

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

Parameters
rowDimension:int

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

the number of rows in the new matrix

columnDimension:int

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

the number of columns in the new matrix

Returns:FieldMatrix<T>

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

a new matrix of the same type as the instance

Annotations
@Override
getColumnDimensionback to summary
public int getColumnDimension()

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

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

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

Returns the number of columns in the matrix.

Returns:int

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

columnDimension

Annotations
@Override
getEntryback to summary
public T getEntry(int row, int column)

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

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

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

Returns the entry in the specified row and column.

Parameters
row:int

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

row location of entry to be fetched

column:int

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

column location of entry to be fetched

Returns:T

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

matrix entry in row,column

Annotations
@Override
getRowDimensionback to summary
public int getRowDimension()

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

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

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

Returns the number of rows in the matrix.

Returns:int

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

rowDimension

Annotations
@Override
multiplyEntryback to summary
public void multiplyEntry(int row, int column, T factor)

Implements abstract org.apache.commons.math3.linear.AbstractFieldMatrix.multiplyEntry.

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

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

Change an entry in the specified row and column.

Parameters
row:int

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

Row location of entry to be set.

column:int

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

Column location of entry to be set.

factor:T

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

Multiplication factor for the current matrix entry in (row,column)

Annotations
@Override
setEntryback to summary
public void setEntry(int row, int column, T value)

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

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

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

Set the entry in the specified row and column.

Parameters
row:int

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

row location of entry to be set

column:int

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

column location of entry to be set

value:T

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

matrix entry to be set in row,column

Annotations
@Override