CppNoddy
0.92
|
An SparseVector class – a sparse vector object. More...
#include <SparseVector.h>
Public Member Functions | |
SparseVector (const std::size_t &max) | |
Constructor for a non-filled vector, to be filled by the user. More... | |
SparseVector (const SparseVector &source) | |
Copy constructor. More... | |
SparseVector & | operator= (const SparseVector &source) |
Assignment operator. More... | |
iter | begin () |
Not a full iterator implementation – just a pass through to the storage container. More... | |
citer | begin () const |
Not a full iterator implementation – just a pass through to the storage container. More... | |
iter | end () |
Not a full iterator implementation – just a pass through to the storage container. More... | |
citer | end () const |
Not a full iterator implementation – just a pass through to the storage container. More... | |
void | resize (const std::size_t &length) |
Resize the maximum length of the sparse vector. More... | |
void | clear () |
Remove all elements from the sparse vector. More... | |
void | erase (const iter &pos) |
Erase an element from the vector. More... | |
void | erase (const std::size_t &index) |
Erase an element from th vector. More... | |
void | swap (const std::size_t &i, const std::size_t &j) |
Swap elements i and j. More... | |
void | swap (SparseVector< _Type > &X) |
Swap ALL elements with those of another SparseVector. More... | |
std::size_t | size () const |
Find the (max) size of the vector. More... | |
std::size_t | nelts () const |
Find the number of non-zero elements in the vector. More... | |
_Type & | set (const std::size_t &i) |
Set an element of the vector. More... | |
const _Type & | get (const std::size_t &i) const |
Get an element of the vector. More... | |
const _Type & | operator[] (const std::size_t &i) const |
Equivalent to the 'get' method. More... | |
_Type & | operator[] (const std::size_t &i) |
Equivalent to the 'set' method. More... | |
SparseVector< _Type > | operator+ (const SparseVector< _Type > &X) const |
Operator overloading for sparse vector addition. More... | |
SparseVector< _Type > | operator+ () const |
Overloading for +. More... | |
SparseVector< _Type > | operator- (const SparseVector< _Type > &X) const |
Operator overloading for sparse vector subtraction. More... | |
SparseVector< _Type > | operator- () const |
Overloading for -. More... | |
SparseVector< _Type > | operator* (const _Type &m) const |
Overloading multiplication for a scalar. More... | |
SparseVector< _Type > & | operator*= (const _Type &m) |
Overloading *= for scalar multiplication. More... | |
SparseVector< _Type > & | operator-= (const SparseVector< _Type > &X) |
Overloading -= for sparse vectors. More... | |
SparseVector< _Type > & | operator+= (const SparseVector< _Type > &X) |
Overloading += for sparse vectors. More... | |
citer | find (std::size_t i) const |
Look for an element index. More... | |
const _Type | dot (const SparseVector< _Type > &x) const |
A dot product. More... | |
double | one_norm () const |
l1-norm. More... | |
double | two_norm () const |
l2-norm. More... | |
double | inf_norm () const |
Infinity norm. More... | |
void | scale (const _Type &scale) |
Scale each element of the vector. More... | |
void | add (const SparseVector< _Type > &X) |
Add a vector, element wise. More... | |
void | sub (const SparseVector< _Type > &X) |
Subtract a vector, element wise. More... | |
std::size_t | nearest_index (const _Type &value) const |
Find the index of the element NEAREST in value to that specified. More... | |
std::size_t | maxabs_index () const |
Find the index of the maximum element in the vector. More... | |
std::size_t | minabs_index () const |
Find the index of the maximum element in the vector. More... | |
void | dump () const |
Output the sparse vector's contents. More... | |
An SparseVector class – a sparse vector object.
This is templated but intended ONLY for double or std::complex<double>.
Definition at line 20 of file SparseVector.h.
|
explicit |
Constructor for a non-filled vector, to be filled by the user.
max | A maximum size for the sparse vector, used in geometry checking. |
Definition at line 18 of file SparseVector.cpp.
CppNoddy::SparseVector< _Type >::SparseVector | ( | const SparseVector< _Type > & | source | ) |
Copy constructor.
source | The source object to be copied |
Definition at line 22 of file SparseVector.cpp.
void CppNoddy::SparseVector< _Type >::add | ( | const SparseVector< _Type > & | X | ) |
Add a vector, element wise.
X | The vector to be added to this object. |
Definition at line 249 of file SparseVector.cpp.
|
inline |
Not a full iterator implementation – just a pass through to the storage container.
Return an iterator pointing to the beginning of the encpsulated STL map storage
Definition at line 240 of file SparseVector.h.
|
inline |
Not a full iterator implementation – just a pass through to the storage container.
Return a constant iterator pointing to the beginning of the encapsulated STL map storage
Definition at line 245 of file SparseVector.h.
void CppNoddy::SparseVector< _Type >::clear |
Remove all elements from the sparse vector.
Definition at line 181 of file SparseVector.cpp.
const _Type CppNoddy::SparseVector< _Type >::dot | ( | const SparseVector< _Type > & | x | ) | const |
A dot product.
x | The vector to be "dotted" with. |
Definition at line 186 of file SparseVector.cpp.
References CppNoddy::SparseVector< _Type >::size().
void CppNoddy::SparseVector< _Type >::dump |
Output the sparse vector's contents.
Definition at line 317 of file SparseVector.cpp.
|
inline |
Not a full iterator implementation – just a pass through to the storage container.
Return an iterator pointing to the end of the encapsulated STL map storage
Definition at line 250 of file SparseVector.h.
|
inline |
Not a full iterator implementation – just a pass through to the storage container.
Return a constant iterator pointing to the end of the encapsulated STL map storage
Definition at line 255 of file SparseVector.h.
|
inline |
Erase an element from the vector.
pos | An std::map< std::size_t, _Type >::iterator to the map element |
Definition at line 333 of file SparseVector.h.
|
inline |
Erase an element from th vector.
index | The index of the element to be erased |
Definition at line 328 of file SparseVector.h.
|
inline |
Look for an element index.
i | The index of the element to search for |
Definition at line 151 of file SparseVector.h.
|
inline |
Get an element of the vector.
i | The index to be accessed |
Definition at line 299 of file SparseVector.h.
double CppNoddy::SparseVector< _Type >::inf_norm |
Infinity norm.
Definition at line 230 of file SparseVector.cpp.
std::size_t CppNoddy::SparseVector< _Type >::maxabs_index |
Find the index of the maximum element in the vector.
Definition at line 275 of file SparseVector.cpp.
std::size_t CppNoddy::SparseVector< _Type >::minabs_index |
Find the index of the maximum element in the vector.
Definition at line 289 of file SparseVector.cpp.
std::size_t CppNoddy::SparseVector< _Type >::nearest_index | ( | const _Type & | value | ) | const |
Find the index of the element NEAREST in value to that specified.
value | The value to search for. |
Definition at line 260 of file SparseVector.cpp.
|
inline |
Find the number of non-zero elements in the vector.
Definition at line 323 of file SparseVector.h.
double CppNoddy::SparseVector< _Type >::one_norm |
l1-norm.
Definition at line 208 of file SparseVector.cpp.
Referenced by main().
SparseVector< _Type > CppNoddy::SparseVector< _Type >::operator* | ( | const _Type & | m | ) | const |
Overloading multiplication for a scalar.
m | The scalar to multiply by |
Definition at line 168 of file SparseVector.cpp.
References m.
SparseVector< _Type > & CppNoddy::SparseVector< _Type >::operator*= | ( | const _Type & | m | ) |
Overloading *= for scalar multiplication.
m | The scalar to multiply by |
Definition at line 37 of file SparseVector.cpp.
References m.
|
inline |
Overloading for +.
Definition at line 351 of file SparseVector.h.
SparseVector< _Type > CppNoddy::SparseVector< _Type >::operator+ | ( | const SparseVector< _Type > & | X | ) | const |
Operator overloading for sparse vector addition.
X | A sparse vector to be added |
Definition at line 131 of file SparseVector.cpp.
References CppNoddy::SparseVector< _Type >::size().
SparseVector< _Type > & CppNoddy::SparseVector< _Type >::operator+= | ( | const SparseVector< _Type > & | X | ) |
Overloading += for sparse vectors.
X | The sparse vector to be added |
Definition at line 88 of file SparseVector.cpp.
References CppNoddy::SparseVector< _Type >::size().
SparseVector< _Type > CppNoddy::SparseVector< _Type >::operator- |
Overloading for -.
Definition at line 161 of file SparseVector.cpp.
SparseVector< _Type > CppNoddy::SparseVector< _Type >::operator- | ( | const SparseVector< _Type > & | X | ) | const |
Operator overloading for sparse vector subtraction.
X | A sparse vector to be subtracted |
Definition at line 146 of file SparseVector.cpp.
References CppNoddy::SparseVector< _Type >::size().
SparseVector< _Type > & CppNoddy::SparseVector< _Type >::operator-= | ( | const SparseVector< _Type > & | X | ) |
Overloading -= for sparse vectors.
X | The sparse vector to be subtracted |
Definition at line 45 of file SparseVector.cpp.
References CppNoddy::SparseVector< _Type >::size().
SparseVector< _Type > & CppNoddy::SparseVector< _Type >::operator= | ( | const SparseVector< _Type > & | source | ) |
Assignment operator.
source | The source object for the assignment |
Definition at line 27 of file SparseVector.cpp.
|
inline |
Equivalent to the 'set' method.
Definition at line 260 of file SparseVector.h.
|
inline |
Equivalent to the 'get' method.
Definition at line 273 of file SparseVector.h.
void CppNoddy::SparseVector< _Type >::resize | ( | const std::size_t & | length | ) |
Resize the maximum length of the sparse vector.
The maximum length is used in geometry checking.
length | The new maximum length of the vector |
Definition at line 176 of file SparseVector.cpp.
void CppNoddy::SparseVector< _Type >::scale | ( | const _Type & | scale | ) |
Scale each element of the vector.
scale | The value to scale each element by. |
Definition at line 242 of file SparseVector.cpp.
|
inline |
Set an element of the vector.
i | The index to be accessed |
Definition at line 286 of file SparseVector.h.
|
inline |
Find the (max) size of the vector.
Definition at line 318 of file SparseVector.h.
Referenced by CppNoddy::SparseVector< _Type >::dot(), CppNoddy::SparseVector< _Type >::operator+(), CppNoddy::SparseVector< _Type >::operator+=(), CppNoddy::SparseVector< _Type >::operator-(), CppNoddy::SparseVector< _Type >::operator-=(), and CppNoddy::SparseVector< _Type >::swap().
void CppNoddy::SparseVector< _Type >::sub | ( | const SparseVector< _Type > & | X | ) |
Subtract a vector, element wise.
X | The vector to be subtracted from this object. |
Definition at line 255 of file SparseVector.cpp.
void CppNoddy::SparseVector< _Type >::swap | ( | const std::size_t & | i, |
const std::size_t & | j | ||
) |
Swap elements i and j.
i | The index of the element to swap. |
j | The index of the other element to swap. |
Definition at line 303 of file SparseVector.cpp.
|
inline |
Swap ALL elements with those of another SparseVector.
X | The sparse vector to exchange with |
Definition at line 338 of file SparseVector.h.
References CppNoddy::SparseVector< _Type >::size().
double CppNoddy::SparseVector< _Type >::two_norm |
l2-norm.
No attention paid to possible overflow for large vectors.
Definition at line 219 of file SparseVector.cpp.
© 2012
R.E. Hewitt