|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.math.linear.SparseFieldVector<T>
T
- the type of the field elementspublic class SparseFieldVector<T extends FieldElement<T>>
This class implements the FieldVector
interface with a OpenIntToFieldHashMap
backing store.
Constructor Summary | |
---|---|
|
SparseFieldVector(Field<T> field)
Build a 0-length vector. |
|
SparseFieldVector(Field<T> field,
int dimension)
Construct a (dimension)-length vector of zeros. |
|
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. |
Method Summary | |
---|---|
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> |
add(T[] v)
Compute the sum of this and v. |
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. |
FieldVector<T> |
append(T[] a)
Construct a vector by appending a T array 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. |
T |
dotProduct(T[] v)
Compute the dot product. |
FieldVector<T> |
ebeDivide(FieldVector<T> v)
Element-by-element division. |
FieldVector<T> |
ebeDivide(T[] v)
Element-by-element division. |
FieldVector<T> |
ebeMultiply(FieldVector<T> v)
Element-by-element multiplication. |
FieldVector<T> |
ebeMultiply(T[] v)
Element-by-element multiplication. |
boolean |
equals(Object obj)
|
T[] |
getData()
Returns vector entries as a T array. |
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. |
FieldMatrix<T> |
outerProduct(T[] v)
Compute the outer product. |
FieldVector<T> |
projection(FieldVector<T> v)
Find the orthogonal projection of this vector onto another vector. |
FieldVector<T> |
projection(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. |
void |
setSubVector(int index,
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 subtract SparseRealVectors. |
FieldVector<T> |
subtract(T[] v)
Compute this minus v. |
T[] |
toArray()
Convert the vector to a T array. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SparseFieldVector(Field<T> field)
Zero-length vectors may be used to initialize construction of vectors
by data gathering. We start with zero-length and use either the SparseFieldVector(SparseFieldVector, int)
constructor
or one of the append
method (append(FieldElement)
,
append(FieldElement[])
, append(FieldVector)
,
append(SparseFieldVector)
) to gather data into this vector.
field
- field to which the elements belongpublic SparseFieldVector(Field<T> field, int dimension)
field
- field to which the elements belongdimension
- Size of the vectorprotected SparseFieldVector(SparseFieldVector<T> v, int resize)
v
- The original vectorresize
- The amount to resize itpublic SparseFieldVector(Field<T> field, int dimension, int expectedSize)
field
- field to which the elements belongdimension
- The size of the vectorexpectedSize
- The expected number of non-zero entriespublic SparseFieldVector(Field<T> field, T[] values)
field
- field to which the elements belongvalues
- The set of values to create frompublic SparseFieldVector(SparseFieldVector<T> v)
v
- The instance to copy fromMethod Detail |
---|
public FieldVector<T> add(SparseFieldVector<T> v) throws IllegalArgumentException
v
- vector to add
this
and v
IllegalArgumentException
- If the dimensions don't matchpublic FieldVector<T> add(T[] v) throws IllegalArgumentException
add
in interface FieldVector<T extends FieldElement<T>>
v
- vector to be added
IllegalArgumentException
- if v is not the same size as thispublic 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)
append
in interface FieldVector<T extends FieldElement<T>>
d
- T to append.
public FieldVector<T> append(T[] a)
append
in interface FieldVector<T extends FieldElement<T>>
a
- T array to append.
public FieldVector<T> copy()
copy
in interface FieldVector<T extends FieldElement<T>>
public T dotProduct(FieldVector<T> v) throws IllegalArgumentException
dotProduct
in interface FieldVector<T extends FieldElement<T>>
v
- vector with which dot product should be computed
IllegalArgumentException
- if v is not the same size as thispublic T dotProduct(T[] v) throws IllegalArgumentException
dotProduct
in interface FieldVector<T extends FieldElement<T>>
v
- vector with which dot product should be computed
IllegalArgumentException
- if v is not the same size as thispublic FieldVector<T> ebeDivide(FieldVector<T> v) throws IllegalArgumentException
ebeDivide
in interface FieldVector<T extends FieldElement<T>>
v
- vector by which instance elements must be divided
IllegalArgumentException
- if v is not the same size as thispublic FieldVector<T> ebeDivide(T[] v) throws IllegalArgumentException
ebeDivide
in interface FieldVector<T extends FieldElement<T>>
v
- vector by which instance elements must be divided
IllegalArgumentException
- if v is not the same size as thispublic FieldVector<T> ebeMultiply(FieldVector<T> v) throws IllegalArgumentException
ebeMultiply
in interface FieldVector<T extends FieldElement<T>>
v
- vector by which instance elements must be multiplied
IllegalArgumentException
- if v is not the same size as thispublic FieldVector<T> ebeMultiply(T[] v) throws IllegalArgumentException
ebeMultiply
in interface FieldVector<T extends FieldElement<T>>
v
- vector by which instance elements must be multiplied
IllegalArgumentException
- if v is not the same size as thispublic T[] getData()
getData
in interface FieldVector<T extends FieldElement<T>>
public int getDimension()
getDimension
in interface FieldVector<T extends FieldElement<T>>
public T getEntry(int index) throws MatrixIndexException
The index start at 0 and must be lesser than the size,
otherwise a MatrixIndexException
is thrown.
getEntry
in interface FieldVector<T extends FieldElement<T>>
index
- index location of entry to be fetched
MatrixIndexException
- if the index is not validFieldVector.setEntry(int, FieldElement)
public Field<T> getField()
getField
in interface FieldVector<T extends FieldElement<T>>
public FieldVector<T> getSubVector(int index, int n) throws MatrixIndexException
getSubVector
in interface FieldVector<T extends FieldElement<T>>
index
- index of first element.n
- number of elements to be retrieved.
MatrixIndexException
- if the index is
inconsistent with vector sizepublic FieldVector<T> mapAdd(T d)
mapAdd
in interface FieldVector<T extends FieldElement<T>>
d
- value to be added to each entry
public FieldVector<T> mapAddToSelf(T d)
The instance is changed by this method.
mapAddToSelf
in interface FieldVector<T extends FieldElement<T>>
d
- value to be added to each entry
public FieldVector<T> mapDivide(T d)
mapDivide
in interface FieldVector<T extends FieldElement<T>>
d
- value to divide all entries by
public FieldVector<T> mapDivideToSelf(T d)
The instance is changed by this method.
mapDivideToSelf
in interface FieldVector<T extends FieldElement<T>>
d
- value to divide all entries by
public FieldVector<T> mapInv()
mapInv
in interface FieldVector<T extends FieldElement<T>>
public FieldVector<T> mapInvToSelf()
The instance is changed by this method.
mapInvToSelf
in interface FieldVector<T extends FieldElement<T>>
public FieldVector<T> mapMultiply(T d)
mapMultiply
in interface FieldVector<T extends FieldElement<T>>
d
- value to multiply all entries by
public FieldVector<T> mapMultiplyToSelf(T d)
The instance is changed by this method.
mapMultiplyToSelf
in interface FieldVector<T extends FieldElement<T>>
d
- value to multiply all entries by
public FieldVector<T> mapSubtract(T d)
mapSubtract
in interface FieldVector<T extends FieldElement<T>>
d
- value to be subtracted to each entry
public FieldVector<T> mapSubtractToSelf(T d)
The instance is changed by this method.
mapSubtractToSelf
in interface FieldVector<T extends FieldElement<T>>
d
- value to be subtracted to each entry
public FieldMatrix<T> outerProduct(SparseFieldVector<T> v) throws IllegalArgumentException
v
- vector with which outer product should be computed
IllegalArgumentException
- if v is not the same size as this
public FieldMatrix<T> outerProduct(T[] v) throws IllegalArgumentException
outerProduct
in interface FieldVector<T extends FieldElement<T>>
v
- vector with which outer product should be computed
IllegalArgumentException
- if v is not the same size as thispublic FieldMatrix<T> outerProduct(FieldVector<T> v) throws IllegalArgumentException
outerProduct
in interface FieldVector<T extends FieldElement<T>>
v
- vector with which outer product should be computed
IllegalArgumentException
- if v is not the same size as thispublic FieldVector<T> projection(FieldVector<T> v) throws IllegalArgumentException
projection
in interface FieldVector<T extends FieldElement<T>>
v
- vector onto which instance must be projected
IllegalArgumentException
- if v is not the same size as thispublic FieldVector<T> projection(T[] v) throws IllegalArgumentException
projection
in interface FieldVector<T extends FieldElement<T>>
v
- vector onto which instance must be projected
IllegalArgumentException
- if v is not the same size as thispublic void set(T value)
set
in interface FieldVector<T extends FieldElement<T>>
value
- single value to set for all elementspublic void setEntry(int index, T value) throws MatrixIndexException
setEntry
in interface FieldVector<T extends FieldElement<T>>
index
- element index.value
- new value for the element.
MatrixIndexException
- if the index is
inconsistent with vector sizeFieldVector.getEntry(int)
public void setSubVector(int index, FieldVector<T> v) throws MatrixIndexException
setSubVector
in interface FieldVector<T extends FieldElement<T>>
index
- index of first element to be set.v
- vector containing the values to set.
MatrixIndexException
- if the index is
inconsistent with vector sizeFieldVector.setSubVector(int, FieldElement[])
public void setSubVector(int index, T[] v) throws MatrixIndexException
setSubVector
in interface FieldVector<T extends FieldElement<T>>
index
- index of first element to be set.v
- vector containing the values to set.
MatrixIndexException
- if the index is
inconsistent with vector sizeFieldVector.setSubVector(int, FieldVector)
public SparseFieldVector<T> subtract(SparseFieldVector<T> v) throws IllegalArgumentException
v
- The vector to subtract from this
this
and v
IllegalArgumentException
- If the dimensions don't matchpublic FieldVector<T> subtract(FieldVector<T> v) throws IllegalArgumentException
subtract
in interface FieldVector<T extends FieldElement<T>>
v
- vector to be subtracted
IllegalArgumentException
- if v is not the same size as thispublic FieldVector<T> subtract(T[] v) throws IllegalArgumentException
subtract
in interface FieldVector<T extends FieldElement<T>>
v
- vector to be subtracted
IllegalArgumentException
- if v is not the same size as thispublic 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 IllegalArgumentException
n
- expected dimension.
IllegalArgumentException
- if the dimension is inconsistent with vector sizepublic FieldVector<T> add(FieldVector<T> v) throws IllegalArgumentException
add
in interface FieldVector<T extends FieldElement<T>>
v
- vector to be added
IllegalArgumentException
- if v is not the same size as thispublic int hashCode()
hashCode
in class Object
public boolean equals(Object obj)
equals
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |