Class CVector

  • Constructor Details

    • CVector

      public CVector(Complex128... entries)
      Creates a complex vector with the specified data.
      Parameters:
      entries - Entries of this vector.
    • CVector

      public CVector(Complex64... entries)
      Creates a complex vector with the specified data.
      Parameters:
      entries - Entries of this vector.
    • CVector

      public CVector(double... entries)
      Creates a complex vector with the specified data.
      Parameters:
      entries - Entries of this vector.
    • CVector

      public CVector(int... entries)
      Creates a complex vector with the specified data.
      Parameters:
      entries - Entries of this vector.
    • CVector

      public CVector(int size, Complex128 fillValue)
      Creates a complex vector with the specified size and filled with fillValue.
      Parameters:
      size - The size of the vector.
      fillValue - The value to fill the vector with.
    • CVector

      public CVector(int size, Complex64 fillValue)
      Creates a complex vector with the specified size and filled with fillValue.
      Parameters:
      size - The size of the vector.
      fillValue - The value to fill the vector with.
    • CVector

      public CVector(int size, double fillValue)
      Creates a complex vector with the specified size and filled with fillValue.
      Parameters:
      size - The size of the vector.
      fillValue - The value to fill the vector with.
    • CVector

      public CVector(int size)
      Creates a complex zero vector with the specified size.
      Parameters:
      size - The size of the vector.
    • CVector

      public CVector(CVector vector)
      Creates a copy of the provided vector.
      Parameters:
      vector - Vector to create a copy of.
    • CVector

      public CVector(Shape shape, Complex128[] data)
      Constructs a dense complex vector with the given shape and entries.
      Parameters:
      shape - The shape of the vector. Must be rank-1 and satisfy shape.totalEntriesIntValueExact() == data.length.
      data - The entries of the vector.
      Throws:
      LinearAlgebraException - If shape.getRank() != 1
      IllegalArgumentException - If shape.totalEntriesIntValueExact() != data.length
    • CVector

      public CVector(Shape shape)
      Constructs a zero vector with the specified shape.
      Parameters:
      shape - Shape of the zero vector to construct. Must be rank 1.
  • 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.
    • set

      public void set(double val, int index)
      Sets the specified index of this vector to the provided real value.
      Parameters:
      val - Value to set in this vector.
      index - Index to set to val in this vector.
      Throws:
      IndexOutOfBoundsException - If index is not in bounds of this vector.
    • getEmpty

      public static CVector getEmpty(int size)
      Constructs an empty vector with the specified size. The data of the resulting vector will be all be null.
      Parameters:
      size - The size of the vector to construct.
      Returns:
      An empty vector (i.e. filled with null values) with the specified size.
    • makeLikeTensor

      public CVector makeLikeTensor(Complex128[] entries)
      Constructs a dense vector with the specified data of the same type as the vector.
      Specified by:
      makeLikeTensor in class AbstractDenseSemiringVector<CVector,CMatrix,Complex128>
      Parameters:
      entries - Entries of the dense vector to construct.
    • makeLikeMatrix

      public CMatrix makeLikeMatrix(Shape shape, Complex128[] entries)
      Constructs a matrix of similar type to this vector with the specified shape and data.
      Specified by:
      makeLikeMatrix in class AbstractDenseSemiringVector<CVector,CMatrix,Complex128>
      Parameters:
      shape - Shape of the matrix to construct.
      entries - Entries of the matrix to construct.
      Returns:
      A matrix of similar type to this vector with the specified shape and data.
    • add

      public CVector add(CooCVector b)
      Computes the element-wise sum between two tensors of the same shape.
      Parameters:
      b - Second tensor in the element-wise sum.
      Returns:
      The sum of this tensor with b.
      Throws:
      TensorShapeException - If this tensor and b do not have the same shape.
    • add

      public CVector add(Vector b)
      Computes the element-wise sum between two tensors of the same shape.
      Parameters:
      b - Second tensor in the element-wise sum.
      Returns:
      The sum of this tensor with b.
      Throws:
      TensorShapeException - If this tensor and b do not have the same shape.
    • addEq

      public void addEq(Vector b)
      Computes the element-wise sum between two tensors of the same shape and stores the result in this tensor.
      Parameters:
      b - Second tensor in the element-wise sum.
      Throws:
      TensorShapeException - If this tensor and b do not have the same shape.
    • add

      public CVector add(CooVector b)
      Computes the element-wise sum between two tensors of the same shape.
      Parameters:
      b - Second tensor in the element-wise sum.
      Returns:
      The sum of this tensor with b.
      Throws:
      TensorShapeException - If this tensor and b do not have the same shape.
    • sub

      public CVector sub(CooCVector b)
      Computes the element-wise difference between two tensors of the same shape.
      Parameters:
      b - Second tensor in the element-wise difference.
      Returns:
      The difference of this tensor with b.
      Throws:
      TensorShapeException - If this tensor and b do not have the same shape.
    • sub

      public CVector sub(Vector b)
      Computes the element-wise difference between two tensors of the same shape.
      Parameters:
      b - Second tensor in the element-wise difference.
      Returns:
      The difference of this tensor with b.
      Throws:
      TensorShapeException - If this tensor and b do not have the same shape.
    • sub

      public CVector sub(CooVector b)
      Computes the element-wise difference between two tensors of the same shape.
      Parameters:
      b - Second tensor in the element-wise difference.
      Returns:
      The difference of this tensor with b.
      Throws:
      TensorShapeException - If this tensor and b do not have the same shape.
    • elemMult

      public CooCVector elemMult(CooCVector b)
      Computes the element-wise multiplication of two tensors of the same shape.
      Parameters:
      b - Second tensor in the element-wise product.
      Returns:
      The element-wise product between this tensor and b.
      Throws:
      IllegalArgumentException - If this tensor and b do not have the same shape.
    • elemMult

      public CVector elemMult(Vector b)
      Computes the element-wise multiplication of two tensors of the same shape.
      Parameters:
      b - Second tensor in the element-wise product.
      Returns:
      The element-wise product between this tensor and b.
      Throws:
      IllegalArgumentException - If this tensor and b do not have the same shape.
    • elemMult

      public CooCVector elemMult(CooVector b)
      Computes the element-wise multiplication of two tensors of the same shape.
      Parameters:
      b - Second tensor in the element-wise product.
      Returns:
      The element-wise product between this tensor and b.
      Throws:
      IllegalArgumentException - If this tensor and b do not have the same shape.
    • div

      public CVector div(Vector b)
      Computes the element-wise quotient between two tensors.
      Parameters:
      b - Second tensor in the element-wise quotient.
      Returns:
      The element-wise quotient of this tensor with b.
    • normalize

      public CVector normalize()
      Normalizes this vector to a unit length vector.
      Specified by:
      normalize in interface VectorMixin<CVector,CMatrix,CMatrix,Complex128>
      Overrides:
      normalize in class AbstractDenseFieldVector<CVector,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<CVector,CMatrix,CMatrix,Complex128>
      Overrides:
      mag in class AbstractDenseFieldVector<CVector,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.
    • makeLikeCooTensor

      protected CooCVector makeLikeCooTensor(Shape shape, Complex128[] entries, int[][] indices)
      Constructs a sparse COO tensor which is of a similar type as this dense tensor.
      Specified by:
      makeLikeCooTensor in class AbstractDenseSemiringTensor<CVector,Complex128>
      Parameters:
      shape - Shape of the COO tensor.
      entries - Non-zero data of the COO tensor.
      indices -
      Returns:
      A sparse COO tensor which is of a similar type as this dense tensor.
    • toCoo

      public CooCVector toCoo()
      Converts this tensor to an equivalent sparse COO tensor.
      Overrides:
      toCoo in class AbstractDenseSemiringTensor<CVector,Complex128>
      Returns:
      A sparse COO tensor that is equivalent to this dense tensor.
      See Also:
    • toCoo

      public CooCVector toCoo(double estimatedSparsity)
      Converts this tensor to an equivalent sparse COO tensor.
      Overrides:
      toCoo in class AbstractDenseSemiringTensor<CVector,Complex128>
      Parameters:
      estimatedSparsity - Estimated sparsity of the tensor. Must be between 0 and 1 inclusive. If this is an accurate estimation it may provide a slight speedup and can reduce unneeded memory consumption. If memory is a concern, it is better to over-estimate the sparsity. If speed is the concern it is better to under-estimate the sparsity.
      Returns:
      A sparse COO tensor that is equivalent to this dense tensor.
      See Also:
    • makeLikeTensor

      public CVector 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<CVector,CVector,Complex128[],Complex128>
      Specified by:
      makeLikeTensor in class AbstractTensor<CVector,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.
    • toReal

      public Vector toReal()
      Converts this complex vector to a real vector. This conversion is done by taking the real component of each entry and ignoring the imaginary component.
      Returns:
      A real vector containing the real components of the data of this vector.
    • isReal

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

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

      public CVector 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 CVector 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.
    • innerSelf

      public double innerSelf()
      Compute the inner product of this vector with itself.
      Returns:
    • cross

      public CVector cross(CVector b)

      Computes the vector cross product between two vectors.

      Note: Formally speaking, the vector cross product cannot be defined for complex vectors while maintaining the same properties as vectors from invalid input: '&#8477'3 (e.g. orthogonality). However, it can still be defined algebraically in the same way as it is for real vectors though it may fail to satisfy properties of a true cross product. This is algebraic definition is what this method implements.

      Parameters:
      b - Second vector in the cross product.
      Returns:
      The result of the vector cross product between this vector and b.
      Throws:
      IllegalArgumentException - If either this vector or b do not have exactly 3 data.
    • subEq

      public void subEq(Vector b)
      Computes the element-wise difference between two vectors of the same shape.
      Parameters:
      b - Second tensor in the element-wise difference.
      Throws:
      TensorShapeException - If !this.shape.equals(b.shape).
    • 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 CVector. false otherwise.
    • hashCode

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

      public String toString()
      Converts this vector to a human-readable string format. To specify the maximum number of data to print, use PrintOptions.setMaxColumns(int).
      Overrides:
      toString in class Object
      Returns:
      A human-readable string representation of this vector.