Class FloatMatrixData
java.lang.Object
org.djunits.value.storage.Storage<FloatMatrixData>
org.djunits.value.vfloat.matrix.data.FloatMatrixData
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
FloatMatrixDataDense
,FloatMatrixDataSparse
Stores the data for a FloatMatrix and carries out basic operations.
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
-
Constructor Summary
ConstructorDescriptionFloatMatrixData
(StorageType storageType) Construct a new DoubleMatrixData store. -
Method Summary
Modifier and TypeMethodDescriptionabstract FloatMatrixData
assign
(FloatFunction doubleFunction) Apply an operation to each cell.(package private) abstract FloatMatrixData
assign
(FloatFunction2 floatFunction, FloatMatrixData right) Apply a binary operation on a cell by cell basis.protected static float[][]
checkRectangularAndNonNull
(float[][] values) Check that a 2D array of float is not null, not empty and not jagged; i.e. all rows have the same length.protected static <U extends Unit<U>,
S extends FloatScalar<U, S>>
S[][]checkRectangularAndNonNull
(S[][] values) Check that a 2D array of float is not null, not empty and not jagged; i.e. all rows have the same length.protected void
checkSizes
(FloatMatrixData other) Check the sizes of this data object and the other data object.int
cols()
Retrieve the column count.protected boolean
Compare contents of a dense and a sparse matrix.final FloatMatrixData
decrementBy
(FloatMatrixData decrement) Subtract a matrix from this matrix on a cell-by-cell basis.abstract FloatMatrixData
divide
(FloatMatrixData right) Divide two matrices on a cell-by-cell basis.final FloatMatrixData
divideBy
(FloatMatrixData right) Divide the values of a matrix by the values of another matrix on a cell-by-cell basis.boolean
abstract float[][]
Create and return a deep copy of the data in dense format.abstract double[][]
Create and return a deep copy of the data in dense format.abstract float
getSI
(int row, int col) Retrieve one value from this data.int
hashCode()
final FloatMatrixData
incrementBy
(FloatMatrixData right) Add a matrix to this matrix on a cell-by-cell basis.static FloatMatrixData
instantiate
(float[][] values, Scale scale, StorageType storageType) Instantiate a FloatMatrixData with the right data type.static <U extends Unit<U>,
S extends FloatScalar<U, S>>
FloatMatrixDatainstantiate
(Collection<FloatSparseValue<U, S>> values, int rows, int cols, StorageType storageType) Instantiate a FloatMatrixData with the right data type.static <U extends Unit<U>,
S extends FloatScalar<U, S>>
FloatMatrixDatainstantiate
(S[][] values, StorageType storageType) Instantiate a FloatMatrixData with the right data type.abstract FloatMatrixData
minus
(FloatMatrixData right) Subtract two matrices on a cell-by-cell basis.final FloatMatrixData
multiplyBy
(FloatMatrixData right) Multiply a matrix with the values of another matrix on a cell-by-cell basis.abstract FloatMatrixData
plus
(FloatMatrixData right) Add two matrices on a cell-by-cell basis.int
rows()
Retrieve the row count.abstract void
setSI
(int row, int col, float valueSI) Sets a value at the [row, col] point in the matrix.abstract FloatMatrixData
times
(FloatMatrixData right) Multiply two matrices on a cell-by-cell basis.abstract FloatMatrixDataDense
toDense()
Return the data of this matrix in dense storage format.abstract FloatMatrixDataSparse
toSparse()
Return the data of this matrix in sparse storage format.toString()
final float
zSum()
Compute and return the sum of the values of all cells of this matrix.Methods inherited from class org.djunits.value.storage.Storage
cardinality, copy, getStorageType, isDense, isSparse
-
Field Details
-
matrixSI
protected float[] matrixSIthe internal storage of the Matrix; can be sparse or dense. The data is stored in an array. -
rows
protected int rowsthe number of rows of the matrix. -
cols
protected int colsthe number of columns of the matrix.
-
-
Constructor Details
-
FloatMatrixData
Construct a new DoubleMatrixData store.- Parameters:
storageType
- StorageType; the data type
-
-
Method Details
-
instantiate
public static FloatMatrixData instantiate(float[][] values, Scale scale, StorageType storageType) throws ValueRuntimeException Instantiate a FloatMatrixData with the right data type. The float array is of the form f[rows][columns] so each value can be found with f[row][column].- Parameters:
values
- float[][]; the (SI) values to storescale
- Scale; the scale of the unit to use for conversion to SIstorageType
- StorageType; the data type to use- Returns:
- the FloatMatrixData with the right data type
- Throws:
ValueRuntimeException
- when values is raggedNullPointerException
- when values are null, or storageType is null
-
instantiate
public static <U extends Unit<U>,S extends FloatScalar<U, FloatMatrixData instantiateS>> (Collection<FloatSparseValue<U, S>> values, int rows, int cols, StorageType storageType) throws NullPointerExceptionInstantiate a FloatMatrixData with the right data type.- Type Parameters:
U
- the unit typeS
- the corresponding scalar type- Parameters:
values
- Collection<FloatSparseValue<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 matrixstorageType
- StorageType; the data type to use- Returns:
- the FloatMatrixData with the right data type
- Throws:
NullPointerException
- when values are null, or storageType is nullValueRuntimeException
- when rows < 0 or cols < 0
-
instantiate
public static <U extends Unit<U>,S extends FloatScalar<U, FloatMatrixData instantiateS>> (S[][] values, StorageType storageType) throws ValueRuntimeException Instantiate a FloatMatrixData with the right data type. The FloatScalar array is of the form fs[rows][columns] so each value can be found with fs[row][column].- Type Parameters:
U
- the unit typeS
- the corresponding scalar type- Parameters:
values
- S[][]; the values to storestorageType
- StorageType; the data type to use- Returns:
- the FloatMatrixData with the right data type
- Throws:
NullPointerException
- when values is null, or storageType is nullValueRuntimeException
- when values is ragged
-
rows
public int rows()Retrieve the row count.- Returns:
- int; the number of rows of the matrix
-
cols
public int cols()Retrieve the column count.- Returns:
- int; the number of columns of the matrix
-
toDense
Return the data of this matrix in dense storage format.- Returns:
- FloatMatrixDataDense; the dense transformation of this data
-
toSparse
Return the data of this matrix in sparse storage format.- Returns:
- FloatMatrixDataSparse; the sparse transformation of this data
-
getSI
public abstract float getSI(int row, int col) Retrieve one value from this data.- 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 abstract void setSI(int row, int col, float valueSI) Sets a value at the [row, col] point in the matrix.- Parameters:
row
- int; the row number to set the value forcol
- int; the column number to set the value forvalueSI
- float; the value at the index
-
zSum
public final float zSum()Compute and return the sum of the values of all cells of this matrix.- Returns:
- float; the sum of the values of all cells
-
getDenseMatrixSI
public abstract float[][] getDenseMatrixSI()Create 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].- Returns:
- float[][]; a safe, dense copy of matrixSI as a matrix
-
getDoubleDenseMatrixSI
public abstract double[][] getDoubleDenseMatrixSI()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].- Returns:
- double[][]; a safe, dense copy of matrixSI as a matrix
-
checkRectangularAndNonNull
protected static float[][] checkRectangularAndNonNull(float[][] values) throws ValueRuntimeException Check that a 2D array of float is not null, not empty and not jagged; i.e. all rows have the same length.- Parameters:
values
- float[][]; the 2D array to check- Returns:
- the values in case the method is used in a constructor
- Throws:
NullPointerException
- whenvalues
is nullValueRuntimeException
- whenvalues
is jagged
-
checkRectangularAndNonNull
protected static <U extends Unit<U>,S extends FloatScalar<U, S[][] checkRectangularAndNonNullS>> (S[][] values) throws ValueRuntimeException Check that a 2D array of float is not null, not empty and not jagged; i.e. all rows have the same length.- Type Parameters:
U
- the unit typeS
- the corresponding scalar type- Parameters:
values
- S[][]; the 2D array to check- Returns:
- the values in case the method is used in a constructor
- Throws:
NullPointerException
- whenvalues
is nullValueRuntimeException
- whenvalues
is jagged
-
checkSizes
Check the sizes of this data object and the other data object.- Parameters:
other
- FloatMatrixData; the other data object- Throws:
ValueRuntimeException
- if matrices have different lengths
-
assign
Apply an operation to each cell.- Parameters:
doubleFunction
- FloatFunction; the operation to apply- Returns:
- FloatMatrixData; this (modified) double vector data object
-
assign
abstract FloatMatrixData assign(FloatFunction2 floatFunction, FloatMatrixData right) throws ValueRuntimeException Apply a binary operation on a cell by cell basis.- Parameters:
floatFunction
- FloatFunction2; the binary operation to applyright
- FloatMatrixData; the right operand for the binary operation- Returns:
- FloatMatrixData; this (modified) double matrix data object
- Throws:
ValueRuntimeException
- when the sizes of the vectors do not match
-
plus
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.- Parameters:
right
- FloatMatrixData; 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
-
incrementBy
Add a matrix to this matrix on a cell-by-cell basis. The type of matrix (sparse, dense) stays the same.- Parameters:
right
- FloatMatrixData; the other data object to add- Returns:
- FloatMatrixData; this modified float matrix data object
- Throws:
ValueRuntimeException
- if matrices have different lengths
-
minus
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.- Parameters:
right
- FloatMatrixData; the other data object to subtract- Returns:
- the sum of this data object and the other data object
- Throws:
ValueRuntimeException
- if matrices have different lengths
-
decrementBy
Subtract a matrix from this matrix on a cell-by-cell basis. The type of matrix (sparse, dense) stays the same.- Parameters:
decrement
- FloatMatrixData; the other data object to subtract- Returns:
- FloatMatrixData; this modified float matrix data object
- Throws:
ValueRuntimeException
- if matrices have different lengths
-
times
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.- Parameters:
right
- FloatMatrixData; the other data object to multiply with- Returns:
- FloatMatrixData; a new double matrix data store holding the result of the multiplications
- Throws:
ValueRuntimeException
- if matrices have different sizes
-
multiplyBy
Multiply a matrix with the values of another matrix on a cell-by-cell basis. The type of matrix (sparse, dense) stays the same.- Parameters:
right
- FloatMatrixData; the other data object to multiply with- Returns:
- FloatMatrixData; this modified data store
- Throws:
ValueRuntimeException
- if matrices have different sizes
-
divide
Divide two matrices on a cell-by-cell basis. If both matrices are dense, a dense matrix is returned, otherwise a sparse matrix is returned.- Parameters:
right
- FloatMatrixData; 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
-
divideBy
Divide the values of a matrix by the values of another matrix on a cell-by-cell basis. The type of matrix (sparse, dense) stays the same.- Parameters:
right
- FloatMatrixData; the other data object to divide by- Returns:
- FloatMatrixData; this modified data store
- Throws:
ValueRuntimeException
- if matrices have different sizes
-
hashCode
public int hashCode() -
compareDenseMatrixWithSparseMatrix
protected boolean compareDenseMatrixWithSparseMatrix(FloatMatrixDataDense dm, FloatMatrixDataSparse sm) Compare contents of a dense and a sparse matrix.- Parameters:
dm
- FloatMatrixDataDense; the dense matrixsm
- FloatMatrixDataSparse; the sparse matrix- Returns:
- boolean; true if the contents are equal
-
equals
-
toString
-