Interface FieldVector<T extends FieldElement<T>>
-
- Type Parameters:
T- the type of the field elements
- All Known Implementing Classes:
ArrayFieldVector,SparseFieldVector
public interface FieldVector<T extends FieldElement<T>>
Interface defining a field-valued vector with basic algebraic operations.vector element indexing is 0-based -- e.g.,
getEntry(0)returns the first element of the vector.The various
mapXxxandmapXxxToSelfmethods operate on vectors element-wise, i.e. they perform the same operation (adding a scalar, applying a function ...) on each element in turn. ThemapXxxversions create a new vector to hold the result and do not change the instance. ThemapXxxToSelfversions use the instance itself to store the results, so the instance is changed by these methods. In both cases, the result vector is returned by the methods, this allows to use the fluent API style, like this:RealVector result = v.mapAddToSelf(3.0).mapTanToSelf().mapSquareToSelf();
Note that as almost all operations on
FieldElementthrowNullArgumentExceptionwhen operating on a null element, it is the responsibility ofFieldVectorimplementations to make sure no null elements are inserted into the vector. This must be done in all constructors and all setters.- Since:
- 2.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description FieldVector<T>add(FieldVector<T> v)Compute the sum ofthisandv.FieldVector<T>append(FieldVector<T> v)Construct a vector by appending a vector to this vector.FieldVector<T>append(T d)Construct a vector by appending a T to this vector.FieldVector<T>copy()Returns a (deep) copy of this.TdotProduct(FieldVector<T> v)Compute the dot product.FieldVector<T>ebeDivide(FieldVector<T> v)Element-by-element division.FieldVector<T>ebeMultiply(FieldVector<T> v)Element-by-element multiplication.intgetDimension()Returns the size of the vector.TgetEntry(int index)Returns the entry in the specified index.Field<T>getField()Get the type of field elements of the vector.FieldVector<T>getSubVector(int index, int n)Get a subvector from consecutive elements.FieldVector<T>mapAdd(T d)Map an addition operation to each entry.FieldVector<T>mapAddToSelf(T d)Map an addition operation to each entry.FieldVector<T>mapDivide(T d)Map a division operation to each entry.FieldVector<T>mapDivideToSelf(T d)Map a division operation to each entry.FieldVector<T>mapInv()Map the 1/x function to each entry.FieldVector<T>mapInvToSelf()Map the 1/x function to each entry.FieldVector<T>mapMultiply(T d)Map a multiplication operation to each entry.FieldVector<T>mapMultiplyToSelf(T d)Map a multiplication operation to each entry.FieldVector<T>mapSubtract(T d)Map a subtraction operation to each entry.FieldVector<T>mapSubtractToSelf(T d)Map a subtraction operation to each entry.FieldMatrix<T>outerProduct(FieldVector<T> v)Compute the outer product.FieldVector<T>projection(FieldVector<T> v)Find the orthogonal projection of this vector onto another vector.voidset(T value)Set all elements to a single value.voidsetEntry(int index, T value)Set a single element.voidsetSubVector(int index, FieldVector<T> v)Set a set of consecutive elements.FieldVector<T>subtract(FieldVector<T> v)Computethisminusv.T[]toArray()Convert the vector to a T array.
-
-
-
Method Detail
-
getField
Field<T> getField()
Get the type of field elements of the vector.- Returns:
- type of field elements of the vector
-
copy
FieldVector<T> copy()
Returns a (deep) copy of this.- Returns:
- vector copy
-
add
FieldVector<T> add(FieldVector<T> v) throws DimensionMismatchException
Compute the sum ofthisandv.- Parameters:
v- vector to be added- Returns:
this + v- Throws:
DimensionMismatchException- ifvis not the same size asthis
-
subtract
FieldVector<T> subtract(FieldVector<T> v) throws DimensionMismatchException
Computethisminusv.- Parameters:
v- vector to be subtracted- Returns:
this - v- Throws:
DimensionMismatchException- ifvis not the same size asthis
-
mapAdd
FieldVector<T> mapAdd(T d) throws NullArgumentException
Map an addition operation to each entry.- Parameters:
d- value to be added to each entry- Returns:
this + d- Throws:
NullArgumentException- ifdisnull.
-
mapAddToSelf
FieldVector<T> mapAddToSelf(T d) throws NullArgumentException
Map an addition operation to each entry.The instance is changed by this method.
- Parameters:
d- value to be added to each entry- Returns:
- for convenience, return
this - Throws:
NullArgumentException- ifdisnull.
-
mapSubtract
FieldVector<T> mapSubtract(T d) throws NullArgumentException
Map a subtraction operation to each entry.- Parameters:
d- value to be subtracted to each entry- Returns:
this - d- Throws:
NullArgumentException- ifdisnull
-
mapSubtractToSelf
FieldVector<T> mapSubtractToSelf(T d) throws NullArgumentException
Map a subtraction operation to each entry.The instance is changed by this method.
- Parameters:
d- value to be subtracted to each entry- Returns:
- for convenience, return
this - Throws:
NullArgumentException- ifdisnull
-
mapMultiply
FieldVector<T> mapMultiply(T d) throws NullArgumentException
Map a multiplication operation to each entry.- Parameters:
d- value to multiply all entries by- Returns:
this * d- Throws:
NullArgumentException- ifdisnull.
-
mapMultiplyToSelf
FieldVector<T> mapMultiplyToSelf(T d) throws NullArgumentException
Map a multiplication operation to each entry.The instance is changed by this method.
- Parameters:
d- value to multiply all entries by- Returns:
- for convenience, return
this - Throws:
NullArgumentException- ifdisnull.
-
mapDivide
FieldVector<T> mapDivide(T d) throws NullArgumentException, MathArithmeticException
Map a division operation to each entry.- Parameters:
d- value to divide all entries by- Returns:
this / d- Throws:
NullArgumentException- ifdisnull.MathArithmeticException- ifdis zero.
-
mapDivideToSelf
FieldVector<T> mapDivideToSelf(T d) throws NullArgumentException, MathArithmeticException
Map a division operation to each entry.The instance is changed by this method.
- Parameters:
d- value to divide all entries by- Returns:
- for convenience, return
this - Throws:
NullArgumentException- ifdisnull.MathArithmeticException- ifdis zero.
-
mapInv
FieldVector<T> mapInv() throws MathArithmeticException
Map the 1/x function to each entry.- Returns:
- a vector containing the result of applying the function to each entry.
- Throws:
MathArithmeticException- if one of the entries is zero.
-
mapInvToSelf
FieldVector<T> mapInvToSelf() throws MathArithmeticException
Map the 1/x function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return
this - Throws:
MathArithmeticException- if one of the entries is zero.
-
ebeMultiply
FieldVector<T> ebeMultiply(FieldVector<T> v) throws DimensionMismatchException
Element-by-element multiplication.- Parameters:
v- vector by which instance elements must be multiplied- Returns:
- a vector containing
this[i] * v[i]for alli - Throws:
DimensionMismatchException- ifvis not the same size asthis
-
ebeDivide
FieldVector<T> ebeDivide(FieldVector<T> v) throws DimensionMismatchException, MathArithmeticException
Element-by-element division.- Parameters:
v- vector by which instance elements must be divided- Returns:
- a vector containing
this[i] / v[i]for alli - Throws:
DimensionMismatchException- ifvis not the same size asthisMathArithmeticException- if one entry ofvis zero.
-
dotProduct
T dotProduct(FieldVector<T> v) throws DimensionMismatchException
Compute the dot product.- Parameters:
v- vector with which dot product should be computed- Returns:
- the scalar dot product of
thisandv - Throws:
DimensionMismatchException- ifvis not the same size asthis
-
projection
FieldVector<T> projection(FieldVector<T> v) throws DimensionMismatchException, MathArithmeticException
Find the orthogonal projection of this vector onto another vector.- Parameters:
v- vector onto whichthismust be projected- Returns:
- projection of
thisontov - Throws:
DimensionMismatchException- ifvis not the same size asthisMathArithmeticException- ifvis the null vector.
-
outerProduct
FieldMatrix<T> outerProduct(FieldVector<T> v)
Compute the outer product.- Parameters:
v- vector with which outer product should be computed- Returns:
- the matrix outer product between instance and v
-
getEntry
T getEntry(int index) throws OutOfRangeException
Returns the entry in the specified index.- Parameters:
index- Index location of entry to be fetched.- Returns:
- the vector entry at
index. - Throws:
OutOfRangeException- if the index is not valid.- See Also:
setEntry(int, FieldElement)
-
setEntry
void setEntry(int index, T value) throws OutOfRangeException
Set a single element.- Parameters:
index- element index.value- new value for the element.- Throws:
OutOfRangeException- if the index is not valid.- See Also:
getEntry(int)
-
getDimension
int getDimension()
Returns the size of the vector.- Returns:
- size
-
append
FieldVector<T> append(FieldVector<T> v)
Construct a vector by appending a vector to this vector.- Parameters:
v- vector to append to this one.- Returns:
- a new vector
-
append
FieldVector<T> append(T d)
Construct a vector by appending a T to this vector.- Parameters:
d- T to append.- Returns:
- a new vector
-
getSubVector
FieldVector<T> getSubVector(int index, int n) throws OutOfRangeException, NotPositiveException
Get a subvector from consecutive elements.- Parameters:
index- index of first element.n- number of elements to be retrieved.- Returns:
- a vector containing n elements.
- Throws:
OutOfRangeException- if the index is not valid.NotPositiveException- if the number of elements if not positive.
-
setSubVector
void setSubVector(int index, FieldVector<T> v) throws OutOfRangeException
Set a set of consecutive elements.- Parameters:
index- index of first element to be set.v- vector containing the values to set.- Throws:
OutOfRangeException- if the index is not valid.
-
set
void set(T value)
Set all elements to a single value.- Parameters:
value- single value to set for all elements
-
-