Class ArrayFieldVector<T extends FieldElement<T>>
- Type Parameters:
T
- the type of the field elements
- All Implemented Interfaces:
Serializable
,FieldVector<T>
FieldVector
interface with a FieldElement
array.- Since:
- 2.0
- See Also:
-
Constructor Summary
ConstructorDescriptionArrayFieldVector
(int size, T preset) Construct an (size)-length vector with preset values.ArrayFieldVector
(Field<T> field) Build a 0-length vector.ArrayFieldVector
(Field<T> field, int size) Construct a (size)-length vector of zeros.ArrayFieldVector
(Field<T> field, T[] d) Construct a vector from an array, copying the input array.ArrayFieldVector
(Field<T> field, T[] d, boolean copyArray) Create a new ArrayFieldVector using the input array as the underlying data array.ArrayFieldVector
(Field<T> field, T[] v1, T[] v2) Construct a vector by appending one vector to another vector.Construct a vector from another vector, using a deep copy.ArrayFieldVector
(ArrayFieldVector<T> v, boolean deep) Construct a vector from another vector.ArrayFieldVector
(ArrayFieldVector<T> v1, ArrayFieldVector<T> v2) Construct a vector by appending one vector to another vector.ArrayFieldVector
(ArrayFieldVector<T> v1, T[] v2) Construct a vector by appending one vector to another vector.Construct a vector from another vector, using a deep copy.ArrayFieldVector
(T[] d) Construct a vector from an array, copying the input array.ArrayFieldVector
(T[] d, boolean copyArray) Create a new ArrayFieldVector using the input array as the underlying data array.ArrayFieldVector
(T[] d, int pos, int size) Construct a vector from part of a array.ArrayFieldVector
(T[] v1, ArrayFieldVector<T> v2) Construct a vector by appending one vector to another vector.ArrayFieldVector
(T[] v1, T[] v2) Construct a vector by appending one vector to another vector. -
Method Summary
Modifier and TypeMethodDescriptionadd
(ArrayFieldVector<T> v) Compute the sum of this and v.add
(FieldVector<T> v) Compute the sum of this and v.Compute the sum of this and v.append
(ArrayFieldVector<T> v) Construct a vector by appending a vector to this vector.append
(FieldVector<T> v) Construct a vector by appending a vector to this vector.Construct a vector by appending a T to this vector.Construct a vector by appending a T array to this vector.copy()
Returns a (deep) copy of this.Compute the dot product.dotProduct
(FieldVector<T> v) Compute the dot product.dotProduct
(T[] v) Compute the dot product.Element-by-element division.ebeDivide
(FieldVector<T> v) Element-by-element division.Element-by-element division.Element-by-element multiplication.ebeMultiply
(FieldVector<T> v) Element-by-element multiplication.ebeMultiply
(T[] v) Element-by-element multiplication.boolean
Test for the equality of two real vectors.T[]
getData()
Returns vector entries as a T array.T[]
Returns a reference to the underlying data array.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.int
hashCode()
Get a hashCode for the real vector.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.Compute the outer product.outerProduct
(FieldVector<T> v) Compute the outer product.outerProduct
(T[] v) Compute the outer product.Find the orthogonal projection of this vector onto another vector.projection
(FieldVector<T> v) Find the orthogonal projection of this vector onto another vector.projection
(T[] v) Find the orthogonal projection of this vector onto another vector.void
set
(int index, ArrayFieldVector<T> v) Set a set of consecutive elements.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.void
setSubVector
(int index, T[] v) Set a set of consecutive elements.Compute this minus v.subtract
(FieldVector<T> v) Compute this minus v.Compute this minus v.T[]
toArray()
Convert the vector to a T array.
-
Constructor Details
-
ArrayFieldVector
Build a 0-length vector.Zero-length vectors may be used to initialized construction of vectors by data gathering. We start with zero-length and use either the
ArrayFieldVector(ArrayFieldVector, ArrayFieldVector)
constructor or one of theappend
methods (append(FieldElement[])
,add(FieldVector)
,append(ArrayFieldVector)
) to gather data into this vector.- Parameters:
field
- field to which the elements belong
-
ArrayFieldVector
Construct a (size)-length vector of zeros.- Parameters:
field
- field to which the elements belongsize
- size of the vector
-
ArrayFieldVector
Construct an (size)-length vector with preset values.- Parameters:
size
- size of the vectorpreset
- fill the vector with this scalar value
-
ArrayFieldVector
Construct a vector from an array, copying the input array.This constructor needs a non-empty
d
array to retrieve the field from its first element. This implies it cannot build 0 length vectors. To build vectors from any size, one should use theArrayFieldVector(Field, FieldElement[])
constructor.- Parameters:
d
- array of Ts.- Throws:
IllegalArgumentException
- ifd
is empty- See Also:
-
ArrayFieldVector
Construct a vector from an array, copying the input array.- Parameters:
field
- field to which the elements belongd
- array of Ts.- See Also:
-
ArrayFieldVector
public ArrayFieldVector(T[] d, boolean copyArray) throws NullPointerException, IllegalArgumentException Create a new ArrayFieldVector using the input array as the underlying data array.If an array is built specially in order to be embedded in a ArrayFieldVector and not used directly, the
copyArray
may be set tofalseinvalid input: '<'/code. This will prevent the copying and improve performance as no new array will be built and no data will be copied.
This constructor needs a non-empty
d
array to retrieve the field from its first element. This implies it cannot build 0 length vectors. To build vectors from any size, one should use theArrayFieldVector(Field, FieldElement[], boolean)
constructor.- Parameters:
d
- data for new vectorcopyArray
- if true, the input array will be copied, otherwise it will be referenced- Throws:
IllegalArgumentException
- ifd
is emptyNullPointerException
- ifd
is null- See Also:
-
ArrayFieldVector
Create a new ArrayFieldVector using the input array as the underlying data array.If an array is built specially in order to be embedded in a ArrayFieldVector and not used directly, the
copyArray
may be set tofalseinvalid input: '<'/code. This will prevent the copying and improve performance as no new array will be built and no data will be copied.
- Parameters:
field
- field to which the elements belongd
- data for new vectorcopyArray
- if true, the input array will be copied, otherwise it will be referenced- See Also:
-
ArrayFieldVector
Construct a vector from part of a array.- Parameters:
d
- array of Ts.pos
- position of first entrysize
- number of entries to copy
-
ArrayFieldVector
Construct a vector from another vector, using a deep copy.- Parameters:
v
- vector to copy
-
ArrayFieldVector
Construct a vector from another vector, using a deep copy.- Parameters:
v
- vector to copy
-
ArrayFieldVector
Construct a vector from another vector.- Parameters:
v
- vector to copydeep
- if true perform a deep copy otherwise perform a shallow copy
-
ArrayFieldVector
Construct a vector by appending one vector to another vector.- Parameters:
v1
- first vector (will be put in front of the new vector)v2
- second vector (will be put at back of the new vector)
-
ArrayFieldVector
Construct a vector by appending one vector to another vector.- Parameters:
v1
- first vector (will be put in front of the new vector)v2
- second vector (will be put at back of the new vector)
-
ArrayFieldVector
Construct a vector by appending one vector to another vector.- Parameters:
v1
- first vector (will be put in front of the new vector)v2
- second vector (will be put at back of the new vector)
-
ArrayFieldVector
Construct a vector by appending one vector to another vector.This constructor needs at least one non-empty array to retrieve the field from its first element. This implies it cannot build 0 length vectors. To build vectors from any size, one should use the
ArrayFieldVector(Field, FieldElement[], FieldElement[])
constructor.- Parameters:
v1
- first vector (will be put in front of the new vector)v2
- second vector (will be put at back of the new vector)- Throws:
IllegalArgumentException
- if both vectors are empty- See Also:
-
ArrayFieldVector
Construct a vector by appending one vector to another vector.- Parameters:
field
- field to which the elements belongv1
- first vector (will be put in front of the new vector)v2
- second vector (will be put at back of the new vector)- See Also:
-
-
Method Details
-
getField
Get the type of field elements of the vector.- Specified by:
getField
in interfaceFieldVector<T extends FieldElement<T>>
- Returns:
- type of field elements of the vector
-
copy
Returns a (deep) copy of this.- Specified by:
copy
in interfaceFieldVector<T extends FieldElement<T>>
- Returns:
- vector copy
-
add
Compute the sum of this and v.- Specified by:
add
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector to be added- Returns:
- this + v
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
add
Compute the sum of this and v.- Specified by:
add
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector to be added- Returns:
- this + v
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
add
Compute the sum of this and v.- Parameters:
v
- vector to be added- Returns:
- this + v
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
subtract
Compute this minus v.- Specified by:
subtract
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector to be subtracted- Returns:
- this + v
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
subtract
Compute this minus v.- Specified by:
subtract
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector to be subtracted- Returns:
- this + v
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
subtract
Compute this minus v.- Parameters:
v
- vector to be subtracted- Returns:
- this + v
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
mapAdd
Map an addition operation to each entry.- Specified by:
mapAdd
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
d
- value to be added to each entry- Returns:
- this + d
-
mapAddToSelf
Map an addition operation to each entry.The instance is changed by this method.
- Specified by:
mapAddToSelf
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
d
- value to be added to each entry- Returns:
- for convenience, return this
-
mapSubtract
Map a subtraction operation to each entry.- Specified by:
mapSubtract
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
d
- value to be subtracted to each entry- Returns:
- this - d
-
mapSubtractToSelf
Map a subtraction operation to each entry.The instance is changed by this method.
- Specified by:
mapSubtractToSelf
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
d
- value to be subtracted to each entry- Returns:
- for convenience, return this
-
mapMultiply
Map a multiplication operation to each entry.- Specified by:
mapMultiply
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
d
- value to multiply all entries by- Returns:
- this * d
-
mapMultiplyToSelf
Map a multiplication operation to each entry.The instance is changed by this method.
- Specified by:
mapMultiplyToSelf
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
d
- value to multiply all entries by- Returns:
- for convenience, return this
-
mapDivide
Map a division operation to each entry.- Specified by:
mapDivide
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
d
- value to divide all entries by- Returns:
- this / d
-
mapDivideToSelf
Map a division operation to each entry.The instance is changed by this method.
- Specified by:
mapDivideToSelf
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
d
- value to divide all entries by- Returns:
- for convenience, return this
-
mapInv
Map the 1/x function to each entry.- Specified by:
mapInv
in interfaceFieldVector<T extends FieldElement<T>>
- Returns:
- a vector containing the result of applying the function to each entry
-
mapInvToSelf
Map the 1/x function to each entry.The instance is changed by this method.
- Specified by:
mapInvToSelf
in interfaceFieldVector<T extends FieldElement<T>>
- Returns:
- for convenience, return this
-
ebeMultiply
Element-by-element multiplication.- Specified by:
ebeMultiply
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector by which instance elements must be multiplied- Returns:
- a vector containing this[i] * v[i] for all i
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
ebeMultiply
Element-by-element multiplication.- Specified by:
ebeMultiply
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector by which instance elements must be multiplied- Returns:
- a vector containing this[i] * v[i] for all i
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
ebeMultiply
Element-by-element multiplication.- Parameters:
v
- vector by which instance elements must be multiplied- Returns:
- a vector containing this[i] * v[i] for all i
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
ebeDivide
Element-by-element division.- Specified by:
ebeDivide
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector by which instance elements must be divided- Returns:
- a vector containing this[i] / v[i] for all i
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
ebeDivide
Element-by-element division.- Specified by:
ebeDivide
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector by which instance elements must be divided- Returns:
- a vector containing this[i] / v[i] for all i
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
ebeDivide
Element-by-element division.- Parameters:
v
- vector by which instance elements must be divided- Returns:
- a vector containing this[i] / v[i] for all i
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
getData
Returns vector entries as a T array.- Specified by:
getData
in interfaceFieldVector<T extends FieldElement<T>>
- Returns:
- T array of entries
-
getDataRef
Returns a reference to the underlying data array.Does not make a fresh copy of the underlying data.
- Returns:
- array of entries
-
dotProduct
Compute the dot product.- Specified by:
dotProduct
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
dotProduct
Compute the dot product.- Specified by:
dotProduct
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
dotProduct
Compute the dot product.- Parameters:
v
- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
projection
Find the orthogonal projection of this vector onto another vector.- Specified by:
projection
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector onto which instance must be projected- Returns:
- projection of the instance onto v
-
projection
Find the orthogonal projection of this vector onto another vector.- Specified by:
projection
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector onto which instance must be projected- Returns:
- projection of the instance onto v
-
projection
Find the orthogonal projection of this vector onto another vector.- Parameters:
v
- vector onto which instance must be projected- Returns:
- projection of the instance onto v
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
outerProduct
Compute the outer product.- Specified by:
outerProduct
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector with which outer product should be computed- Returns:
- the square matrix outer product between instance and v
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
outerProduct
Compute the outer product.- Parameters:
v
- vector with which outer product should be computed- Returns:
- the square matrix outer product between instance and v
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
outerProduct
Compute the outer product.- Specified by:
outerProduct
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector with which outer product should be computed- Returns:
- the square matrix outer product between instance and v
- Throws:
IllegalArgumentException
- if v is not the same size as this
-
getEntry
Returns the entry in the specified index.The index start at 0 and must be lesser than the size, otherwise a
MatrixIndexException
is thrown.- Specified by:
getEntry
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
index
- index location of entry to be fetched- Returns:
- vector entry at index
- Throws:
MatrixIndexException
- if the index is not valid- See Also:
-
getDimension
public int getDimension()Returns the size of the vector.- Specified by:
getDimension
in interfaceFieldVector<T extends FieldElement<T>>
- Returns:
- size
-
append
Construct a vector by appending a vector to this vector.- Specified by:
append
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
v
- vector to append to this one.- Returns:
- a new vector
-
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.- Specified by:
append
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
in
- T to append.- Returns:
- a new vector
-
append
Construct a vector by appending a T array to this vector.- Specified by:
append
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
in
- T array to append.- Returns:
- a new vector
-
getSubVector
Get a subvector from consecutive elements.- Specified by:
getSubVector
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
index
- index of first element.n
- number of elements to be retrieved.- Returns:
- a vector containing n elements.
-
setEntry
Set a single element.- Specified by:
setEntry
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
index
- element index.value
- new value for the element.- See Also:
-
setSubVector
Set a set of consecutive elements.- Specified by:
setSubVector
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
index
- index of first element to be set.v
- vector containing the values to set.- See Also:
-
setSubVector
Set a set of consecutive elements.- Specified by:
setSubVector
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
index
- index of first element to be set.v
- vector containing the values to set.- See Also:
-
set
Set a set of consecutive elements.- Parameters:
index
- index of first element to be set.v
- vector containing the values to set.- Throws:
MatrixIndexException
- if the index is inconsistent with vector size
-
set
Set all elements to a single value.- Specified by:
set
in interfaceFieldVector<T extends FieldElement<T>>
- Parameters:
value
- single value to set for all elements
-
toArray
Convert the vector to a T array.The array is independent from vector data, it's elements are copied.
- Specified by:
toArray
in interfaceFieldVector<T extends FieldElement<T>>
- Returns:
- array containing a copy of vector elements
-
equals
Test for the equality of two real vectors.If all coordinates of two real vectors are exactly the same, and none are
Double.NaN
, the two real vectors are considered to be equal.NaN
coordinates are considered to affect globally the vector and be equals to each other - i.e, if either (or all) coordinates of the real vector are equal toDouble.NaN
, the real vector is equal to a vector with allDouble.NaN
coordinates. -
hashCode
public int hashCode()Get a hashCode for the real vector.All NaN values have the same hash code.
-