Class FloatMatrixData

java.lang.Object
org.djunits.value.storage.AbstractStorage<FloatMatrixData>
org.djunits.value.vfloat.matrix.data.FloatMatrixData
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
FloatMatrixDataDense, FloatMatrixDataSparse

public abstract class FloatMatrixData
extends AbstractStorage<FloatMatrixData>
implements Serializable
Stores the data for a FloatMatrix and carries out basic operations.

Copyright (c) 2013-2019 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
  • Field Details

    • matrixSI

      protected float[] matrixSI
      the internal storage of the Matrix; can be sparse or dense. The data is stored in an array.
    • rows

      protected int rows
      the number of rows of the matrix.
    • cols

      protected int cols
      the number of columns of the matrix.
  • Constructor Details

    • FloatMatrixData

      public FloatMatrixData​(StorageType storageType)
      Construct a new DoubleMatrixData store.
      Parameters:
      storageType - StorageType; the data type
  • Method Details

    • instantiate

      public static FloatMatrixData instantiate​(float[][] values, Scale scale, StorageType storageType) throws ValueRuntimeException
      Instantiate a FloatMatrixData with the right data type. The float array is of the form f[rows][columns] so each value can be found with f[row][column].
      Parameters:
      values - float[][]; the (SI) values to store
      scale - Scale; the scale of the unit to use for conversion to SI
      storageType - StorageType; the data type to use
      Returns:
      the FloatMatrixData with the right data type
      Throws:
      ValueRuntimeException - when values are null, or storageType is null
    • instantiate

      public static <U extends Unit<U>,​ S extends FloatScalarInterface<U,​ S>> FloatMatrixData instantiate​(Collection<FloatSparseValue<U,​S>> values, int rows, int cols, StorageType storageType) throws ValueRuntimeException
      Instantiate a FloatMatrixData with the right data type.
      Type Parameters:
      U - the unit type
      S - the corresponding scalar type
      Parameters:
      values - 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
      storageType - StorageType; the data type to use
      Returns:
      the FloatMatrixData with the right data type
      Throws:
      ValueRuntimeException - when values are null, or storageType is null
    • instantiate

      public static <U extends Unit<U>,​ S extends FloatScalarInterface<U,​ S>> FloatMatrixData instantiate​(S[][] values, StorageType storageType) throws ValueRuntimeException
      Instantiate a FloatMatrixData with the right data type. The FloatScalar array is of the form fs[rows][columns] so each value can be found with fs[row][column].
      Type Parameters:
      U - the unit type
      S - the corresponding scalar type
      Parameters:
      values - FloatScalarInterface[][]; the values to store
      storageType - StorageType; the data type to use
      Returns:
      the FloatMatrixData with the right data type
      Throws:
      ValueRuntimeException - when values is null, or storageType is null
    • rows

      public int rows()
      Retrieve the row count.
      Returns:
      int; the number of rows of the matrix
    • cols

      public int cols()
      Retrieve the column count.
      Returns:
      int; the number of columns of the matrix
    • toDense

      public abstract FloatMatrixDataDense toDense()
      Return the data of this matrix in dense storage format.
      Returns:
      FloatMatrixDataDense; the dense transformation of this data
    • toSparse

      public abstract FloatMatrixDataSparse toSparse()
      Return the data of this matrix in sparse storage format.
      Returns:
      FloatMatrixDataSparse; the sparse transformation of this data
    • getSI

      public abstract float getSI​(int row, int col)
      Retrieve one value from this data.
      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 abstract void setSI​(int row, int col, float valueSI)
      Sets a value at the [row, col] point in the matrix.
      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
    • zSum

      public final float zSum()
      Compute and return the sum of the values of all cells of this matrix.
      Returns:
      float; the sum of the values of all cells
    • getDenseMatrixSI

      public abstract 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].
      Returns:
      float[][]; a safe, dense copy of matrixSI as a matrix
    • getDoubleDenseMatrixSI

      public abstract 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].
      Returns:
      double[][]; a safe, dense copy of matrixSI as a matrix
    • checkRectangularAndNonEmpty

      protected static float[][] checkRectangularAndNonEmpty​(float[][] values) throws ValueRuntimeException
      Check that a 2D array of float is not null, not empty and not jagged; i.e. all rows have the same length.
      Parameters:
      values - float[][]; the 2D array to check
      Returns:
      the values in case the method is used in a constructor
      Throws:
      NullPointerException - when values is null
      ValueRuntimeException - when values is empty, or jagged
    • checkRectangularAndNonEmpty

      protected static <U extends Unit<U>,​ S extends FloatScalarInterface<U,​ S>> S[][] checkRectangularAndNonEmpty​(S[][] values) throws ValueRuntimeException
      Check that a 2D array of float is not null, not empty and not jagged; i.e. all rows have the same length.
      Type Parameters:
      U - the unit type
      S - the corresponding scalar type
      Parameters:
      values - S[][]; the 2D array to check
      Returns:
      the values in case the method is used in a constructor
      Throws:
      NullPointerException - when values is null
      ValueRuntimeException - when values is empty, or jagged
    • checkSizes

      protected void checkSizes​(FloatMatrixData other) throws ValueRuntimeException
      Check the sizes of this data object and the other data object.
      Parameters:
      other - FloatMatrixData; the other data object
      Throws:
      ValueRuntimeException - if matrices have different lengths
    • assign

      public abstract FloatMatrixData assign​(FloatFunction doubleFunction)
      Apply an operation to each cell.
      Parameters:
      doubleFunction - DoubleFunction; the operation to apply
      Returns:
      FloatMatrixData; this (modified) double vector data object
    • assign

      abstract FloatMatrixData assign​(FloatFunction2 floatFunction, FloatMatrixData right) throws ValueRuntimeException
      Apply a binary operation on a cell by cell basis.
      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
      Throws:
      ValueRuntimeException - when the sizes of the vectors do not match
    • plus

      public abstract 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.
      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
    • incrementBy

      public final FloatMatrixData incrementBy​(FloatMatrixData right) throws ValueRuntimeException
      Add a matrix to this matrix on a cell-by-cell basis. The type of matrix (sparse, dense) stays the same.
      Parameters:
      right - FloatMatrixData; the other data object to add
      Returns:
      FloatMatrixData; this modified float matrix data object
      Throws:
      ValueRuntimeException - if matrices have different lengths
    • minus

      public abstract FloatMatrixData minus​(FloatMatrixData right) throws ValueRuntimeException
      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.
      Parameters:
      right - FloatMatrixData; the other data object to subtract
      Returns:
      the sum of this data object and the other data object
      Throws:
      ValueRuntimeException - if matrices have different lengths
    • decrementBy

      public final FloatMatrixData decrementBy​(FloatMatrixData decrement) throws ValueRuntimeException
      Subtract a matrix from this matrix on a cell-by-cell basis. The type of matrix (sparse, dense) stays the same.
      Parameters:
      decrement - FloatMatrixData; the other data object to subtract
      Returns:
      FloatMatrixData; this modified float matrix data object
      Throws:
      ValueRuntimeException - if matrices have different lengths
    • times

      public abstract 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.
      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
    • multiplyBy

      public final FloatMatrixData multiplyBy​(FloatMatrixData right) throws ValueRuntimeException
      Multiply a matrix with the values of another matrix on a cell-by-cell basis. The type of matrix (sparse, dense) stays the same.
      Parameters:
      right - FloatMatrixData; the other data object to multiply with
      Returns:
      FloatMatrixData; this modified data store
      Throws:
      ValueRuntimeException - if matrices have different sizes
    • divide

      public abstract 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.
      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
    • divideBy

      public final FloatMatrixData divideBy​(FloatMatrixData right) throws ValueRuntimeException
      Divide the values of a matrix by the values of another matrix on a cell-by-cell basis. The type of matrix (sparse, dense) stays the same.
      Parameters:
      right - FloatMatrixData; the other data object to divide by
      Returns:
      FloatMatrixData; this modified data store
      Throws:
      ValueRuntimeException - if matrices have different sizes
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareDenseMatrixWithSparseMatrix

      protected boolean compareDenseMatrixWithSparseMatrix​(FloatMatrixDataDense dm, FloatMatrixDataSparse sm)
      Compare contents of a dense and a sparse matrix.
      Parameters:
      dm - FloatMatrixDataDense; the dense matrix
      sm - FloatMatrixDataSparse; the sparse matrix
      Returns:
      boolean; true if the contents are equal
    • equals

      public boolean equals​(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object