Class CooVector

All Implemented Interfaces:
Serializable, TensorOverField<CooVector,CooVector,double[],Double>, TensorOverRing<CooVector,CooVector,double[],Double>, TensorOverSemiring<CooVector,CooVector,double[],Double>, VectorMixin<CooVector,CooMatrix,Matrix,Double>

public class CooVector extends AbstractDoubleTensor<CooVector> implements VectorMixin<CooVector,CooMatrix,Matrix,Double>

A real sparse vector stored in coordinate list (COO) format. The AbstractTensor.data of this COO vector are primitive doubles.

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:

Some ops on sparse tensors behave differently than on dense tensors. For instance, add(Complex128) will not add the scalar to all data of the tensor since this would cause catastrophic loss of sparsity. Instead, such non-zero preserving element-wise ops only act on the non-zero data of the sparse tensor as to not affect the sparsity.

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 sortIndices().

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int[]
    The indices of the non-zero data in this sparse COO vector.
    final int
    The number of non-zero values in this sparse COO vector.
    final int
    The full size of this sparse COO vector (including the zeros.).

    Fields inherited from class org.flag4j.arrays.backend.AbstractTensor

    data, rank, shape
  • Constructor Summary

    Constructors
    Constructor
    Description
    CooVector(int size)
    Creates a zero vector of the specified size.
    CooVector(int size, double[] entries, int[] indices)
    Creates sparse COO vector with the specified size, non-zero data, and non-zero indices.
    CooVector(int size, int[] entries, int[] indices)
    Creates sparse COO vector with the specified size, non-zero data, and non-zero indices.
    CooVector(int size, List<Double> entries, List<Integer> indices)
    Creates sparse COO vector with the specified size, non-zero data, and non-zero indices.
    CooVector(Shape shape, double[] entries, int[] indices)
    Creates sparse COO vector with the specified size, non-zero data, and non-zero indices.
    CooVector(Shape shape, List<Double> data, List<Integer> indices)
    Creates sparse COO vector with the specified size, non-zero data, and non-zero indices.
    Constructs a copy of the specified sparse COO vector.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(double b)
    Adds a scalar value to each non-zero element of this tensor.
    Adds a scalar field value to each entry of this tensor.
    Adds a scalar field value to each non-zero entry of this tensor.
    Computes the element-wise sum between two tensors of the same shape.
    Computes the element-wise sum between two tensors of the same shape.
    void
    Adds a scalar value to each entry of this tensor and stores the result in this tensor.
    int[]
    Finds the indices of the maximum value in this tensor.
    int[]
    Finds the indices of the maximum absolute value in this tensor.
    int[]
    Finds the indices of the minimum value in this tensor.
    int[]
    Finds the indices of the minimum absolute value in this tensor.
    Coalesces this sparse COO vector.
    Coalesces this sparse COO vector.
    div(Complex128 divisor)
    Divides each element of this sparse COO vector by a complex-valued scalar.
    Computes the element-wise division of two vectors.
    Computes the element-wise division of two vectors.
    Computes the element-wise quotient between two tensors.
    Computes the dot product between two vectors.
    Drops any explicit zeros in this sparse COO vector.
    Computes the element-wise multiplication between this vector and a real dense vector.
    Computes the element-wise multiplication of two tensors of the same shape.
    boolean
    equals(Object object)
    Checks if an object is equal to this vector object.
    Flattens tensor to single dimension while preserving order of data.
    flatten(int axis)
    Flattens a tensor along the specified axis.
    static CooVector
    Creates a sparse tensor from a dense tensor.
    get(int target)
    Gets the element of this vector at the specified index.
    get(int... target)
    Gets the element of this tensor at the specified target index.
    H()
    Computes the conjugate transpose of a tensor by exchanging the first and last axes of this tensor and conjugating the exchanged values.
    H(int... axes)
    Computes the conjugate transpose of this tensor.
    H(int axis1, int axis2)
    Computes the conjugate transpose of a tensor by conjugating and exchanging axis1 and axis2.
    int
     
    Computes the inner product between two vectors.
    boolean
    Checks if a vector is parallel to this vector.
    boolean
    Checks if a vector is perpendicular to this vector.
    Joints specified vector with this vector.
    int
    Gets the length of a vector.
    mag()
    Computes the magnitude of this vector.
    makeLikeTensor(int size, double[] entries, int[] indices)
    Constructs a vector of the same type as this tensor with the given the shape and data.
    makeLikeTensor(Shape shape, double[] entries)
    Constructs a tensor of the same type as this tensor with the given the shape and data.
    mult(Complex128 factor)
    Multiplies this vector by a complex scalar value.
    double
    Computes the Euclidean norm of this vector.
    double
    norm(int p)
    Computes the p-norm of this vector.
    Computes a unit vector in the same direction as this vector.
    Computes the outer product of two vectors.
    Computes the product of all non-zero values in this tensor.
    Computes the element-wise reciprocals of the non-zero values of this tensor.
    repeat(int n, int axis)
    Repeats a vector n times along a certain axis to create a matrix.
    reshape(Shape newShape)
    Copies and reshapes this tensor.
    set(Double value, int... indices)
    Sets the element of this tensor at the specified indices.
    void
    Sorts the indices of this tensor in lexicographical order while maintaining the associated value for each index.
    double
    The sparsity of this sparse tensor.
    Stacks two vectors vertically as if they were row vectors to form a matrix with two rows.
    stack(CooVector b, int axis)
    Stacks two vectors along specified axis.
    sub(double b)
    Subtracts a scalar value non-zero from each element of this tensor.
    Subtracts a scalar value from each non-zero entry of this tensor.
    Subtracts a scalar value from each non-zero entry of this tensor.
    Computes the element-wise difference between two tensors of the same shape.
    void
    Subtracts a scalar value from each non-zero entry of this tensor and stores the result in this tensor.
    T()
    Computes the transpose of a tensor by exchanging the first and last axes of this tensor.
    T(int... axes)
    Computes the transpose of this tensor.
    T(int axis1, int axis2)
    Computes the transpose of a tensor by exchanging axis1 and axis2.
    tensorDot(CooVector src2, int[] aAxes, int[] bAxes)
    Computes the tensor contraction of this tensor with a specified tensor over the specified set of axes.
    tensorTr(int axis1, int axis2)
    Computes the generalized trace of this tensor along the specified axes.
    Converts this vector to an equivalent sparse vector.
    Converts this sparse tensor to an equivalent dense tensor.
    toMatrix(boolean columVector)
    Converts a vector to an equivalent matrix representing either a row or column vector.
    Formats this tensor as a human-readable string.
    Converts this sparse vector to an equivalent tensor.

    Methods inherited from class org.flag4j.arrays.backend.primitive_arrays.AbstractDoubleTensor

    abs, addEq, conj, copy, div, div, divEq, divEq, isFinite, isInfinite, isNaN, isNeg, isOnes, isPos, isZeros, max, maxAbs, min, minAbs, mult, mult, multEq, multEq, round, round, roundToZero, roundToZero, sqrt, subEq, sum

    Methods inherited from class org.flag4j.arrays.backend.AbstractTensor

    getData, getRank, getShape, reshape, sameShape, totalEntries

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.flag4j.arrays.backend.semiring_arrays.TensorOverSemiring

    getData, getRank, getShape, tensorDot, tensorDot, tensorDot, tensorTr

    Methods inherited from interface org.flag4j.arrays.backend.VectorMixin

    size, toMatrix
  • Field Details

    • indices

      public final int[] indices
      The indices of the non-zero data in this sparse COO vector.
    • size

      public final int size
      The full size of this sparse COO vector (including the zeros.).
    • nnz

      public final int nnz
      The number of non-zero values in this sparse COO vector.
  • Constructor Details

    • CooVector

      public CooVector(Shape shape, double[] entries, int[] indices)
      Creates sparse COO vector with the specified size, non-zero data, and non-zero indices.
      Parameters:
      entries - The non-zero data of this vector.
      indices - The indices of the non-zero values.
      size - The size of this vector.
    • CooVector

      public CooVector(Shape shape, List<Double> data, List<Integer> indices)
      Creates sparse COO vector with the specified size, non-zero data, and non-zero indices.
      Parameters:
      data - The non-zero data of this vector.
      indices - The indices of the non-zero values.
      size - The size of this vector.
    • CooVector

      public CooVector(int size, double[] entries, int[] indices)
      Creates sparse COO vector with the specified size, non-zero data, and non-zero indices.
      Parameters:
      size - The size of this vector.
      entries - The non-zero data of this vector.
      indices - The indices of the non-zero values.
    • CooVector

      public CooVector(int size, List<Double> entries, List<Integer> indices)
      Creates sparse COO vector with the specified size, non-zero data, and non-zero indices.
      Parameters:
      size - The size of this vector.
      entries - The non-zero data of this vector.
      indices - The indices of the non-zero values.
    • CooVector

      public CooVector(int size)
      Creates a zero vector of the specified size.
    • CooVector

      public CooVector(int size, int[] entries, int[] indices)
      Creates sparse COO vector with the specified size, non-zero data, and non-zero indices.
      Parameters:
      size - The size of this vector.
      entries - The non-zero data of this vector.
      indices - The indices of the non-zero values.
    • CooVector

      public CooVector(CooVector b)
      Constructs a copy of the specified sparse COO vector.
      Parameters:
      b - The vector to construct a copy of.
  • Method Details

    • fromDense

      public static CooVector fromDense(Vector src)
      Creates a sparse tensor from a dense tensor.
      Parameters:
      src - Dense tensor to convert to a sparse tensor.
      Returns:
      A sparse tensor which is equivalent to the src dense tensor.
    • makeLikeTensor

      public CooVector makeLikeTensor(Shape shape, double[] entries)
      Constructs a tensor of the same type as this tensor with the given the shape and data.
      Specified by:
      makeLikeTensor in interface TensorOverSemiring<CooVector,CooVector,double[],Double>
      Specified by:
      makeLikeTensor in class AbstractTensor<CooVector,double[],Double>
      Parameters:
      shape - Shape of the tensor to construct.
      entries - Entries of the tensor to construct.
      Returns:
      A tensor of the same type as this tensor with the given the shape and data.
    • makeLikeTensor

      public CooVector makeLikeTensor(int size, double[] entries, int[] indices)
      Constructs a vector of the same type as this tensor with the given the shape and data.
      Parameters:
      entries - Non-zero data of the vector to construct.
      indices - Indices of the non-zero values in this vector.
      shape - Shape of the vector to construct.
      Returns:
      A vector of the same type as this tensor with the given the shape and data.
    • tensorDot

      public Vector tensorDot(CooVector src2, int[] aAxes, int[] bAxes)
      Computes the tensor contraction of this tensor with a specified tensor over the specified set of axes. That is, computes the sum of products between the two tensors along the specified set of axes.
      Specified by:
      tensorDot in interface TensorOverSemiring<CooVector,CooVector,double[],Double>
      Parameters:
      src2 - Tensor to contract with this tensor.
      aAxes - Axes along which to compute products for this tensor.
      bAxes - Axes along which to compute products for src2 tensor.
      Returns:
      The tensor dot product over the specified axes.
      Throws:
      IllegalArgumentException - If the two tensors shapes do not match along the specified axes pairwise in aAxes and bAxes.
      IllegalArgumentException - If aAxes and bAxes do not match in length, or if any of the axes are out of bounds for the corresponding tensor.
    • T

      public CooVector T(int axis1, int axis2)
      Computes the transpose of a tensor by exchanging axis1 and axis2.
      Specified by:
      T in class AbstractTensor<CooVector,double[],Double>
      Parameters:
      axis1 - First axis to exchange.
      axis2 - Second axis to exchange.
      Returns:
      The transpose of this tensor according to the specified axes.
      Throws:
      IndexOutOfBoundsException - If either axis1 or axis2 are out of bounds for the rank of this tensor.
      See Also:
    • T

      public CooVector T(int... axes)
      Computes the transpose of this tensor. That is, permutes the axes of this tensor so that it matches the permutation specified by axes.
      Specified by:
      T in class AbstractTensor<CooVector,double[],Double>
      Parameters:
      axes - Permutation of tensor axis. If the tensor has rank N, then this must be an array of length N which is a permutation of {0, 1, 2, ..., N-1}.
      Returns:
      The transpose of this tensor with its axes permuted by the axes array.
      Throws:
      IndexOutOfBoundsException - If any element of axes is out of bounds for the rank of this tensor.
      IllegalArgumentException - If axes is not a permutation of {1, 2, 3, ... N-1}.
      See Also:
    • join

      public CooVector join(CooVector b)
      Joints specified vector with this vector. That is, creates a vector of length this.length() + b.length() containing first the elements of this vector followed by the elements of b.
      Specified by:
      join in interface VectorMixin<CooVector,CooMatrix,Matrix,Double>
      Parameters:
      b - Vector to join with this vector.
      Returns:
      A vector resulting from joining the specified vector with this vector.
    • inner

      public Double inner(CooVector b)

      Computes the inner product between two vectors.

      Note: this method is distinct from dot(CooVector). The inner product is equivalent to the dot product of this tensor with the conjugation of b.

      Specified by:
      inner in interface VectorMixin<CooVector,CooMatrix,Matrix,Double>
      Parameters:
      b - Second vector in the inner product.
      Returns:
      The inner product between this vector and the vector b.
      Throws:
      IllegalArgumentException - If this vector and vector b do not have the same number of data.
      See Also:
    • dot

      public Double dot(CooVector b)

      Computes the dot product between two vectors.

      Note: this method is distinct from inner(CooVector). The inner product is equivalent to the dot product of this tensor with the conjugation of b.

      Specified by:
      dot in interface VectorMixin<CooVector,CooMatrix,Matrix,Double>
      Parameters:
      b - Second vector in the dot product.
      Returns:
      The dot product between this vector and the vector b.
      Throws:
      IllegalArgumentException - If this vector and vector b do not have the same number of data.
      See Also:
    • norm

      public double norm()
      Computes the Euclidean norm of this vector.
      Returns:
      The Euclidean norm of this vector.
    • norm

      public double norm(int p)
      Computes the p-norm of this vector.
      Parameters:
      p - p value in the p-norm.
      Returns:
      The Euclidean norm of this vector.
    • normalize

      public CooVector normalize()
      Computes a unit vector in the same direction as this vector.
      Specified by:
      normalize in interface VectorMixin<CooVector,CooMatrix,Matrix,Double>
      Returns:
      A unit vector with the same direction as this vector. If this vector is zeros, then an equivalently sized zero vector will be returned.
    • mag

      public Double mag()
      Computes the magnitude of this vector.
      Specified by:
      mag in interface VectorMixin<CooVector,CooMatrix,Matrix,Double>
      Returns:
      The magnitude of this vector.
    • get

      public Double get(int target)
      Gets the element of this vector at the specified index.
      Specified by:
      get in interface VectorMixin<CooVector,CooMatrix,Matrix,Double>
      Parameters:
      target - Index of the element to get within this vector.
      Returns:
      The element of this vector at index target.
    • isParallel

      public boolean isParallel(CooVector b)
      Checks if a vector is parallel to this vector.
      Parameters:
      b - Vector to compare to this vector.
      Returns:
      true if the vector b is parallel to this vector and the same size; false otherwise.
      See Also:
    • isPerp

      public boolean isPerp(CooVector b)
      Checks if a vector is perpendicular to this vector.
      Parameters:
      b - Vector to compare to this vector.
      Returns:
      true if the vector b is perpendicular to this vector and the same size; false otherwise.
      See Also:
    • length

      public int length()
      Gets the length of a vector.
      Specified by:
      length in interface VectorMixin<CooVector,CooMatrix,Matrix,Double>
      Returns:
      The length, i.e. the number of data, in this vector.
    • sparsity

      public double sparsity()
      The sparsity of this sparse tensor. That is, the percentage of elements in this tensor which are zero as a decimal.
      Returns:
      The density of this sparse tensor.
    • toDense

      public Vector toDense()
      Converts this sparse tensor to an equivalent dense tensor.
      Returns:
      A dense tensor equivalent to this sparse tensor.
    • sortIndices

      public void sortIndices()
      Sorts the indices of this tensor in lexicographical order while maintaining the associated value for each index.
    • get

      public Double get(int... target)
      Gets the element of this tensor at the specified target index.
      Specified by:
      get in class AbstractTensor<CooVector,double[],Double>
      Parameters:
      target - Index of the element to get.
      Returns:
      The element of this tensor at the specified target index.
      Throws:
      IllegalArgumentException - If target.length != 1.
    • set

      public CooVector set(Double value, int... indices)
      Sets the element of this tensor at the specified indices.
      Specified by:
      set in class AbstractTensor<CooVector,double[],Double>
      Parameters:
      value - New value to set the specified index of this tensor to.
      indices - Indices of the element to set.
      Returns:
      A copy of this tensor with the updated value is returned.
      Throws:
      IndexOutOfBoundsException - If indices is not within the bounds of this tensor.
    • flatten

      public CooVector flatten()
      Flattens tensor to single dimension while preserving order of data.
      Specified by:
      flatten in class AbstractTensor<CooVector,double[],Double>
      Returns:
      The flattened tensor.
      See Also:
    • flatten

      public CooVector flatten(int axis)
      Flattens a tensor along the specified axis.
      Specified by:
      flatten in class AbstractTensor<CooVector,double[],Double>
      Parameters:
      axis - Axis along which to flatten tensor.
      Throws:
      ArrayIndexOutOfBoundsException - If the axis is not positive or larger than this.{@link #getRank()}-1.
      See Also:
    • reshape

      public CooVector reshape(Shape newShape)
      Copies and reshapes this tensor.
      Specified by:
      reshape in class AbstractTensor<CooVector,double[],Double>
      Parameters:
      newShape - New shape for the tensor.
      Returns:
      A copy of this tensor with the new shape.
      Throws:
      TensorShapeException - If newShape is not broadcastable to this.shape.
    • sub

      public CooVector sub(Double b)
      Subtracts a scalar value from each non-zero entry of this tensor.
      Specified by:
      sub in interface TensorOverRing<CooVector,CooVector,double[],Double>
      Overrides:
      sub in class AbstractDoubleTensor<CooVector>
      Parameters:
      b - Scalar value in difference.
      Returns:
      The difference of this tensor's non-zero values and the scalar b.
    • sub

      public CooCVector sub(Complex128 b)
      Subtracts a scalar value from each non-zero entry of this tensor.
      Parameters:
      b - Scalar value in difference.
      Returns:
      The difference of this tensor's non-zero values and the scalar b.
    • subEq

      public void subEq(Double b)
      Subtracts a scalar value from each non-zero entry of this tensor and stores the result in this tensor.
      Specified by:
      subEq in interface TensorOverRing<CooVector,CooVector,double[],Double>
      Overrides:
      subEq in class AbstractDoubleTensor<CooVector>
      Parameters:
      b - Scalar value in difference.
    • add

      public CooVector add(Double b)
      Adds a scalar field value to each entry of this tensor.
      Specified by:
      add in interface TensorOverSemiring<CooVector,CooVector,double[],Double>
      Overrides:
      add in class AbstractDoubleTensor<CooVector>
      Parameters:
      b - Scalar field value in sum.
      Returns:
      The sum of this tensor with the scalar b.
    • add

      public CooCVector add(Complex128 b)
      Adds a scalar field value to each non-zero entry of this tensor.
      Parameters:
      b - Scalar field value in sum.
      Returns:
      The sparse COO vector resulting from adding b to each non-zero entry of this vector.
    • addEq

      public void addEq(Double b)
      Adds a scalar value to each entry of this tensor and stores the result in this tensor.
      Specified by:
      addEq in interface TensorOverSemiring<CooVector,CooVector,double[],Double>
      Overrides:
      addEq in class AbstractDoubleTensor<CooVector>
      Parameters:
      b - Scalar field value in sum.
    • add

      public CooVector add(CooVector b)
      Computes the element-wise sum between two tensors of the same shape.
      Specified by:
      add in interface TensorOverSemiring<CooVector,CooVector,double[],Double>
      Parameters:
      b - Second tensor in the element-wise sum.
      Returns:
      The sum of this tensor with b.
      Throws:
      IllegalArgumentException - If this tensor and b do not have the same shape.
    • add

      public CooCVector 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:
      IllegalArgumentException - If this tensor and b do not have the same shape.
    • sub

      public CooVector sub(CooVector b)
      Computes the element-wise difference between two tensors of the same shape.
      Specified by:
      sub in interface TensorOverRing<CooVector,CooVector,double[],Double>
      Parameters:
      b - Second tensor in the element-wise difference.
      Returns:
      The difference of this tensor with b.
      Throws:
      IllegalArgumentException - If this tensor and b do not have the same shape.
    • elemMult

      public CooVector elemMult(CooVector b)
      Computes the element-wise multiplication of two tensors of the same shape.
      Specified by:
      elemMult in interface TensorOverSemiring<CooVector,CooVector,double[],Double>
      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.
    • tensorTr

      public CooVector tensorTr(int axis1, int axis2)

      Computes the generalized trace of this tensor along the specified axes.

      The generalized tensor trace is the sum along the diagonal values of the 2D sub-arrays of this tensor specified by axis1 and axis2. The shape of the resulting tensor is equal to this tensor with the axis1 and axis2 removed.

      Specified by:
      tensorTr in interface TensorOverSemiring<CooVector,CooVector,double[],Double>
      Parameters:
      axis1 - First axis for 2D sub-array.
      axis2 - Second axis for 2D sub-array.
      Returns:
      The generalized trace of this tensor along axis1 and axis2. This will be a tensor of rank this.getRank() - 2 with the same shape as this tensor but with axis1 and axis2 removed.
      Throws:
      IndexOutOfBoundsException - If the two axes are not both larger than zero and less than this tensors rank.
      IllegalArgumentException - If axis1 == axis2 or this.shape.get(axis1) != this.shape.get(axis1) (i.e. the axes are equal or the tensor does not have the same length along the two axes.)
    • prod

      public Double prod()
      Computes the product of all non-zero values in this tensor.
      Specified by:
      prod in interface TensorOverSemiring<CooVector,CooVector,double[],Double>
      Overrides:
      prod in class AbstractDoubleTensor<CooVector>
      Returns:
      The product of all non-zero values in this tensor.
    • T

      public CooVector T()
      Computes the transpose of a tensor by exchanging the first and last axes of this tensor.
      Overrides:
      T in class AbstractTensor<CooVector,double[],Double>
      Returns:
      The transpose of this tensor.
      See Also:
    • H

      public CooVector H()
      Computes the conjugate transpose of a tensor by exchanging the first and last axes of this tensor and conjugating the exchanged values.
      Specified by:
      H in interface TensorOverRing<CooVector,CooVector,double[],Double>
      Returns:
      The conjugate transpose of this tensor.
      See Also:
    • H

      public CooVector H(int axis1, int axis2)
      Computes the conjugate transpose of a tensor by conjugating and exchanging axis1 and axis2.
      Specified by:
      H in interface TensorOverRing<CooVector,CooVector,double[],Double>
      Overrides:
      H in class AbstractDoubleTensor<CooVector>
      Parameters:
      axis1 - First axis to exchange and conjugate.
      axis2 - Second axis to exchange and conjugate.
      Returns:
      The conjugate transpose of this tensor according to the specified axes.
      Throws:
      IndexOutOfBoundsException - If either axis1 or axis2 are out of bounds for the rank of this tensor.
      See Also:
    • H

      public CooVector H(int... axes)
      Computes the conjugate transpose of this tensor. That is, conjugates and permutes the axes of this tensor so that it matches the permutation specified by axes.
      Specified by:
      H in interface TensorOverRing<CooVector,CooVector,double[],Double>
      Overrides:
      H in class AbstractDoubleTensor<CooVector>
      Parameters:
      axes - Permutation of tensor axis. If the tensor has rank N, then this must be an array of length N which is a permutation of {0, 1, 2, ..., N-1}.
      Returns:
      The conjugate transpose of this tensor with its axes permuted by the axes array.
      Throws:
      IndexOutOfBoundsException - If any element of axes is out of bounds for the rank of this tensor.
      IllegalArgumentException - If axes is not a permutation of {1, 2, 3, ... N-1}.
      See Also:
    • argmin

      public int[] argmin()
      Finds the indices of the minimum value in this tensor.
      Specified by:
      argmin in interface TensorOverRing<CooVector,CooVector,double[],Double>
      Returns:
      The indices of the minimum value in this tensor. If this value occurs multiple times, the indices of the first entry (in row-major ordering) are returned.
    • argmax

      public int[] argmax()
      Finds the indices of the maximum value in this tensor.
      Specified by:
      argmax in interface TensorOverRing<CooVector,CooVector,double[],Double>
      Returns:
      The indices of the maximum value in this tensor. If this value occurs multiple times, the indices of the first entry (in row-major ordering) are returned.
    • argminAbs

      public int[] argminAbs()
      Finds the indices of the minimum absolute value in this tensor.
      Specified by:
      argminAbs in interface TensorOverRing<CooVector,CooVector,double[],Double>
      Returns:
      The indices of the minimum absolute value in this tensor. If this value occurs multiple times, the indices of the first entry (in row-major ordering) are returned.
    • argmaxAbs

      public int[] argmaxAbs()
      Finds the indices of the maximum absolute value in this tensor.
      Specified by:
      argmaxAbs in interface TensorOverRing<CooVector,CooVector,double[],Double>
      Returns:
      The indices of the maximum absolute value in this tensor. If this value occurs multiple times, the indices of the first entry (in row-major ordering) are returned.
    • recip

      public CooVector recip()
      Computes the element-wise reciprocals of the non-zero values of this tensor.
      Specified by:
      recip in interface TensorOverField<CooVector,CooVector,double[],Double>
      Overrides:
      recip in class AbstractDoubleTensor<CooVector>
      Returns:
      A tensor containing the reciprocal elements of the non-zero values of this tensor.
    • add

      public CooVector add(double b)
      Adds a scalar value to each non-zero element of this tensor.
      Specified by:
      add in interface TensorOverField<CooVector,CooVector,double[],Double>
      Overrides:
      add in class AbstractDoubleTensor<CooVector>
      Parameters:
      b - Value to add to each non-zero entry of this tensor.
      Returns:
      The result of adding the specified scalar value to each entry of this tensor.
    • sub

      public CooVector sub(double b)
      Subtracts a scalar value non-zero from each element of this tensor.
      Specified by:
      sub in interface TensorOverField<CooVector,CooVector,double[],Double>
      Overrides:
      sub in class AbstractDoubleTensor<CooVector>
      Parameters:
      b - Value to subtract from each non-zero entry of this tensor.
      Returns:
      The result of subtracting the specified scalar value from each entry of this tensor.
    • div

      public CooVector div(CooVector b)

      Computes the element-wise quotient between two tensors.

      WARNING: This method is not supported for sparse vectors. If called on a sparse vector, an UnsupportedOperationException will be thrown. Element-wise division is undefined for sparse vectors as it would almost certainly result in a division by zero.

      Specified by:
      div in interface TensorOverField<CooVector,CooVector,double[],Double>
      Parameters:
      b - Second tensor in the element-wise quotient.
      Returns:
      The element-wise quotient of this tensor with b.
    • 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 CooVector. False otherwise.
    • hashCode

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

      public CooMatrix repeat(int n, int axis)
      Repeats a vector n times along a certain axis to create a matrix.
      Specified by:
      repeat in interface VectorMixin<CooVector,CooMatrix,Matrix,Double>
      Parameters:
      n - Number of times to repeat vector.
      axis - Axis along which to repeat vector:
      • If axis=0, then the vector will be treated as a row vector and stacked vertically n times.
      • If axis=1 then the vector will be treated as a column vector and stacked horizontally n times.
      Returns:
      A matrix whose rows/columns are this vector repeated.
    • stack

      public CooMatrix stack(CooVector b)
      Stacks two vectors vertically as if they were row vectors to form a matrix with two rows.
      Specified by:
      stack in interface VectorMixin<CooVector,CooMatrix,Matrix,Double>
      Parameters:
      b - Vector to stack below this vector.
      Returns:
      The result of stacking this vector and vector b.
      Throws:
      IllegalArgumentException - If the number of data in this vector is different from the number of data in the vector b.
    • stack

      public CooMatrix stack(CooVector b, int axis)

      Stacks two vectors along specified axis.

      Stacking two vectors of length n along axis 0 stacks the vectors as if they were row vectors resulting in a 2-by-n matrix.

      Stacking two vectors of length n along axis 1 stacks the vectors as if they were column vectors resulting in a n-by-2 matrix.

      Specified by:
      stack in interface VectorMixin<CooVector,CooMatrix,Matrix,Double>
      Parameters:
      b - Vector to stack with this vector.
      axis - Axis along which to stack vectors. If axis=0, then vectors are stacked as if they are row vectors. If axis=1, then vectors are stacked as if they are column vectors.
      Returns:
      The result of stacking this vector and the vector b.
      Throws:
      IllegalArgumentException - If the number of data in this vector is different from the number of data in the vector b.
      IllegalArgumentException - If axis is not either 0 or 1.
    • outer

      public Matrix outer(CooVector b)
      Computes the outer product of two vectors.
      Specified by:
      outer in interface VectorMixin<CooVector,CooMatrix,Matrix,Double>
      Parameters:
      b - Second vector in the outer product.
      Returns:
      The result of the vector outer product between this vector and b.
      Throws:
      IllegalArgumentException - If the two vectors do not have the same number of data.
    • toMatrix

      public CooMatrix toMatrix(boolean columVector)
      Converts a vector to an equivalent matrix representing either a row or column vector.
      Specified by:
      toMatrix in interface VectorMixin<CooVector,CooMatrix,Matrix,Double>
      Parameters:
      columVector - Flag indicating whether to convert this vector to a matrix representing a row or column vector:

      If true, the vector will be converted to a matrix representing a column vector.

      If false, The vector will be converted to a matrix representing a row vector.

      Returns:
      A matrix equivalent to this vector.
    • toComplex

      public CooCVector toComplex()
      Converts this vector to an equivalent sparse vector.
      Returns:
      A complex COO vector equivalent to this vector.
    • elemMult

      public CooVector elemMult(Vector b)
      Computes the element-wise multiplication between this vector and a real dense vector.
      Parameters:
      b - The real dense vector in the element-wise product.
      Returns:
      The element-wise product of this vector and b.
      Throws:
      TensorShapeException - If the two vectors are not the same size.
    • mult

      public CooCVector mult(Complex128 factor)
      Multiplies this vector by a complex scalar value.
      Parameters:
      factor - Scalar value to multiply this vector by.
      Returns:
      The result of multiplying this vector by the scalar factor.
    • toTensor

      public CooTensor toTensor()
      Converts this sparse vector to an equivalent tensor.
      Returns:
      A tensor equivalent to this vector.
    • div

      public CooVector div(Vector b)
      Computes the element-wise division of two vectors.
      Parameters:
      b - The second vector in the element-wise quotient (denominator).
      Returns:
      The element-wise quotient of this vector and b.
    • div

      public CooCVector div(CVector b)
      Computes the element-wise division of two vectors.
      Parameters:
      b - The second vector in the element-wise quotient (denominator).
      Returns:
      The element-wise quotient of this vector and b.
    • div

      public CooCVector div(Complex128 divisor)
      Divides each element of this sparse COO vector by a complex-valued scalar.
      Parameters:
      divisor - Scalar in the vector-scalar quotient.
      Returns:
      The vector-scalar quotient of this vector and divisor.
    • coalesce

      public CooVector coalesce()
      Coalesces this sparse COO vector. An uncoalesced vector is a sparse vector with multiple data for a single index. This method will ensure that each index only has one non-zero value by summing duplicated data. If another form of aggregation other than summing is desired, use coalesce(BinaryOperator).
      Returns:
      A new coalesced sparse COO vector which is equivalent to this COO vector.
      See Also:
    • coalesce

      public CooVector coalesce(BinaryOperator<Double> aggregator)
      Coalesces this sparse COO vector. An uncoalesced vector is a sparse vector with multiple data for a single index. This method will ensure that each index only has one non-zero value by aggregating duplicated data using aggregator.
      Parameters:
      aggregator - Custom aggregation function to combine multiple.
      Returns:
      A new coalesced sparse COO vector which is equivalent to this COO vector.
      See Also:
    • dropZeros

      public CooVector dropZeros()
      Drops any explicit zeros in this sparse COO vector.
      Returns:
      A copy of this COO vector with any explicitly stored zeros removed.
    • 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.