Interface Vector<E>

All Superinterfaces:
AbelianGroup<Vector<E>>, AbelianMonoid<Vector<E>>, Group<Vector<E>>, Magma<Vector<E>>, Module<Vector<E>, E>, Monoid<Vector<E>>, Set<Vector<E>>
All Known Implementing Classes:
DenseVector, GenericVector, NativeRealDoubleVector, RealDoubleVector, RealFloatVector, SparseVector, Vector2D, Vector3D, Vector4D, VectorND

public interface Vector<E> extends Module<Vector<E>, E>
Represents a vector in a vector space.

A vector is an element of a vector space, which is a module over a field. This interface provides operations for vector addition, scalar multiplication, and dot product.

Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Method Details

    • of

      static <E> Vector<E> of(List<E> data, Ring<E> ring)
      Creates a vector from a list of elements.
    • of

      static <E> Vector<E> of(E[] data, Ring<E> ring)
      Creates a vector from an array of elements.
    • of

      @SafeVarargs static <E> Vector<E> of(Ring<E> ring, E... elements)
      Creates a vector from a variable number of elements.
    • zeros

      static <E> Vector<E> zeros(int dimension, Ring<E> ring)
      Creates a vector of zeros.
    • dimension

      int dimension()
      Returns the dimension of this vector.
      Returns:
      the number of elements in this vector
    • get

      E get(int index)
      Returns the element at the specified index.
      Parameters:
      index - the index of the element to return (0-based)
      Returns:
      the element at the specified index
      Throws:
      IndexOutOfBoundsException - if the index is out of range
    • getStorage

      VectorStorage<E> getStorage()
      Returns the underlying storage of this vector.
      Returns:
      the vector storage
    • getProvider

      default LinearAlgebraProvider<E> getProvider()
      Returns the provider that created or manages this vector.
      Returns:
      the linear algebra provider
    • map

      default Vector<E> map(Function<E,E> mapper)
      Applies a mapping function to each element of this vector.
      Parameters:
      mapper - the function to apply
      Returns:
      a new vector with mapped elements
    • add

      Vector<E> add(Vector<E> other)
      Returns the sum of this vector and another.
      Parameters:
      other - the vector to add
      Returns:
      this + other
      Throws:
      IllegalArgumentException - if dimensions do not match
    • subtract

      Vector<E> subtract(Vector<E> other)
      Returns the difference of this vector and another.
      Parameters:
      other - the vector to subtract
      Returns:
      this - other
      Throws:
      IllegalArgumentException - if dimensions do not match
    • multiply

      Vector<E> multiply(E scalar)
      Returns the scalar product of this vector.
      Parameters:
      scalar - the scalar multiplier
      Returns:
      this * scalar
    • negate

      Vector<E> negate()
      Returns the negation of this vector (-this).
      Returns:
      -this
    • dot

      E dot(Vector<E> other)
      Returns the dot product of this vector with another vector.
      Parameters:
      other - the other vector
      Returns:
      the dot product
      Throws:
      IllegalArgumentException - if the dimensions do not match
    • norm

      E norm()
      Returns the norm (length) of this vector.
      Returns:
      the norm of this vector
    • normalize

      default Vector<E> normalize()
      Returns the normalized vector (unit vector).
      Returns:
      this / norm()
      Throws:
      ArithmeticException - if norm is zero
    • cross

      default Vector<E> cross(Vector<E> other)
      Returns the cross product of this vector and another (only for 3D).
      Parameters:
      other - the other vector
      Returns:
      this x other
      Throws:
      ArithmeticException - if dimensions are not 3
    • angle

      default E angle(Vector<E> other)
      Returns the angle between this vector and another.
      Parameters:
      other - the other vector
      Returns:
      the angle in radians (or appropriate unit)
    • projection

      default Vector<E> projection(Vector<E> other)
      Returns the projection of this vector onto another.
      Parameters:
      other - the vector to project onto
      Returns:
      proj_other(this)
    • toMatrix

      default Matrix<E> toMatrix()
      Converts this vector to a column matrix (Nx1).
      Returns:
      the corresponding column matrix
      Throws:
      UnsupportedOperationException - if the scalar ring is not a Field
    • toTensor

      default Tensor<E> toTensor()
      Converts this vector to a rank-1 tensor.
      Returns:
      the corresponding tensor
      Throws:
      UnsupportedOperationException - if the vector is empty or scalars are not compatible