Class FloatMatrixDataSparse

  • All Implemented Interfaces:
    Serializable, Cloneable

    public class FloatMatrixDataSparse
    extends FloatMatrixData
    Stores sparse data for a FloatMatrix and carries out basic operations. The index in the sparse matrix data is calculated as r * columns + c, where r is the row number, cols is the total number of columns, and c is the column number.

    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
    • Constructor Detail

      • FloatMatrixDataSparse

        public FloatMatrixDataSparse​(float[] matrixSI,
                                     long[] indices,
                                     int rows,
                                     int cols)
        Create a matrix with sparse data.
        Parameters:
        matrixSI - float[]; the data to store
        indices - long[]; the index values of the Matrix, with <tt>index = row * cols + col</tt>
        rows - int; the number of rows
        cols - int; the number of columns
      • FloatMatrixDataSparse

        public FloatMatrixDataSparse​(Collection<FloatSparseValue<U,​S>> dataSI,
                                     int rows,
                                     int cols)
                              throws NullPointerException
        Create a matrix with sparse data.
        Type Parameters:
        U - the unit type
        S - the corresponding scalar type
        Parameters:
        dataSI - Collection<FloatSparseValue<U, S>>; the sparse [X, Y, SI] values to store
        rows - int; the number of rows of the matrix
        cols - int; the number of columns of the matrix
        Throws:
        NullPointerException - when storageType is null or dataSI is null
    • Method Detail

      • cardinality

        public final int cardinality()
        Compute and return the number of non-zero cells in this indexed value.
        Specified by:
        cardinality in class AbstractStorage<FloatMatrixData>
        Returns:
        int; the number of non-zero cells
      • assign

        public FloatMatrixData assign​(FloatFunction floatFunction)
        Apply an operation to each cell.
        Specified by:
        assign in class FloatMatrixData
        Parameters:
        floatFunction - FloatFunction; the operation to apply
        Returns:
        FloatMatrixData; this (modified) double vector data object
      • assign

        public final FloatMatrixDataSparse assign​(FloatFunction2 floatFunction,
                                                  FloatMatrixData right)
        Apply a binary operation on a cell by cell basis.
        Specified by:
        assign in class FloatMatrixData
        Parameters:
        floatFunction - FloatFunction2; the binary operation to apply
        right - FloatMatrixData; the right operand for the binary operation
        Returns:
        FloatMatrixData; this (modified) double matrix data object
      • toDense

        public final FloatMatrixDataDense toDense()
        Return the data of this matrix in dense storage format.
        Specified by:
        toDense in class FloatMatrixData
        Returns:
        FloatMatrixDataDense; the dense transformation of this data
      • toSparse

        public final FloatMatrixDataSparse toSparse()
        Return the data of this matrix in sparse storage format.
        Specified by:
        toSparse in class FloatMatrixData
        Returns:
        FloatMatrixDataSparse; the sparse transformation of this data
      • getSI

        public final float getSI​(int row,
                                 int col)
        Retrieve one value from this data.
        Specified by:
        getSI in class FloatMatrixData
        Parameters:
        row - int; the row number to get the value for
        col - int; the column number to get the value for
        Returns:
        the value at the [row, col] point
      • setSI

        public final void setSI​(int row,
                                int col,
                                float valueSI)
        Sets a value at the [row, col] point in the matrix.
        Specified by:
        setSI in class FloatMatrixData
        Parameters:
        row - int; the row number to set the value for
        col - int; the column number to set the value for
        valueSI - float; the value at the index
      • getDenseMatrixSI

        public final 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].
        Specified by:
        getDenseMatrixSI in class FloatMatrixData
        Returns:
        float[][]; a safe, dense copy of matrixSI as a matrix
      • getDoubleDenseMatrixSI

        public final 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].
        Specified by:
        getDoubleDenseMatrixSI in class FloatMatrixData
        Returns:
        double[][]; a safe, dense copy of matrixSI as a matrix
      • instantiate

        public static FloatMatrixDataSparse instantiate​(float[][] valuesSI)
                                                 throws ValueRuntimeException
        Instantiate a FloatMatrixDataSparse from an array.
        Parameters:
        valuesSI - float[][]; the (SI) values to store
        Returns:
        the FloatMatrixDataSparse
        Throws:
        ValueRuntimeException - in case matrix is ragged
      • instantiate

        public static FloatMatrixDataSparse instantiate​(float[][] values,
                                                        Scale scale)
                                                 throws ValueRuntimeException
        Instantiate a FloatMatrixDataSparse from an array.
        Parameters:
        values - float[][]; the values to store
        scale - Scale; the scale that will convert values to SI
        Returns:
        the DoubleMatrixDataSparse
        Throws:
        ValueRuntimeException - in case matrix is ragged
      • plus

        public FloatMatrixData plus​(FloatMatrixData right)
                             throws ValueRuntimeException
        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.
        Specified by:
        plus in class FloatMatrixData
        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
      • minus

        public final FloatMatrixData minus​(FloatMatrixData right)
        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.
        Specified by:
        minus in class FloatMatrixData
        Parameters:
        right - FloatMatrixData; the other data object to subtract
        Returns:
        the sum of this data object and the other data object
      • times

        public FloatMatrixData times​(FloatMatrixData right)
                              throws ValueRuntimeException
        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.
        Specified by:
        times in class FloatMatrixData
        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
      • divide

        public FloatMatrixData divide​(FloatMatrixData right)
                               throws ValueRuntimeException
        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.
        Specified by:
        divide in class FloatMatrixData
        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