Class SparseFloatDataSi

java.lang.Object
org.djunits.vecmat.storage.SparseFloatDataSi
All Implemented Interfaces:
DataGridSi<SparseFloatDataSi>

public class SparseFloatDataSi extends Object implements 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

    Constructors
    Modifier
    Constructor
    Description
     
    SparseFloatDataSi(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].
    protected
    SparseFloatDataSi(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 Type
    Method
    Description
    int
    Compute and return the number of non-zero cells in this indexed value.
    protected void
    checkIndexes(int[] indexArray)
    Check the correctness of the indexes array.
    int
    Return the number of columns in the grid.
    Return a deep copy of the DataGrid object.
    boolean
     
    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.
    double[]
    Return the data in row-major format.
    int
     
    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.
    boolean
    Return whether the data is dense.
    boolean
    Return whether the data is double precision.
    int
    Return the number of rows in the grid.
    void
    storeSparse(double[] denseData)
    Store sparse data[] and indexes[].
    void
    storeSparse(double[][] denseData)
    Store sparse data[] and indexes[].
    void
    storeSparse(float[] denseData)
    Store sparse data[] and indexes[].
    void
    storeSparse(float[][] denseData)
    Store sparse data[] and indexes[].
    <Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>
    void
    storeSparse(Q[] denseData)
    Store sparse data[] and indexes[].
    <Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>
    void
    storeSparse(Q[][] denseData)
    Store sparse data[] and indexes[].

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods 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 values
      indexes - 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 order
      IndexOutOfBoundsException - 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 format
      rows - the number of rows
      cols - 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 format
      rows - the number of rows
      cols - 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 type
      U - the unit type
      Parameters:
      sparseData - the sparse data in row-major format
      indexes - the indexes with the data coordinates, where index = row * cols() + col (0-based)
      rows - the number of rows
      cols - 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 order
      IndexOutOfBoundsException - 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 type
      U - the unit type
      Parameters:
      denseData - the dense data in row-major format
      rows - the number of rows
      cols - 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 type
      U - the unit type
      Parameters:
      denseData - the data in row-major format as a double[][]
      Throws:
      IllegalArgumentException - when the data matrix is ragged
    • SparseFloatDataSi

      public SparseFloatDataSi(Collection<FloatSparseValue<Q,U>> indexedData, int rows, int cols)
      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 type
      U - the unit type
      Parameters:
      indexedData - the sparse data in an indexed format
      rows - the number of rows
      cols - 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 order
      IndexOutOfBoundsException - 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

      public <Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>> void storeSparse(Q[] denseData)
      Store sparse data[] and indexes[].
      Type Parameters:
      Q - the quantity type
      U - the unit type
      Parameters:
      denseData - the dense data in row-major format
    • storeSparse

      public <Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>> void storeSparse(Q[][] denseData)
      Store sparse data[] and indexes[].
      Type Parameters:
      Q - the quantity type
      U - the unit type
      Parameters:
      denseData - the dense data in row-major format
    • rows

      public int rows()
      Description copied from interface: DataGridSi
      Return the number of rows in the grid.
      Specified by:
      rows in interface DataGridSi<SparseFloatDataSi>
      Returns:
      the number of rows in the grid
    • cols

      public int cols()
      Description copied from interface: DataGridSi
      Return the number of columns in the grid.
      Specified by:
      cols in interface DataGridSi<SparseFloatDataSi>
      Returns:
      the number of columns in the grid
    • isDense

      public boolean isDense()
      Description copied from interface: DataGridSi
      Return whether the data is dense.
      Specified by:
      isDense in interface DataGridSi<SparseFloatDataSi>
      Returns:
      whether the data is dense
    • isDouble

      public boolean isDouble()
      Description copied from interface: DataGridSi
      Return whether the data is double precision.
      Specified by:
      isDouble in interface DataGridSi<SparseFloatDataSi>
      Returns:
      whether the data is double precision
    • get

      public double get(int row, int col)
      Description copied from interface: DataGridSi
      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.
      Specified by:
      get in interface DataGridSi<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: DataGridSi
      Return the data in row-major format. When the data is available in the correct format, NO safe copy is made.
      Specified by:
      getDataArray in interface DataGridSi<SparseFloatDataSi>
      Returns:
      the data in row-major format
    • copy

      public SparseFloatDataSi copy()
      Description copied from interface: DataGridSi
      Return a deep copy of the DataGrid object.
      Specified by:
      copy in interface DataGridSi<SparseFloatDataSi>
      Returns:
      a deep copy of the DataGrid object
    • cardinality

      public int cardinality()
      Description copied from interface: DataGridSi
      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.
      Specified by:
      cardinality in interface DataGridSi<SparseFloatDataSi>
      Returns:
      the number of non-zero cells
    • instantiateNew

      public SparseFloatDataSi instantiateNew(double[] denseData)
      Description copied from interface: DataGridSi
      Instantiate a new version of the DataGrid object with the given data and the same number of rows and columns.
      Specified by:
      instantiateNew in interface DataGridSi<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

      public SparseFloatDataSi instantiateNew(double[] denseData, int newRows, int newCols)
      Description copied from interface: DataGridSi
      Instantiate a new version of the DataGrid object with the given data and the given number of rows and columns.
      Specified by:
      instantiateNew in interface DataGridSi<SparseFloatDataSi>
      Parameters:
      denseData - the data in row-major format
      newRows - the new number of rows
      newCols - 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()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object