1 Mapped Vector
1.1 Description
The templated class mapped_vector<T, A>
isthe base container adaptor for sparse vectors using element maps. For an-dimensional sparse vector and 0 <= i < nthe non-zero elements vi are mapped toconsecutive elements of the associative container, i.e. forelements k =vi1andk + 1 =vi2of thecontainer holds i1 <i2.
//之所以说是映射向量,是因为它将稀疏向量中的非零元素映射到另一相关联的容器中,其元素在关联容器中连续排列
1.2 Example
#include <boost/numeric/ublas/vector_sparse.hpp> //最后的结果为(0,1,2),其实Mapped vector 是稀疏矩阵的一种表示方法 #include <boost/numeric/ublas/io.hpp> int main () { using namespace boost::numeric::ublas; mapped_vector<double> v (3, 3); for (unsigned i = 0; i < v.size (); ++ i) v (i) = i; std::cout << v << std::endl; }
1.3 Definition
Defined in the header vector_sparse.hpp.
1.4 Template parameters
Parameter | Description | Default |
---|---|---|
T | The type of object stored in the mapped vector. | |
A | The type of the adapted array. [1] | map_std<std::size_t, T> |
1.5 Model of
Vector .
1.6 Type requirements
None, except for those imposed by the requirements of Vector .
1.7 Public base classes
vector_container<mapped_vector<T, A>>
1.8 Members
Member | Description |
---|---|
mapped_vector () | Allocates a mapped_vector that holds zeroelements. |
mapped_vector (size_type size, size_typenon_zeros = 0) | Allocates a mapped_vector that holds at mostsize elements. |
mapped_vector (const mapped_vector &v) | The copy constructor. |
template<class AE> | The extended copy constructor. |
void resize (size_type size, boolpreserve = true) | Reallocates a mapped_vector to hold at mostsize elements. The existing elements of themapped_vector are preseved when specified. |
size_type size () const | Returns the size of the mapped_vector . |
const_reference operator () (size_type i)const | Returns the value of the i -th element. |
reference operator () (size_type i) | Returns a reference of the i -th element. |
const_reference operator [] (size_type i)const | Returns the value of the i -th element. |
reference operator [] (size_type i) | Returns a reference of the i -th element. |
mapped_vector &operator = (const mapped_vector&v) | The assignment operator. |
mapped_vector &assign_temporary (mapped_vector&v) | Assigns a temporary. May change the mapped vectorv . |
template<class AE> | The extended assignment operator. |
template<class AE> | Assigns a vector expression to the mapped vector. Left andright hand side of the assignment should be independent. |
template<class AE> | A computed assignment operator. Adds the vector expression tothe mapped vector. |
template<class AE> | Adds a vector expression to the mapped vector. Left and righthand side of the assignment should be independent. |
template<class AE> | A computed assignment operator. Subtracts the vector expressionfrom the mapped vector. |
template<class AE> | Subtracts a vector expression from the mapped vector. Left andright hand side of the assignment should be independent. |
template<class AT> | A computed assignment operator. Multiplies the mapped vectorwith a scalar. |
template<class AT> | A computed assignment operator. Divides the mapped vectorthrough a scalar. |
void swap (mapped_vector &v) | Swaps the contents of the mapped vectors. |
true_reference insert_element (size_type i, const_reference t) | Inserts the value t at the i -thelement. Duplicates elements are not allowed. |
void erase_element (size_type i) | Erases the value at the i -th element. |
void clear () | Clears the mapped vector. |
const_iterator begin () const | Returns a const_iterator pointing to the beginningof the mapped_vector . |
const_iterator end () const | Returns a const_iterator pointing to the end ofthe mapped_vector . |
iterator begin () | Returns a iterator pointing to the beginning ofthe mapped_vector . |
iterator end () | Returns a iterator pointing to the end of themapped_vector . |
const_reverse_iterator rbegin () const | Returns a const_reverse_iterator pointing to thebeginning of the reversed mapped_vector . |
const_reverse_iterator rend () const | Returns a const_reverse_iterator pointing to theend of the reversed mapped_vector . |
reverse_iterator rbegin () | Returns a reverse_iterator pointing to thebeginning of the reversed mapped_vector . |
reverse_iterator rend () | Returns a reverse_iterator pointing to the end ofthe reversed mapped_vector . |
1.9 Notes
[1] Supportedparameters for the adapted array aremap_array<std::size_t, T>
andmap_std<std::size_t, T>
. The latter isequivalent to std::map<std::size_t, T>
.
2 Compressed Vector
2.1 Description
The templated class compressed_vector<T, IB, IA,TA>
is the base container adaptor for compressed vectors.For a n-dimensional compressed vector and 0 <= i< n the non-zero elements viare mapped to consecutive elements of the index and value container, i.e. for elements k =vi1andk + 1 =vi2of these containers holds i1 <i2.
//压缩向量与之前的映射向量,它们之间的不同是索引的值也参与了映射,索引值如何参加映射就不得而知了
2.2 Example
#include <boost/numeric/ublas/vector_sparse.hpp>//结果和之前的相同 #include <boost/numeric/ublas/io.hpp> int main () { using namespace boost::numeric::ublas; compressed_vector<double> v (3, 3); for (unsigned i = 0; i < v.size (); ++ i) v (i) = i; std::cout << v << std::endl; }
2.3 Definition
Defined in the header vector_sparse.hpp.
2.4 Template parameters
Parameter | Description | Default |
---|---|---|
T | The type of object stored in the compressed vector. | |
IB | The index base of the compressed vector. [1] | 0 |
IA | The type of the adapted array for indices. [2] | unbounded_array<std::size_t> |
TA | The type of the adapted array for values. [2] | unbounded_array<T> |
2.5 Model of
Vector .
2.6 Type requirements
None, except for those imposed by the requirements of Vector .
2.7 Public base classes
vector_container<compressed_vector<T, IB, IA,TA> >
2.8 Members
Member | Description |
---|---|
compressed_vector () | Allocates a compressed_vector that holds zeroelements. |
compressed_vector (size_type size, size_typenon_zeros) | Allocates a compressed_vector that holds at mostsize elements. |
compressed_vector (const compressed_vector&v) | The copy constructor. |
template<class AE> | The extended copy constructor. |
void resize (size_type size, boolpreserve = true) | Reallocates a compressed_vector to hold at mostsize elements. The existing elements of thecompress_vector are preseved when specified. |
size_type size () const | Returns the size of the compressed_vector . |
const_reference operator () (size_type i)const | Returns the value of the i -th element. |
reference operator () (size_type i) | Returns a reference of the i -th element. |
const_reference operator [] (size_type i)const | Returns the value of the i -th element. |
reference operator [] (size_type i) | Returns a reference of the i -th element. |
compressed_vector &operator = (constcompressed_vector &v) | The assignment operator. |
compressed_vector &assign_temporary(compressed_vector &v) | Assigns a temporary. May change the compressed vectorv . |
template<class AE> | The extended assignment operator. |
template<class AE> | Assigns a vector expression to the compressed vector. Left andright hand side of the assignment should be independent. |
template<class AE> | A computed assignment operator. Adds the vector expression tothe compressed vector. |
template<class AE> | Adds a vector expression to the compressed vector. Left andright hand side of the assignment should be independent. |
template<class AE> | A computed assignment operator. Subtracts the vector expressionfrom the compressed vector. |
template<class AE> | Subtracts a vector expression from the compressed vector. Leftand right hand side of the assignment should be independent. |
template<class AT> | A computed assignment operator. Multiplies the compressedvector with a scalar. |
template<class AT> | A computed assignment operator. Divides the compressed vectorthrough a scalar. |
void swap (compressed_vector &v) | Swaps the contents of the compressed vectors. |
true_reference insert_element (size_type i, const_reference t) | Inserts the value t at the i -thelement. Duplicates elements are not allowed. |
void erase_element (size_type i) | Erases the value at the i -th element. |
void clear () | Clears the compressed vector. |
const_iterator begin () const | Returns a const_iterator pointing to the beginningof the compressed_vector . |
const_iterator end () const | Returns a const_iterator pointing to the end ofthe compressed_vector . |
iterator begin () | Returns a iterator pointing to the beginning ofthe compressed_vector . |
iterator end () | Returns a iterator pointing to the end of thecompressed_vector . |
const_reverse_iterator rbegin () const | Returns a const_reverse_iterator pointing to thebeginning of the reversed compressed_vector . |
const_reverse_iterator rend () const | Returns a const_reverse_iterator pointing to theend of the reversed compressed_vector . |
reverse_iterator rbegin () | Returns a reverse_iterator pointing to thebeginning of the reversed compressed_vector . |
reverse_iterator rend () | Returns a reverse_iterator pointing to the end ofthe reversed compressed_vector . |
2.9 Notes
[1]Supported parameters for the index base are 0
and1
at least.
[2]Supported parameters for the adapted array areunbounded_array<>
,bounded_array<>
andstd::vector<>
.
3 Coordinate Vector
3.1 Description
The templated class coordinate_vector<T, IB, IA,TA>
is the base container adaptor for compressed vectors.For a n-dimensional sorted coordinate vector and 0<= i < n the non-zero elementsvi are mapped to consecutive elementsof the index and value container, i.e. for elements k =vi1andk + 1 =vi2of thesecontainers holds i1 <i2.
3.2 Example
#include <boost/numeric/ublas/vector_sparse.hpp>// 结果和之前相同 #include <boost/numeric/ublas/io.hpp> int main () { using namespace boost::numeric::ublas; coordinate_vector<double> v (3, 3); for (unsigned i = 0; i < v.size (); ++ i) v (i) = i; std::cout << v << std::endl; }
3.3 Definition
Defined in the header vector_sparse.hpp.
3.4 Template parameters
Parameter | Description | Default |
---|---|---|
T | The type of object stored in the coordinate vector. | |
IB | The index base of the coordinate vector. [1] | 0 |
IA | The type of the adapted array for indices. [2] | unbounded_array<std::size_t> |
TA | The type of the adapted array for values. [2] | unbounded_array<T> |
3.5 Model of
Vector .
3.6 Type requirements
None, except for those imposed by the requirements of Vector .
3.7 Public base classes
vector_container<coordinate_vector<T, IB, IA,TA> >
3.8 Members
Member | Description |
---|---|
coordinate_vector () | Allocates a coordinate_vector that holds zeroelements. |
coordinate_vector (size_type size, size_typenon_zeros) | Allocates a coordinate_vector that holds at mostsize elements. |
coordinate_vector (const coordinate_vector&v) | The copy constructor. |
template<class AE> | The extended copy constructor. |
void resize (size_type size, boolpreserve = true) | Reallocates a coordinate_vector to hold at mostsize elements. The existing elements of thecoordinate_vector are preseved when specified. |
size_type size () const | Returns the size of the coordinate_vector . |
const_reference operator () (size_type i)const | Returns the value of the i -th element. |
reference operator () (size_type i) | Returns a reference of the i -th element. |
const_reference operator [] (size_type i)const | Returns the value of the i -th element. |
reference operator [] (size_type i) | Returns a reference of the i -th element. |
coordinate_vector &operator = (constcoordinate_vector &v) | The assignment operator. |
coordinate_vector &assign_temporary(coordinate_vector &v) | Assigns a temporary. May change the coordinate vectorv . |
template<class AE> | The extended assignment operator. |
template<class AE> | Assigns a vector expression to the coordinate vector. Left andright hand side of the assignment should be independent. |
template<class AE> | A computed assignment operator. Adds the vector expression tothe coordinate vector. |
template<class AE> | Adds a vector expression to the coordinate vector. Left andright hand side of the assignment should be independent. |
template<class AE> | A computed assignment operator. Subtracts the vector expressionfrom the coordinate vector. |
template<class AE> | Subtracts a vector expression from the coordinate vector. Leftand right hand side of the assignment should be independent. |
template<class AT> | A computed assignment operator. Multiplies the coordinatevector with a scalar. |
template<class AT> | A computed assignment operator. Divides the coordinate vectorthrough a scalar. |
void swap (coordinate_vector &v) | Swaps the contents of the coordinate vectors. |
true_reference insert_element (size_type i, const_reference t) | Inserts the value t at the i -thelement. Duplicates elements are not allowed. |
void append_element (size_type i, size_type j, const_reference t) | Appends the value t at the i -th element.Duplicate elements can be appended to a coordinate_vector . They are merged into a singlearithmetically summed element by the sort function. |
void erase_element (size_type i) | Erases the value at the i -th element. |
void clear () | Clears the coordinate vector. |
const_iterator begin () const | Returns a const_iterator pointing to the beginningof the coordinate_vector . |
const_iterator end () const | Returns a const_iterator pointing to the end ofthe coordinate_vector . |
iterator begin () | Returns a iterator pointing to the beginning ofthe coordinate_vector . |
iterator end () | Returns a iterator pointing to the end of thecoordinate_vector . |
const_reverse_iterator rbegin () const | Returns a const_reverse_iterator pointing to thebeginning of the reversed coordinate_vector . |
const_reverse_iterator rend () const | Returns a const_reverse_iterator pointing to theend of the reversed coordinate_vector . |
reverse_iterator rbegin () | Returns a reverse_iterator pointing to thebeginning of the reversed coordinate_vector . |
reverse_iterator rend () | Returns a reverse_iterator pointing to the end ofthe reversed coordinate_vector . |
3.9 Notes
[1]Supported parameters for the index base are 0
and1
at least.
[2]Supported parameters for the adapted array areunbounded_array<>
,bounded_array<>
andstd::vector<>
.