Class for a sparse vector. More...
#include <uservector.h>
Classes | |
struct | VectorElement |
The structure of one element form my vector in my list of elements. More... | |
Public Member Functions | |
const VectorElement * | gethead () |
SparseVector (int n=0) | |
(Standard-)Constructor for optional dimension. | |
SparseVector (int n, int i, Type v) | |
Constructor for dimension and one element. | |
SparseVector (int n, int i, int j, Type vi, Type vj) | |
Constructor for dimension and two elements. | |
SparseVector (const SparseVector< Type > &v) | |
Copy-Constructor for a SparseVector. | |
SparseVector (const UserVector< Type > &v) | |
Copy-Constructor for a UserVector. | |
SparseVector (const UserVector< Type > &v, const int low, const int up) | |
Copy-Constructor for a part of a UserVector. | |
SparseVector (const UserVector< Type > &v, const UserVector< int > &block) | |
Copy-Constructor for a UserVector and a block-description. | |
SparseVector (const vector< Pointer< UserVector< Type > > > &v, const vector< DenseVector< int > > &block) | |
Copy-Constructor for a vector of UserVectors and a vector of block-describtions. | |
SparseVector (const Type *v, const int &n) | |
Copy-Constructor for an array of Types. | |
SparseVector (const int &n, const int &nz, const int *indices, const double *elements) | |
Pointer< UserVector< Type > > | getemptycopy (int n) const |
Gives an empty UserVector of this type. | |
Pointer< UserVector< Type > > | getemptycopy () const |
Gives an empty UserVector of this type and dimension. | |
Pointer< UserVector< Type > > | getcopy () const |
Gives a copy of this UserVector. | |
Pointer< UserVector< Type > > | getcopy (const UserVector< int > &block) const |
Gives a Pointer to a copy of one block of this UserVector. | |
~SparseVector () | |
Destructor. | |
int | dim () const |
Gives the dimension. | |
void | resize (const int n) |
Resize this vector. | |
void | SetElement (int i, const Type &v, bool test_for_zero) |
Sets one element of this vector. | |
void | SetElement (const int i, const Type &v) |
Sets one element of this UserVector. | |
void | DelElement (int i) |
Deletes one element of this vector. | |
Type & | operator[] (const int i) |
Gives a reference to one component of this UserVector. | |
Type | operator[] (const int i) const |
Gives one element of this UserVector. | |
Type | operator() (const int i) const |
Gives a copy of one component of this UserVector. | |
UserVector< Type > & | operator= (const UserVector< Type > &v) |
SparseVector< Type > & | operator= (const SparseVector< Type > &v) |
Assign-Operator for a SparseVector. | |
UserVector< Type > & | operator= (const Type &v) |
Assign-Operator for a value from type Type. | |
void | set (const Type *v, int n) |
Assign-Operator for a Type*. | |
void | set (const Type *v) |
Sets this UserVector to the values of v. | |
UserVector< Type > & | AddMult (Type a, const UserVector< Type > &v) |
UserVector< Type > & | operator+= (const UserVector< Type > &v) |
SparseVector< Type > & | AddMult (Type a, const SparseVector< Type > &v) |
Adds a UserVector, multiplied by a Type, to this UserVector. | |
SparseVector< Type > & | operator+= (const SparseVector< Type > &v) |
Adds a SparseVector to this one. | |
UserVector< Type > & | operator-= (const UserVector< Type > &v) |
SparseVector< Type > & | operator-= (const SparseVector< Type > &v) |
Substracts a SparseVector to this one. | |
UserVector< Type > & | operator*= (const Type &v) |
Multiplies all components with a value from type Type. | |
UserVector< Type > & | operator/= (const Type &v) |
Divides all components through a value from type Type. | |
DenseVector< Type > | operator* (const Type &v) const |
Computes the product of this UserVector and a value from type v. | |
bool | operator>= (const Type &v) const |
Compares each element of this UserVector with a value of type Type. | |
bool | operator== (const Type &v) const |
Compares each element of this UserVector with a value of type Type. | |
bool | operator== (const UserVector< Type > &v) const |
Type | operator* (const UserVector< Type > &v) const |
Type | operator* (const SparseVector< Type > &v) const |
Computes the scalar product for this and another SparseVector. | |
SparseVector< Type > | operator+ (const SparseVector< Type > &v) const |
Computes the sum of this SparseVector and another one. | |
SparseVector< Type > | operator- (const SparseVector< Type > &v) const |
Computes the difference of this SparseVector and another one. | |
void | diagmult (SparseVector< Type > y, const SparseVector< Type > &v) const |
Computes the diagonal multiplication of this SparseVector and another one. | |
void | diagmult (UserVector< Type > &y, const UserVector< Type > &v) const |
void | set_block (const UserVector< Type > &v, const UserVector< int > &block) |
operator const Pointer< Type > () const | |
Cast-Operator to a const Pointer of Type. | |
Type | sq_norm2 () const |
Square of 2-Norm. | |
void | print (ostream &out) const |
Prints this UserVector. | |
Static Public Member Functions | |
static Pointer< SparseVector < Type > > | random (const int n, const Type lb, const Type ub) |
Gives a random SparseVector. | |
static Pointer< SparseVector < Type > > | random (const int n, const Type lb, const Type ub, const double sparsity) |
Gives a random SparseVector with specified sparsity. | |
Protected Member Functions | |
VectorElement * | GetElement (const int i, bool create_if_not_exists=true) |
Get an element from this vector. | |
void | clear (VectorElement *v) |
Clears all elements, starting from the next one. | |
Protected Attributes | |
VectorElement * | head |
A pointer to the head of my list of elements, which is no element itselfe. | |
VectorElement * | last |
The last element from my list. | |
int | dim_ |
The dimenion. | |
Friends | |
class | SparseMatrix |
class | IntervalVector |
SparseVector< Type > | operator* (const Type &v1, const SparseVector< Type > &v2) |
Computes the product of a Type and a SparseVector. |
Class for a sparse vector.
The elements are stored in a simple list sorted by the indices.
Definition at line 814 of file uservector.h.
SparseVector< Type >::SparseVector | ( | int | n = 0 |
) | [inline] |
(Standard-)Constructor for optional dimension.
n | The dimension, default is 0. |
Definition at line 922 of file uservector.h.
SparseVector< Type >::SparseVector | ( | int | n, | |
int | i, | |||
Type | v | |||
) | [inline] |
Constructor for dimension and one element.
n | The dimension. | |
i | The index of the element. | |
v | The value of the element. |
Definition at line 933 of file uservector.h.
SparseVector< Type >::SparseVector | ( | int | n, | |
int | i, | |||
int | j, | |||
Type | vi, | |||
Type | vj | |||
) | [inline] |
Constructor for dimension and two elements.
n | The dimension. | |
i | First index. | |
j | Second index. | |
vi | First value. | |
vj | Second value. |
Definition at line 947 of file uservector.h.
SparseVector< Type >::SparseVector | ( | const SparseVector< Type > & | v | ) | [inline] |
Copy-Constructor for a SparseVector.
v | The SparseVector to copy. |
Definition at line 958 of file uservector.h.
SparseVector< Type >::SparseVector | ( | const UserVector< Type > & | v | ) | [inline] |
Copy-Constructor for a UserVector.
v | The UserVector to copy. |
Definition at line 975 of file uservector.h.
SparseVector< Type >::SparseVector | ( | const UserVector< Type > & | v, | |
const int | low, | |||
const int | up | |||
) | [inline] |
Copy-Constructor for a part of a UserVector.
v | The UserVector to copy the part [low,up] from. | |
low | The lower index of the range of elements to copy. | |
up | The upper index. |
Definition at line 995 of file uservector.h.
SparseVector< Type >::SparseVector | ( | const UserVector< Type > & | v, | |
const UserVector< int > & | block | |||
) | [inline] |
Copy-Constructor for a UserVector and a block-description.
v | The UserVector to take one the block from. | |
block | The block-describtion. |
Definition at line 1014 of file uservector.h.
SparseVector< Type >::SparseVector | ( | const vector< Pointer< UserVector< Type > > > & | v, | |
const vector< DenseVector< int > > & | block | |||
) | [inline] |
Copy-Constructor for a vector of UserVectors and a vector of block-describtions.
v | The vector of UserVectors. | |
block | The block-describtion. |
Definition at line 1024 of file uservector.h.
SparseVector< Type >::SparseVector | ( | const Type * | v, | |
const int & | n | |||
) | [inline] |
Copy-Constructor for an array of Types.
v | The array of Types. | |
n | The length of v. |
Definition at line 1037 of file uservector.h.
SparseVector< Type >::SparseVector | ( | const int & | n, | |
const int & | nz, | |||
const int * | indices, | |||
const double * | elements | |||
) | [inline] |
Definition at line 1050 of file uservector.h.
SparseVector< Type >::~SparseVector | ( | ) | [inline] |
Destructor.
Deletes the list by calling clear(head).
Definition at line 1083 of file uservector.h.
static Pointer<SparseVector<Type> > SparseVector< Type >::random | ( | const int | n, | |
const Type | lb, | |||
const Type | ub | |||
) | [inline, static] |
Gives a random SparseVector.
n | The dimension. | |
lb | The lower bound. | |
ub | The upper bound. |
Definition at line 823 of file uservector.h.
static Pointer<SparseVector<Type> > SparseVector< Type >::random | ( | const int | n, | |
const Type | lb, | |||
const Type | ub, | |||
const double | sparsity | |||
) | [inline, static] |
Gives a random SparseVector with specified sparsity.
n | The random DenseVector. | |
lb | The lower bound. | |
ub | The upper bound. | |
sparsity | The sparsity, between 0 and 1. |
Definition at line 835 of file uservector.h.
VectorElement* SparseVector< Type >::GetElement | ( | const int | i, | |
bool | create_if_not_exists = true | |||
) | [inline, protected] |
Get an element from this vector.
Checks first, if it's behind the last element. If not, starts to search for the right place at the beginning.
i | The index of the element to set. | |
create_if_not_exists | If true (default), a new element will be added, when no element i existed. |
Definition at line 874 of file uservector.h.
void SparseVector< Type >::clear | ( | VectorElement * | v | ) | [inline, protected] |
Clears all elements, starting from the next one.
Deletes v->next and all elements, which comes later in this list. Sets last to v.
v | The VectorElement, where to start to delete the next elements. |
Definition at line 909 of file uservector.h.
const VectorElement* SparseVector< Type >::gethead | ( | ) | [inline] |
Definition at line 917 of file uservector.h.
Pointer<UserVector<Type> > SparseVector< Type >::getemptycopy | ( | int | n | ) | const [inline, virtual] |
Gives an empty UserVector of this type.
Abstract.
n | The size of the new UserVector. |
Implements UserVector< Type >.
Definition at line 1063 of file uservector.h.
Pointer<UserVector<Type> > SparseVector< Type >::getemptycopy | ( | ) | const [inline, virtual] |
Gives an empty UserVector of this type and dimension.
Reimplemented from UserVector< Type >.
Definition at line 1067 of file uservector.h.
Pointer<UserVector<Type> > SparseVector< Type >::getcopy | ( | ) | const [inline, virtual] |
Gives a copy of this UserVector.
Reimplemented from UserVector< Type >.
Definition at line 1071 of file uservector.h.
Pointer<UserVector<Type> > SparseVector< Type >::getcopy | ( | const UserVector< int > & | block | ) | const [inline, virtual] |
Gives a Pointer to a copy of one block of this UserVector.
block | The block-describtion. |
Reimplemented from UserVector< Type >.
Definition at line 1075 of file uservector.h.
int SparseVector< Type >::dim | ( | ) | const [inline, virtual] |
Gives the dimension.
Implements UserVector< Type >.
Definition at line 1092 of file uservector.h.
void SparseVector< Type >::resize | ( | const int | n | ) | [inline, virtual] |
Resize this vector.
Deletes all elements with index greater equal n.
n | The new dimension. |
Reimplemented from UserVector< Type >.
Definition at line 1099 of file uservector.h.
void SparseVector< Type >::SetElement | ( | int | i, | |
const Type & | v, | |||
bool | test_for_zero | |||
) | [inline] |
Sets one element of this vector.
If the element isn't existing, it's created. If the element exists and set to zero and test_for_zero is true, it's deleted.
i | The index of the element to set. | |
v | The value to set. | |
test_for_zero | If true, a new element is only created, if it's not zero. |
Definition at line 1118 of file uservector.h.
void SparseVector< Type >::SetElement | ( | const int | i, | |
const Type & | v | |||
) | [inline, virtual] |
Sets one element of this UserVector.
i | The index of the element. | |
v | The value to set. |
Reimplemented from UserVector< Type >.
Definition at line 1126 of file uservector.h.
void SparseVector< Type >::DelElement | ( | int | i | ) | [inline] |
Deletes one element of this vector.
i | The index of the element to delete. |
Definition at line 1131 of file uservector.h.
Type& SparseVector< Type >::operator[] | ( | const int | i | ) | [inline, virtual] |
Gives a reference to one component of this UserVector.
Abstract. Use operator(int), when you want to read a component only!
i | The index of the element. |
Implements UserVector< Type >.
Definition at line 1141 of file uservector.h.
Type SparseVector< Type >::operator[] | ( | const int | i | ) | const [inline, virtual] |
Gives one element of this UserVector.
i | The index of the element. |
Reimplemented from UserVector< Type >.
Definition at line 1145 of file uservector.h.
Type SparseVector< Type >::operator() | ( | const int | i | ) | const [inline, virtual] |
Gives a copy of one component of this UserVector.
Use this one, when you want to read a component only! Abstract
i | The index of the element. |
Implements UserVector< Type >.
Definition at line 1149 of file uservector.h.
UserVector<Type>& SparseVector< Type >::operator= | ( | const UserVector< Type > & | v | ) | [inline] |
Definition at line 1159 of file uservector.h.
SparseVector<Type>& SparseVector< Type >::operator= | ( | const SparseVector< Type > & | v | ) | [inline, virtual] |
Assign-Operator for a SparseVector.
v | The SparseVector to assign. |
Implements UserVector< Type >.
Definition at line 1169 of file uservector.h.
UserVector<Type>& SparseVector< Type >::operator= | ( | const Type & | v | ) | [inline, virtual] |
Assign-Operator for a value from type Type.
Abstract.
v | The value to assign to all elements of this vector. |
Implements UserVector< Type >.
Definition at line 1209 of file uservector.h.
void SparseVector< Type >::set | ( | const Type * | v, | |
int | n | |||
) | [inline, virtual] |
Assign-Operator for a Type*.
v | The Type*. | |
n | The length of v. |
Reimplemented from UserVector< Type >.
Definition at line 1218 of file uservector.h.
void SparseVector< Type >::set | ( | const Type * | v | ) | [inline] |
Sets this UserVector to the values of v.
Be careful with this one. v needs to have the length dim().
v | The Type*. |
Reimplemented from UserVector< Type >.
Definition at line 1231 of file uservector.h.
UserVector<Type>& SparseVector< Type >::AddMult | ( | Type | a, | |
const UserVector< Type > & | v | |||
) | [inline] |
Definition at line 1233 of file uservector.h.
UserVector<Type>& SparseVector< Type >::operator+= | ( | const UserVector< Type > & | v | ) | [inline] |
Definition at line 1270 of file uservector.h.
SparseVector<Type>& SparseVector< Type >::AddMult | ( | Type | a, | |
const SparseVector< Type > & | v | |||
) | [inline, virtual] |
Adds a UserVector, multiplied by a Type, to this UserVector.
a | The Type to multiply v with. | |
v | The UserVector to add, after multiplication with a. |
Reimplemented from UserVector< Type >.
Definition at line 1307 of file uservector.h.
SparseVector<Type>& SparseVector< Type >::operator+= | ( | const SparseVector< Type > & | v | ) | [inline, virtual] |
Adds a SparseVector to this one.
v | The SparseVector to add. |
Implements UserVector< Type >.
Definition at line 1340 of file uservector.h.
UserVector<Type>& SparseVector< Type >::operator-= | ( | const UserVector< Type > & | v | ) | [inline] |
Definition at line 1369 of file uservector.h.
SparseVector<Type>& SparseVector< Type >::operator-= | ( | const SparseVector< Type > & | v | ) | [inline, virtual] |
Substracts a SparseVector to this one.
v | The SparseVector to substract. |
Implements UserVector< Type >.
Definition at line 1409 of file uservector.h.
UserVector<Type>& SparseVector< Type >::operator*= | ( | const Type & | v | ) | [inline, virtual] |
Multiplies all components with a value from type Type.
Abstract.
v | The value to multiply with. |
Implements UserVector< Type >.
Definition at line 1438 of file uservector.h.
UserVector<Type>& SparseVector< Type >::operator/= | ( | const Type & | v | ) | [inline, virtual] |
Divides all components through a value from type Type.
Abstract.
v | The value to divide. |
Implements UserVector< Type >.
Definition at line 1448 of file uservector.h.
DenseVector<Type> SparseVector< Type >::operator* | ( | const Type & | v | ) | const [inline, virtual] |
Computes the product of this UserVector and a value from type v.
v | The value to multiply with. |
Reimplemented from UserVector< Type >.
Definition at line 1453 of file uservector.h.
bool SparseVector< Type >::operator>= | ( | const Type & | v | ) | const [inline, virtual] |
Compares each element of this UserVector with a value of type Type.
v | The value to compare with. |
Reimplemented from UserVector< Type >.
Definition at line 1459 of file uservector.h.
bool SparseVector< Type >::operator== | ( | const Type & | v | ) | const [inline, virtual] |
Compares each element of this UserVector with a value of type Type.
v | The value to compare with. |
Reimplemented from UserVector< Type >.
Definition at line 1465 of file uservector.h.
bool SparseVector< Type >::operator== | ( | const UserVector< Type > & | v | ) | const [inline] |
Definition at line 1472 of file uservector.h.
Type SparseVector< Type >::operator* | ( | const UserVector< Type > & | v | ) | const [inline] |
Definition at line 1489 of file uservector.h.
Type SparseVector< Type >::operator* | ( | const SparseVector< Type > & | v | ) | const [inline, virtual] |
Computes the scalar product for this and another SparseVector.
v | The sparse vector to multiply with. |
Reimplemented from UserVector< Type >.
Definition at line 1501 of file uservector.h.
SparseVector<Type> SparseVector< Type >::operator+ | ( | const SparseVector< Type > & | v | ) | const [inline, virtual] |
Computes the sum of this SparseVector and another one.
v | The SparseVector to add. |
Reimplemented from UserVector< Type >.
Definition at line 1530 of file uservector.h.
SparseVector<Type> SparseVector< Type >::operator- | ( | const SparseVector< Type > & | v | ) | const [inline, virtual] |
Computes the difference of this SparseVector and another one.
v | The SparseVector to substract. |
Reimplemented from UserVector< Type >.
Definition at line 1567 of file uservector.h.
void SparseVector< Type >::diagmult | ( | SparseVector< Type > | y, | |
const SparseVector< Type > & | v | |||
) | const [inline] |
Computes the diagonal multiplication of this SparseVector and another one.
v | The SparseVector to multiply with. |
Definition at line 1610 of file uservector.h.
void SparseVector< Type >::diagmult | ( | UserVector< Type > & | y, | |
const UserVector< Type > & | v | |||
) | const [inline] |
Definition at line 1630 of file uservector.h.
void SparseVector< Type >::set_block | ( | const UserVector< Type > & | v, | |
const UserVector< int > & | block | |||
) | [inline] |
Definition at line 1639 of file uservector.h.
SparseVector< Type >::operator const Pointer< Type > | ( | ) | const [inline, virtual] |
Cast-Operator to a const Pointer of Type.
Implements UserVector< Type >.
Definition at line 1643 of file uservector.h.
Type SparseVector< Type >::sq_norm2 | ( | ) | const [inline, virtual] |
Square of 2-Norm.
Reimplemented from UserVector< Type >.
Definition at line 1654 of file uservector.h.
void SparseVector< Type >::print | ( | ostream & | out | ) | const [inline, virtual] |
Prints this UserVector.
Prints all elements of this UserVector.
out | The ostream to print to. |
Reimplemented from UserVector< Type >.
Definition at line 1660 of file uservector.h.
friend class SparseMatrix [friend] |
Definition at line 815 of file uservector.h.
friend class IntervalVector [friend] |
Definition at line 816 of file uservector.h.
SparseVector<Type> operator* | ( | const Type & | v1, | |
const SparseVector< Type > & | v2 | |||
) | [friend] |
Computes the product of a Type and a SparseVector.
v1 | The first factor as Type. | |
v2 | The second factor as SparseVector. |
Reimplemented from UserVector< Type >.
Definition at line 1519 of file uservector.h.
VectorElement* SparseVector< Type >::head [protected] |
A pointer to the head of my list of elements, which is no element itselfe.
Definition at line 858 of file uservector.h.
VectorElement* SparseVector< Type >::last [protected] |
The last element from my list.
Definition at line 861 of file uservector.h.
int SparseVector< Type >::dim_ [protected] |
The dimenion.
Definition at line 865 of file uservector.h.