Class SubVectorRef
- java.lang.Object
-
- dev.nm.algebra.linear.vector.doubles.SubVectorRef
-
- All Implemented Interfaces:
Vector
,AbelianGroup<Vector>
,BanachSpace<Vector,Real>
,HilbertSpace<Vector,Real>
,VectorSpace<Vector,Real>
,DeepCopyable
public class SubVectorRef extends Object
Represents a sub-vector backed by the referenced vector, without data copying. Note that changes to the referenced vector will also be reflected in the sub-vector instance.
-
-
Constructor Summary
Constructors Constructor Description SubVectorRef(Vector v, int from, int to)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Vector
add(double c)
Add a constant to all entries in this vector.Vector
add(Vector that)
\(this + that\)double
angle(Vector that)
Measure the angle, \(\theta\), betweenthis
andthat
.Vector
deepCopy()
The implementation returns an instance created fromthis
by the copy constructor of the class, or justthis
if the instance itself is immutable.Vector
divide(Vector that)
Dividethis
bythat
, entry-by-entry.double
get(int i)
Get the value at position i.double
innerProduct(Vector that)
Inner product in the Euclidean space is the dot product.Vector
minus(double c)
Subtract a constant from all entries in this vector.Vector
minus(Vector that)
\(this - that\)Vector
multiply(Vector that)
Multiplythis
bythat
, entry-by-entry.double
norm()
Compute the length or magnitude or Euclidean norm of a vector, namely, \(\|v\|\).double
norm(double p)
Gets the \(L^p\)-norm \(\|v\|_p\) of this vector.Vector
opposite()
Get the opposite of this vector.Vector
pow(double c)
Take the exponentiation of all entries in this vector, entry-by-entry.Vector
scaled(double c)
Scale this vector by a constant, entry-by-entry.Vector
scaled(Real c)
Scale this vector by a constant, entry-by-entry.void
set(int i, double value)
Deprecated.int
size()
Get the length of this vector.double[]
toArray()
Cast this vector into a 1Ddouble[]
.String
toString()
Vector
ZERO()
Get a 0-vector that has the same length as this vector.
-
-
-
Constructor Detail
-
SubVectorRef
public SubVectorRef(Vector v, int from, int to)
-
-
Method Detail
-
size
public int size()
Description copied from interface:Vector
Get the length of this vector.- Returns:
- the vector length
-
get
public double get(int i)
Description copied from interface:Vector
Get the value at position i.- Parameters:
i
- the position of a vector entry- Returns:
- v[i]
-
set
@Deprecated public void set(int i, double value)
Deprecated.Description copied from interface:Vector
Change the value of an entry in this vector. This is the only method that may change the entries of a vector.- Parameters:
i
- the index of the entry to change. The indices are counting from 1, NOT 0.value
- the value to change to
-
add
public Vector add(double c)
Description copied from interface:Vector
Add a constant to all entries in this vector.
-
minus
public Vector minus(double c)
Description copied from interface:Vector
Subtract a constant from all entries in this vector.
-
innerProduct
public double innerProduct(Vector that)
Description copied from interface:Vector
Inner product in the Euclidean space is the dot product.- Specified by:
innerProduct
in interfaceHilbertSpace<Vector,Real>
- Specified by:
innerProduct
in interfaceVector
- Parameters:
that
- a vector- Returns:
- \(this \cdot that\)
- See Also:
- Wikipedia: Dot product
-
pow
public Vector pow(double c)
Description copied from interface:Vector
Take the exponentiation of all entries in this vector, entry-by-entry.
-
scaled
public Vector scaled(double c)
Description copied from interface:Vector
Scale this vector by a constant, entry-by-entry. Here is a way to get a unit version of the vector:vector.scaled(1. / vector.norm())
-
scaled
public Vector scaled(Real c)
Description copied from interface:Vector
Scale this vector by a constant, entry-by-entry. Here is a way to get a unit version of the vector:vector.scaled(1. / vector.norm())
- Specified by:
scaled
in interfaceVector
- Specified by:
scaled
in interfaceVectorSpace<Vector,Real>
- Parameters:
c
- a constant- Returns:
- \(c \times this\)
- See Also:
- Wikipedia: Scalar multiplication
-
norm
public double norm()
Description copied from interface:Vector
Compute the length or magnitude or Euclidean norm of a vector, namely, \(\|v\|\).- Specified by:
norm
in interfaceBanachSpace<Vector,Real>
- Specified by:
norm
in interfaceVector
- Returns:
- the Euclidean norm
- See Also:
- Wikipedia: Norm (mathematics)
-
opposite
public Vector opposite()
Description copied from interface:Vector
Get the opposite of this vector.- Specified by:
opposite
in interfaceAbelianGroup<Vector>
- Specified by:
opposite
in interfaceVector
- Returns:
- -v
- See Also:
- Wikipedia: Additive inverse
-
toArray
public double[] toArray()
Description copied from interface:Vector
Cast this vector into a 1Ddouble[]
.- Returns:
- a copy of all vector entries as a
double[]
-
deepCopy
public Vector deepCopy()
Description copied from interface:DeepCopyable
The implementation returns an instance created fromthis
by the copy constructor of the class, or justthis
if the instance itself is immutable.- Returns:
- an independent (deep) copy of the instance
-
add
public Vector add(Vector that)
Description copied from interface:Vector
\(this + that\)- Specified by:
add
in interfaceAbelianGroup<Vector>
- Specified by:
add
in interfaceVector
- Parameters:
that
- a vector- Returns:
- \(this + that\)
-
minus
public Vector minus(Vector that)
Description copied from interface:Vector
\(this - that\)- Specified by:
minus
in interfaceAbelianGroup<Vector>
- Specified by:
minus
in interfaceVector
- Parameters:
that
- a vector- Returns:
- \(this - that\)
-
multiply
public Vector multiply(Vector that)
Description copied from interface:Vector
Multiplythis
bythat
, entry-by-entry.
-
divide
public Vector divide(Vector that)
Description copied from interface:Vector
Dividethis
bythat
, entry-by-entry.
-
norm
public double norm(double p)
Description copied from interface:Vector
Gets the \(L^p\)-norm \(\|v\|_p\) of this vector.- When p is finite, \(\|v\|_p = \sum_{i}|v_i^p|^\frac{1}{p}\).
- When p is \(+\infty\) (
Double.POSITIVE_INFINITY
), \(\|v\|_p = \max|v_i|\). - When p is \(-\infty\) (
Double.NEGATIVE_INFINITY
), \(\|v\|_p = \min|v_i|\).
- Specified by:
norm
in interfaceVector
- Parameters:
p
- p ≥ 1, orDouble.POSITIVE_INFINITY
orDouble.NEGATIVE_INFINITY
- Returns:
- \(\|v\|_p\)
- See Also:
- Wikipedia: Norm (mathematics)
-
angle
public double angle(Vector that)
Description copied from interface:Vector
Measure the angle, \(\theta\), betweenthis
andthat
. That is, \[ this \cdot that = \|this\| \times \|that\| \times \cos \theta \]
-
-