Class AbstractRealVector

java.lang.Object
com.apple.foundationdb.linear.AbstractRealVector
All Implemented Interfaces:
RealVector
Direct Known Subclasses:
DoubleRealVector, FloatRealVector, HalfRealVector

public abstract class AbstractRealVector extends Object implements RealVector
An abstract base class representing a mathematical vector.

This class provides a generic framework for vectors of different numerical types, where R is a subtype of Number. It includes common operations and functionalities like size, component access, equality checks, and conversions. Concrete implementations must provide specific logic for data type conversions and raw data representation.

  • Field Details

  • Constructor Details

    • AbstractRealVector

      protected AbstractRealVector(@Nonnull double[] data)
      Constructs a new RealVector with the given data.

      This constructor uses the provided array directly as the backing store for the vector. It does not create a defensive copy. Therefore, any subsequent modifications to the input array will be reflected in this vector's state. The contract of this constructor is that callers do not modify data after calling the constructor. We do not want to copy the array here for performance reasons.

      Parameters:
      data - the components of this vector
      Throws:
      NullPointerException - if the provided data array is null.
  • Method Details

    • getNumDimensions

      public int getNumDimensions()
      Returns the number of elements in the vector.
      Specified by:
      getNumDimensions in interface RealVector
      Returns:
      the number of elements
    • getComponent

      public double getComponent(int dimension)
      Gets the component of this object at the specified dimension.

      The dimension is a zero-based index. For a 3D vector, for example, dimension 0 might correspond to the x-component, 1 to the y-component, and 2 to the z-component. This method provides direct access to the underlying data element.

      Specified by:
      getComponent in interface RealVector
      Parameters:
      dimension - the zero-based index of the component to retrieve.
      Returns:
      the component at the specified dimension, which is guaranteed to be non-null.
      Throws:
      IndexOutOfBoundsException - if the dimension is negative or greater than or equal to the number of dimensions of this object.
    • getData

      @Nonnull public double[] getData()
      Returns the underlying data array.

      The returned array is guaranteed to be non-null. Note that this method returns a direct reference to the internal array, not a copy.

      Specified by:
      getData in interface RealVector
      Returns:
      the data array of type R[], never null.
    • getRawData

      @Nonnull public byte[] getRawData()
      Gets the raw byte data representation of this object.

      This method provides a direct, unprocessed view of the object's underlying data. The format of the byte array is implementation-specific and should be documented by the concrete class that implements this method.

      Specified by:
      getRawData in interface RealVector
      Returns:
      a non-null byte array containing the raw data.
    • computeRawData

      @Nonnull protected abstract byte[] computeRawData()
      Computes the raw byte data representation of this object.

      This method provides a direct, unprocessed view of the object's underlying data. The format of the byte array is implementation-specific and should be documented by the concrete class that implements this method.

      Returns:
      a non-null byte array containing the raw data.
    • equals

      public boolean equals(Object o)
      Compares this vector to the specified object for equality.

      The result is true if and only if the argument is not null and is a RealVector object that has the same data elements as this object. This method performs a deep equality check on the underlying data elements using Objects.deepEquals(Object, Object).

      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare with this RealVector for equality.
      Returns:
      true if the given object is a RealVector equivalent to this vector, false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The hash code is computed once and memoized.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for this object.
    • toString

      public String toString()
      Returns a string representation of the object.

      This method provides a default string representation by calling toString(int) with a predefined indentation level of 3.

      Overrides:
      toString in class Object
      Returns:
      a string representation of this object with a default indentation.
    • toString

      public String toString(int limitDimensions)
      Generates a string representation of the data array, with an option to limit the number of dimensions shown.

      If the specified limitDimensions is less than the actual number of dimensions in the data array, the resulting string will be a truncated view, ending with ", ..." to indicate that more elements exist. Otherwise, the method returns a complete string representation of the entire array.

      Parameters:
      limitDimensions - The maximum number of array elements to include in the string. A non-positive value will cause an VerifyException.
      Returns:
      A string representation of the data array, potentially truncated.
      Throws:
      com.google.common.base.VerifyException - if limitDimensions is not positive
    • fromInts

      @Nonnull protected static double[] fromInts(@Nonnull int[] ints)
    • fromLongs

      @Nonnull protected static double[] fromLongs(@Nonnull long[] longs)