Package org.djunits.vecmat.storage
Interface DataGridSi<D extends DataGridSi<D>>
- Type Parameters:
D- The datagrid type
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
DenseDoubleDataSi,DenseFloatDataSi,SparseDoubleDataSi,SparseFloatDataSi
DataGrid is an interface identifies the methods for storing and changing data for an N x M grid. Vectors are stored as a grid
with dimensions N x 1 or 1 x N. The DataGrid communicates as if it is a dense grid of double values, but underneath,
storage can be, e.g., sparse and/or float.
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
-
Method Summary
Modifier and TypeMethodDescriptionintcols()Return the number of columns in the grid.copy()Return a deep copy of the DataGrid object.default booleanequals(DataGridSi<?> other, double epsilon) Test if two datagrids are equal to a maximum absolute error epsilon.doubleget(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.default double[]getColArray(int col) Get the data of a column as a (dense) double array.default double[]getRowArray(int row) Get the data of a row as a (dense) double array.double[]Return a safe copy of the data in row-major format.instantiateNew(double[] data) Instantiate a new version of the DataGrid object with the given data and the same number of rows and columns.instantiateNew(double[] data, 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.default booleanisFloat()Return whether the data is single precision.default booleanisSparse()Return whether the data is sparse.default intnnz()Compute and return the number of non-zero cells in this indexed value.intCompute and return the number of non-zero cells in this indexed value.introws()Return the number of rows in the grid.double[]Return the data in row-major format.
-
Method Details
-
rows
int rows()Return the number of rows in the grid.- Returns:
- the number of rows in the grid
-
cols
int cols()Return the number of columns in the grid.- Returns:
- the number of columns in the grid
-
get
double get(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. Note that row and col are 0-based for fast calculations.- Parameters:
row- the row number (0-based)col- the column number (0-based)- Returns:
- element (row, col) from the grid as a double value
- Throws:
IndexOutOfBoundsException- when row > rows() or col > cols() or row < 0 or col < 0
-
unsafeSiArray
double[] unsafeSiArray()Return the data in row-major format. When the data is available in the correct format, NO safe copy is made.- Returns:
- the data in row-major format
-
getSiArray
double[] getSiArray()Return a safe copy of the data in row-major format.- Returns:
- the data in row-major format
-
copy
D copy()Return a deep copy of the DataGrid object.- Returns:
- a deep copy of the DataGrid object
-
nonZeroCount
int nonZeroCount()Compute 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.- Returns:
- the number of non-zero cells
-
nnz
default int nnz()Compute 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.- Returns:
- the number of non-zero cells
-
instantiateNew
Instantiate a new version of the DataGrid object with the given data and the same number of rows and columns.- Parameters:
data- 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
Instantiate a new version of the DataGrid object with the given data and the given number of rows and columns.- Parameters:
data- 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
-
isDense
boolean isDense()Return whether the data is dense.- Returns:
- whether the data is dense
-
isSparse
default boolean isSparse()Return whether the data is sparse.- Returns:
- whether the data is sparse
-
isDouble
boolean isDouble()Return whether the data is double precision.- Returns:
- whether the data is double precision
-
isFloat
default boolean isFloat()Return whether the data is single precision.- Returns:
- whether the data is single precision
-
getRowArray
default double[] getRowArray(int row) Get the data of a row as a (dense) double array.- Parameters:
row- the row number (0-based)- Returns:
- a double[] of length cols() with all the row values
- Throws:
IndexOutOfBoundsException- when row > rows() or col < 0
-
getColArray
default double[] getColArray(int col) Get the data of a column as a (dense) double array.- Parameters:
col- the column number (0-based)- Returns:
- a double[] of length rows() with all the column values
- Throws:
IndexOutOfBoundsException- when col > cols() or col < 0
-
equals
Test if two datagrids are equal to a maximum absolute error epsilon. The number of rows and columns is also compared.- Parameters:
other- the other datagrid to compare toepsilon- the maximum absolute error for a value- Returns:
- whether two datagrid arrays are equal to a maximum absolute error epsilon
-