Class ImmutableVector
java.lang.Object
dev.nm.algebra.linear.vector.doubles.ImmutableVector
- All Implemented Interfaces:
Vector
,AbelianGroup<Vector>
,BanachSpace<Vector,
,Real> HilbertSpace<Vector,
,Real> VectorSpace<Vector,
,Real> DeepCopyable
This is a read-only view of a
Vector
instance. It keeps the reference to the
instance and delegates all operations to the instance except for
set(int, double) which will always result in an VectorAccessException
.
It may, however, still be modified indirectly via the reference of the
original vector. To ensure complete immutability, an independent copy is needed.
That is,
ImmutableVector immutable = new ImmutableVector(v.deepCopy());
Note that the returned values of all operations (e.g., add
) has
the same types as the original ones.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd
(double scalar) Add a constant to all entries in this vector.\(this + that\)double
Measure the angle, \(\theta\), betweenthis
andthat
.deepCopy()
The implementation returns an instance created fromthis
by the copy constructor of the class, or justthis
if the instance itself is immutable.Dividethis
bythat
, entry-by-entry.boolean
double
get
(int index) Get the value at position i.int
hashCode()
double
innerProduct
(Vector that) Inner product in the Euclidean space is the dot product.minus
(double scalar) Subtract a constant from all entries in this vector.\(this - 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.opposite()
Get the opposite of this vector.pow
(double scalar) Take the exponentiation of all entries in this vector, entry-by-entry.scaled
(double scalar) Scale this vector by a constant, entry-by-entry.Scale this vector by a constant, entry-by-entry.final void
set
(int i, double value) This method is overridden to always throwVectorAccessException
.int
size()
Get the length of this vector.double[]
toArray()
Cast this vector into a 1Ddouble[]
.toString()
ZERO()
Get a 0-vector that has the same length as this vector.
-
Constructor Details
-
ImmutableVector
Construct a read-only version of a vector. Note that, however, changing the original vector changes the "immutable" version as well.- Parameters:
v
- a vector
-
-
Method Details
-
set
public final void set(int i, double value) This method is overridden to always throwVectorAccessException
.- Specified by:
set
in interfaceVector
- Parameters:
i
- the index of the entry to change. The indices are counting from 1, NOT 0.value
- the value to change to- Throws:
VectorAccessException
- always
-
size
public int size()Description copied from interface:Vector
Get the length of this vector. -
get
public double get(int index) Description copied from interface:Vector
Get the value at position i. -
add
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
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
Description copied from interface:Vector
Multiplythis
bythat
, entry-by-entry. -
divide
Description copied from interface:Vector
Dividethis
bythat
, entry-by-entry. -
add
Description copied from interface:Vector
Add a constant to all entries in this vector. -
minus
Description copied from interface:Vector
Subtract a constant from all entries in this vector. -
innerProduct
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:
-
pow
Description copied from interface:Vector
Take the exponentiation of all entries in this vector, entry-by-entry. -
scaled
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
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())
-
norm
public double norm()Description copied from interface:Vector
Compute the length or magnitude or Euclidean norm of a vector, namely, \(\|v\|\). -
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:
-
angle
Description copied from interface:Vector
Measure the angle, \(\theta\), betweenthis
andthat
. That is, \[ this \cdot that = \|this\| \times \|that\| \times \cos \theta \] -
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:
-
ZERO
Description copied from interface:Vector
Get a 0-vector that has the same length as this vector.- Specified by:
ZERO
in interfaceAbelianGroup<Vector>
- Specified by:
ZERO
in interfaceVector
- Returns:
- the 0-vector
-
toArray
public double[] toArray()Description copied from interface:Vector
Cast this vector into a 1Ddouble[]
. -
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.- Specified by:
deepCopy
in interfaceDeepCopyable
- Specified by:
deepCopy
in interfaceVector
- Returns:
- an independent (deep) copy of the instance
-
toString
-
equals
-
hashCode
public int hashCode()
-