Package no.uib.cipr.matrix
Class AbstractVector
- java.lang.Object
-
- no.uib.cipr.matrix.AbstractVector
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<VectorEntry>
,Vector
- Direct Known Subclasses:
DenseVector
,DistVector
,SparseVector
public abstract class AbstractVector extends java.lang.Object implements Vector, java.io.Serializable
Partial implementation ofVector
. The following methods throwUnsupportedOperationException
, and should be overridden by a subclass:get(int)
set(int,double)
copy
For the rest of the methods, simple default implementations using a vector iterator has been provided. There are some kernel operations which the simpler operations forward to, and they are:
-
add(double,Vector)
andset(double,Vector)
. -
scale(double)
. dot(Vector)
and all the norms.
Finally, a default iterator is provided by this class, which works by calling the
get
function. A tailored replacement should be used by subclasses.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface no.uib.cipr.matrix.Vector
Vector.Norm
-
-
Field Summary
Fields Modifier and Type Field Description protected int
size
Size of the vector
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractVector(int size)
Constructor for AbstractVector.protected
AbstractVector(Vector x)
Constructor for AbstractVector, same size as x
-
Method Summary
All Methods Instance Methods Concrete 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
protected void
check(int index)
Checks the indexprotected void
checkSize(Vector y)
Checks for conformant sizesVector
copy()
Creates a deep copy of the vectordouble
dot(Vector y)
xT*y
double
get(int index)
Returnsx(index)
java.util.Iterator<VectorEntry>
iterator()
double
norm(Vector.Norm type)
Computes the given norm of the vectorprotected double
norm1()
protected double
norm2()
protected double
norm2_robust()
protected double
normInf()
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 vectorjava.lang.String
toString()
Vector
zero()
Zeros all the entries in the vector, while preserving any underlying structure
-
-
-
Constructor Detail
-
AbstractVector
protected AbstractVector(int size)
Constructor for AbstractVector.- Parameters:
size
- Size of the vector
-
AbstractVector
protected AbstractVector(Vector x)
Constructor for AbstractVector, same size as x- Parameters:
x
- Vector to get the size from
-
-
Method Detail
-
size
public int size()
Description copied from interface:Vector
Size of the vector
-
set
public void set(int index, double value)
Description copied from interface:Vector
x(index) = value
-
add
public void add(int index, double value)
Description copied from interface:Vector
x(index) += value
-
get
public double get(int index)
Description copied from interface:Vector
Returnsx(index)
-
copy
public Vector copy()
Description copied from interface:Vector
Creates a deep copy of the vector
-
check
protected void check(int index)
Checks the index
-
zero
public Vector zero()
Description copied from interface:Vector
Zeros all the entries in the vector, while preserving any underlying structure
-
add
public Vector add(double alpha, Vector y)
Description copied from interface:Vector
x = alpha*y + x
-
checkSize
protected void checkSize(Vector y)
Checks for conformant sizes
-
norm
public double norm(Vector.Norm type)
Description copied from interface:Vector
Computes the given norm of the vector
-
norm1
protected double norm1()
-
norm2
protected double norm2()
-
norm2_robust
protected double norm2_robust()
-
normInf
protected double normInf()
-
iterator
public java.util.Iterator<VectorEntry> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<VectorEntry>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-