Class CooCTensor

All Implemented Interfaces:
Serializable, FieldTensorMixin<CooCTensor,CooCTensor,Complex128>, TensorOverField<CooCTensor,CooCTensor,Complex128[],Complex128>, RingTensorMixin<CooCTensor,CooCTensor,Complex128>, TensorOverRing<CooCTensor,CooCTensor,Complex128[],Complex128>, SemiringTensorMixin<CooCTensor,CooCTensor,Complex128>, TensorOverSemiring<CooCTensor,CooCTensor,Complex128[],Complex128>

public class CooCTensor extends AbstractCooFieldTensor<CooCTensor,CTensor,Complex128>

Sparse complex tensor stored in coordinate list (COO) format. The data of this COO tensor are of type Complex128

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

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

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

A sparse COO tensor is stored as:

See Also:
  • Constructor Details

    • CooCTensor

      public CooCTensor(Shape shape, Complex128[] entries, int[][] indices)
      Creates a tensor with the specified data and shape.
      Parameters:
      shape - Shape of this tensor.
      entries - Non-zero data of this tensor of this tensor.
      indices - Indices of the non-zero data of this tensor.
    • CooCTensor

      public CooCTensor(Shape shape, List<Complex128> entries, List<int[]> indices)
      Creates a tensor with the specified data and shape.
      Parameters:
      shape - Shape of this tensor.
      entries - Non-zero data of this tensor of this tensor.
      indices - Indices of the non-zero data of this tensor.
    • CooCTensor

      public CooCTensor(Shape shape, Complex64[] entries, int[][] indices)
      Creates a tensor with the specified data and shape.
      Parameters:
      shape - Shape of this tensor.
      entries - Non-zero data of this tensor of this tensor.
      indices - Indices of the non-zero data of this tensor.
    • CooCTensor

      public CooCTensor(Shape shape)
      Creates a tensor with the specified data and shape.
      Parameters:
      shape - Shape of this tensor.
      entries - Non-zero data of this tensor of this tensor.
      indices - Indices of the non-zero data of this tensor.
    • CooCTensor

      public CooCTensor(Shape shape, double[] entries, int[][] indices)
      Creates a tensor with the specified data and shape.
      Parameters:
      shape - Shape of this tensor.
      entries - Non-zero data of this tensor of this tensor.
      indices - Indices of the non-zero data of this tensor.
    • CooCTensor

      public CooCTensor(CooCTensor b)
      Constructs a copy of a sparse COO tensor.
      Parameters:
      b - Tensor to construct 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 CooCTensor 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<CooCTensor,CooCTensor,Complex128[],Complex128>
      Specified by:
      makeLikeTensor in class AbstractTensor<CooCTensor,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.
    • makeLikeTensor

      public CooCTensor makeLikeTensor(Shape shape, Complex128[] entries, int[][] indices)
      Constructs a tensor of the same type as this tensor with the specified shape and non-zero data.
      Specified by:
      makeLikeTensor in class AbstractCooSemiringTensor<CooCTensor,CTensor,Complex128>
      Parameters:
      shape - Shape of the tensor to construct.
      entries - Non-zero data of the tensor to construct.
      indices - Indices of the non-zero data of the tensor.
      Returns:
      A tensor of the same type as this tensor with the specified shape and non-zero data.
    • makeLikeTensor

      public CooCTensor makeLikeTensor(Shape shape, List<Complex128> entries, List<int[]> indices)
      Constructs a tensor of the same type as this tensor with the specified shape and non-zero data.
      Specified by:
      makeLikeTensor in class AbstractCooSemiringTensor<CooCTensor,CTensor,Complex128>
      Parameters:
      shape - Shape of the tensor to construct.
      entries - Non-zero data of the tensor to construct.
      indices - Indices of the non-zero data of the tensor.
      Returns:
      A tensor of the same type as this tensor with the specified shape and non-zero data.
    • makeLikeDenseTensor

      public CTensor makeLikeDenseTensor(Shape shape, Complex128[] entries)
      Constructs a dense tensor that is a similar type as this sparse COO tensor.
      Specified by:
      makeLikeDenseTensor in class AbstractCooSemiringTensor<CooCTensor,CTensor,Complex128>
      Parameters:
      shape - Shape of the tensor to construct.
      entries - The data of the dense tensor to construct.
      Returns:
      A dense tensor that is a similar type as this sparse COO tensor.
    • toReal

      public CooTensor 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 CooCTensor round(int precision)
      Rounds all data within this tensor 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 tensor containing the data of this tensor rounded to the specified precision.
    • roundToZero

      public CooCTensor roundToZero(double tolerance)
      Sets all elements of this tensor 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 tensor with all data within tol of zero set to zero.
    • toMatrix

      public CooCMatrix toMatrix(Shape newShape)
      Converts this tensor to a matrix with specified shape.
      Parameters:
      newShape - Shape of matrix to convert this tensor to. Shape must be broadcastable with this tensors shape and have rank 2.
      Returns:
      A matrix of the specified shape with the same non-zero data as this tensor.
    • set

      public CooCTensor set(double value, int... target)
      Sets the element of this tensor at the specified target index.
      Parameters:
      value - New value to set the specified index of this tensor to.
      target - Index of the element to set.
      Returns:
      If this tensor is dense, a reference to this tensor is returned. If this tensor is sparse, a copy of this tensor with the updated value is returned.
      Throws:
      IndexOutOfBoundsException - If target is not within the bounds of this tensor.
    • equals

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

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

      public String toString()

      Formats this sparse COO tensor as a human-readable string specifying the full shape, non-zero data, and non-zero indices.

      Overrides:
      toString in class Object
      Returns:
      A human-readable string specifying the full shape, non-zero data, and non-zero indices of this tensor.