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:
Serializable
,Iterable<VectorEntry>
,ISparseVector
,Vector
Sparse vector
- See Also:
-
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
ConstructorsConstructorDescriptionSparseVector
(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 SparseVectorConstructor 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
Modifier and TypeMethodDescriptionvoid
add
(int index, double value) x(index) += value
void
compact()
Compacts the vectorcopy()
Creates a deep copy of the vectordouble
xT*y
double
get
(int index) Returnsx(index)
double[]
getData()
Returns the internal dataint[]
getIndex()
Returns the indicesint
getUsed()
Number of entries used in the sparse structureiterator()
protected double
norm1()
protected double
norm2()
protected double
protected double
normInf()
scale
(double alpha) x=alpha*x
void
set
(int index, double value) x(index) = value
x=y
zero()
Zeros all the entries in the vector, while preserving any underlying structureMethods inherited from class no.uib.cipr.matrix.AbstractVector
add, add, check, checkSize, norm, set, size, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SparseVector
public SparseVector(int size, int nz) Constructor for SparseVector.- Parameters:
size
- Size of the vectornz
- Initial number of non-zeros
-
SparseVector
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,x
must be aSparseVector
-
SparseVector
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 Details
-
set
public void set(int index, double value) Description copied from interface:Vector
x(index) = value
- Specified by:
set
in interfaceVector
- Overrides:
set
in classAbstractVector
-
add
public void add(int index, double value) Description copied from interface:Vector
x(index) += value
- Specified by:
add
in interfaceVector
- Overrides:
add
in classAbstractVector
-
get
public double get(int index) Description copied from interface:Vector
Returnsx(index)
- Specified by:
get
in interfaceVector
- Overrides:
get
in classAbstractVector
-
copy
Description copied from interface:Vector
Creates a deep copy of the vector- Specified by:
copy
in interfaceVector
- Overrides:
copy
in classAbstractVector
-
zero
Description copied from interface:Vector
Zeros all the entries in the vector, while preserving any underlying structure- Specified by:
zero
in interfaceVector
- Overrides:
zero
in classAbstractVector
-
scale
Description copied from interface:Vector
x=alpha*x
- Specified by:
scale
in interfaceVector
- Overrides:
scale
in classAbstractVector
- Returns:
- x
-
dot
Description copied from interface:Vector
xT*y
- Specified by:
dot
in interfaceVector
- Overrides:
dot
in classAbstractVector
-
norm1
protected double norm1()- Overrides:
norm1
in classAbstractVector
-
norm2
protected double norm2()- Overrides:
norm2
in classAbstractVector
-
norm2_robust
protected double norm2_robust()- Overrides:
norm2_robust
in classAbstractVector
-
normInf
protected double normInf()- Overrides:
normInf
in classAbstractVector
-
getData
public double[] getData()Returns the internal data -
getIndex
public int[] getIndex()Returns the indices- Specified by:
getIndex
in interfaceISparseVector
-
getUsed
public int getUsed()Number of entries used in the sparse structure- Specified by:
getUsed
in interfaceISparseVector
-
compact
public void compact()Compacts the vector -
iterator
- Specified by:
iterator
in interfaceIterable<VectorEntry>
- Overrides:
iterator
in classAbstractVector
-
set
Description copied from interface:Vector
x=y
- Specified by:
set
in interfaceVector
- Overrides:
set
in classAbstractVector
- Returns:
- x
-