public class ImmutableVector extends java.lang.Object implements Vector
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
IsVector.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 and Description |
|---|
ImmutableVector(Vector v)
Construct a read-only version of a vector.
|
| Modifier and Type | Method and Description |
|---|---|
Vector |
add(double scalar)
Add a constant to all entries in this vector.
|
Vector |
add(Vector that)
\(this + that\)
|
double |
angle(Vector that)
Measure the angle, \(\theta\), between
this and that. |
ImmutableVector |
deepCopy()
The implementation returns an instance created from
this by the copy
constructor of the class, or just this if the instance itself is
immutable. |
Vector |
divide(Vector that)
Divide
this by that, entry-by-entry. |
boolean |
equals(java.lang.Object obj) |
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.
|
Vector |
minus(double scalar)
Subtract a constant from all entries in this vector.
|
Vector |
minus(Vector that)
\(this - that\)
|
Vector |
multiply(Vector that)
Multiply
this by that, entry-by-entry. |
double |
norm()
Compute the length or magnitude or Euclidean norm of a vector, namely, \(\|v\|\).
|
double |
norm(int p)
Get the norm of a vector.
|
Vector |
opposite()
Get the opposite of this vector.
|
Vector |
pow(double scalar)
Take the exponentiation of all entries in this vector, entry-by-entry.
|
Vector |
scaled(double scalar)
Scale this vector by a constant, entry-by-entry.
|
Vector |
scaled(Real scalar)
Scale this vector by a constant, entry-by-entry.
|
void |
set(int i,
double value)
This method is overridden to always throw
VectorAccessException. |
int |
size()
Get the length of this vector.
|
double[] |
toArray()
Cast this vector into a 1D
double[]. |
java.lang.String |
toString() |
Vector |
ZERO()
Get a 0-vector that has the same length as this vector.
|
public ImmutableVector(Vector v)
v - a vectorpublic final void set(int i,
double value)
VectorAccessException.set in interface Vectori - the index of the entry to change. The indices are counting from 1, NOT 0.value - the value to change toIsVector.VectorAccessException - alwayspublic int size()
Vectorpublic double get(int index)
Vectorpublic Vector add(Vector that)
Vectoradd in interface AbelianGroup<Vector>add in interface Vectorthat - a vectorpublic Vector minus(Vector that)
Vectorminus in interface AbelianGroup<Vector>minus in interface Vectorthat - a vectorpublic Vector multiply(Vector that)
Vectorthis by that, entry-by-entry.public Vector divide(Vector that)
Vectorthis by that, entry-by-entry.public Vector add(double scalar)
Vectorpublic Vector minus(double scalar)
Vectorpublic double innerProduct(Vector that)
VectorinnerProduct in interface HilbertSpace<Vector,Real>innerProduct in interface Vectorthat - a vectorpublic Vector pow(double scalar)
Vectorpublic Vector scaled(double scalar)
Vector
vector.scaled(1. / vector.norm())
public Vector scaled(Real scalar)
Vector
vector.scaled(1. / vector.norm())
scaled in interface VectorSpace<Vector,Real>scaled in interface Vectorscalar - a constantpublic double norm()
Vectornorm in interface BanachSpace<Vector,Real>norm in interface Vectorpublic double norm(int p)
Vectorpublic double angle(Vector that)
Vectorthis and that.
That is,
\[
this \cdot that = \|this\| \times \|that\| \times \cos \theta
\]public Vector opposite()
Vectoropposite in interface AbelianGroup<Vector>opposite in interface Vectorpublic Vector ZERO()
VectorZERO in interface AbelianGroup<Vector>ZERO in interface Vectorpublic double[] toArray()
Vectordouble[].public ImmutableVector deepCopy()
DeepCopyablethis by the copy
constructor of the class, or just this if the instance itself is
immutable.deepCopy in interface DeepCopyabledeepCopy in interface Vectorpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object