public interface Vector extends Iterable<VectorEntry>, Serializable
double
s in an array, and is
used alongside Matrix
in numerical computations. Implementing
classes decides on the actual storage.
Use size
to get the vector size. get(int)
gets
an element, and there are corresponding set(int,double)
and
add(int,double)
methods as well. Note that vector indices are
zero-based (typical for Java and C). This means that they range from 0 to
size-1
. It is legal to have size
equal zero.
Other basic operations are zero
which zeros all the entries of
the vector, which can be cheaper than either zeroing the vector manually, or
creating a new vector, and the operation copy
which creates a
deep copy of the vector. This copy has separate storage, but starts with the
same contents as the current vector.
The vector interface extends Iterable
, and the iterator
returns a VectorEntry
which contains current index and entry
value. Note that the iterator may skip non-zero entries. Using an iterator,
many simple and efficient algorithms can be created. The iterator also
permits changing values in the vector, however only non-zero entries can be
changed.
A selection of basic linear algebra operations are available. To ensure high efficiency, little or no internal memory allocation is done, and the user is required to supply the output arguments.
The operations available include:
Modifier and Type | Interface and Description |
---|---|
static class |
Vector.Norm
Supported vector-norms.
|
Modifier and Type | Method and Description |
---|---|
Vector |
add(double alpha,
Vector y)
x = alpha*y + x |
void |
add(int index,
double value)
x(index) += value |
Vector |
add(Vector y)
x = y + x |
Vector |
copy()
Creates a deep copy of the vector
|
double |
dot(Vector y)
xT*y |
double |
get(int index)
Returns
x(index) |
double |
norm(Vector.Norm type)
Computes the given norm of the vector
|
Vector |
scale(double alpha)
x=alpha*x |
Vector |
set(double alpha,
Vector y)
x=alpha*y |
void |
set(int index,
double value)
x(index) = value |
Vector |
set(Vector y)
x=y |
int |
size()
Size of the vector
|
Vector |
zero()
Zeros all the entries in the vector, while preserving any underlying
structure
|
int size()
void set(int index, double value)
x(index) = value
void add(int index, double value)
x(index) += value
double get(int index)
x(index)
Vector copy()
Vector zero()
Vector scale(double alpha)
x=alpha*x
double dot(Vector y)
xT*y
double norm(Vector.Norm type)
type
- The type of norm to computeCopyright © 2013. All Rights Reserved.