T
- the type of the field elementspublic class SparseFieldVector<T extends FieldElement<T>> extends Object implements FieldVector<T>, Serializable
FieldVector
interface with a OpenIntToFieldHashMap
backing store.
Caveat: This implementation assumes that, for any x
,
the equality x * 0d == 0d
holds. But it is is not true for
NaN
. Moreover, zero entries will lose their sign.
Some operations (that involve NaN
and/or infinities) may
thus give incorrect results.
Modifier | Constructor and Description |
---|---|
|
SparseFieldVector(Field<T> field)
Build a 0-length vector.
|
|
SparseFieldVector(Field<T> field,
int dimension)
Construct a vector of zeroes.
|
|
SparseFieldVector(Field<T> field,
int dimension,
int expectedSize)
Build a vector with known the sparseness (for advanced use only).
|
|
SparseFieldVector(Field<T> field,
T[] values)
Create from a Field array.
|
|
SparseFieldVector(SparseFieldVector<T> v)
Copy constructor.
|
protected |
SparseFieldVector(SparseFieldVector<T> v,
int resize)
Build a resized vector, for use with append.
|
Modifier and Type | Method and Description |
---|---|
FieldVector<T> |
add(FieldVector<T> v)
Compute the sum of
this and v . |
FieldVector<T> |
add(SparseFieldVector<T> v)
Optimized method to add sparse vectors.
|
FieldVector<T> |
append(FieldVector<T> v)
Construct a vector by appending a vector to this vector.
|
FieldVector<T> |
append(SparseFieldVector<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.
|
protected void |
checkVectorDimensions(int n)
Check if instance dimension is equal to some expected value.
|
FieldVector<T> |
copy()
Returns a (deep) copy of this.
|
T |
dotProduct(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.
|
boolean |
equals(Object obj) |
int |
getDimension()
Returns the size of the vector.
|
T |
getEntry(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.
|
int |
hashCode() |
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.
|
FieldMatrix<T> |
outerProduct(SparseFieldVector<T> v)
Optimized method to compute outer product when both vectors are sparse.
|
FieldVector<T> |
projection(FieldVector<T> v)
Find the orthogonal projection of this vector onto another vector.
|
void |
set(T value)
Set all elements to a single value.
|
void |
setEntry(int index,
T value)
Set a single element.
|
void |
setSubVector(int index,
FieldVector<T> v)
Set a set of consecutive elements.
|
FieldVector<T> |
subtract(FieldVector<T> v)
Compute
this minus v . |
SparseFieldVector<T> |
subtract(SparseFieldVector<T> v)
Optimized method to compute
this minus v . |
T[] |
toArray()
Convert the vector to a T array.
|
T |
walkInDefaultOrder(FieldVectorChangingVisitor<T> visitor)
Visits (and possibly alters) all entries of this vector in default order
(increasing index).
|
T |
walkInDefaultOrder(FieldVectorChangingVisitor<T> visitor,
int start,
int end)
Visits (and possibly alters) some entries of this vector in default order
(increasing index).
|
T |
walkInDefaultOrder(FieldVectorPreservingVisitor<T> visitor)
Visits (but does not alter) all entries of this vector in default order
(increasing index).
|
T |
walkInDefaultOrder(FieldVectorPreservingVisitor<T> visitor,
int start,
int end)
Visits (but does not alter) some entries of this vector in default order
(increasing index).
|
T |
walkInOptimizedOrder(FieldVectorChangingVisitor<T> visitor)
Visits (and possibly alters) all entries of this vector in optimized
order.
|
T |
walkInOptimizedOrder(FieldVectorChangingVisitor<T> visitor,
int start,
int end)
Visits (and possibly change) some entries of this vector in optimized
order.
|
T |
walkInOptimizedOrder(FieldVectorPreservingVisitor<T> visitor)
Visits (but does not alter) all entries of this vector in optimized
order.
|
T |
walkInOptimizedOrder(FieldVectorPreservingVisitor<T> visitor,
int start,
int end)
Visits (but does not alter) some entries of this vector in optimized
order.
|
public SparseFieldVector(Field<T> field)
SparseFieldVector(SparseFieldVector, int)
constructor
or one of the append
method (append(FieldVector)
or
append(SparseFieldVector)
) to gather data into this vector.field
- Field to which the elements belong.public SparseFieldVector(Field<T> field, int dimension)
field
- Field to which the elements belong.dimension
- Size of the vector.protected SparseFieldVector(SparseFieldVector<T> v, int resize)
v
- Original vectorresize
- Amount to add.public SparseFieldVector(Field<T> field, int dimension, int expectedSize)
field
- Field to which the elements belong.dimension
- Size of the vector.expectedSize
- Expected number of non-zero entries.public SparseFieldVector(Field<T> field, T[] values) throws NullArgumentException
field
- Field to which the elements belong.values
- Set of values to create from.NullArgumentException
- if values is nullpublic SparseFieldVector(SparseFieldVector<T> v)
v
- Instance to copy.public FieldVector<T> add(SparseFieldVector<T> v) throws MathIllegalArgumentException
v
- Vector to add.this + v
.MathIllegalArgumentException
- if v
is not the same size as
this
.public FieldVector<T> append(SparseFieldVector<T> v)
v
- Vector to append to this one.public FieldVector<T> append(FieldVector<T> v)
append
in interface FieldVector<T extends FieldElement<T>>
v
- vector to append to this one.public FieldVector<T> append(T d) throws NullArgumentException
append
in interface FieldVector<T extends FieldElement<T>>
d
- T to append.NullArgumentException
- if d is nullpublic FieldVector<T> copy()
copy
in interface FieldVector<T extends FieldElement<T>>
public T dotProduct(FieldVector<T> v) throws MathIllegalArgumentException
dotProduct
in interface FieldVector<T extends FieldElement<T>>
v
- vector with which dot product should be computedthis
and v
MathIllegalArgumentException
- if v
is not the same size as this
public FieldVector<T> ebeDivide(FieldVector<T> v) throws MathIllegalArgumentException, MathRuntimeException
ebeDivide
in interface FieldVector<T extends FieldElement<T>>
v
- vector by which instance elements must be dividedthis[i] / v[i]
for all i
MathIllegalArgumentException
- if v
is not the same size as this
MathRuntimeException
- if one entry of v
is zero.public FieldVector<T> ebeMultiply(FieldVector<T> v) throws MathIllegalArgumentException
ebeMultiply
in interface FieldVector<T extends FieldElement<T>>
v
- vector by which instance elements must be multipliedthis[i] * v[i]
for all i
MathIllegalArgumentException
- if v
is not the same size as this
public int getDimension()
getDimension
in interface FieldVector<T extends FieldElement<T>>
public T getEntry(int index) throws MathIllegalArgumentException
getEntry
in interface FieldVector<T extends FieldElement<T>>
index
- Index location of entry to be fetched.index
.MathIllegalArgumentException
- if the index is not valid.FieldVector.setEntry(int, FieldElement)
public Field<T> getField()
getField
in interface FieldVector<T extends FieldElement<T>>
public FieldVector<T> getSubVector(int index, int n) throws MathIllegalArgumentException
getSubVector
in interface FieldVector<T extends FieldElement<T>>
index
- index of first element.n
- number of elements to be retrieved.MathIllegalArgumentException
- if the index is not valid.public FieldVector<T> mapAdd(T d) throws NullArgumentException
mapAdd
in interface FieldVector<T extends FieldElement<T>>
d
- value to be added to each entrythis + d
NullArgumentException
- if d
is null
.public FieldVector<T> mapAddToSelf(T d) throws NullArgumentException
The instance is changed by this method.
mapAddToSelf
in interface FieldVector<T extends FieldElement<T>>
d
- value to be added to each entrythis
NullArgumentException
- if d
is null
.public FieldVector<T> mapDivide(T d) throws NullArgumentException, MathRuntimeException
mapDivide
in interface FieldVector<T extends FieldElement<T>>
d
- value to divide all entries bythis / d
NullArgumentException
- if d
is null
.MathRuntimeException
- if d
is zero.public FieldVector<T> mapDivideToSelf(T d) throws NullArgumentException, MathRuntimeException
The instance is changed by this method.
mapDivideToSelf
in interface FieldVector<T extends FieldElement<T>>
d
- value to divide all entries bythis
NullArgumentException
- if d
is null
.MathRuntimeException
- if d
is zero.public FieldVector<T> mapInv() throws MathRuntimeException
mapInv
in interface FieldVector<T extends FieldElement<T>>
MathRuntimeException
- if one of the entries is zero.public FieldVector<T> mapInvToSelf() throws MathRuntimeException
The instance is changed by this method.
mapInvToSelf
in interface FieldVector<T extends FieldElement<T>>
this
MathRuntimeException
- if one of the entries is zero.public FieldVector<T> mapMultiply(T d) throws NullArgumentException
mapMultiply
in interface FieldVector<T extends FieldElement<T>>
d
- value to multiply all entries bythis * d
NullArgumentException
- if d
is null
.public FieldVector<T> mapMultiplyToSelf(T d) throws NullArgumentException
The instance is changed by this method.
mapMultiplyToSelf
in interface FieldVector<T extends FieldElement<T>>
d
- value to multiply all entries bythis
NullArgumentException
- if d
is null
.public FieldVector<T> mapSubtract(T d) throws NullArgumentException
mapSubtract
in interface FieldVector<T extends FieldElement<T>>
d
- value to be subtracted to each entrythis - d
NullArgumentException
- if d
is null
public FieldVector<T> mapSubtractToSelf(T d) throws NullArgumentException
The instance is changed by this method.
mapSubtractToSelf
in interface FieldVector<T extends FieldElement<T>>
d
- value to be subtracted to each entrythis
NullArgumentException
- if d
is null
public FieldMatrix<T> outerProduct(SparseFieldVector<T> v)
v
- vector with which outer product should be computedpublic FieldMatrix<T> outerProduct(FieldVector<T> v)
outerProduct
in interface FieldVector<T extends FieldElement<T>>
v
- vector with which outer product should be computedpublic FieldVector<T> projection(FieldVector<T> v) throws MathIllegalArgumentException, MathRuntimeException
projection
in interface FieldVector<T extends FieldElement<T>>
v
- vector onto which this
must be projectedthis
onto v
MathIllegalArgumentException
- if v
is not the same size as this
MathRuntimeException
- if v
is the null vector.public void set(T value)
set
in interface FieldVector<T extends FieldElement<T>>
value
- single value to set for all elementsNullArgumentException
- if value is nullpublic void setEntry(int index, T value) throws MathIllegalArgumentException, NullArgumentException
setEntry
in interface FieldVector<T extends FieldElement<T>>
index
- element index.value
- new value for the element.NullArgumentException
- if value is nullMathIllegalArgumentException
- if the index is not valid.FieldVector.getEntry(int)
public void setSubVector(int index, FieldVector<T> v) throws MathIllegalArgumentException
setSubVector
in interface FieldVector<T extends FieldElement<T>>
index
- index of first element to be set.v
- vector containing the values to set.MathIllegalArgumentException
- if the index is not valid.public SparseFieldVector<T> subtract(SparseFieldVector<T> v) throws MathIllegalArgumentException
this
minus v
.v
- vector to be subtractedthis - v
MathIllegalArgumentException
- if v
is not the same size as
this
.public FieldVector<T> subtract(FieldVector<T> v) throws MathIllegalArgumentException
this
minus v
.subtract
in interface FieldVector<T extends FieldElement<T>>
v
- vector to be subtractedthis - v
MathIllegalArgumentException
- if v
is not the same size as this
public T[] toArray()
The array is independent from vector data, it's elements are copied.
toArray
in interface FieldVector<T extends FieldElement<T>>
protected void checkVectorDimensions(int n) throws MathIllegalArgumentException
n
- Expected dimension.MathIllegalArgumentException
- if the dimensions do not match.public FieldVector<T> add(FieldVector<T> v) throws MathIllegalArgumentException
this
and v
.add
in interface FieldVector<T extends FieldElement<T>>
v
- vector to be addedthis + v
MathIllegalArgumentException
- if v
is not the same size as this
public T walkInDefaultOrder(FieldVectorPreservingVisitor<T> visitor)
visitor
- the visitor to be used to process the entries of this
vectorFieldVectorPreservingVisitor.end()
at the end of the walkpublic T walkInDefaultOrder(FieldVectorPreservingVisitor<T> visitor, int start, int end) throws MathIllegalArgumentException
visitor
- visitor to be used to process the entries of this vectorstart
- the index of the first entry to be visitedend
- the index of the last entry to be visited (inclusive)FieldVectorPreservingVisitor.end()
at the end of the walkMathIllegalArgumentException
- if end < start
.MathIllegalArgumentException
- if the indices are not valid.public T walkInOptimizedOrder(FieldVectorPreservingVisitor<T> visitor)
visitor
- the visitor to be used to process the entries of this
vectorFieldVectorPreservingVisitor.end()
at the end of the walkpublic T walkInOptimizedOrder(FieldVectorPreservingVisitor<T> visitor, int start, int end) throws MathIllegalArgumentException
visitor
- visitor to be used to process the entries of this vectorstart
- the index of the first entry to be visitedend
- the index of the last entry to be visited (inclusive)FieldVectorPreservingVisitor.end()
at the end of the walkMathIllegalArgumentException
- if end < start
.MathIllegalArgumentException
- if the indices are not valid.public T walkInDefaultOrder(FieldVectorChangingVisitor<T> visitor)
visitor
- the visitor to be used to process and modify the entries
of this vectorFieldVectorChangingVisitor.end()
at the end of the walkpublic T walkInDefaultOrder(FieldVectorChangingVisitor<T> visitor, int start, int end) throws MathIllegalArgumentException
visitor
- visitor to be used to process the entries of this vectorstart
- the index of the first entry to be visitedend
- the index of the last entry to be visited (inclusive)FieldVectorChangingVisitor.end()
at the end of the walkMathIllegalArgumentException
- if end < start
.MathIllegalArgumentException
- if the indices are not valid.public T walkInOptimizedOrder(FieldVectorChangingVisitor<T> visitor)
visitor
- the visitor to be used to process the entries of this
vectorFieldVectorChangingVisitor.end()
at the end of the walkpublic T walkInOptimizedOrder(FieldVectorChangingVisitor<T> visitor, int start, int end) throws MathIllegalArgumentException
visitor
- visitor to be used to process the entries of this vectorstart
- the index of the first entry to be visitedend
- the index of the last entry to be visited (inclusive)FieldVectorChangingVisitor.end()
at the end of the walkMathIllegalArgumentException
- if end < start
.MathIllegalArgumentException
- if the indices are not valid.Copyright © 2016–2017 Hipparchus.org. All rights reserved.