Class DoubleVectorDataSparse

All Implemented Interfaces:
Serializable, Cloneable

public class DoubleVectorDataSparse extends DoubleVectorData
Stores sparse data for a DoubleVector and carries out basic operations.

Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.

Author:
Alexander Verbraeck, Peter Knoppers
See Also:
  • Constructor Details

    • DoubleVectorDataSparse

      public DoubleVectorDataSparse(double[] vectorSI, int[] indices, int size)
      Create a vector with sparse data.
      Parameters:
      vectorSI - double[]; the data to store
      indices - int[]; the index values of the Vector
      size - int; the length of the vector (padded with 0 after highest index in indices)
  • Method Details

    • cardinality

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

      public DoubleVectorData assign(DoubleFunction doubleFunction)
      Description copied from class: DoubleVectorData
      Apply an operation to each cell.
      Specified by:
      assign in class DoubleVectorData
      Parameters:
      doubleFunction - DoubleFunction; the operation to apply
      Returns:
      DoubleVectorData; this (modified) double vector data object
    • assign

      public final DoubleVectorDataSparse assign(DoubleFunction2 doubleFunction, DoubleVectorData right)
      Description copied from class: DoubleVectorData
      Apply a binary operation on a cell by cell basis.
      Specified by:
      assign in class DoubleVectorData
      Parameters:
      doubleFunction - DoubleFunction2; the binary operation to apply
      right - DoubleVectorData; the right operand for the binary operation
      Returns:
      DoubleVectorData; this (modified) double vector data object
    • toDense

      public final DoubleVectorDataDense toDense()
      Description copied from class: DoubleVectorData
      Return the densely stored equivalent of this data.
      Specified by:
      toDense in class DoubleVectorData
      Returns:
      DoubleVectorDataDense; the dense transformation of this data
    • toSparse

      public final DoubleVectorDataSparse toSparse()
      Description copied from class: DoubleVectorData
      Return the sparsely stored equivalent of this data.
      Specified by:
      toSparse in class DoubleVectorData
      Returns:
      DoubleVectorDataSparse; the sparse transformation of this data
    • size

      public final int size()
      Description copied from class: DoubleVectorData
      Retrieve the size of the vector.
      Specified by:
      size in class DoubleVectorData
      Returns:
      int; the size of the vector
    • getSI

      public final double getSI(int index)
      Description copied from class: DoubleVectorData
      Retrieve the SI value of one element of this data.
      Specified by:
      getSI in class DoubleVectorData
      Parameters:
      index - int; the index to get the value for
      Returns:
      double; the value at the index
    • setSI

      public final void setSI(int index, double valueSI)
      Description copied from class: DoubleVectorData
      Sets a value at the index in the vector.
      Specified by:
      setSI in class DoubleVectorData
      Parameters:
      index - int; the index to set the value for
      valueSI - double; the value at the index
    • getDenseVectorSI

      public final double[] getDenseVectorSI()
      Description copied from class: DoubleVectorData
      Create and return a dense copy of the data.
      Specified by:
      getDenseVectorSI in class DoubleVectorData
      Returns:
      double[]; a safe copy of VectorSI
    • copy

      public final DoubleVectorDataSparse copy()
      Description copied from class: Storage
      Create and return a deep copy of the data.
      Specified by:
      copy in class Storage<DoubleVectorData>
      Returns:
      T; a deep copy of the data
    • instantiate

      public static DoubleVectorDataSparse instantiate(double[] valuesSI)
      Instantiate a DoubleVectorDataSparse from an array.
      Parameters:
      valuesSI - double[]; the (SI) values to store
      Returns:
      the DoubleVectorDataSparse
    • plus

      public final DoubleVectorData plus(DoubleVectorData right)
      Description copied from class: DoubleVectorData
      Add two vectors on a cell-by-cell basis. If both vectors are sparse, a sparse vector is returned, otherwise a dense vector is returned. Neither of the two objects is changed.
      Specified by:
      plus in class DoubleVectorData
      Parameters:
      right - DoubleVectorData; the other data object to add
      Returns:
      DoubleVectorData; the sum of this data object and the other data object as a new data object
    • minus

      public final DoubleVectorData minus(DoubleVectorData right)
      Description copied from class: DoubleVectorData
      Subtract two vectors on a cell-by-cell basis. If both vectors are sparse, a sparse vector is returned, otherwise a dense vector is returned. Neither of the two objects is changed.
      Specified by:
      minus in class DoubleVectorData
      Parameters:
      right - DoubleVectorData; the other data object to subtract
      Returns:
      DoubleVectorData; the difference of this data object and the other data object as a new data object
    • times

      public final DoubleVectorData times(DoubleVectorData right)
      Description copied from class: DoubleVectorData
      Multiply two vectors on a cell-by-cell basis. If both vectors are dense, a dense vector is returned, otherwise a sparse vector is returned.
      Specified by:
      times in class DoubleVectorData
      Parameters:
      right - DoubleVectorData; the other data object to multiply with
      Returns:
      DoubleVectorData; a new double vector data store holding the result of the multiplications
    • divide

      public final DoubleVectorData divide(DoubleVectorData right) throws ValueRuntimeException
      Description copied from class: DoubleVectorData
      Divide two vectors on a cell-by-cell basis. If this vector is sparse and right is dense, a sparse vector is returned, otherwise a dense vector is returned.
      Specified by:
      divide in class DoubleVectorData
      Parameters:
      right - DoubleVectorData; the other data object to divide by
      Returns:
      DoubleVectorData; the ratios of the values of this data object and the other data object
      Throws:
      ValueRuntimeException - if vectors have different lengths
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class DoubleVectorData
    • equals

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