Class FreeVector<I>
- Type Parameters:
I- the index type
Coordinate values are represented as double numbers. Thus they
are subject to imprecise floating-point arithmetics. Vectors should not be
compared for exact coordinate-wise equality.
Some operations on vectors distinguish zero and non-zero coordinates. These are particularly prone to floating-point errors. It is recommended that they be used only on vectors with nonnegative coordinates: Calculations with such vectors only use floating-point addition, multiplication and square root. These are guaranteed to never represent a value that should be zero in theory by a non-zero floating-point number in practice.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class eu.bandm.tools.ops.AbstractFreeVector
coords -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(FreeVector<I> other) Returns a vector that is the sum of this and another vector.doublebreadth()static <I> FreeVector<I> build(Set<I> support, ToDoubleFunction<? super I> value) Returns a vector with computed coordinates.doubledepth()doubleReturns the coordinate for the given index.multiply(FreeMatrix<I> other) doublemultiply(FreeVector<I> other) Returns the scalar product of this and another vector.intnorm0()doublenorm1()Returns the length of this vector measured along unit vectors.doublenorm2()Returns the length of this vector measured in a straight line.doublenormMax()scale(double factor) Returns a scaled copy of this vector.support()Returns the set of indices for which this vector has explicit coordinates.<J> FreeVector<J> Returns a vector that reassigns the coordinates of this vector to different indices.trim(double epsilon) Return a copy of this vector with coordinate values close to zero removed.static <I> FreeVector<I> unit(I index) Returns a unit vector for the given index.static <I> FreeVector<I> unit(I index, double value) Returns a scaled unit vector for the given index.static <I> FreeVector<I> zero()Returns a zero vector.Methods inherited from class eu.bandm.tools.ops.AbstractFreeVector
addCoords, buildCoords, hasNonNegativeCoords, hasZeroCoords, isNonNegative, isZero, nearlyEqual, scaleCoords, transformCoords, trimCoords
-
Constructor Details
-
FreeVector
Creates a new instance.- Parameters:
coords- a map containing at least all nonzero coordinates
-
-
Method Details
-
get
Returns the coordinate for the given index.- Parameters:
index- an index- Returns:
- the coordinate for index, or zero if not specified
-
zero
Returns a zero vector.- Returns:
- a vector whose coordinates are all zero
-
unit
Returns a unit vector for the given index.- Parameters:
index- an index- Returns:
- a vector whose coordinate is one for the given index, or otherwise zero
- Throws:
NullPointerException- ifindexis null
-
unit
Returns a scaled unit vector for the given index.- Parameters:
index- an indexvalue- the scale value- Returns:
- a vector whose coordinate is the given value for the given index, or otherwise zero
- Throws:
NullPointerException- ifindexis null
-
build
Returns a vector with computed coordinates.- Parameters:
support- the set of index elements with nonzero coordinatesvalue- a function to compute the coordinate for each index- Returns:
- a vector built by evaluating
valueonce for each element ofsupport - Throws:
NullPointerException- ifsupportorvalueis null
-
scale
Returns a scaled copy of this vector.- Specified by:
scalein classAbstractFreeVector<I>- Parameters:
factor- the scaling factor- Returns:
- a vector that has the coordinates of this vector multiplied by
factor
-
normalize
-
trim
Return a copy of this vector with coordinate values close to zero removed.- Specified by:
trimin classAbstractFreeVector<I>- Parameters:
epsilon- the largest absolute value to treat as removable- Returns:
- a vector that retains all coordinates of this vector with absolute
value greater than
epsilon
-
add
Returns a vector that is the sum of this and another vector.- Parameters:
other- the other vector- Returns:
- a vector whose coordinates for each index are the sum of the respective coordinates of this and the other vector
-
multiply
Returns the scalar product of this and another vector.- Parameters:
other- the other vector- Returns:
- the sum of the pairwise products of the respective coordinates of this and the other vector
-
transform
Returns a vector that reassigns the coordinates of this vector to different indices.The new indices are computed from the old ones by means of a function. If multiple old indices are mapped to the same new index, the respective coordinates are added.
- Parameters:
fun- the index transforming function- Returns:
- a vector with coordinates from this vector reassigned to new
indices as specified by
fun
-
norm0
public int norm0() -
norm1
public double norm1()Returns the length of this vector measured along unit vectors. -
norm2
public double norm2()Returns the length of this vector measured in a straight line. -
normMax
public double normMax() -
breadth
public double breadth() -
depth
public double depth() -
support
Returns the set of indices for which this vector has explicit coordinates. All other coordinates are implicitly zero. -
multiply
-