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
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 Summary
Modifier and TypeMethodDescriptionReturns the sum of this vector and another.default EReturns the angle between this vector and another.Returns the cross product of this vector and another (only for 3D).intReturns the dimension of this vector.Returns the dot product of this vector with another vector.get(int index) Returns the element at the specified index.default LinearAlgebraProvider<E> Returns the provider that created or manages this vector.Returns the underlying storage of this vector.Applies a mapping function to each element of this vector.Returns the scalar product of this vector.negate()Returns the negation of this vector (-this).norm()Returns the norm (length) of this vector.Returns the normalized vector (unit vector).static <E> Vector<E> Creates a vector from an array of elements.static <E> Vector<E> Creates a vector from a list of elements.static <E> Vector<E> Creates a vector from a variable number of elements.projection(Vector<E> other) Returns the projection of this vector onto another.Returns the difference of this vector and another.toMatrix()Converts this vector to a column matrix (Nx1).toTensor()Converts this vector to a rank-1 tensor.static <E> Vector<E> Creates a vector of zeros.Methods inherited from interface AbelianGroup
isCommutative, negate, subtractMethods inherited from interface AbelianMonoid
add, identity, zeroMethods inherited from interface Module
getScalarRing, scale, scaleMethods inherited from interface Monoid
isAssociativeMethods inherited from interface Set
contains, description, isEmpty
-
Method Details
-
of
-
of
-
of
Creates a vector from a variable number of elements. -
zeros
-
dimension
int dimension()Returns the dimension of this vector.- Returns:
- the number of elements in this vector
-
get
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
Returns the provider that created or manages this vector.- Returns:
- the linear algebra provider
-
map
-
add
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
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
-
negate
-
dot
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
-
normalize
Returns the normalized vector (unit vector).- Returns:
- this / norm()
- Throws:
ArithmeticException- if norm is zero
-
cross
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
-
projection
-
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
Converts this vector to a rank-1 tensor.- Returns:
- the corresponding tensor
- Throws:
UnsupportedOperationException- if the vector is empty or scalars are not compatible
-