Top Description Fields Constructors Methods
org.apache.commons.math3.linear

public Class SparseFieldVector<T extends FieldElement<T>>

extends Object
implements FieldVector<T extends FieldElement<T>>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.math3.linear.FieldVector
Type Parameters
<T>
the type of the field elements
Imports
java.io.Serializable, org.apache.commons.math3.Field, .FieldElement, org.apache.commons.math3.exception.DimensionMismatchException, .MathArithmeticException, .NotPositiveException, .NullArgumentException, .NumberIsTooSmallException, .OutOfRangeException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.util.MathArrays, .MathUtils, .OpenIntToFieldHashMap

This class implements the 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.

Since
2.0

Field Summary

Modifier and TypeField and Description
private final OpenIntToFieldHashMap<T>
entries

Entries of the vector.

private final Field<T>
field

Field to which the elements belong.

private static final long
serialVersionUID

Serialization identifier.

private final int
virtualSize

Dimension of the vector.

Constructor Summary

AccessConstructor and Description
public
SparseFieldVector(Field<T>
Field to which the elements belong.
field
)

Build a 0-length vector.

public
SparseFieldVector(Field<T>
Field to which the elements belong.
field
,
int
Size of the vector.
dimension
)

Construct a vector of zeroes.

protected
SparseFieldVector(SparseFieldVector<T>
Original vector
v
,
int
Amount to add.
resize
)

Build a resized vector, for use with append.

public
SparseFieldVector(Field<T>
Field to which the elements belong.
field
,
int
Size of the vector.
dimension
,
int
Expected number of non-zero entries.
expectedSize
)

Build a vector with known the sparseness (for advanced use only).

public
SparseFieldVector(Field<T>
Field to which the elements belong.
field
,
T[]
Set of values to create from.
values
)

Create from a Field array.

public
SparseFieldVector(SparseFieldVector<T>
Instance to copy.
v
)

Copy constructor.

Method Summary

Modifier and TypeMethod and Description
public FieldVector<T>

Returns:

this + v.
add
(SparseFieldVector<T>
Vector to add.
v
)

Optimized method to add sparse vectors.

public FieldVector<T>
add(FieldVector<T>
vector to be added
v
)

Implements org.apache.commons.math3.linear.FieldVector.add.

Compute the sum of this and v.

public FieldVector<T>

Returns:

a new vector.
append
(SparseFieldVector<T>
Vector to append to this one.
v
)

Implements org.apache.commons.math3.linear.FieldVector.append.

Construct a vector by appending a vector to this vector.

public FieldVector<T>
append(FieldVector<T>
vector to append to this one.
v
)

Implements org.apache.commons.math3.linear.FieldVector.append, org.apache.commons.math3.linear.FieldVector.append.

Construct a vector by appending a vector to this vector.

public FieldVector<T>
append(T
T to append.
d
)

Implements org.apache.commons.math3.linear.FieldVector.append.

Construct a vector by appending a T to this vector.

private void
checkIndex(final int
Index to check.
index
)

Check whether an index is valid.

private void
checkIndices(final int
the index of the first entry of the subvector
start
,
final int
the index of the last entry of the subvector (inclusive)
end
)

Checks that the indices of a subvector are valid.

protected void
checkVectorDimensions(int
Expected dimension.
n
)

Check if instance dimension is equal to some expected value.

public FieldVector<T>
copy()

Implements org.apache.commons.math3.linear.FieldVector.copy.

Returns a (deep) copy of this.

public T
dotProduct(FieldVector<T>
vector with which dot product should be computed
v
)

Implements org.apache.commons.math3.linear.FieldVector.dotProduct.

Compute the dot product.

public FieldVector<T>
ebeDivide(FieldVector<T>
vector by which instance elements must be divided
v
)

Implements org.apache.commons.math3.linear.FieldVector.ebeDivide.

Element-by-element division.

public FieldVector<T>
ebeMultiply(FieldVector<T>
vector by which instance elements must be multiplied
v
)

Implements org.apache.commons.math3.linear.FieldVector.ebeMultiply.

Element-by-element multiplication.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public T[]
getData()

Implements org.apache.commons.math3.linear.FieldVector.getData.

Deprecated as of 3.1, to be removed in 4.0. Please use the toArray() method instead.

Returns vector entries as a T array.

public int
getDimension()

Implements org.apache.commons.math3.linear.FieldVector.getDimension.

Returns the size of the vector.

private OpenIntToFieldHashMap<T>

Returns:

the entries of this instance
getEntries
()

Get the entries of this instance.

public T
getEntry(int
Index location of entry to be fetched.
index
)

Implements org.apache.commons.math3.linear.FieldVector.getEntry.

Returns the entry in the specified index.

public Field<T>
getField()

Implements org.apache.commons.math3.linear.FieldVector.getField.

Get the type of field elements of the vector.

public FieldVector<T>
getSubVector(int
index of first element.
index
,
int
number of elements to be retrieved.
n
)

Implements org.apache.commons.math3.linear.FieldVector.getSubVector.

Get a subvector from consecutive elements.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public FieldVector<T>
mapAdd(T
value to be added to each entry
d
)

Implements org.apache.commons.math3.linear.FieldVector.mapAdd.

Map an addition operation to each entry.

public FieldVector<T>
mapAddToSelf(T
value to be added to each entry
d
)

Implements org.apache.commons.math3.linear.FieldVector.mapAddToSelf.

Map an addition operation to each entry.

public FieldVector<T>
mapDivide(T
value to divide all entries by
d
)

Implements org.apache.commons.math3.linear.FieldVector.mapDivide.

Map a division operation to each entry.

public FieldVector<T>
mapDivideToSelf(T
value to divide all entries by
d
)

Implements org.apache.commons.math3.linear.FieldVector.mapDivideToSelf.

Map a division operation to each entry.

public FieldVector<T>
mapInv()

Implements org.apache.commons.math3.linear.FieldVector.mapInv.

Map the 1/x function to each entry.

public FieldVector<T>
mapInvToSelf()

Implements org.apache.commons.math3.linear.FieldVector.mapInvToSelf.

Map the 1/x function to each entry.

public FieldVector<T>
mapMultiply(T
value to multiply all entries by
d
)

Implements org.apache.commons.math3.linear.FieldVector.mapMultiply.

Map a multiplication operation to each entry.

public FieldVector<T>
mapMultiplyToSelf(T
value to multiply all entries by
d
)

Implements org.apache.commons.math3.linear.FieldVector.mapMultiplyToSelf.

Map a multiplication operation to each entry.

public FieldVector<T>
mapSubtract(T
value to be subtracted to each entry
d
)

Implements org.apache.commons.math3.linear.FieldVector.mapSubtract.

Map a subtraction operation to each entry.

public FieldVector<T>
mapSubtractToSelf(T
value to be subtracted to each entry
d
)

Implements org.apache.commons.math3.linear.FieldVector.mapSubtractToSelf.

Map a subtraction operation to each entry.

public FieldMatrix<T>

Returns:

the matrix outer product between instance and v
outerProduct
(SparseFieldVector<T>
vector with which outer product should be computed
v
)

Optimized method to compute outer product when both vectors are sparse.

public FieldMatrix<T>
outerProduct(FieldVector<T>
vector with which outer product should be computed
v
)

Implements org.apache.commons.math3.linear.FieldVector.outerProduct.

Compute the outer product.

public FieldVector<T>
projection(FieldVector<T>
vector onto which this must be projected
v
)

Implements org.apache.commons.math3.linear.FieldVector.projection.

Find the orthogonal projection of this vector onto another vector.

public void
set(T
single value to set for all elements
value
)

Implements org.apache.commons.math3.linear.FieldVector.set.

Set all elements to a single value.

public void
setEntry(int
element index.
index
,
T
new value for the element.
value
)

Implements org.apache.commons.math3.linear.FieldVector.setEntry.

Set a single element.

public void
setSubVector(int
index of first element to be set.
index
,
FieldVector<T>
vector containing the values to set.
v
)

Implements org.apache.commons.math3.linear.FieldVector.setSubVector.

Set a set of consecutive elements.

public SparseFieldVector<T>

Returns:

this - v
subtract
(SparseFieldVector<T>
vector to be subtracted
v
)

Optimized method to compute this minus v.

public FieldVector<T>
subtract(FieldVector<T>
vector to be subtracted
v
)

Implements org.apache.commons.math3.linear.FieldVector.subtract.

Compute this minus v.

public T[]
toArray()

Implements org.apache.commons.math3.linear.FieldVector.toArray.

Convert the vector to a T array.

public T

Returns:

the value returned by FieldVectorPreservingVisitor#end() at the end of the walk
walkInDefaultOrder
(final FieldVectorPreservingVisitor<T>
the visitor to be used to process the entries of this vector
visitor
)

Visits (but does not alter) all entries of this vector in default order (increasing index).

public T

Returns:

the value returned by FieldVectorPreservingVisitor#end() at the end of the walk
walkInDefaultOrder
(final FieldVectorPreservingVisitor<T>
visitor to be used to process the entries of this vector
visitor
,
final int
the index of the first entry to be visited
start
,
final int
the index of the last entry to be visited (inclusive)
end
)

Visits (but does not alter) some entries of this vector in default order (increasing index).

public T

Returns:

the value returned by FieldVectorChangingVisitor#end() at the end of the walk
walkInDefaultOrder
(final FieldVectorChangingVisitor<T>
the visitor to be used to process and modify the entries of this vector
visitor
)

Visits (and possibly alters) all entries of this vector in default order (increasing index).

public T

Returns:

the value returned by FieldVectorChangingVisitor#end() at the end of the walk
walkInDefaultOrder
(final FieldVectorChangingVisitor<T>
visitor to be used to process the entries of this vector
visitor
,
final int
the index of the first entry to be visited
start
,
final int
the index of the last entry to be visited (inclusive)
end
)

Visits (and possibly alters) some entries of this vector in default order (increasing index).

public T

Returns:

the value returned by FieldVectorPreservingVisitor#end() at the end of the walk
walkInOptimizedOrder
(final FieldVectorPreservingVisitor<T>
the visitor to be used to process the entries of this vector
visitor
)

Visits (but does not alter) all entries of this vector in optimized order.

public T

Returns:

the value returned by FieldVectorPreservingVisitor#end() at the end of the walk
walkInOptimizedOrder
(final FieldVectorPreservingVisitor<T>
visitor to be used to process the entries of this vector
visitor
,
final int
the index of the first entry to be visited
start
,
final int
the index of the last entry to be visited (inclusive)
end
)

Visits (but does not alter) some entries of this vector in optimized order.

public T

Returns:

the value returned by FieldVectorChangingVisitor#end() at the end of the walk
walkInOptimizedOrder
(final FieldVectorChangingVisitor<T>
the visitor to be used to process the entries of this vector
visitor
)

Visits (and possibly alters) all entries of this vector in optimized order.

public T

Returns:

the value returned by FieldVectorChangingVisitor#end() at the end of the walk
walkInOptimizedOrder
(final FieldVectorChangingVisitor<T>
visitor to be used to process the entries of this vector
visitor
,
final int
the index of the first entry to be visited
start
,
final int
the index of the last entry to be visited (inclusive)
end
)

Visits (and possibly change) some entries of this vector in optimized order.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait