Class DoubleVectorData

java.lang.Object
org.djunits.value.storage.AbstractStorage<DoubleVectorData>
org.djunits.value.vdouble.vector.data.DoubleVectorData
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
DoubleVectorDataDense, DoubleVectorDataSparse

public abstract class DoubleVectorData
extends AbstractStorage<DoubleVectorData>
implements Serializable
Stores the data for a DoubleVector 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

    • vectorSI

      protected double[] vectorSI
      The internal storage of the Vector; can be sparse or dense.
    • PARALLEL_THRESHOLD

      protected static final int PARALLEL_THRESHOLD
      Threshold to do parallel execution.
      See Also:
      Constant Field Values
  • Constructor Details

    • DoubleVectorData

      DoubleVectorData​(StorageType storageType)
      Construct a new DoubleVectorData object.
      Parameters:
      storageType - StorageType; the data type.
  • Method Details

    • instantiate

      public static DoubleVectorData instantiate​(double[] values, Scale scale, StorageType storageType) throws ValueRuntimeException
      Instantiate a DoubleVectorData with the right data type.
      Parameters:
      values - double[]; 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:
      DoubleVectorData; the DoubleVectorData with the right data type
      Throws:
      ValueRuntimeException - when values are null, or storageType is null
    • instantiate

      public static DoubleVectorData instantiate​(List<Double> values, Scale scale, StorageType storageType) throws ValueRuntimeException
      Instantiate a DoubleVectorData with the right data type.
      Parameters:
      values - List<Double>; the values to store
      scale - Scale; the scale of the unit to use for conversion to SI
      storageType - StorageType; the data type to use
      Returns:
      DoubleVectorData; the DoubleVectorData with the right data type
      Throws:
      ValueRuntimeException - when list is null, or storageType is null
    • instantiate

      public static <U extends Unit<U>,​ S extends DoubleScalarInterface<U,​ S>> DoubleVectorData instantiate​(S[] values, StorageType storageType) throws ValueRuntimeException
      Instantiate a DoubleVectorData with the right data type.
      Type Parameters:
      U - the unit type
      S - the corresponding scalar type
      Parameters:
      values - DoubleScalarInterface[]; the values to store
      storageType - StorageType; the data type to use
      Returns:
      DoubleVectorData; the DoubleVectorData with the right data type
      Throws:
      ValueRuntimeException - when values is null, or storageType is null
    • instantiateList

      public static <U extends Unit<U>,​ S extends DoubleScalarInterface<U,​ S>> DoubleVectorData instantiateList​(List<S> valueList, StorageType storageType) throws ValueRuntimeException
      Instantiate a DoubleVectorData with the right data type.
      Type Parameters:
      U - the unit type
      S - the corresponding scalar type
      Parameters:
      valueList - List<S>; the values to store
      storageType - StorageType; the data type to use
      Returns:
      DoubleVectorData; the DoubleVectorData with the right data type
      Throws:
      ValueRuntimeException - when values is null, or storageType is null
    • instantiate

      public static DoubleVectorData instantiate​(SortedMap<Integer,​Double> valueMap, int length, Scale scale, StorageType storageType) throws ValueRuntimeException
      Instantiate a DoubleVectorData with the right data type.
      Parameters:
      valueMap - SortedMap<Integer,Double>; the DoubleScalar values to store
      length - int; the length of the vector to pad with 0 after last entry in map
      scale - Scale; the scale of the unit to use for conversion to SI
      storageType - StorageType; the data type to use
      Returns:
      DoubleVectorData; the DoubleVectorData with the right data type
      Throws:
      ValueRuntimeException - when values is null, or storageType is null
    • instantiateMap

      public static <U extends Unit<U>,​ S extends DoubleScalarInterface<U,​ S>> DoubleVectorData instantiateMap​(SortedMap<Integer,​S> values, int length, StorageType storageType) throws ValueRuntimeException
      Instantiate a DoubleVectorData with the right data type.
      Type Parameters:
      U - the unit
      S - the corresponding scalar type
      Parameters:
      values - SortedMap<Integer,S>; the DoubleScalar values to store
      length - int; the length of the vector to pad with 0 after last entry in map
      storageType - StorageType; the data type to use
      Returns:
      DoubleVectorData; the DoubleVectorData with the right data type
      Throws:
      ValueRuntimeException - when values is null, or storageType is null
    • size

      public abstract int size()
      Retrieve the size of the vector.
      Returns:
      int; the size of the vector
    • toDense

      public abstract DoubleVectorDataDense toDense()
      Return the densely stored equivalent of this data.
      Returns:
      DoubleVectorDataDense; the dense transformation of this data
    • toSparse

      public abstract DoubleVectorDataSparse toSparse()
      Return the sparsely stored equivalent of this data.
      Returns:
      DoubleVectorDataSparse; the sparse transformation of this data
    • getSI

      public abstract double getSI​(int index)
      Retrieve the SI value of one element of this data.
      Parameters:
      index - int; the index to get the value for
      Returns:
      double; the value at the index
    • setSI

      public abstract void setSI​(int index, double valueSI)
      Sets a value at the index in the vector.
      Parameters:
      index - int; the index to set the value for
      valueSI - double; the value at the index
    • zSum

      public final double zSum()
      Compute and return the sum of all values.
      Returns:
      double; the sum of the values of all cells
    • getDenseVectorSI

      public abstract double[] getDenseVectorSI()
      Create and return a dense copy of the data.
      Returns:
      double[]; a safe copy of VectorSI
    • checkSizes

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

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

      abstract DoubleVectorData assign​(DoubleFunction2 doubleFunction2, DoubleVectorData right) throws ValueRuntimeException
      Apply a binary operation on a cell by cell basis.
      Parameters:
      doubleFunction2 - DoubleFunction2; the binary operation to apply
      right - DoubleVectorData; the right operand for the binary operation
      Returns:
      DoubleVectorData; this (modified) double vector data object
      Throws:
      ValueRuntimeException - when the sizes of the vectors do not match
    • plus

      public abstract DoubleVectorData plus​(DoubleVectorData right) throws ValueRuntimeException
      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.
      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
      Throws:
      ValueRuntimeException - if vectors have different lengths
    • incrementBy

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

      public abstract DoubleVectorData minus​(DoubleVectorData right) throws ValueRuntimeException
      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.
      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
      Throws:
      ValueRuntimeException - if vectors have different lengths
    • decrementBy

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

      public abstract DoubleVectorData times​(DoubleVectorData right) throws ValueRuntimeException
      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.
      Parameters:
      right - DoubleVectorData; the other data object to multiply with
      Returns:
      DoubleVectorData; a new double vector data store holding the result of the multiplications
      Throws:
      ValueRuntimeException - if vectors have different lengths
    • multiplyBy

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

      public final void multiplyBy​(double valueSI)
      Multiply the values of this vector with a number on a cell-by-cell basis.
      Parameters:
      valueSI - double; the value to multiply with
    • divide

      public abstract DoubleVectorData divide​(DoubleVectorData right) throws ValueRuntimeException
      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.
      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
    • divideBy

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

      public final void divideBy​(double valueSI)
      Divide the values of this vector by a number on a cell-by-cell basis.
      Parameters:
      valueSI - double; the value to multiply with
    • hashCode

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

      protected boolean compareDenseVectorWithSparseVector​(DoubleVectorDataDense dm, DoubleVectorDataSparse sm)
      Compare contents of a dense and a sparse vector.
      Parameters:
      dm - DoubleVectorDataDense; the dense vector
      sm - DoubleVectorDataSparse; the sparse vector
      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