Record Class SparseDoubleVector

java.lang.Object
java.lang.Record
io.micronaut.data.model.vector.SparseDoubleVector
Record Components:
length - The dense vector length.
indices - Sorted non-zero positions.
values - Non-zero values aligned with indices.
All Implemented Interfaces:
SparseVector, Vector

@TypeDef(type=OBJECT, converter=SparseDoubleVectorAttributeConverter.class) public record SparseDoubleVector(int length, int[] indices, double[] values) extends Record implements SparseVector
Sparse DoubleVector representation.
Since:
5.0.0
  • Constructor Details

    • SparseDoubleVector

      public SparseDoubleVector(int length, int[] indices, double[] values)
      Creates a sparse double vector.
      Parameters:
      length - dense vector length
      indices - sorted non-zero indices
      values - non-zero values aligned with indices
  • Method Details

    • fromDense

      public static SparseDoubleVector fromDense(double[] denseValues)
      Creates a sparse vector from dense double values.
      Parameters:
      denseValues - dense values
      Returns:
      sparse vector representation
    • fromDense

      public static SparseDoubleVector fromDense(DoubleVector denseVector)
      Creates a sparse vector from a dense DoubleVector.
      Parameters:
      denseVector - dense vector
      Returns:
      sparse vector representation
    • indices

      public int[] indices()
      Specified by:
      indices in interface SparseVector
      Returns:
      sorted non-zero indices
    • values

      public double[] values()
      Returns the value of the values record component.
      Returns:
      the value of the values record component
    • getType

      public @NonNull Class<? extends Number> getType()
      Return the primitive number type the vector is backed by.
      Specified by:
      getType in interface Vector
      Returns:
      the primitive number type (Byte.TYPE, Float.TYPE or Double.TYPE)
    • toFloatArray

      public float[] toFloatArray()
      Convert this vector to a new float array copy.
      Specified by:
      toFloatArray in interface Vector
      Returns:
      a new float[] with the vector content
    • toDoubleArray

      public double[] toDoubleArray()
      Convert this vector to a new double array copy.
      Specified by:
      toDoubleArray in interface Vector
      Returns:
      a new double[] with the vector content
    • toByteArray

      public byte[] toByteArray()
      Convert this vector to a new byte array copy.
      Specified by:
      toByteArray in interface Vector
      Returns:
      a new byte[] with the vector content
    • toDenseVector

      public DoubleVector toDenseVector()
      Converts this sparse vector into dense DoubleVector form.
      Returns:
      dense double vector
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public boolean equals(Object obj)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      obj - the object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • length

      public int length()
      Returns the value of the length record component.
      Specified by:
      length in interface SparseVector
      Returns:
      the value of the length record component