Class FloatMatrixDataSparse
java.lang.Object
org.djunits.value.storage.Storage<FloatMatrixData>
org.djunits.value.vfloat.matrix.data.FloatMatrixData
org.djunits.value.vfloat.matrix.data.FloatMatrixDataSparse
- All Implemented Interfaces:
Serializable,Cloneable
Stores sparse data for a FloatMatrix 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-2025 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.vfloat.matrix.data.FloatMatrixData
cols, matrixSI, rows -
Constructor Summary
ConstructorsConstructorDescriptionFloatMatrixDataSparse(float[] matrixSI, long[] indices, int rows, int cols) Create a matrix with sparse data.FloatMatrixDataSparse(Collection<FloatSparseValue<U, S>> dataSI, int rows, int cols) Create a matrix with sparse data. -
Method Summary
Modifier and TypeMethodDescriptionassign(FloatFunction floatFunction) Apply an operation to each cell.final FloatMatrixDataSparseassign(FloatFunction2 floatFunction, FloatMatrixData right) Apply a binary operation on a cell by cell basis.final intCompute and return the number of non-zero cells in this indexed value.final FloatMatrixDataSparsecopy()Create and return a deep copy of the data.divide(FloatMatrixData right) Divide two matrices on a cell-by-cell basis.booleanfinal float[][]Create and return a deep copy of the data in dense format.final double[][]Create and return a deep copy of the data in dense format.final floatgetSI(int row, int col) Retrieve one value from this data.inthashCode()static FloatMatrixDataSparseinstantiate(float[][] valuesSI) Instantiate a FloatMatrixDataSparse from an array.static FloatMatrixDataSparseinstantiate(float[][] values, Scale scale) Instantiate a FloatMatrixDataSparse from an array.final FloatMatrixDataminus(FloatMatrixData right) Subtract two matrices on a cell-by-cell basis.plus(FloatMatrixData right) Add two matrices on a cell-by-cell basis.final voidsetSI(int row, int col, float valueSI) Sets a value at the [row, col] point in the matrix.times(FloatMatrixData right) Multiply two matrices on a cell-by-cell basis.final FloatMatrixDataDensetoDense()Return the data of this matrix in dense storage format.final FloatMatrixDataSparsetoSparse()Return the data of this matrix in sparse storage format.Methods inherited from class org.djunits.value.vfloat.matrix.data.FloatMatrixData
checkRectangularAndNonNull, checkRectangularAndNonNull, checkSizes, cols, compareDenseMatrixWithSparseMatrix, decrementBy, divideBy, incrementBy, instantiate, instantiate, instantiate, multiplyBy, rows, toString, zSumMethods inherited from class org.djunits.value.storage.Storage
getStorageType, isDense, isSparse
-
Constructor Details
-
FloatMatrixDataSparse
public FloatMatrixDataSparse(float[] matrixSI, long[] indices, int rows, int cols) Create a matrix with sparse data.- Parameters:
matrixSI- the data to storeindices- the index values of the Matrix, with <tt>index = row * cols + col</tt>rows- the number of rowscols- the number of columns
-
FloatMatrixDataSparse
public FloatMatrixDataSparse(Collection<FloatSparseValue<U, S>> dataSI, int rows, int cols) throws NullPointerExceptionCreate a matrix with sparse data.- Type Parameters:
U- the unit typeS- the corresponding scalar type- Parameters:
dataSI- the sparse [X, Y, SI] values to storerows- the number of rows of the matrixcols- 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:StorageCompute and return the number of non-zero cells in this indexed value.- Specified by:
cardinalityin classStorage<FloatMatrixData>- Returns:
- the number of non-zero cells
-
assign
Description copied from class:FloatMatrixDataApply an operation to each cell.- Specified by:
assignin classFloatMatrixData- Parameters:
floatFunction- the operation to apply- Returns:
- this (modified) double vector data object
-
assign
Description copied from class:FloatMatrixDataApply a binary operation on a cell by cell basis.- Specified by:
assignin classFloatMatrixData- Parameters:
floatFunction- the binary operation to applyright- the right operand for the binary operation- Returns:
- this (modified) double matrix data object
-
toDense
Description copied from class:FloatMatrixDataReturn the data of this matrix in dense storage format.- Specified by:
toDensein classFloatMatrixData- Returns:
- the dense transformation of this data
-
toSparse
Description copied from class:FloatMatrixDataReturn the data of this matrix in sparse storage format.- Specified by:
toSparsein classFloatMatrixData- Returns:
- the sparse transformation of this data
-
getSI
public final float getSI(int row, int col) Description copied from class:FloatMatrixDataRetrieve one value from this data.- Specified by:
getSIin classFloatMatrixData- Parameters:
row- the row number to get the value forcol- 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, float valueSI) Description copied from class:FloatMatrixDataSets a value at the [row, col] point in the matrix.- Specified by:
setSIin classFloatMatrixData- Parameters:
row- the row number to set the value forcol- the column number to set the value forvalueSI- the value at the index
-
getDenseMatrixSI
public final float[][] getDenseMatrixSI()Description copied from class:FloatMatrixDataCreate and return a deep copy of the data in dense format. The float array is of the form f[rows][columns] so each value can be found with f[row][column].- Specified by:
getDenseMatrixSIin classFloatMatrixData- Returns:
- a safe, dense copy of matrixSI as a matrix
-
getDoubleDenseMatrixSI
public final double[][] getDoubleDenseMatrixSI()Description copied from class:FloatMatrixDataCreate 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:
getDoubleDenseMatrixSIin classFloatMatrixData- Returns:
- a safe, dense copy of matrixSI as a matrix
-
copy
Description copied from class:StorageCreate and return a deep copy of the data.- Specified by:
copyin classStorage<FloatMatrixData>- Returns:
- a deep copy of the data
-
instantiate
Instantiate a FloatMatrixDataSparse from an array.- Parameters:
valuesSI- the (SI) values to store- Returns:
- the FloatMatrixDataSparse
- Throws:
ValueRuntimeException- in case matrix is ragged
-
instantiate
public static FloatMatrixDataSparse instantiate(float[][] values, Scale scale) throws ValueRuntimeException Instantiate a FloatMatrixDataSparse from an array.- Parameters:
values- the values to storescale- the scale that will convert values to SI- Returns:
- the DoubleMatrixDataSparse
- Throws:
ValueRuntimeException- in case matrix is ragged
-
plus
Description copied from class:FloatMatrixDataAdd 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:
plusin classFloatMatrixData- Parameters:
right- 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:FloatMatrixDataSubtract 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:
minusin classFloatMatrixData- Parameters:
right- the other data object to subtract- Returns:
- the sum of this data object and the other data object
-
times
Description copied from class:FloatMatrixDataMultiply 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:
timesin classFloatMatrixData- Parameters:
right- the other data object to multiply with- Returns:
- a new double matrix data store holding the result of the multiplications
- Throws:
ValueRuntimeException- if matrices have different sizes
-
divide
Description copied from class:FloatMatrixDataDivide 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:
dividein classFloatMatrixData- Parameters:
right- the other data object to divide by- Returns:
- the sum of this data object and the other data object
- Throws:
ValueRuntimeException- if matrices have different sizes
-
hashCode
public int hashCode()- Overrides:
hashCodein classFloatMatrixData
-
equals
- Overrides:
equalsin classFloatMatrixData
-