Package org.hipparchus.linear
Class SparseFieldMatrix<T extends FieldElement<T>>
- java.lang.Object
-
- org.hipparchus.linear.AbstractFieldMatrix<T>
-
- org.hipparchus.linear.SparseFieldMatrix<T>
-
- Type Parameters:
T
- the type of the field elements
- All Implemented Interfaces:
AnyMatrix
,FieldMatrix<T>
,FieldBlendable<FieldMatrix<T>,T>
public class SparseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMatrix<T>
Sparse matrix implementation based on an open addressed map.Caveat: This implementation assumes that, for any
x
, the equalityx * 0d == 0d
holds. But it is is not true forNaN
. Moreover, zero entries will lose their sign. Some operations (that involveNaN
and/or infinities) may thus give incorrect results.
-
-
Constructor Summary
Constructors Constructor Description SparseFieldMatrix(Field<T> field)
Create a matrix with no data.SparseFieldMatrix(Field<T> field, int rowDimension, int columnDimension)
Create a newSparseFieldMatrix
with the supplied row and column dimensions.SparseFieldMatrix(FieldMatrix<T> other)
Generic copy constructor.SparseFieldMatrix(SparseFieldMatrix<T> other)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addToEntry(int row, int column, T increment)
Change an entry in the specified row and column.FieldMatrix<T>
copy()
Make a (deep) copy of this.FieldMatrix<T>
createMatrix(int rowDimension, int columnDimension)
Create a newFieldMatrix
of the same type as the instance with the supplied row and column dimensions.int
getColumnDimension()
Returns the number of columns in the matrix.T
getEntry(int row, int column)
Returns the entry in the specified row and column.int
getRowDimension()
Returns the number of rows in the matrix.void
multiplyEntry(int row, int column, T factor)
Change an entry in the specified row and column.FieldMatrix<T>
multiplyTransposed(FieldMatrix<T> m)
Returns the result of postmultiplyingthis
bym^T
.void
setEntry(int row, int column, T value)
Set the entry in the specified row and column.FieldMatrix<T>
transposeMultiply(FieldMatrix<T> m)
Returns the result of postmultiplyingthis^T
bym
.-
Methods inherited from class org.hipparchus.linear.AbstractFieldMatrix
add, checkAdditionCompatible, checkColumnIndex, checkMultiplicationCompatible, checkRowIndex, checkSubMatrixIndex, checkSubMatrixIndex, checkSubtractionCompatible, copySubMatrix, copySubMatrix, equals, extractField, extractField, getColumn, getColumnMatrix, getColumnVector, getData, getField, getRow, getRowMatrix, getRowVector, getSubMatrix, getSubMatrix, getTrace, hashCode, isSquare, multiply, operate, operate, power, preMultiply, preMultiply, preMultiply, scalarAdd, scalarMultiply, setColumn, setColumnMatrix, setColumnVector, setRow, setRowMatrix, setRowVector, setSubMatrix, subtract, 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.FieldMatrix
blendArithmeticallyWith, map, mapToSelf
-
-
-
-
Constructor Detail
-
SparseFieldMatrix
public SparseFieldMatrix(Field<T> field)
Create a matrix with no data.- Parameters:
field
- Field to which the elements belong.
-
SparseFieldMatrix
public SparseFieldMatrix(Field<T> field, int rowDimension, int columnDimension)
Create a newSparseFieldMatrix
with the supplied row and column dimensions.- Parameters:
field
- Field to which the elements belong.rowDimension
- Number of rows in the new matrix.columnDimension
- Number of columns in the new matrix.- Throws:
MathIllegalArgumentException
- if row or column dimension is not positive.
-
SparseFieldMatrix
public SparseFieldMatrix(SparseFieldMatrix<T> other)
Copy constructor.- Parameters:
other
- Instance to copy.
-
SparseFieldMatrix
public SparseFieldMatrix(FieldMatrix<T> other)
Generic copy constructor.- Parameters:
other
- Instance to copy.
-
-
Method Detail
-
addToEntry
public void addToEntry(int row, int column, T increment)
Change an entry in the specified row and column.- Specified by:
addToEntry
in interfaceFieldMatrix<T extends FieldElement<T>>
- Specified by:
addToEntry
in classAbstractFieldMatrix<T extends FieldElement<T>>
- Parameters:
row
- Row location of entry to be set.column
- Column location of entry to be set.increment
- Value to add to the current matrix entry in(row, column)
.
-
copy
public FieldMatrix<T> copy()
Make a (deep) copy of this.- Specified by:
copy
in interfaceFieldMatrix<T extends FieldElement<T>>
- Specified by:
copy
in classAbstractFieldMatrix<T extends FieldElement<T>>
- Returns:
- a copy of this matrix.
-
createMatrix
public FieldMatrix<T> createMatrix(int rowDimension, int columnDimension)
Create a newFieldMatrix
of the same type as the instance with the supplied row and column dimensions.- Specified by:
createMatrix
in interfaceFieldMatrix<T extends FieldElement<T>>
- Specified by:
createMatrix
in classAbstractFieldMatrix<T extends FieldElement<T>>
- 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
-
getColumnDimension
public int getColumnDimension()
Returns the number of columns in the matrix.- Specified by:
getColumnDimension
in interfaceAnyMatrix
- Specified by:
getColumnDimension
in classAbstractFieldMatrix<T extends FieldElement<T>>
- Returns:
- columnDimension
-
getEntry
public T getEntry(int row, int column)
Returns the entry in the specified row and column.- Specified by:
getEntry
in interfaceFieldMatrix<T extends FieldElement<T>>
- Specified by:
getEntry
in classAbstractFieldMatrix<T extends FieldElement<T>>
- Parameters:
row
- row location of entry to be fetchedcolumn
- column location of entry to be fetched- Returns:
- matrix entry in row,column
-
getRowDimension
public int getRowDimension()
Returns the number of rows in the matrix.- Specified by:
getRowDimension
in interfaceAnyMatrix
- Specified by:
getRowDimension
in classAbstractFieldMatrix<T extends FieldElement<T>>
- Returns:
- rowDimension
-
multiplyEntry
public void multiplyEntry(int row, int column, T factor)
Change an entry in the specified row and column.- Specified by:
multiplyEntry
in interfaceFieldMatrix<T extends FieldElement<T>>
- Specified by:
multiplyEntry
in classAbstractFieldMatrix<T extends FieldElement<T>>
- Parameters:
row
- Row location of entry to be set.column
- Column location of entry to be set.factor
- Multiplication factor for the current matrix entry in(row,column)
-
setEntry
public void setEntry(int row, int column, T value)
Set the entry in the specified row and column.- Specified by:
setEntry
in interfaceFieldMatrix<T extends FieldElement<T>>
- Specified by:
setEntry
in classAbstractFieldMatrix<T extends FieldElement<T>>
- Parameters:
row
- row location of entry to be setcolumn
- column location of entry to be setvalue
- matrix entry to be set in row,column
-
multiplyTransposed
public FieldMatrix<T> multiplyTransposed(FieldMatrix<T> m) throws MathIllegalArgumentException
Returns the result of postmultiplyingthis
bym^T
.This is equivalent to call
multiply
(m.FieldMatrix.transpose()
), but some implementations may avoid building the intermediate transposed matrix.- 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
public FieldMatrix<T> transposeMultiply(FieldMatrix<T> m) throws MathIllegalArgumentException
Returns the result of postmultiplyingthis^T
bym
.This is equivalent to call
FieldMatrix.transpose()
.multiply(m)
, but some implementations may avoid building the intermediate transposed matrix.- 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
.
-
-