Class CooCVector

All Implemented Interfaces:
Serializable, FieldTensorMixin<CooCVector,CVector,Complex128>, TensorOverField<CooCVector,CVector,Complex128[],Complex128>, RingTensorMixin<CooCVector,CVector,Complex128>, TensorOverRing<CooCVector,CVector,Complex128[],Complex128>, SemiringTensorMixin<CooCVector,CVector,Complex128>, TensorOverSemiring<CooCVector,CVector,Complex128[],Complex128>, VectorMixin<CooCVector,CooCMatrix,CMatrix,Complex128>

A complex sparse vector stored in coordinate list (COO) format. The AbstractTensor.data of this COO vector are Complex128's.

The non-zero data and non-zero indices of a COO vector are mutable but the AbstractTensor.shape and total number of non-zero data is fixed.

Sparse vectors allow for the efficient storage of and ops on vectors that contain many zero values.

COO vectors are optimized for hyper-sparse vectors (i.e. vectors which contain almost all zeros relative to the size of the vector).

A sparse COO vector is stored as:

Note: many ops assume that the data of the COO vector are sorted lexicographically. However, this is not explicitly verified. Every operation implemented in this class will preserve the lexicographical sorting.

If indices need to be sorted for any reason, call AbstractCooSemiringVector.sortIndices().

See Also:
  • Constructor Details

    • CooCVector

      public CooCVector(int size, Complex128[] entries, int[] indices)
      Creates a tensor with the specified data and shape.
      Parameters:
      size - Full size of the vector.
      entries - Non-zero data of the sparse vector.
      indices - Non-zero indices of the sparse vector.
    • CooCVector

      public CooCVector(Shape shape, Complex128[] entries, int[] indices)
      Creates a tensor with the specified data and shape.
      Parameters:
      shape - Full shape of the vector. Must be rank 1.
      entries - Non-zero data of the sparse vector.
      indices - Non-zero indices of the sparse vector.
    • CooCVector

      public CooCVector(int size, List<Complex128> entries, List<Integer> indices)
      Constructs a complex COO vector with the specified size, non-zero data, and non-zero indices.
      Parameters:
      size - Full size of the vector.
      entries - The non-zero data of the vector.
      indices - The indices of the non-zero data.
    • CooCVector

      public CooCVector(Shape shape, List<Complex128> entries, List<Integer> indices)
      Constructs a complex COO vector with the specified size, non-zero data, and non-zero indices.
      Parameters:
      shape - Full shape of the sparse vector. Must be rank 1.
      entries - The non-zero data of the vector.
      indices - The indices of the non-zero data.
    • CooCVector

      public CooCVector(int size)
      Constructs a zero vector of the specified size.
      Parameters:
      size - Full size of the vector.
    • CooCVector

      public CooCVector(int size, double[] entries, int[] indices)
      Constructs a sparse complex COO vector from an array of double values.
      Parameters:
      size - Full size of the vector.
      entries - Non-zero data of the sparse vector.
      indices - Non-zero indices of the sparse vector.
    • CooCVector

      public CooCVector(CooCVector b)
      Constructs a copy of the specified vector.
      Parameters:
      b - The vector to create a copy of.
  • Method Details

    • makeEmptyDataArray

      public Complex128[] makeEmptyDataArray(int length)
      Description copied from interface: SemiringTensorMixin
      Creates an empty array of the same type as the data array of this tensor.
      Parameters:
      length - The length of the array to construct.
      Returns:
      An empty array of the same type as the data array of this tensor.
    • makeLikeTensor

      public CooCVector makeLikeTensor(Shape shape, Complex128[] entries, int[] indices)
      Constructs a sparse COO vector of the same type as this vector with the specified non-zero data and indices.
      Specified by:
      makeLikeTensor in class AbstractCooSemiringVector<CooCVector,CVector,CooCMatrix,CMatrix,Complex128>
      Parameters:
      shape - Shape of the vector to construct.
      entries - Non-zero data of the vector to construct.
      indices - Non-zero row indices of the vector to construct.
      Returns:
      A sparse COO vector of the same type as this vector with the specified non-zero data and indices.
    • makeLikeDenseTensor

      public CVector makeLikeDenseTensor(Shape shape, Complex128... entries)
      Constructs a dense vector of a similar type as this vector with the specified shape and data.
      Specified by:
      makeLikeDenseTensor in class AbstractCooSemiringVector<CooCVector,CVector,CooCMatrix,CMatrix,Complex128>
      Parameters:
      shape - Shape of the vector to construct.
      entries - Entries of the vector to construct.
      Returns:
      A dense vector of a similar type as this vector with the specified data.
    • makeLikeDenseMatrix

      public CMatrix makeLikeDenseMatrix(Shape shape, Complex128... entries)
      Constructs a dense matrix of a similar type as this vector with the specified shape and data.
      Specified by:
      makeLikeDenseMatrix in class AbstractCooSemiringVector<CooCVector,CVector,CooCMatrix,CMatrix,Complex128>
      Parameters:
      shape - Shape of the matrix to construct.
      entries - Entries of the matrix to construct.
      Returns:
      A dense matrix of a similar type as this vector with the specified data.
    • makeLikeTensor

      public CooCVector makeLikeTensor(Shape shape, List<Complex128> entries, List<Integer> indices)
      Constructs a COO vector with the specified shape, non-zero data, and non-zero indices.
      Specified by:
      makeLikeTensor in class AbstractCooSemiringVector<CooCVector,CVector,CooCMatrix,CMatrix,Complex128>
      Parameters:
      shape - Shape of the vector.
      entries - Non-zero values of the vector.
      indices - Indices of the non-zero values in the vector.
      Returns:
      A COO vector of the same type as this vector with the specified shape, non-zero data, and non-zero indices.
    • makeLikeMatrix

      public CooCMatrix makeLikeMatrix(Shape shape, Complex128[] entries, int[] rowIndices, int[] colIndices)
      Constructs a COO matrix with the specified shape, non-zero data, and row and column indices.
      Specified by:
      makeLikeMatrix in class AbstractCooSemiringVector<CooCVector,CVector,CooCMatrix,CMatrix,Complex128>
      Parameters:
      shape - Shape of the matrix to construct.
      entries - Non-zero data of the matrix.
      rowIndices - Row indices of the matrix.
      colIndices - Column indices of the matrix.
      Returns:
      A COO matrix of similar type as this vector with the specified shape, non-zero data, and non-zero row/col indices.
    • makeLikeTensor

      public CooCVector makeLikeTensor(Shape shape, Complex128[] entries)
      Constructs a tensor of the same type as this tensor with the given the shape and data. The resulting tensor will also have the same non-zero indices as this tensor.
      Specified by:
      makeLikeTensor in interface TensorOverSemiring<CooCVector,CVector,Complex128[],Complex128>
      Specified by:
      makeLikeTensor in class AbstractTensor<CooCVector,Complex128[],Complex128>
      Parameters:
      shape - Shape of the tensor to construct.
      entries - Entries of the tensor to construct.
      Returns:
      A tensor of the same type and with the same non-zero indices as this tensor with the given the shape and data.
    • toTensor

      public CooCTensor toTensor()
      Converts this matrix to an equivalent rank 1 tensor.
      Specified by:
      toTensor in class AbstractCooSemiringVector<CooCVector,CVector,CooCMatrix,CMatrix,Complex128>
      Returns:
      A tensor which is equivalent to this matrix.
    • toTensor

      public CooCTensor toTensor(Shape newShape)
      Converts this vector to an equivalent tensor with the specified shape.
      Specified by:
      toTensor in class AbstractCooSemiringVector<CooCVector,CVector,CooCMatrix,CMatrix,Complex128>
      Parameters:
      newShape - New shape for the tensor. Can be any rank but must be broadcastable to this.shape.
      Returns:
      A tensor equivalent to this matrix which has been reshaped to newShape
    • toReal

      public CooVector toReal()
      Converts this complex vector to a real vector.
      Returns:
      A real vector containing the real components of all non-zero values in this vector. The imaginary components are ignored.
    • isReal

      public boolean isReal()
      Checks if all data of this matrix are real.
      Returns:
      true if all data of this matrix are real; false otherwise.
    • isComplex

      public boolean isComplex()
      Checks if any entry within this matrix has non-zero imaginary component.
      Returns:
      true if any entry of this matrix has a non-zero imaginary component.
    • round

      public CooCVector round(int precision)
      Rounds all data within this vector to the specified precision.
      Parameters:
      precision - The precision to round to (i.e. the number of decimal places to round to). Must be non-negative.
      Returns:
      A new vector containing the data of this vector rounded to the specified precision.
    • roundToZero

      public CooCVector roundToZero(double tolerance)
      Sets all elements of this vector to zero if they are within tol of zero. This is not done in place.
      Parameters:
      precision - The precision to round to (i.e. the number of decimal places to round to). Must be non-negative.
      Returns:
      A copy of this vector with all data within tol of zero set to zero.
    • add

      public CooCVector add(CooVector b)
      Computes the element-wise sum of two vectors.
      Parameters:
      b - Second vector in the sum.
      Returns:
      The element-wise sum of this vector and b.
    • normalize

      public CooCVector normalize()
      Normalizes this vector to a unit length vector.
      Specified by:
      normalize in interface VectorMixin<CooCVector,CooCMatrix,CMatrix,Complex128>
      Overrides:
      normalize in class AbstractCooFieldVector<CooCVector,CVector,CooCMatrix,CMatrix,Complex128>
      Returns:
      This vector normalized to a unit length.
    • mag

      public Complex128 mag()
      Computes the magnitude of this vector.
      Specified by:
      mag in interface VectorMixin<CooCVector,CooCMatrix,CMatrix,Complex128>
      Overrides:
      mag in class AbstractCooFieldVector<CooCVector,CVector,CooCMatrix,CMatrix,Complex128>
      Returns:
      The magnitude of this vector.
    • magAsDouble

      public double magAsDouble()
      Computes the magnitude of this vector as a double value.
      Returns:
      The magnitude of this vector as a double value.
    • equals

      public boolean equals(Object object)
      Checks if an object is equal to this vector object.
      Overrides:
      equals in class Object
      Parameters:
      object - Object to check equality with this vector.
      Returns:
      True if the two vectors have the same shape, are numerically equivalent, and are of type CooCVector. False otherwise.
    • hashCode

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

      public String toString()
      Formats this tensor as a human-readable string. Specifically, a string containing the shape and flatten data of this tensor.
      Overrides:
      toString in class Object
      Returns:
      A human-readable string representing this tensor.