Interface RealVector
- All Known Implementing Classes:
AbstractRealVector,DoubleRealVector,EncodedRealVector,FloatRealVector,HalfRealVector
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.
-
Method Summary
Modifier and TypeMethodDescriptiondefault RealVectoradd(double scalar) default RealVectoradd(RealVector other) default doubledot(RealVector other) doublegetComponent(int dimension) Gets the component of this object at the specified dimension.double[]getData()Returns the underlying data array.intReturns the number of elements in the vector, i.e.byte[]Gets the raw byte data representation of this object.default doublel2Norm()default RealVectormultiply(double scalarFactor) default RealVectordefault RealVectorsubtract(double scalar) default RealVectorsubtract(RealVector other) Converts this vector into aDoubleRealVector.Converts this object into aRealVectorof single precision floating-point numbers.Converts this object into aRealVectorofHalfprecision floating-point numbers.withData(double[] data)
-
Method Details
-
getNumDimensions
int getNumDimensions()Returns the number of elements in the vector, i.e. the number of dimensions.- Returns:
- the number of dimensions
-
getComponent
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.
- 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 thedimensionis negative or greater than or equal to the number of dimensions of this object.
-
getData
@Nonnull 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.
- Returns:
- the data array of type
R[], nevernull.
-
withData
-
getRawData
@Nonnull 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.
- Returns:
- a non-null byte array containing the raw data.
-
toHalfRealVector
Converts this object into aRealVectorofHalfprecision floating-point numbers.As this is an abstract method, implementing classes are responsible for defining the specific conversion logic from their internal representation to a
RealVectorusingHalfobjects to serialize and deserialize the vector. If this object already is aHalfRealVectorthis method should returnthis.- Returns:
- a non-null
HalfRealVectorcontaining theHalfprecision floating-point representation of this object.
-
toFloatRealVector
Converts this object into aRealVectorof single precision floating-point numbers.As this is an abstract method, implementing classes are responsible for defining the specific conversion logic from their internal representation to a
RealVectorusing floating point numbers to serialize and deserialize the vector. If this object already is aFloatRealVectorthis method should returnthis.- Returns:
- a non-null
FloatRealVectorcontaining the single precision floating-point representation of this object.
-
toDoubleRealVector
Converts this vector into aDoubleRealVector.This method provides a way to obtain a double-precision floating-point representation of the vector. If the vector is already an instance of
DoubleRealVector, this method may return the instance itself. Otherwise, it will create a newDoubleRealVectorcontaining the same elements, which may involve a conversion of the underlying data type.- Returns:
- a non-null
DoubleRealVectorrepresentation of this vector.
-
dot
-
l2Norm
default double l2Norm() -
normalize
-
add
-
add
-
subtract
-
subtract
-
multiply
-