AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects
Version of the Day
|
Sparse Vector class template. More...
#include <AbstractLinAlgPack_SparseVectorClassDecl.hpp>
Public Member Functions | |
SparseVector< T_Element, T_Alloc > & | operator= (const SparseVector< T_Element, T_Alloc > &sp_vec) |
Assignment operator. More... | |
SparseVector< T_Element, T_Alloc > & | operator= (const SparseVectorSlice< T_Element > &sp_vec_slc) |
Assignment operator. More... | |
EOverLap | overlap (const SparseVectorSlice< T_Element > &sv) const |
Public Types. | |
typedef T_Alloc | allocator_type |
typedef T_Element | element_type |
typedef AbstractLinAlgPack::size_type | size_type |
typedef ptrdiff_t | difference_type |
typedef element_type * | iterator |
typedef const element_type * | const_iterator |
typedef std::reverse_iterator < iterator > | reverse_iterator |
typedef std::reverse_iterator < const_iterator > | const_reverse_iterator |
typedef SparseVectorUtilityPack::DoesNotExistException | DoesNotExistException |
typedef SparseVectorUtilityPack::NotSortedException | NotSortedException |
typedef SparseVectorUtilityPack::DuplicateIndexesException | DuplicateIndexesException |
typedef SparseVectorUtilityPack::OutOfRoomException | OutOfRoomException |
typedef SparseVectorUtilityPack::UnsizedException | UnsizedException |
typedef SparseVectorUtilityPack::NoNonZeroElementsException | NoNonZeroElementsException |
Constuctors | |
SparseVector (const allocator_type &alloc=allocator_type()) | |
Constructs a sparse vector with no elements (nz() == dim() == 0#) and assumes the elements are not sorted. More... | |
SparseVector (bool assume_sorted, const allocator_type &alloc=allocator_type()) | |
Constructs a sparse vector with no elements (nz() == dim() == 0#). More... | |
SparseVector (size_type size, size_type max_nz, difference_type offset=0, bool assume_sorted=false, const allocator_type &alloc=allocator_type()) | |
Constructs a sparse vector of size #size# with storage for max_nz# elements (nz() == 0#) More... | |
SparseVector (const SparseVector< T_Element, T_Alloc > &sp_vec) | |
Constructs a sparse vector from another sparse vector. More... | |
SparseVector (SparseVectorSlice< T_Element > sp_vec_slc, const allocator_type &alloc=allocator_type()) | |
Constructs a sparse vector of from a sparse vector slice. More... | |
~SparseVector () | |
Destructor (frees storage for elements). More... | |
SparseVectorTemplateInterface for linear algebra operations | |
size_type | dim () const |
Return the number of elements in the full vector. More... | |
size_type | nz () const |
Return the number of non-zero elements. More... | |
difference_type | offset () const |
Return the offset for the indexes (ith real index = begin()[i-1]->index() + offset()# , for i = 1,,,nz()#) More... | |
bool | is_sorted () const |
Return true if the sequence is sorted. More... | |
Iterator access to elements. | |
These functions return random access iterators that yield SparseElementTemplateInterface objects when dereferenced. This is required for the template argument. | |
iterator | begin () |
Returns iterator that iterates forward through the nonzero elements. More... | |
const_iterator | begin () const |
iterator | end () |
const_iterator | end () const |
reverse_iterator | rbegin () |
Returns iterator that iterates backward through the nonzero elements. More... | |
const_reverse_iterator | rbegin () const |
reverse_iterator | rend () |
const_reverse_iterator | rend () const |
Element setup and modification | |
void | resize (size_type size, size_type max_nz, difference_type offset=0) |
Resize to #size# with a maximum of max_nz# non-zero elements. More... | |
void | uninitialized_resize (size_type size, size_type nz, size_type max_nz, difference_type offset=0) |
Resize to #size# with a max_nz# uninitialized non-zero elements. More... | |
size_type | max_nz () const |
Return the max number of elements that can be held without resizing. More... | |
void | add_element (element_type ele) |
Add an unsorted element. More... | |
void | insert_element (element_type ele) |
Add an element into a sorted sequence. More... | |
void | assume_sorted (bool assume_is_sorted) |
Called by the client to inform this sparse vector object that the elements be assumed to be in sequence and it is the clients responcibiliy to make sure that it is. More... | |
void | sort () |
Sort the elements into assending order by index. More... | |
void | assert_valid_and_sorted () const |
Assert that sparse vector is sorted. More... | |
Lookup an element. | |
If element v(i) exists, then a pointer to the element will be returned. If v(i) does not exist, then the NULL pointer will be returned. If i is out of range then a std::out_of_range exception will be thrown. If the elements are sored then this operation is O(log(nz)) for a binary search. Otherwise, it requries a O(nz) linear search. | |
element_type * | lookup_element (size_type i) |
const element_type * | lookup_element (size_type i) const |
Creating a slice (subregion) of the sparse vector. | |
If the vector is not sorted (is_sorted() == false#) then all of these functions will throw an exception (NotSortedException#). ** Say something about the cost of these operations! ** | |
operator SparseVectorSlice< T_Element > () | |
Allow an implicit conversion to a SparseVectorSlice<> object. More... | |
operator const SparseVectorSlice< T_Element > () const | |
SparseVectorSlice< T_Element > | operator() () |
Returns a SparseVectorSlice representing the entire sparse vector. More... | |
const SparseVectorSlice < T_Element > | operator() () const |
SparseVectorSlice< T_Element > | operator() (const Range1D &rng) |
const SparseVectorSlice < T_Element > | operator() (const Range1D &rng) const |
SparseVectorSlice< T_Element > | operator() (size_type lbound, size_type ubound) |
const SparseVectorSlice < T_Element > | operator() (size_type lbound, size_type ubound) const |
Same as above. More... | |
Sparse Vector class template.
This is a class for abstracting a sparse vector of a templated element type. All of the operations are based on the element type. Access to the elements is provided by iterators. It is also templated by an allocator that is that is used to allocate memory for the nonzero elements.
The templated type T_Element must support the following interface (SparseElementTemplateInterface): {description} [value_type] public typedef for the stored value of the element [index_type] public typedef for the stored index of the element [value_type& value()] function returning a lvalue for the value of the element [value_type value() const] const function returning a rvalue for the value of the element [index_type index() const] const function returning a rvalue for the index of the element. [T_Element& operator=(const T_Element&)] assignment operator [T_Element(const T_Element&)] copy constructor {description}
Definition at line 127 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef T_Alloc AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::allocator_type |
Definition at line 133 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef T_Element AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::element_type |
Definition at line 135 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef AbstractLinAlgPack::size_type AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::size_type |
Definition at line 137 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef ptrdiff_t AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::difference_type |
Definition at line 139 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef element_type* AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::iterator |
Definition at line 141 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef const element_type* AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::const_iterator |
Definition at line 143 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef std::reverse_iterator<iterator> AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::reverse_iterator |
Definition at line 157 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef std::reverse_iterator<const_iterator> AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::const_reverse_iterator |
Definition at line 159 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef SparseVectorUtilityPack::DoesNotExistException AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::DoesNotExistException |
Definition at line 164 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef SparseVectorUtilityPack::NotSortedException AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::NotSortedException |
Definition at line 166 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef SparseVectorUtilityPack::DuplicateIndexesException AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::DuplicateIndexesException |
Definition at line 168 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef SparseVectorUtilityPack::OutOfRoomException AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::OutOfRoomException |
Definition at line 170 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef SparseVectorUtilityPack::UnsizedException AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::UnsizedException |
Definition at line 172 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
typedef SparseVectorUtilityPack::NoNonZeroElementsException AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::NoNonZeroElementsException |
Definition at line 174 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Constructs a sparse vector with no elements (nz() == dim() == 0#) and assumes the elements are not sorted.
Definition at line 838 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Constructs a sparse vector with no elements (nz() == dim() == 0#).
Definition at line 843 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Constructs a sparse vector of size #size# with storage for max_nz# elements (nz() == 0#)
Definition at line 848 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::SparseVector | ( | const SparseVector< T_Element, T_Alloc > & | sp_vec | ) |
Constructs a sparse vector from another sparse vector.
Copies the complete state including the same max_nz() but a fresh copy of the elements are made.
Definition at line 103 of file AbstractLinAlgPack_SparseVectorClassDef.hpp.
AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::SparseVector | ( | SparseVectorSlice< T_Element > | sp_vec_slc, |
const allocator_type & | alloc = allocator_type() |
||
) |
Constructs a sparse vector of from a sparse vector slice.
Definition at line 131 of file AbstractLinAlgPack_SparseVectorClassDef.hpp.
|
inline |
Destructor (frees storage for elements).
Definition at line 856 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
SparseVector< T_Element, T_Alloc > & AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::operator= | ( | const SparseVector< T_Element, T_Alloc > & | sp_vec | ) |
Assignment operator.
If max_nz() > sp_vec.nz()# then no new allocation takes place otherwise #this# will will be resized to #sp_vec.nz()#.
Definition at line 162 of file AbstractLinAlgPack_SparseVectorClassDef.hpp.
SparseVector< T_Element, T_Alloc > & AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::operator= | ( | const SparseVectorSlice< T_Element > & | sp_vec_slc | ) |
Assignment operator.
If max_nz() > sp_vec_slc.nz()# then no new allocation takes place otherwise #this# will will be resized to #sp_vec_slc.nz()#.
Definition at line 210 of file AbstractLinAlgPack_SparseVectorClassDef.hpp.
EOverLap AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::overlap | ( | const SparseVectorSlice< T_Element > & | sv | ) | const |
Returns the degree of memory overlap of this SparseVector and a SparseVectorSlice.
Definition at line 256 of file AbstractLinAlgPack_SparseVectorClassDef.hpp.
|
inline |
Return the number of elements in the full vector.
Definition at line 863 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Return the number of non-zero elements.
Definition at line 868 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Return the offset for the indexes (ith real index = begin()[i-1]->index() + offset()# , for i = 1,,,nz()#)
Definition at line 873 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Return true if the sequence is sorted.
If sorted() was called prior to this then it is garrented to be sorted and if assume_sorted(true) was called then a client is assumed to be responcible for it being sorted by it can not be garrented to be sorted.
Definition at line 878 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Returns iterator that iterates forward through the nonzero elements.
If is_sorted() == true# then the elements will be forward iterated in accending indexes.
Definition at line 883 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Definition at line 888 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Definition at line 898 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Returns iterator that iterates backward through the nonzero elements.
If is_sorted() == true# then the elements will be forward iterated in deaccending indexes.
Definition at line 903 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Definition at line 908 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Definition at line 918 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
void AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::resize | ( | size_type | size, |
size_type | max_nz, | ||
difference_type | offset = 0 |
||
) |
Resize to #size# with a maximum of max_nz# non-zero elements.
This does not preserve the existing elements already in the sparse vector. If you pass in #size == 0# or max_nz == 0# then the storage will be deallocated and no storage will be reallocated.
Definition at line 278 of file AbstractLinAlgPack_SparseVectorClassDef.hpp.
void AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::uninitialized_resize | ( | size_type | size, |
size_type | nz, | ||
size_type | max_nz, | ||
difference_type | offset = 0 |
||
) |
Resize to #size# with a max_nz# uninitialized non-zero elements.
This function has the same basic behavior as resize(...)# accept on return nz()# will equal nz#. The elements are initialized to garbage so it is imparative that the client initialize the elements before the sparse vector is used.
Definition at line 318 of file AbstractLinAlgPack_SparseVectorClassDef.hpp.
|
inline |
Return the max number of elements that can be held without resizing.
Definition at line 925 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Add an unsorted element.
If nz() = max_nz()#) then the exception OutOfRoomException will be thrown.
If you want to add more elements than you have reserved space for in the construction or resize operation then you have to mannually copy the elements in the sparse vector, resize the sparse vector, and then readd the elements including the extra ones you want to add.
Definition at line 930 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
void AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::insert_element | ( | element_type | ele | ) |
Add an element into a sorted sequence.
If nz() = max_nz()#) then the exception OutOfRoomException will be thrown.
If you want to add more elements than you have reserved space for in the construction or resize operation then you have to mannually copy the elements in the sparse vector, resize the sparse vector, and then readd the elements including the extra ones you want to add.
Definition at line 332 of file AbstractLinAlgPack_SparseVectorClassDef.hpp.
|
inline |
Called by the client to inform this sparse vector object that the elements be assumed to be in sequence and it is the clients responcibiliy to make sure that it is.
Definition at line 942 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
void AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::sort | ( | ) |
Sort the elements into assending order by index.
Definition at line 369 of file AbstractLinAlgPack_SparseVectorClassDef.hpp.
void AbstractLinAlgPack::SparseVector< T_Element, T_Alloc >::assert_valid_and_sorted | ( | ) | const |
Assert that sparse vector is sorted.
This function will throw an exception if any of the following are not true: {enumerate} The sequence is not sorted by index (NotSortedException#) There are duplicate indexes (DuplicateIndexesException#) The indexes are out of range (#std::out_of_range#) {enumerate}
This function will throw an exception for the first error it finds.
Definition at line 376 of file AbstractLinAlgPack_SparseVectorClassDef.hpp.
|
inline |
Definition at line 951 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Definition at line 959 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Allow an implicit conversion to a SparseVectorSlice<> object.
This is a very cheap operation.
Definition at line 967 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Definition at line 972 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Returns a SparseVectorSlice representing the entire sparse vector.
It is used to provide a quick, explicit conversion so that the SparseVector object can be used in functions that expect a SparseVectorSlice object.
Definition at line 977 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Definition at line 982 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Returns a continous subregion of the SparseVector object.
The returned SparseVectorSlice object represents the range of the rng argument.
Preconditions:
Postconditions:
rng | Index range [lbound,ubound] of the region being returned. |
Definition at line 987 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Definition at line 992 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Returns a SparseVectorSlice object for the continous subregion [ubound, lbound].
Preconditions:
Postconditions:
lbound | Lower bound of range [lbound,ubound] of the region being returned. |
ubound | Upper bound of range [lbound,ubound] of the region being returned. |
Definition at line 997 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.
|
inline |
Same as above.
Definition at line 1002 of file AbstractLinAlgPack_SparseVectorClassDecl.hpp.