Interface Vector
-
- All Superinterfaces:
java.lang.Iterable<VectorEntry>
,java.io.Serializable
- All Known Subinterfaces:
ISparseVector
- All Known Implementing Classes:
AbstractVector
,DenseVector
,DistVector
,SparseVector
public interface Vector extends java.lang.Iterable<VectorEntry>, java.io.Serializable
Basic vector interface. It holdsdouble
s in an array, and is used alongsideMatrix
in numerical computations. Implementing classes decides on the actual storage.Basic operations
Use
size
to get the vector size.get(int)
gets an element, and there are correspondingset(int,double)
andadd(int,double)
methods as well. Note that vector indices are zero-based (typical for Java and C). This means that they range from 0 tosize-1
. It is legal to havesize
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 operationcopy
which creates a deep copy of the vector. This copy has separate storage, but starts with the same contents as the current vector.Iterators
The vector interface extends
Iterable
, and the iterator returns aVectorEntry
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.Basic linear algebra
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:
- Additions
- Vectors can be added to each other, even if their underlying vector structures are incompatible
- Scaling
- Scalar multiplication (scaling) of a whole vector
- Norms
- Both innerproducts and norms can be computed. Several common norms are supported
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Vector.Norm
Supported vector-norms.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method 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 vectordouble
dot(Vector y)
xT*y
double
get(int index)
Returnsx(index)
double
norm(Vector.Norm type)
Computes the given norm of the vectorVector
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 vectorVector
zero()
Zeros all the entries in the vector, while preserving any underlying structure
-
-
-
Method Detail
-
size
int size()
Size of the vector
-
set
void set(int index, double value)
x(index) = value
-
add
void add(int index, double value)
x(index) += value
-
get
double get(int index)
Returnsx(index)
-
copy
Vector copy()
Creates a deep copy of the vector
-
zero
Vector zero()
Zeros all the entries in the vector, while preserving any underlying structure
-
scale
Vector scale(double alpha)
x=alpha*x
- Returns:
- x
-
dot
double dot(Vector y)
xT*y
-
norm
double norm(Vector.Norm type)
Computes the given norm of the vector- Parameters:
type
- The type of norm to compute
-
-