Interface FieldVector<T extends FieldElement<T>>
- Type Parameters:
T
- the type of the field elements
- All Known Implementing Classes:
ArrayFieldVector
,SparseFieldVector
vector element indexing is 0-based -- e.g., getEntry(0)
returns the first element of the vector.
The various mapXxx
and mapXxxToSelf
methods operate
on vectors element-wise, i.e. they perform the same operation (adding a scalar,
applying a function ...) on each element in turn. The mapXxx
versions create a new vector to hold the result and do not change the instance.
The mapXxxToSelf
versions 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 FieldElement
throw NullArgumentException
when operating on a null element, it is the responsibility
of FieldVector
implementations to make sure no null elements
are inserted into the vector. This must be done in all constructors and
all setters.
-
Method Summary
Modifier and TypeMethodDescriptionadd
(FieldVector<T> v) Compute the sum ofthis
andv
.append
(FieldVector<T> v) Construct a vector by appending a vector to this vector.Construct a vector by appending a T to this vector.copy()
Returns a (deep) copy of this.dotProduct
(FieldVector<T> v) Compute the dot product.ebeDivide
(FieldVector<T> v) Element-by-element division.ebeMultiply
(FieldVector<T> v) Element-by-element multiplication.int
Returns the size of the vector.getEntry
(int index) Returns the entry in the specified index.getField()
Get the type of field elements of the vector.getSubVector
(int index, int n) Get a subvector from consecutive elements.Map an addition operation to each entry.mapAddToSelf
(T d) Map an addition operation to each entry.Map a division operation to each entry.mapDivideToSelf
(T d) Map a division operation to each entry.mapInv()
Map the 1/x function to each entry.Map the 1/x function to each entry.mapMultiply
(T d) Map a multiplication operation to each entry.Map a multiplication operation to each entry.mapSubtract
(T d) Map a subtraction operation to each entry.Map a subtraction operation to each entry.outerProduct
(FieldVector<T> v) Compute the outer product.projection
(FieldVector<T> v) Find the orthogonal projection of this vector onto another vector.void
Set all elements to a single value.void
Set a single element.void
setSubVector
(int index, FieldVector<T> v) Set a set of consecutive elements.subtract
(FieldVector<T> v) Computethis
minusv
.T[]
toArray()
Convert the vector to a T array.
-
Method Details
-
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
Compute the sum ofthis
andv
.- Parameters:
v
- vector to be added- Returns:
this + v
- Throws:
MathIllegalArgumentException
- ifv
is not the same size asthis
-
subtract
Computethis
minusv
.- Parameters:
v
- vector to be subtracted- Returns:
this - v
- Throws:
MathIllegalArgumentException
- ifv
is not the same size asthis
-
mapAdd
Map an addition operation to each entry.- Parameters:
d
- value to be added to each entry- Returns:
this + d
- Throws:
NullArgumentException
- ifd
isnull
.
-
mapAddToSelf
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
- ifd
isnull
.
-
mapSubtract
Map a subtraction operation to each entry.- Parameters:
d
- value to be subtracted to each entry- Returns:
this - d
- Throws:
NullArgumentException
- ifd
isnull
-
mapSubtractToSelf
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
- ifd
isnull
-
mapMultiply
Map a multiplication operation to each entry.- Parameters:
d
- value to multiply all entries by- Returns:
this * d
- Throws:
NullArgumentException
- ifd
isnull
.
-
mapMultiplyToSelf
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
- ifd
isnull
.
-
mapDivide
Map a division operation to each entry.- Parameters:
d
- value to divide all entries by- Returns:
this / d
- Throws:
NullArgumentException
- ifd
isnull
.MathRuntimeException
- ifd
is zero.
-
mapDivideToSelf
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
- ifd
isnull
.MathRuntimeException
- ifd
is zero.
-
mapInv
Map the 1/x function to each entry.- Returns:
- a vector containing the result of applying the function to each entry.
- Throws:
MathRuntimeException
- if one of the entries is zero.
-
mapInvToSelf
Map the 1/x function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return
this
- Throws:
MathRuntimeException
- if one of the entries is zero.
-
ebeMultiply
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:
MathIllegalArgumentException
- ifv
is not the same size asthis
-
ebeDivide
FieldVector<T> ebeDivide(FieldVector<T> v) throws MathIllegalArgumentException, MathRuntimeException 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:
MathIllegalArgumentException
- ifv
is not the same size asthis
MathRuntimeException
- if one entry ofv
is zero.
-
dotProduct
Compute the dot product.- Parameters:
v
- vector with which dot product should be computed- Returns:
- the scalar dot product of
this
andv
- Throws:
MathIllegalArgumentException
- ifv
is not the same size asthis
-
projection
FieldVector<T> projection(FieldVector<T> v) throws MathIllegalArgumentException, MathRuntimeException Find the orthogonal projection of this vector onto another vector.- Parameters:
v
- vector onto whichthis
must be projected- Returns:
- projection of
this
ontov
- Throws:
MathIllegalArgumentException
- ifv
is not the same size asthis
MathRuntimeException
- ifv
is the null vector.
-
outerProduct
Compute the outer product.- Parameters:
v
- vector with which outer product should be computed- Returns:
- the matrix outer product between instance and v
-
getEntry
Returns the entry in the specified index.- Parameters:
index
- Index location of entry to be fetched.- Returns:
- the vector entry at
index
. - Throws:
MathIllegalArgumentException
- if the index is not valid.- See Also:
-
setEntry
Set a single element.- Parameters:
index
- element index.value
- new value for the element.- Throws:
MathIllegalArgumentException
- if the index is not valid.- See Also:
-
getDimension
int getDimension()Returns the size of the vector.- Returns:
- size
-
append
Construct a vector by appending a vector to this vector.- Parameters:
v
- vector to append to this one.- Returns:
- a new vector
-
append
Construct a vector by appending a T to this vector.- Parameters:
d
- T to append.- Returns:
- a new vector
-
getSubVector
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:
MathIllegalArgumentException
- if the index is not valid.MathIllegalArgumentException
- if the number of elements if not positive.
-
setSubVector
Set a set of consecutive elements.- Parameters:
index
- index of first element to be set.v
- vector containing the values to set.- Throws:
MathIllegalArgumentException
- if the index is not valid.
-
set
Set all elements to a single value.- Parameters:
value
- single value to set for all elements
-
toArray
T[] toArray()Convert the vector to a T array.The array is independent from vector data, it's elements are copied.
- Returns:
- array containing a copy of vector elements
-