Package no.uib.cipr.matrix.sparse
Class SparseVector
- java.lang.Object
-
- no.uib.cipr.matrix.AbstractVector
-
- no.uib.cipr.matrix.sparse.SparseVector
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<VectorEntry>,ISparseVector,Vector
public class SparseVector extends AbstractVector implements ISparseVector
Sparse vector- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface no.uib.cipr.matrix.Vector
Vector.Norm
-
-
Field Summary
-
Fields inherited from class no.uib.cipr.matrix.AbstractVector
size
-
-
Constructor Summary
Constructors Constructor Description SparseVector(int size)Constructor for SparseVector.SparseVector(int size, int nz)Constructor for SparseVector.SparseVector(int size, int[] index, double[] data)Constructor for SparseVectorSparseVector(int size, int[] index, double[] data, boolean deep)Constructor for SparseVectorSparseVector(Vector x)Constructor for SparseVector, and copies the contents from the supplied vector.SparseVector(Vector x, boolean deep)Constructor for SparseVector, and copies the contents from the supplied vector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, double value)x(index) += valuevoidcompact()Compacts the vectorSparseVectorcopy()Creates a deep copy of the vectordoubledot(Vector y)xT*ydoubleget(int index)Returnsx(index)double[]getData()Returns the internal dataint[]getIndex()Returns the indicesintgetUsed()Number of entries used in the sparse structurejava.util.Iterator<VectorEntry>iterator()protected doublenorm1()protected doublenorm2()protected doublenorm2_robust()protected doublenormInf()SparseVectorscale(double alpha)x=alpha*xvoidset(int index, double value)x(index) = valueVectorset(Vector y)x=ySparseVectorzero()Zeros all the entries in the vector, while preserving any underlying structure-
Methods inherited from class no.uib.cipr.matrix.AbstractVector
add, add, check, checkSize, norm, set, size, toString
-
-
-
-
Constructor Detail
-
SparseVector
public SparseVector(int size, int nz)Constructor for SparseVector.- Parameters:
size- Size of the vectornz- Initial number of non-zeros
-
SparseVector
public SparseVector(Vector x, boolean deep)
Constructor for SparseVector, and copies the contents from the supplied vector.- Parameters:
x- Vector to copy fromdeep- True if a deep copy is to be made. If the copy is shallow,xmust be aSparseVector
-
SparseVector
public SparseVector(Vector x)
Constructor for SparseVector, and copies the contents from the supplied vector. Zero initial pre-allocation- Parameters:
x- Vector to copy from. A deep copy is made
-
SparseVector
public SparseVector(int size)
Constructor for SparseVector. Zero initial pre-allocation- Parameters:
size- Size of the vector
-
SparseVector
public SparseVector(int size, int[] index, double[] data, boolean deep)Constructor for SparseVector- Parameters:
size- Size of the vectorindex- Indices of the vectordata- Entries of the vectordeep- True for a deep copy. For shallow copies, the given indices will be used internally
-
SparseVector
public SparseVector(int size, int[] index, double[] data)Constructor for SparseVector- Parameters:
size- Size of the vectorindex- The vector indices are copies from this arraydata- The vector entries are copies from this array
-
-
Method Detail
-
set
public void set(int index, double value)Description copied from interface:Vectorx(index) = value- Specified by:
setin interfaceVector- Overrides:
setin classAbstractVector
-
add
public void add(int index, double value)Description copied from interface:Vectorx(index) += value- Specified by:
addin interfaceVector- Overrides:
addin classAbstractVector
-
get
public double get(int index)
Description copied from interface:VectorReturnsx(index)- Specified by:
getin interfaceVector- Overrides:
getin classAbstractVector
-
copy
public SparseVector copy()
Description copied from interface:VectorCreates a deep copy of the vector- Specified by:
copyin interfaceVector- Overrides:
copyin classAbstractVector
-
zero
public SparseVector zero()
Description copied from interface:VectorZeros all the entries in the vector, while preserving any underlying structure- Specified by:
zeroin interfaceVector- Overrides:
zeroin classAbstractVector
-
scale
public SparseVector scale(double alpha)
Description copied from interface:Vectorx=alpha*x- Specified by:
scalein interfaceVector- Overrides:
scalein classAbstractVector- Returns:
- x
-
dot
public double dot(Vector y)
Description copied from interface:VectorxT*y- Specified by:
dotin interfaceVector- Overrides:
dotin classAbstractVector
-
norm1
protected double norm1()
- Overrides:
norm1in classAbstractVector
-
norm2
protected double norm2()
- Overrides:
norm2in classAbstractVector
-
norm2_robust
protected double norm2_robust()
- Overrides:
norm2_robustin classAbstractVector
-
normInf
protected double normInf()
- Overrides:
normInfin classAbstractVector
-
getData
public double[] getData()
Returns the internal data
-
getIndex
public int[] getIndex()
Returns the indices- Specified by:
getIndexin interfaceISparseVector
-
getUsed
public int getUsed()
Number of entries used in the sparse structure- Specified by:
getUsedin interfaceISparseVector
-
compact
public void compact()
Compacts the vector
-
iterator
public java.util.Iterator<VectorEntry> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<VectorEntry>- Overrides:
iteratorin classAbstractVector
-
-