Class FloatVectorDataSparse
java.lang.Object
org.djunits.value.storage.Storage<FloatVectorData>
org.djunits.value.vfloat.vector.data.FloatVectorData
org.djunits.value.vfloat.vector.data.FloatVectorDataSparse
- All Implemented Interfaces:
Serializable
,Cloneable
Stores sparse data for a FloatVector 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
Fields inherited from class org.djunits.value.vfloat.vector.data.FloatVectorData
vectorSI
-
Constructor Summary
ConstructorDescriptionFloatVectorDataSparse
(float[] vectorSI, int[] indices, int size) Create a vector with sparse data. -
Method Summary
Modifier and TypeMethodDescriptionassign
(FloatFunction floatFunction) Apply an operation to each cell.final FloatVectorDataSparse
assign
(FloatFunction2 floatFunction, FloatVectorData 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 FloatVectorDataSparse
copy()
Create and return a deep copy of the data.final FloatVectorData
divide
(FloatVectorData right) Divide two vectors on a cell-by-cell basis.boolean
final float[]
Create and return a dense copy of the data.final float
getSI
(int index) Retrieve the SI value of one element of this data.int
hashCode()
static FloatVectorDataSparse
instantiate
(float[] valuesSI) Instantiate a FloatVectorDataSparse from an array.final FloatVectorData
minus
(FloatVectorData right) Subtract two vectors on a cell-by-cell basis.final FloatVectorData
plus
(FloatVectorData right) Add two vectors on a cell-by-cell basis.final void
setSI
(int index, float valueSI) Sets a value at the index in the vector.final int
size()
Retrieve the size of the vector.final FloatVectorData
times
(FloatVectorData right) Multiply two vector on a cell-by-cell basis.final FloatVectorDataDense
toDense()
Return the densely stored equivalent of this data.final FloatVectorDataSparse
toSparse()
Return the sparsely stored equivalent of this data.Methods inherited from class org.djunits.value.vfloat.vector.data.FloatVectorData
checkSizes, compareDenseVectorWithSparseVector, decrementBy, divideBy, incrementBy, instantiate, instantiate, instantiate, instantiate, multiplyBy, toString, zSum
Methods inherited from class org.djunits.value.storage.Storage
getStorageType, isDense, isSparse
-
Constructor Details
-
FloatVectorDataSparse
public FloatVectorDataSparse(float[] vectorSI, int[] indices, int size) Create a vector with sparse data.- Parameters:
vectorSI
- float[]; the data to storeindices
- int[]; the index values of the Vectorsize
- int; the length of the vector (padded with 0 after highest index in indices)
-
-
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<FloatVectorData>
- Returns:
- int; the number of non-zero cells
-
assign
Description copied from class:FloatVectorData
Apply an operation to each cell.- Specified by:
assign
in classFloatVectorData
- Parameters:
floatFunction
- FloatFunction; the operation to apply- Returns:
- FloatVectorData; this (modified) float vector data object
-
assign
Description copied from class:FloatVectorData
Apply a binary operation on a cell by cell basis.- Specified by:
assign
in classFloatVectorData
- Parameters:
floatFunction
- FloatFunction2; the binary operation to applyright
- FloatVectorData; the right operand for the binary operation- Returns:
- DoubleMatrixData; this (modified) float vector data object
-
toDense
Description copied from class:FloatVectorData
Return the densely stored equivalent of this data.- Specified by:
toDense
in classFloatVectorData
- Returns:
- FloatVectorDataDense; the dense transformation of this data
-
toSparse
Description copied from class:FloatVectorData
Return the sparsely stored equivalent of this data.- Specified by:
toSparse
in classFloatVectorData
- Returns:
- FloatVectorDataSparse; the sparse transformation of this data
-
size
public final int size()Description copied from class:FloatVectorData
Retrieve the size of the vector.- Specified by:
size
in classFloatVectorData
- Returns:
- int; the size of the vector
-
getSI
public final float getSI(int index) Description copied from class:FloatVectorData
Retrieve the SI value of one element of this data.- Specified by:
getSI
in classFloatVectorData
- Parameters:
index
- int; the index to get the value for- Returns:
- the value at the index
-
setSI
public final void setSI(int index, float valueSI) Description copied from class:FloatVectorData
Sets a value at the index in the vector.- Specified by:
setSI
in classFloatVectorData
- Parameters:
index
- int; the index to set the value forvalueSI
- float; the value at the index
-
getDenseVectorSI
public final float[] getDenseVectorSI()Description copied from class:FloatVectorData
Create and return a dense copy of the data.- Specified by:
getDenseVectorSI
in classFloatVectorData
- Returns:
- float[]; a safe copy of VectorSI
-
copy
Description copied from class:Storage
Create and return a deep copy of the data.- Specified by:
copy
in classStorage<FloatVectorData>
- Returns:
- T; a deep copy of the data
-
instantiate
Instantiate a FloatVectorDataSparse from an array.- Parameters:
valuesSI
- float[]; the (SI) values to store- Returns:
- the FloatVectorDataSparse
-
plus
Description copied from class:FloatVectorData
Add two vectors on a cell-by-cell basis. If both vectors are sparse, a sparse vector is returned, otherwise a dense vector is returned.- Specified by:
plus
in classFloatVectorData
- Parameters:
right
- FloatVectorData; the other data object to add- Returns:
- FloatVectorData; the sum of this data object and the other data object
-
minus
Description copied from class:FloatVectorData
Subtract two vectors on a cell-by-cell basis. If both vectors are sparse, a sparse vector is returned, otherwise a dense vector is returned.- Specified by:
minus
in classFloatVectorData
- Parameters:
right
- FloatVectorData; the other data object to subtract- Returns:
- FloatVectorData; the difference of this data object and the other data object
-
times
Description copied from class:FloatVectorData
Multiply two vector on a cell-by-cell basis. If both vectors are dense, a dense vector is returned, otherwise a sparse vector is returned.- Specified by:
times
in classFloatVectorData
- Parameters:
right
- FloatVectorData; the other data object to multiply with- Returns:
- FloatVectorData; a new double vector data store holding the result of the multiplications
-
divide
Description copied from class:FloatVectorData
Divide two vectors on a cell-by-cell basis. If this vector is sparse andright
is dense, a sparse vector is returned, otherwise a dense vector is returned.- Specified by:
divide
in classFloatVectorData
- Parameters:
right
- FloatVectorData; the other data object to divide by- Returns:
- FloatVectorData; the ratios of the values of this data object and the other data object
- Throws:
ValueRuntimeException
- if vectors have different lengths
-
hashCode
public int hashCode()- Overrides:
hashCode
in classFloatVectorData
-
equals
- Overrides:
equals
in classFloatVectorData
-