Class DoubleMatrixDataSparse
java.lang.Object
org.djunits.value.storage.Storage<DoubleMatrixData>
org.djunits.value.vdouble.matrix.data.DoubleMatrixData
org.djunits.value.vdouble.matrix.data.DoubleMatrixDataSparse
- All Implemented Interfaces:
Serializable
,Cloneable
Stores sparse data for a DoubleMatrix and carries out basic operations. The index in the sparse matrix data is calculated as
r * columns + c
, where r is the row number, cols is the total number of columns, and c is the column number.
Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.
- Author:
- Alexander Verbraeck, Peter Knoppers
- See Also:
-
Field Summary
Fields inherited from class org.djunits.value.vdouble.matrix.data.DoubleMatrixData
cols, matrixSI, rows
-
Constructor Summary
ConstructorDescriptionDoubleMatrixDataSparse
(double[] matrixSI, long[] indices, int rows, int cols) Create a matrix with sparse data.DoubleMatrixDataSparse
(Collection<DoubleSparseValue<U, S>> dataSI, int rows, int cols) Create a matrix with sparse data. -
Method Summary
Modifier and TypeMethodDescriptionassign
(DoubleFunction doubleFunction) Apply an operation to each cell.final DoubleMatrixDataSparse
assign
(DoubleFunction2 doubleFunction, DoubleMatrixData right) Apply a binary operation on a cell by cell basis.final int
Compute and return the number of non-zero cells in this indexed value.final DoubleMatrixDataSparse
copy()
Create and return a deep copy of the data.divide
(DoubleMatrixData right) Divide two matrices on a cell-by-cell basis.boolean
final double[][]
Create and return a deep copy of the data in dense format.final double
getSI
(int row, int col) Retrieve one value from this data.int
hashCode()
static DoubleMatrixDataSparse
instantiate
(double[][] valuesSI) Instantiate a DoubleMatrixDataSparse from an array.static DoubleMatrixDataSparse
instantiate
(double[][] values, Scale scale) Instantiate a DoubleMatrixDataSparse from an array.final DoubleMatrixData
minus
(DoubleMatrixData right) Subtract two matrices on a cell-by-cell basis.plus
(DoubleMatrixData right) Add two matrices on a cell-by-cell basis.final void
setSI
(int row, int col, double valueSI) Sets a value at the [row, col] point in the matrix.times
(DoubleMatrixData right) Multiply two matrices on a cell-by-cell basis.final DoubleMatrixDataDense
toDense()
Return the data of this matrix in dense storage format.final DoubleMatrixDataSparse
toSparse()
Return the data of this matrix in sparse storage format.toString()
Methods inherited from class org.djunits.value.vdouble.matrix.data.DoubleMatrixData
checkRectangularAndNonNull, checkRectangularAndNonNull, checkSizes, cols, compareDenseMatrixWithSparseMatrix, decrementBy, divideBy, incrementBy, instantiate, instantiate, instantiate, multiplyBy, rows, zSum
Methods inherited from class org.djunits.value.storage.Storage
getStorageType, isDense, isSparse
-
Constructor Details
-
DoubleMatrixDataSparse
public DoubleMatrixDataSparse(double[] matrixSI, long[] indices, int rows, int cols) Create a matrix with sparse data.- Parameters:
matrixSI
- double[]; the data to storeindices
- long[]; the index values of the Matrix, with <tt>index = row * cols + col</tt>rows
- int; the number of rowscols
- int; the number of columns
-
DoubleMatrixDataSparse
public DoubleMatrixDataSparse(Collection<DoubleSparseValue<U, S>> dataSI, int rows, int cols) throws NullPointerExceptionCreate a matrix with sparse data.- Type Parameters:
U
- the unitS
- the corresponding scalar type- Parameters:
dataSI
- Collection<DoubleSparseValue<U, S>>; the sparse [X, Y, SI] values to storerows
- int; the number of rows of the matrixcols
- int; the number of columns of the matrix- Throws:
NullPointerException
- when storageType is null or dataSI is null
-
-
Method Details
-
cardinality
public final int cardinality()Description copied from class:Storage
Compute and return the number of non-zero cells in this indexed value.- Specified by:
cardinality
in classStorage<DoubleMatrixData>
- Returns:
- int; the number of non-zero cells
-
assign
Description copied from class:DoubleMatrixData
Apply an operation to each cell.- Specified by:
assign
in classDoubleMatrixData
- Parameters:
doubleFunction
- DoubleFunction; the operation to apply- Returns:
- DoubleMatrixData; this (modified) double matrix data object
-
assign
Description copied from class:DoubleMatrixData
Apply a binary operation on a cell by cell basis.- Specified by:
assign
in classDoubleMatrixData
- Parameters:
doubleFunction
- DoubleFunction2; the binary operation to applyright
- DoubleMatrixData; the right operand for the binary operation- Returns:
- DoubleMatrixData; this (modified) double matrix data object
-
toDense
Description copied from class:DoubleMatrixData
Return the data of this matrix in dense storage format.- Specified by:
toDense
in classDoubleMatrixData
- Returns:
- DoubleMatrixDataDense; the dense transformation of this data
-
toSparse
Description copied from class:DoubleMatrixData
Return the data of this matrix in sparse storage format.- Specified by:
toSparse
in classDoubleMatrixData
- Returns:
- DoubleMatrixDataSparse; the sparse transformation of this data
-
getSI
public final double getSI(int row, int col) Description copied from class:DoubleMatrixData
Retrieve one value from this data.- Specified by:
getSI
in classDoubleMatrixData
- Parameters:
row
- int; the row number to get the value forcol
- int; the column number to get the value for- Returns:
- the value at the [row, col] point
-
setSI
public final void setSI(int row, int col, double valueSI) Description copied from class:DoubleMatrixData
Sets a value at the [row, col] point in the matrix.- Specified by:
setSI
in classDoubleMatrixData
- Parameters:
row
- int; the row number to set the value forcol
- int; the column number to set the value forvalueSI
- double; the value at the index
-
getDenseMatrixSI
public final double[][] getDenseMatrixSI()Description copied from class:DoubleMatrixData
Create and return a deep copy of the data in dense format. The double array is of the form d[rows][columns] so each value can be found with d[row][column].- Specified by:
getDenseMatrixSI
in classDoubleMatrixData
- Returns:
- double[][]; a safe, dense copy of matrixSI as a matrix
-
copy
Description copied from class:Storage
Create and return a deep copy of the data.- Specified by:
copy
in classStorage<DoubleMatrixData>
- Returns:
- T; a deep copy of the data
-
instantiate
Instantiate a DoubleMatrixDataSparse from an array.- Parameters:
valuesSI
- double[][]; the (SI) values to store- Returns:
- the DoubleMatrixDataSparse
- Throws:
ValueRuntimeException
- in case matrix is ragged
-
instantiate
public static DoubleMatrixDataSparse instantiate(double[][] values, Scale scale) throws ValueRuntimeException Instantiate a DoubleMatrixDataSparse from an array.- Parameters:
values
- double[][]; the values to storescale
- Scale; the scale that will convert values to SI- Returns:
- the DoubleMatrixDataSparse
- Throws:
ValueRuntimeException
- in case matrix is ragged
-
plus
Description copied from class:DoubleMatrixData
Add two matrices on a cell-by-cell basis. If both matrices are sparse, a sparse matrix is returned, otherwise a dense matrix is returned.- Specified by:
plus
in classDoubleMatrixData
- Parameters:
right
- DoubleMatrixData; the other data object to add- Returns:
- the sum of this data object and the other data object
- Throws:
ValueRuntimeException
- if matrices have different lengths
-
minus
Description copied from class:DoubleMatrixData
Subtract two matrices on a cell-by-cell basis. If both matrices are sparse, a sparse matrix is returned, otherwise a dense matrix is returned.- Specified by:
minus
in classDoubleMatrixData
- Parameters:
right
- DoubleMatrixData; the other data object to subtract- Returns:
- the sum of this data object and the other data object
-
times
Description copied from class:DoubleMatrixData
Multiply two matrices on a cell-by-cell basis. If both matrices are dense, a dense matrix is returned, otherwise a sparse matrix is returned.- Specified by:
times
in classDoubleMatrixData
- Parameters:
right
- DoubleMatrixData; the other data object to multiply with- Returns:
- DoubleVectorData; a new double matrix data store holding the result of the multiplications
- Throws:
ValueRuntimeException
- if matrices have different sizes
-
divide
Description copied from class:DoubleMatrixData
Divide two matrices on a cell-by-cell basis. If this matrix is sparse andright
is dense, a sparse matrix is returned, otherwise a dense matrix is returned.- Specified by:
divide
in classDoubleMatrixData
- Parameters:
right
- DoubleMatrixData; the other data object to divide by- Returns:
- DoubleMatrixData; the ratios of the values of this data object and the other data object
- Throws:
ValueRuntimeException
- if matrices have different sizes
-
hashCode
public int hashCode()- Overrides:
hashCode
in classDoubleMatrixData
-
equals
- Overrides:
equals
in classDoubleMatrixData
-
toString
-