Class FloatMatrixData
java.lang.Object
org.djunits.value.storage.AbstractStorage<FloatMatrixData>
org.djunits.value.vfloat.matrix.data.FloatMatrixData
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
FloatMatrixDataDense
,FloatMatrixDataSparse
public abstract class FloatMatrixData extends AbstractStorage<FloatMatrixData> implements Serializable
Stores the data for a FloatMatrix and carries out basic operations.
Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Alexander Verbraeck, Peter Knoppers
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Constructor Description FloatMatrixData(StorageType storageType)
Construct a new DoubleMatrixData store. -
Method Summary
Modifier and Type Method Description abstract 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[][]
checkRectangularAndNonEmpty(float[][] values)
Check that a 2D array of float is not null, not empty and not jagged; i.e.protected static <U extends Unit<U>, S extends FloatScalarInterface<U, S>>
S[][]checkRectangularAndNonEmpty(S[][] values)
Check that a 2D array of float is not null, not empty and not jagged; i.e.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
compareDenseMatrixWithSparseMatrix(FloatMatrixDataDense dm, FloatMatrixDataSparse sm)
Compare contents of a dense and a sparse matrix.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.FloatMatrixData
divideBy(FloatMatrixData right)
Divide the values of a matrix by the values of another matrix on a cell-by-cell basis.boolean
equals(Object obj)
abstract float[][]
getDenseMatrixSI()
Create and return a deep copy of the data in dense format.abstract double[][]
getDoubleDenseMatrixSI()
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()
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 FloatScalarInterface<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 FloatScalarInterface<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.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.String
toString()
float
zSum()
Compute and return the sum of the values of all cells of this matrix.Methods inherited from class org.djunits.value.storage.AbstractStorage
cardinality, copy, getStorageType, isDense, isSparse
-
Field Details
-
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 ValueRuntimeExceptionInstantiate 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 are null, or storageType is null
-
instantiate
public static <U extends Unit<U>, S extends FloatScalarInterface<U, S>> FloatMatrixData instantiate(Collection<FloatSparseValue<U,S>> values, int rows, int cols, StorageType storageType) throws ValueRuntimeExceptionInstantiate 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:
ValueRuntimeException
- when values are null, or storageType is null
-
instantiate
public static <U extends Unit<U>, S extends FloatScalarInterface<U, S>> FloatMatrixData instantiate(S[][] values, StorageType storageType) throws ValueRuntimeExceptionInstantiate 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:
ValueRuntimeException
- when values is null, or storageType is null
-
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
-
checkRectangularAndNonEmpty
protected static float[][] checkRectangularAndNonEmpty(float[][] values) throws ValueRuntimeExceptionCheck 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 empty, or jagged
-
checkRectangularAndNonEmpty
protected static <U extends Unit<U>, S extends FloatScalarInterface<U, S>> S[][] checkRectangularAndNonEmpty(S[][] values) throws ValueRuntimeExceptionCheck 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 empty, or 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 ValueRuntimeExceptionApply 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
-