Package org.djunits.vecmat.storage
Class SparseFloatDataSi
java.lang.Object
org.djunits.vecmat.storage.SparseFloatDataSi
- All Implemented Interfaces:
DataGridSi<SparseFloatDataSi>
SparseFloatData implements a sparse data grid for N x M matrices or N x 1 or 1 x N vectors with float values. The sparse grid
is implemented with an index array that indicates the position of the data values in the dense array. Any index that is
missing indicates a data value of 0.
Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.
- Author:
- Alexander Verbraeck
-
Constructor Summary
ConstructorsModifierConstructorDescriptionSparseFloatDataSi(double[][] denseData) Instantiate a data object with a dense double[rows][cols].SparseFloatDataSi(double[] denseData, int rows, int cols) Instantiate a data object with one array in row-major format.SparseFloatDataSi(float[][] denseData) Instantiate a data object with a dense double[rows][cols].protectedSparseFloatDataSi(float[] sparseData, int[] indexes, int rows, int cols) Instantiate a data object with one array in row-major format.SparseFloatDataSi(float[] denseData, int rows, int cols) Instantiate a data object with one array in row-major format.SparseFloatDataSi(Collection<FloatSparseValue<Q, U>> indexedData, int rows, int cols) Instantiate a data object with an indexed collection of values.SparseFloatDataSi(Q[][] denseData) Instantiate a data object with a dense double[rows][cols].SparseFloatDataSi(Q[] sparseData, int[] indexes, int rows, int cols) Instantiate a data object with one array in row-major format.SparseFloatDataSi(Q[] denseData, int rows, int cols) Instantiate a data object with one array in row-major format. -
Method Summary
Modifier and TypeMethodDescriptionintCompute and return the number of non-zero cells in this indexed value.protected voidcheckIndexes(int[] indexArray) Check the correctness of the indexes array.intcols()Return the number of columns in the grid.copy()Return a deep copy of the DataGrid object.booleandoubleget(int row, int col) Return element (row, col) from the grid as a double value, independent of the fact whether it is stored as a double.double[]Return the data in row-major format.inthashCode()instantiateNew(double[] denseData) Instantiate a new version of the DataGrid object with the given data and the same number of rows and columns.instantiateNew(double[] denseData, int newRows, int newCols) Instantiate a new version of the DataGrid object with the given data and the given number of rows and columns.booleanisDense()Return whether the data is dense.booleanisDouble()Return whether the data is double precision.introws()Return the number of rows in the grid.voidstoreSparse(double[] denseData) Store sparse data[] and indexes[].voidstoreSparse(double[][] denseData) Store sparse data[] and indexes[].voidstoreSparse(float[] denseData) Store sparse data[] and indexes[].voidstoreSparse(float[][] denseData) Store sparse data[] and indexes[].<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>>
voidstoreSparse(Q[] denseData) Store sparse data[] and indexes[].<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>>
voidstoreSparse(Q[][] denseData) Store sparse data[] and indexes[].Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.djunits.vecmat.storage.DataGridSi
equals, getColArray, getRowArray, isFloat, isSparse
-
Constructor Details
-
SparseFloatDataSi
protected SparseFloatDataSi(float[] sparseData, int[] indexes, int rows, int cols) Instantiate a data object with one array in row-major format. Note that NO safe copy of the data is stored. Also note that get(r, c) methods will be 0-based in this underlying class, whereas the Matrix.get(r, c) method is 1-based.- Parameters:
sparseData- the sparse data valuesindexes- the indexes with the data coordinates, where index = row * cols() + col (0-based)rows- the number of rows (1-based)cols- the number of columns (1-based)- Throws:
IllegalArgumentException- when the size of the data object is not equal to rows*cols, or when the number of rows or columns is not positive, or when indexes is not in strictly increasing orderIndexOutOfBoundsException- when one of the entries in indexes is out of bounds
-
SparseFloatDataSi
public SparseFloatDataSi(double[] denseData, int rows, int cols) Instantiate a data object with one array in row-major format. Note that NO safe copy of the data is stored.- Parameters:
denseData- the dense data as double values in row-major formatrows- the number of rowscols- the number of columns- Throws:
IllegalArgumentException- when the size of the data object is not equal to rows*cols, or when the number of rows or columns is not positive
-
SparseFloatDataSi
public SparseFloatDataSi(float[] denseData, int rows, int cols) Instantiate a data object with one array in row-major format. Note that NO safe copy of the data is stored.- Parameters:
denseData- the dense data as float values in row-major formatrows- the number of rowscols- the number of columns- Throws:
IllegalArgumentException- when the size of the data object is not equal to rows*cols, or when the number of rows or columns is not positive
-
SparseFloatDataSi
public SparseFloatDataSi(double[][] denseData) Instantiate a data object with a dense double[rows][cols]. A sparse, safe copy of the data is stored.- Parameters:
denseData- the data in row-major format as a double[][]- Throws:
IllegalArgumentException- when the matrix is ragged
-
SparseFloatDataSi
public SparseFloatDataSi(float[][] denseData) Instantiate a data object with a dense double[rows][cols]. A sparse, safe copy of the data is stored.- Parameters:
denseData- the data in row-major format as a float[][]- Throws:
IllegalArgumentException- when the matrix is ragged
-
SparseFloatDataSi
public SparseFloatDataSi(Q[] sparseData, int[] indexes, int rows, int cols) Instantiate a data object with one array in row-major format. Note that a safe copy of the data is stored.- Type Parameters:
Q- the quantity typeU- the unit type- Parameters:
sparseData- the sparse data in row-major formatindexes- the indexes with the data coordinates, where index = row * cols() + col (0-based)rows- the number of rowscols- the number of columns- Throws:
IllegalArgumentException- when the size of the data object is not equal to rows*cols, or when the number of rows or columns is not positive, or when indexes is not in strictly increasing orderIndexOutOfBoundsException- when one of the entries in indexes is out of bounds
-
SparseFloatDataSi
public SparseFloatDataSi(Q[] denseData, int rows, int cols) Instantiate a data object with one array in row-major format. Note that a safe copy of the data is stored.- Type Parameters:
Q- the quantity typeU- the unit type- Parameters:
denseData- the dense data in row-major formatrows- the number of rowscols- the number of columns- Throws:
IllegalArgumentException- when the size of the data object is not equal to rows*cols, or when the number of rows or columns is not positive
-
SparseFloatDataSi
public SparseFloatDataSi(Q[][] denseData) Instantiate a data object with a dense double[rows][cols]. A sparse, safe copy of the data is stored.- Type Parameters:
Q- the quantity typeU- the unit type- Parameters:
denseData- the data in row-major format as a double[][]- Throws:
IllegalArgumentException- when the data matrix is ragged
-
SparseFloatDataSi
Instantiate a data object with an indexed collection of values. Note that a safe copy of the data is stored.- Type Parameters:
Q- the quantity typeU- the unit type- Parameters:
indexedData- the sparse data in an indexed formatrows- the number of rowscols- the number of columns- Throws:
IndexOutOfBoundsException- when a row or column index of an element is out of bounds
-
-
Method Details
-
checkIndexes
protected void checkIndexes(int[] indexArray) Check the correctness of the indexes array.- Parameters:
indexArray- the indexes with the data coordinates, where index = row * cols() + col (0-based)- Throws:
IllegalArgumentException- when indexes is not in strictly increasing orderIndexOutOfBoundsException- when one of the entries in indexes is out of bounds
-
storeSparse
public void storeSparse(double[] denseData) Store sparse data[] and indexes[].- Parameters:
denseData- the dense data in row-major format
-
storeSparse
public void storeSparse(float[] denseData) Store sparse data[] and indexes[].- Parameters:
denseData- the dense data in row-major format
-
storeSparse
public void storeSparse(double[][] denseData) Store sparse data[] and indexes[].- Parameters:
denseData- the dense data in row-major format
-
storeSparse
public void storeSparse(float[][] denseData) Store sparse data[] and indexes[].- Parameters:
denseData- the dense data in row-major format
-
storeSparse
Store sparse data[] and indexes[].- Type Parameters:
Q- the quantity typeU- the unit type- Parameters:
denseData- the dense data in row-major format
-
storeSparse
Store sparse data[] and indexes[].- Type Parameters:
Q- the quantity typeU- the unit type- Parameters:
denseData- the dense data in row-major format
-
rows
public int rows()Description copied from interface:DataGridSiReturn the number of rows in the grid.- Specified by:
rowsin interfaceDataGridSi<SparseFloatDataSi>- Returns:
- the number of rows in the grid
-
cols
public int cols()Description copied from interface:DataGridSiReturn the number of columns in the grid.- Specified by:
colsin interfaceDataGridSi<SparseFloatDataSi>- Returns:
- the number of columns in the grid
-
isDense
public boolean isDense()Description copied from interface:DataGridSiReturn whether the data is dense.- Specified by:
isDensein interfaceDataGridSi<SparseFloatDataSi>- Returns:
- whether the data is dense
-
isDouble
public boolean isDouble()Description copied from interface:DataGridSiReturn whether the data is double precision.- Specified by:
isDoublein interfaceDataGridSi<SparseFloatDataSi>- Returns:
- whether the data is double precision
-
get
public double get(int row, int col) Description copied from interface:DataGridSiReturn element (row, col) from the grid as a double value, independent of the fact whether it is stored as a double. Note that row and col are 0-based for fast calculations.- Specified by:
getin interfaceDataGridSi<SparseFloatDataSi>- Parameters:
row- the row number (0-based)col- the column number (0-based)- Returns:
- element (row, col) from the grid as a double value
-
getDataArray
public double[] getDataArray()Description copied from interface:DataGridSiReturn the data in row-major format. When the data is available in the correct format, NO safe copy is made.- Specified by:
getDataArrayin interfaceDataGridSi<SparseFloatDataSi>- Returns:
- the data in row-major format
-
copy
Description copied from interface:DataGridSiReturn a deep copy of the DataGrid object.- Specified by:
copyin interfaceDataGridSi<SparseFloatDataSi>- Returns:
- a deep copy of the DataGrid object
-
cardinality
public int cardinality()Description copied from interface:DataGridSiCompute and return the number of non-zero cells in this indexed value. Counts entries that are not exactly 0.0 (including -0.0 as zero). NaN and infinite values are counted as non-zero.- Specified by:
cardinalityin interfaceDataGridSi<SparseFloatDataSi>- Returns:
- the number of non-zero cells
-
instantiateNew
Description copied from interface:DataGridSiInstantiate a new version of the DataGrid object with the given data and the same number of rows and columns.- Specified by:
instantiateNewin interfaceDataGridSi<SparseFloatDataSi>- Parameters:
denseData- the data in row-major format- Returns:
- a new version of the DataGrid object with the given data, same number of rows and columns
-
instantiateNew
Description copied from interface:DataGridSiInstantiate a new version of the DataGrid object with the given data and the given number of rows and columns.- Specified by:
instantiateNewin interfaceDataGridSi<SparseFloatDataSi>- Parameters:
denseData- the data in row-major formatnewRows- the new number of rowsnewCols- the new number of columms- Returns:
- a new version of the DataGrid object with the given data, new number of rows and columns
-
hashCode
public int hashCode() -
equals
-