mirror of
https://github.com/boostorg/ublas.git
synced 2026-02-12 00:22:22 +00:00
2054 lines
72 KiB
HTML
2054 lines
72 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content=
|
|
"text/html; charset=iso-8859-1">
|
|
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
|
|
<title>Sparse Matrix</title>
|
|
</head>
|
|
<body bgcolor="#ffffff">
|
|
<h1><img src="c++boost.gif" alt="c++boost.gif" align="Center">
|
|
Sparse Matrix</h1>
|
|
|
|
<h2><a name="sparse_matrix"></a> Sparse Matrix</h2>
|
|
|
|
<h4>Description</h4>
|
|
|
|
<p>The templated class <code>sparse_matrix<T, F, A></code> is
|
|
the base container adaptor for sparse matrices. For a <em>(m x
|
|
n</em>)-dimensional sparse matrix and <em>0 <= i < m</em>,
|
|
<em>0 <= j < n</em> the non-zero elements
|
|
<em>m</em><sub><em>i, j</em></sub> are mapped via <em>(i x n +
|
|
j)</em> for row major orientation or via <em>(i + j x m)</em> for
|
|
column major orientation to consecutive elements of the associative
|
|
container, i.e. for elements <em>k</em> =
|
|
<em>m</em><sub><em>i</em></sub><sub><sub><em>1</em></sub></sub><sub>
|
|
<em>,j</em></sub><sub><sub><em>1</em></sub></sub><sub><em></em></sub>and
|
|
<em>k + 1 =
|
|
m</em><sub><em>i</em></sub><sub><sub><em>2</em></sub></sub><sub><em>
|
|
,j</em></sub><sub><sub><em>2</em></sub></sub><sub><em></em></sub>of
|
|
the container holds <em>i</em><sub><em>1</em></sub> <em><
|
|
i</em><sub><em>2</em></sub> or <em>(i</em><sub><em>1</em></sub>
|
|
<em>= i</em><sub><em>2</em></sub> and
|
|
<em>j</em><sub><em>1</em></sub> <em><
|
|
j</em><sub><em>2</em></sub><em>)</em> with row major orientation or
|
|
<em>j</em><sub><em>1</em></sub> <em><
|
|
j</em><sub><em>2</em></sub> or <em>(j</em><sub><em>1</em></sub>
|
|
<em>= j</em><sub><em>2</em></sub> and
|
|
<em>i</em><sub><em>1</em></sub> <em><
|
|
i</em><sub><em>2</em></sub><em>)</em> with column major
|
|
orientation.</p>
|
|
|
|
<h4>Example</h4>
|
|
|
|
<pre>
|
|
#include <boost/numeric/ublas/matrix_sparse.hpp><br>
|
|
#include <boost/numeric/ublas/io.hpp><br>
|
|
<br>
|
|
int main () {<br>
|
|
using namespace boost::numeric::ublas;<br>
|
|
sparse_matrix<double> m (3, 3, 3 * 3);<br>
|
|
for (unsigned i = 0; i < m.size1 (); ++ i)<br>
|
|
for (unsigned j = 0; j < m.size2 (); ++ j)<br>
|
|
m (i, j) = 3 * i + j;<br>
|
|
std::cout << m << std::endl;<br>
|
|
}
|
|
</pre>
|
|
|
|
<h4>Definition</h4>
|
|
|
|
<p>Defined in the header matrix_sparse.hpp.</p>
|
|
|
|
<h4>Template parameters</h4>
|
|
|
|
<table border="1">
|
|
<tbody>
|
|
<tr>
|
|
<th>Parameter</th>
|
|
<th>Description</th>
|
|
<th>Default</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>T</code> </td>
|
|
<td>The type of object stored in the sparse matrix.</td>
|
|
<td> </td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>F</code></td>
|
|
<td>Functor describing the storage organization. <a href=
|
|
"#sparse_matrix_1">[1]</a> </td>
|
|
<td><code>row_major</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>A</code></td>
|
|
<td>The type of the adapted array. <a href=
|
|
"#sparse_matrix_2">[2]</a> </td>
|
|
<td><code>map_array<std::size_t, T></code></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h4>Model of</h4>
|
|
|
|
<p><a href="container.htm#matrix">Matrix</a> .</p>
|
|
|
|
<h4>Type requirements</h4>
|
|
|
|
<p>None, except for those imposed by the requirements of <a href=
|
|
"container.htm#matrix">Matrix</a> .</p>
|
|
|
|
<h4>Public base classes</h4>
|
|
|
|
<p><code>matrix_expression<sparse_matrix<T, F, A>
|
|
></code></p>
|
|
|
|
<h4>Members</h4>
|
|
|
|
<table border="1">
|
|
<tbody>
|
|
<tr>
|
|
<th>Member</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>sparse_matrix ()</code> </td>
|
|
<td>Allocates a <code>sparse_matrix</code> that holds at most zero
|
|
rows of zero elements.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>sparse_matrix (size_type size1, size_type2, size_type
|
|
non_zeros)</code></td>
|
|
<td>Allocates a <code>sparse_matrix</code> that holds at most
|
|
<code>size1</code> rows of <code>size2</code> elements.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>sparse_matrix (const sparse_matrix &m)</code></td>
|
|
<td>The copy constructor.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
sparse_matrix (size_type non_zeros, const
|
|
matrix_expression<AE> &ae)</code></td>
|
|
<td>The extended copy constructor.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void resize (size_type size1, size_type size2, size_type
|
|
non_zeros)</code></td>
|
|
<td>Reallocates a <code>sparse_matrix</code> to hold at most
|
|
<code>size1</code> rows of <code>size2</code> elements. The content
|
|
of the <code>sparse_matrix</code> is preserved.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>size_type size1 () const</code></td>
|
|
<td>Returns the number of rows.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>size_type size2 () const</code></td>
|
|
<td>Returns the number of columns.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reference operator () (size_type i, size_type j)
|
|
const</code></td>
|
|
<td>Returns the value of the <code>j</code>-th element in the
|
|
<code>i</code>-th row.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reference operator () (size_type i, size_type
|
|
j)</code></td>
|
|
<td>Returns a reference of the <code>j</code>-th element in the
|
|
<code>i</code>-th row.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>sparse_matrix &operator = (const sparse_matrix
|
|
&m)</code></td>
|
|
<td>The assignment operator.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>sparse_matrix &assign_temporary (sparse_matrix
|
|
&m)</code></td>
|
|
<td>Assigns a temporary. May change the sparse matrix
|
|
<code>m</code> .</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
sparse_matrix &operator = (const matrix_expression<AE>
|
|
&ae)</code></td>
|
|
<td>The extended assignment operator.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
sparse_matrix &assign (const matrix_expression<AE>
|
|
&ae)</code></td>
|
|
<td>Assigns a matrix expression to the sparse matrix. Left and
|
|
right hand side of the assignment should be independent.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
sparse_matrix &operator += (const matrix_expression<AE>
|
|
&ae)</code></td>
|
|
<td>A computed assignment operator. Adds the matrix expression to
|
|
the sparse matrix.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
sparse_matrix &plus_assign (const matrix_expression<AE>
|
|
&ae)</code></td>
|
|
<td>Adds a matrix expression to the sparse matrix. Left and right
|
|
hand side of the assignment should be independent.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
sparse_matrix &operator -= (const matrix_expression<AE>
|
|
&ae)</code></td>
|
|
<td>A computed assignment operator. Subtracts the matrix expression
|
|
from the sparse matrix.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
sparse_matrix &minus_assign (const matrix_expression<AE>
|
|
&ae)</code></td>
|
|
<td>Subtracts a matrix expression from the sparse matrix. Left and
|
|
right hand side of the assignment should be independent.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AT><br>
|
|
sparse_matrix &operator *= (const AT &at)</code></td>
|
|
<td>A computed assignment operator. Multiplies the sparse matrix
|
|
with a scalar.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AT><br>
|
|
sparse_matrix &operator /= (const AT &at)</code></td>
|
|
<td>A computed assignment operator. Divides the sparse matrix
|
|
through a scalar.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void swap (sparse_matrix &m)</code></td>
|
|
<td>Swaps the contents of the sparse matrices.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void insert (size_type i, size_type j, const_reference
|
|
t)</code></td>
|
|
<td>Inserts the value <code>t</code> at the <code>j</code>-th
|
|
element of the <code>i</code>-th row.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void erase (size_type i, size_type j)</code></td>
|
|
<td>Erases the value at the <code>j</code>-th element of the
|
|
<code>i</code>-th row.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void clear ()</code></td>
|
|
<td>Clears the sparse matrix.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_iterator1 begin1 () const</code></td>
|
|
<td>Returns a <code>const_iterator1</code> pointing to the
|
|
beginning of the <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_iterator1 end1 () const</code></td>
|
|
<td>Returns a <code>const_iterator1</code> pointing to the end of
|
|
the <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>iterator1 begin1 ()</code> </td>
|
|
<td>Returns a <code>iterator1</code> pointing to the beginning of
|
|
the <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>iterator1 end1 ()</code> </td>
|
|
<td>Returns a <code>iterator1</code> pointing to the end of the
|
|
<code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_iterator2 begin2 () const</code></td>
|
|
<td>Returns a <code>const_iterator2</code> pointing to the
|
|
beginning of the <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_iterator2 end2 () const</code></td>
|
|
<td>Returns a <code>const_iterator2</code> pointing to the end of
|
|
the <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>iterator2 begin2 ()</code> </td>
|
|
<td>Returns a <code>iterator2</code> pointing to the beginning of
|
|
the <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>iterator2 end2 ()</code> </td>
|
|
<td>Returns a <code>iterator2</code> pointing to the end of the
|
|
<code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reverse_iterator1 rbegin1 () const</code></td>
|
|
<td>Returns a <code>const_reverse_iterator1</code> pointing to the
|
|
beginning of the reversed <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reverse_iterator1 rend1 () const</code></td>
|
|
<td>Returns a <code>const_reverse_iterator1</code> pointing to the
|
|
end of the reversed <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reverse_iterator1 rbegin1 ()</code> </td>
|
|
<td>Returns a <code>reverse_iterator1</code> pointing to the
|
|
beginning of the reversed <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reverse_iterator1 rend1 ()</code> </td>
|
|
<td>Returns a <code>reverse_iterator1</code> pointing to the end of
|
|
the reversed <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reverse_iterator2 rbegin2 () const</code></td>
|
|
<td>Returns a <code>const_reverse_iterator2</code> pointing to the
|
|
beginning of the reversed <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reverse_iterator2 rend2 () const</code></td>
|
|
<td>Returns a <code>const_reverse_iterator2</code> pointing to the
|
|
end of the reversed <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reverse_iterator2 rbegin2 ()</code> </td>
|
|
<td>Returns a <code>reverse_iterator2</code> pointing to the
|
|
beginning of the reversed <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reverse_iterator2 rend2 ()</code> </td>
|
|
<td>Returns a <code>reverse_iterator2</code> pointing to the end of
|
|
the reversed <code>sparse_matrix</code>.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h4>Notes</h4>
|
|
|
|
<p><a name="#sparse_matrix_1">[1]</a> Supported parameters for the
|
|
storage organization are <code>row_major</code> and
|
|
<code>column_major</code>.</p>
|
|
|
|
<p><a name="#sparse_matrix_2">[2]</a> Supported parameters for the
|
|
adapted array are <code>map_array<std::size_t, T></code> and
|
|
<code>std::map<std::size_t, T></code>.</p>
|
|
|
|
<h4>Interface</h4>
|
|
|
|
<pre>
|
|
<code>// Array based sparse matrix class<br>
|
|
template<class T, class F, class A><br>
|
|
class sparse_matrix:<br>
|
|
public matrix_expression<sparse_matrix<T, F, A> > {<br>
|
|
public: <br>
|
|
typedef std::size_t size_type;<br>
|
|
typedef std::ptrdiff_t difference_type;<br>
|
|
typedef T value_type;<br>
|
|
typedef const T &const_reference;<br>
|
|
typedef T &reference;<br>
|
|
typedef const T *const_pointer;<br>
|
|
typedef T *pointer;<br>
|
|
typedef F functor_type;<br>
|
|
typedef A array_type;<br>
|
|
typedef const A const_array_type;<br>
|
|
typedef const sparse_matrix<T, F, A> const_self_type;<br>
|
|
typedef sparse_matrix<T, F, A> self_type;<br>
|
|
typedef const matrix_const_reference<const_self_type> const_closure_type;<br>
|
|
typedef matrix_reference<self_type> closure_type;<br>
|
|
typedef typename A::const_iterator const_iterator_type;<br>
|
|
typedef typename A::iterator iterator_type;<br>
|
|
typedef sparse_tag storage_category;<br>
|
|
typedef typename F::orientation_category orientation_category;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
sparse_matrix ();<br>
|
|
sparse_matrix (size_type size1, size_type size2, size_type non_zeros = 0);<br>
|
|
sparse_matrix (const sparse_matrix &m);<br>
|
|
template<class AE><br>
|
|
sparse_matrix (const matrix_expression<AE> &ae, size_type non_zeros = 0);<br>
|
|
<br>
|
|
// Accessors<br>
|
|
size_type size1 () const;<br>
|
|
size_type size2 () const;<br>
|
|
size_type non_zeros () const;<br>
|
|
const_array_type &data () const;<br>
|
|
array_type &data ();<br>
|
|
<br>
|
|
// Resizing<br>
|
|
void resize (size_type size1, size_type size2, size_type non_zeros = 0);<br>
|
|
<br>
|
|
// Element access<br>
|
|
const_reference operator () (size_type i, size_type j) const;<br>
|
|
reference operator () (size_type i, size_type j);<br>
|
|
<br>
|
|
// Assignment<br>
|
|
sparse_matrix &operator = (const sparse_matrix &m);<br>
|
|
sparse_matrix &assign_temporary (sparse_matrix &m);<br>
|
|
template<class AE><br>
|
|
sparse_matrix &operator = (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
sparse_matrix &reset (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
sparse_matrix &assign (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
sparse_matrix& operator += (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
sparse_matrix &plus_assign (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
sparse_matrix& operator -= (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
sparse_matrix &minus_assign (const matrix_expression<AE> &ae);<br>
|
|
template<class AT><br>
|
|
sparse_matrix& operator *= (const AT &at);<br>
|
|
template<class AT><br>
|
|
sparse_matrix& operator /= (const AT &at);<br>
|
|
<br>
|
|
// Swapping<br>
|
|
void swap (sparse_matrix &m);<br>
|
|
friend void swap (sparse_matrix &m1, sparse_matrix &m2);<br>
|
|
<br>
|
|
// Element insertion and erasure<br>
|
|
void insert (size_type i, size_type j, const_reference t);<br>
|
|
void erase (size_type i, size_type j);<br>
|
|
void clear ();<br>
|
|
<br>
|
|
class const_iterator1;<br>
|
|
class iterator1;<br>
|
|
class const_iterator2;<br>
|
|
class iterator2;<br>
|
|
typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;<br>
|
|
typedef reverse_iterator_base1<iterator1> reverse_iterator1;<br>
|
|
typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;<br>
|
|
typedef reverse_iterator_base2<iterator2> reverse_iterator2;<br>
|
|
<br>
|
|
// Element lookup<br>
|
|
const_iterator1 find1 (int rank, size_type i, size_type j) const;<br>
|
|
iterator1 find1 (int rank, size_type i, size_type j);<br>
|
|
const_iterator2 find2 (int rank, size_type i, size_type j) const;<br>
|
|
iterator2 find2 (int rank, size_type i, size_type j);<br>
|
|
const_iterator1 find_first1 (int rank, size_type i, size_type j) const;<br>
|
|
iterator1 find_first1 (int rank, size_type i, size_type j);<br>
|
|
const_iterator1 find_last1 (int rank, size_type i, size_type j) const;<br>
|
|
iterator1 find_last1 (int rank, size_type i, size_type j);<br>
|
|
const_iterator2 find_first2 (int rank, size_type i, size_type j) const;<br>
|
|
iterator2 find_first2 (int rank, size_type i, size_type j);<br>
|
|
const_iterator2 find_last2 (int rank, size_type i, size_type j) const;<br>
|
|
iterator2 find_last2 (int rank, size_type i, size_type j);<br>
|
|
<br>
|
|
// Iterators simply are pointers.<br>
|
|
<br>
|
|
class const_iterator1:<br>
|
|
public container_const_reference<sparse_matrix>,<br>
|
|
public bidirectional_iterator_base<const_iterator1, value_type> {<br>
|
|
public:<br>
|
|
typedef sparse_bidirectional_iterator_tag iterator_category;<br>
|
|
typedef typename sparse_matrix::difference_type difference_type;<br>
|
|
typedef typename sparse_matrix::value_type value_type;<br>
|
|
typedef typename sparse_matrix::const_reference reference;<br>
|
|
typedef typename sparse_matrix::const_pointer pointer;<br>
|
|
typedef const_iterator2 dual_iterator_type;<br>
|
|
typedef const_reverse_iterator2 dual_reverse_iterator_type;<br>
|
|
typedef typename functor_type::functor1_type functor1_type;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
const_iterator1 ();<br>
|
|
const_iterator1 (const sparse_matrix &m, int rank, size_type i, size_type j, const const_iterator_type &it);<br>
|
|
const_iterator1 (const iterator1 &it);<br>
|
|
<br>
|
|
// Arithmetic<br>
|
|
const_iterator1 &operator ++ ();<br>
|
|
const_iterator1 &operator -- ();<br>
|
|
<br>
|
|
// Dereference<br>
|
|
reference operator * () const;<br>
|
|
<br>
|
|
const_iterator2 begin () const;<br>
|
|
const_iterator2 end () const;<br>
|
|
const_reverse_iterator2 rbegin () const;<br>
|
|
const_reverse_iterator2 rend () const;<br>
|
|
<br>
|
|
// Indices<br>
|
|
size_type index1 () const;<br>
|
|
size_type index2 () const;<br>
|
|
<br>
|
|
// Assignment<br>
|
|
const_iterator1 &operator = (const const_iterator1 &it);<br>
|
|
<br>
|
|
// Comparison<br>
|
|
bool operator == (const const_iterator1 &it) const;<br>
|
|
};<br>
|
|
<br>
|
|
const_iterator1 begin1 () const;<br>
|
|
const_iterator1 end1 () const;<br>
|
|
<br>
|
|
class iterator1:<br>
|
|
public container_reference<sparse_matrix>,<br>
|
|
public bidirectional_iterator_base<iterator1, value_type> {<br>
|
|
public:<br>
|
|
typedef sparse_bidirectional_iterator_tag iterator_category;<br>
|
|
typedef typename sparse_matrix::difference_type difference_type;<br>
|
|
typedef typename sparse_matrix::value_type value_type;<br>
|
|
typedef typename sparse_matrix::reference reference;<br>
|
|
typedef typename sparse_matrix::pointer pointer;<br>
|
|
typedef iterator2 dual_iterator_type;<br>
|
|
typedef reverse_iterator2 dual_reverse_iterator_type;<br>
|
|
typedef typename functor_type::functor1_type functor1_type;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
iterator1 ();<br>
|
|
iterator1 (sparse_matrix &m, int rank, size_type i, size_type j, const iterator_type &it);<br>
|
|
<br>
|
|
// Arithmetic<br>
|
|
iterator1 &operator ++ ();<br>
|
|
iterator1 &operator -- ();<br>
|
|
<br>
|
|
// Dereference<br>
|
|
reference operator * () const;<br>
|
|
<br>
|
|
iterator2 begin () const;<br>
|
|
iterator2 end () const;<br>
|
|
reverse_iterator2 rbegin () const;<br>
|
|
reverse_iterator2 rend () const;<br>
|
|
<br>
|
|
// Indices<br>
|
|
size_type index1 () const;<br>
|
|
size_type index2 () const;<br>
|
|
<br>
|
|
// Assignment<br>
|
|
iterator1 &operator = (const iterator1 &it);<br>
|
|
<br>
|
|
// Comparison<br>
|
|
bool operator == (const iterator1 &it) const;<br>
|
|
};<br>
|
|
<br>
|
|
iterator1 begin1 ();<br>
|
|
iterator1 end1 ();<br>
|
|
<br>
|
|
class const_iterator2:<br>
|
|
public container_const_reference<sparse_matrix>,<br>
|
|
public bidirectional_iterator_base<const_iterator2, value_type> {<br>
|
|
public:<br>
|
|
typedef sparse_bidirectional_iterator_tag iterator_category;<br>
|
|
typedef typename sparse_matrix::difference_type difference_type;<br>
|
|
typedef typename sparse_matrix::value_type value_type;<br>
|
|
typedef typename sparse_matrix::const_reference reference;<br>
|
|
typedef typename sparse_matrix::const_pointer pointer;<br>
|
|
typedef const_iterator1 dual_iterator_type;<br>
|
|
typedef const_reverse_iterator1 dual_reverse_iterator_type;<br>
|
|
typedef typename functor_type::functor2_type functor2_type;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
const_iterator2 ();<br>
|
|
const_iterator2 (const sparse_matrix &m, int rank, size_type i, size_type j, const const_iterator_type &it);<br>
|
|
const_iterator2 (const iterator2 &it);<br>
|
|
<br>
|
|
// Arithmetic<br>
|
|
const_iterator2 &operator ++ ();<br>
|
|
const_iterator2 &operator -- ();<br>
|
|
<br>
|
|
// Dereference<br>
|
|
reference operator * () const;<br>
|
|
<br>
|
|
const_iterator1 begin () const;<br>
|
|
const_iterator1 end () const;<br>
|
|
const_reverse_iterator1 rbegin () const;<br>
|
|
const_reverse_iterator1 rend () const;<br>
|
|
<br>
|
|
// Indices<br>
|
|
size_type index1 () const;<br>
|
|
size_type index2 () const;<br>
|
|
<br>
|
|
// Assignment<br>
|
|
const_iterator2 &operator = (const const_iterator2 &it);<br>
|
|
<br>
|
|
// Comparison<br>
|
|
bool operator == (const const_iterator2 &it) const;<br>
|
|
};<br>
|
|
<br>
|
|
const_iterator2 begin2 () const;<br>
|
|
const_iterator2 end2 () const;<br>
|
|
<br>
|
|
class iterator2:<br>
|
|
public container_reference<sparse_matrix>,<br>
|
|
public bidirectional_iterator_base<iterator2, value_type> {<br>
|
|
public:<br>
|
|
typedef sparse_bidirectional_iterator_tag iterator_category;<br>
|
|
typedef typename sparse_matrix::difference_type difference_type;<br>
|
|
typedef typename sparse_matrix::value_type value_type;<br>
|
|
typedef typename sparse_matrix::reference reference;<br>
|
|
typedef typename sparse_matrix::pointer pointer;<br>
|
|
typedef iterator1 dual_iterator_type;<br>
|
|
typedef reverse_iterator1 dual_reverse_iterator_type;<br>
|
|
typedef typename functor_type::functor2_type functor2_type;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
iterator2 ();<br>
|
|
iterator2 (sparse_matrix &m, int rank, size_type i, size_type j, const iterator_type &it);<br>
|
|
<br>
|
|
// Arithmetic<br>
|
|
iterator2 &operator ++ ();<br>
|
|
iterator2 &operator -- ();<br>
|
|
<br>
|
|
// Dereference<br>
|
|
reference operator * () const;<br>
|
|
<br>
|
|
iterator1 begin () const;<br>
|
|
iterator1 end () const;<br>
|
|
reverse_iterator1 rbegin () const;<br>
|
|
reverse_iterator1 rend () const;<br>
|
|
<br>
|
|
// Indices<br>
|
|
size_type index1 () const;<br>
|
|
size_type index2 () const;<br>
|
|
<br>
|
|
// Assignment<br>
|
|
iterator2 &operator = (const iterator2 &it);<br>
|
|
<br>
|
|
// Comparison<br>
|
|
bool operator == (const iterator2 &it) const;<br>
|
|
};<br>
|
|
<br>
|
|
iterator2 begin2 ();<br>
|
|
iterator2 end2 ();<br>
|
|
<br>
|
|
// Reverse iterators<br>
|
|
<br>
|
|
const_reverse_iterator1 rbegin1 () const;<br>
|
|
const_reverse_iterator1 rend1 () const;<br>
|
|
<br>
|
|
reverse_iterator1 rbegin1 ();<br>
|
|
reverse_iterator1 rend1 ();<br>
|
|
<br>
|
|
const_reverse_iterator2 rbegin2 () const;<br>
|
|
const_reverse_iterator2 rend2 () const;<br>
|
|
<br>
|
|
reverse_iterator2 rbegin2 ();<br>
|
|
reverse_iterator2 rend2 ();<br>
|
|
};</code>
|
|
</pre>
|
|
|
|
<h2><a name="compressed_matrix"></a> Compressed Matrix</h2>
|
|
|
|
<h4>Description</h4>
|
|
|
|
<p>The templated class <code>compressed_matrix<T, F, IB, IA,
|
|
TA></code> is the base container adaptor for compressed
|
|
matrices. For a <em>(m x n</em> )-dimensional compressed matrix and
|
|
<em>0 <= i < m</em>, <em>0 <= j < n</em> the non-zero
|
|
elements <em>m</em><sub><em>i, j</em></sub> are mapped via <em>(i x
|
|
n + j)</em> for row major orientation or via <em>(i + j x m)</em>
|
|
for column major orientation to consecutive elements of the index
|
|
and value containers, i.e. for elements <em>k</em> =
|
|
<em>m</em><sub><em>i</em></sub><sub><sub><em>1</em></sub></sub><sub>
|
|
<em>,j</em></sub><sub><sub><em>1</em></sub></sub><sub><em></em></sub>and
|
|
<em>k + 1 =
|
|
m</em><sub><em>i</em></sub><sub><sub><em>2</em></sub></sub><sub><em>
|
|
,j</em></sub><sub><sub><em>2</em></sub></sub><sub><em></em></sub>of
|
|
the container holds <em>i</em><sub><em>1</em></sub> <em><
|
|
i</em><sub><em>2</em></sub> or <em>(i</em><sub><em>1</em></sub>
|
|
<em>= i</em><sub><em>2</em></sub> and
|
|
<em>j</em><sub><em>1</em></sub> <em><
|
|
j</em><sub><em>2</em></sub><em>)</em> with row major orientation or
|
|
<em>j</em><sub><em>1</em></sub> <em><
|
|
j</em><sub><em>2</em></sub> or <em>(j</em><sub><em>1</em></sub>
|
|
<em>= j</em><sub><em>2</em></sub> and
|
|
<em>i</em><sub><em>1</em></sub> <em><
|
|
i</em><sub><em>2</em></sub><em>)</em> with column major
|
|
orientation.</p>
|
|
|
|
<h4>Example</h4>
|
|
|
|
<pre>
|
|
#include <boost/numeric/ublas/matrix_sparse.hpp><br>
|
|
#include <boost/numeric/ublas/io.hpp><br>
|
|
<br>
|
|
int main () {<br>
|
|
using namespace boost::numeric::ublas;<br>
|
|
compressed_matrix<double> m (3, 3, 3 * 3);<br>
|
|
for (unsigned i = 0; i < m.size1 (); ++ i)<br>
|
|
for (unsigned j = 0; j < m.size2 (); ++ j)<br>
|
|
m (i, j) = 3 * i + j;<br>
|
|
std::cout << m << std::endl;<br>
|
|
}<br>
|
|
</pre>
|
|
|
|
<h4>Definition</h4>
|
|
|
|
<p>Defined in the header matrix_sparse.hpp.</p>
|
|
|
|
<h4>Template parameters</h4>
|
|
|
|
<table border="1">
|
|
<tbody>
|
|
<tr>
|
|
<th>Parameter</th>
|
|
<th>Description</th>
|
|
<th>Default</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>T</code> </td>
|
|
<td>The type of object stored in the compressed matrix.</td>
|
|
<td> </td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>F</code></td>
|
|
<td>Functor describing the storage organization. <a href=
|
|
"#compressed_matrix_1">[1]</a> </td>
|
|
<td><code>row_major</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>IB</code></td>
|
|
<td>The index base of the compressed vector. <a href=
|
|
"#compressed_matrix_2">[2]</a> </td>
|
|
<td><code>0</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>IA</code></td>
|
|
<td>The type of the adapted array for indices. <a href=
|
|
"#compressed_matrix_3">[3]</a> </td>
|
|
<td><code>unbounded_array<std::size_t></code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>TA</code></td>
|
|
<td>The type of the adapted array for values. <a href=
|
|
"#compressed_matrix_3">[3]</a> </td>
|
|
<td><code>unbounded_array<T></code></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h4>Model of</h4>
|
|
|
|
<p><a href="container.htm#matrix">Matrix</a> .</p>
|
|
|
|
<h4>Type requirements</h4>
|
|
|
|
<p>None, except for those imposed by the requirements of <a href=
|
|
"container.htm#matrix">Matrix</a> .</p>
|
|
|
|
<h4>Public base classes</h4>
|
|
|
|
<p><code>matrix_expression<compressed_matrix<T, F, IB, IA,
|
|
TA> ></code></p>
|
|
|
|
<h4>Members</h4>
|
|
|
|
<table border="1">
|
|
<tbody>
|
|
<tr>
|
|
<th>Member</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>compressed_matrix ()</code> </td>
|
|
<td>Allocates a <code>compressed_matrix</code> that holds at most
|
|
zero rows of zero elements.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>compressed_matrix (size_type size1, size_type2, size_type
|
|
non_zeros)</code></td>
|
|
<td>Allocates a <code>compressed_matrix</code> that holds at most
|
|
<code>size1</code> rows of <code>size2</code> elements.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>compressed_matrix (const compressed_matrix
|
|
&m)</code></td>
|
|
<td>The copy constructor.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
compressed_matrix (size_type non_zeros, const
|
|
matrix_expression<AE> &ae)</code></td>
|
|
<td>The extended copy constructor.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void resize (size_type size1, size_type size2, size_type
|
|
non_zeros)</code></td>
|
|
<td>Reallocates a <code>compressed_matrix</code> to hold at most
|
|
<code>size1</code> rows of <code>size2</code> elements. The content
|
|
of the <code>compressed_matrix</code> is preserved.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>size_type size1 () const</code></td>
|
|
<td>Returns the number of rows.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>size_type size2 () const</code></td>
|
|
<td>Returns the number of columns.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reference operator () (size_type i, size_type j)
|
|
const</code></td>
|
|
<td>Returns the value of the <code>j</code>-th element in the
|
|
<code>i</code>-th row.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reference operator () (size_type i, size_type
|
|
j)</code></td>
|
|
<td>Returns a reference of the <code>j</code>-th element in the
|
|
<code>i</code>-th row.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>compressed_matrix &operator = (const
|
|
compressed_matrix &m)</code></td>
|
|
<td>The assignment operator.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>compressed_matrix &assign_temporary
|
|
(compressed_matrix &m)</code></td>
|
|
<td>Assigns a temporary. May change the compressed matrix
|
|
<code>m</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
compressed_matrix &operator = (const
|
|
matrix_expression<AE> &ae)</code></td>
|
|
<td>The extended assignment operator.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
compressed_matrix &assign (const matrix_expression<AE>
|
|
&ae)</code></td>
|
|
<td>Assigns a matrix expression to the compressed matrix. Left and
|
|
right hand side of the assignment should be independent.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
compressed_matrix &operator += (const
|
|
matrix_expression<AE> &ae)</code></td>
|
|
<td>A computed assignment operator. Adds the matrix expression to
|
|
the compressed matrix.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
compressed_matrix &plus_assign (const
|
|
matrix_expression<AE> &ae)</code></td>
|
|
<td>Adds a matrix expression to the compressed matrix. Left and
|
|
right hand side of the assignment should be independent.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
compressed_matrix &operator -= (const
|
|
matrix_expression<AE> &ae)</code></td>
|
|
<td>A computed assignment operator. Subtracts the matrix expression
|
|
from the compressed matrix.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
compressed_matrix &minus_assign (const
|
|
matrix_expression<AE> &ae)</code></td>
|
|
<td>Subtracts a matrix expression from the compressed matrix. Left
|
|
and right hand side of the assignment should be independent.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AT><br>
|
|
compressed_matrix &operator *= (const AT &at)</code></td>
|
|
<td>A computed assignment operator. Multiplies the compressed
|
|
matrix with a scalar.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AT><br>
|
|
compressed_matrix &operator /= (const AT &at)</code></td>
|
|
<td>A computed assignment operator. Divides the compressed matrix
|
|
through a scalar.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void swap (compressed_matrix &m)</code></td>
|
|
<td>Swaps the contents of the compressed matrices.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void insert (size_type i, size_type j, const_reference
|
|
t)</code></td>
|
|
<td>Inserts the value <code>t</code> at the <code>j</code>-th
|
|
element of the <code>i</code>-th row.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void erase (size_type i, size_type j)</code></td>
|
|
<td>Erases the value at the <code>j</code>-th element of the
|
|
<code>i</code>-th row.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void clear ()</code></td>
|
|
<td>Clears the compressed matrix.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_iterator1 begin1 () const</code></td>
|
|
<td>Returns a <code>const_iterator1</code> pointing to the
|
|
beginning of the <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_iterator1 end1 () const</code></td>
|
|
<td>Returns a <code>const_iterator1</code> pointing to the end of
|
|
the <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>iterator1 begin1 ()</code> </td>
|
|
<td>Returns a <code>iterator1</code> pointing to the beginning of
|
|
the <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>iterator1 end1 ()</code> </td>
|
|
<td>Returns a <code>iterator1</code> pointing to the end of the
|
|
<code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_iterator2 begin2 () const</code></td>
|
|
<td>Returns a <code>const_iterator2</code> pointing to the
|
|
beginning of the <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_iterator2 end2 () const</code></td>
|
|
<td>Returns a <code>const_iterator2</code> pointing to the end of
|
|
the <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>iterator2 begin2 ()</code> </td>
|
|
<td>Returns a <code>iterator2</code> pointing to the beginning of
|
|
the <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>iterator2 end2 ()</code> </td>
|
|
<td>Returns a <code>iterator2</code> pointing to the end of the
|
|
<code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reverse_iterator1 rbegin1 () const</code></td>
|
|
<td>Returns a <code>const_reverse_iterator1</code> pointing to the
|
|
beginning of the reversed <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reverse_iterator1 rend1 () const</code></td>
|
|
<td>Returns a <code>const_reverse_iterator1</code> pointing to the
|
|
end of the reversed <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reverse_iterator1 rbegin1 ()</code> </td>
|
|
<td>Returns a <code>reverse_iterator1</code> pointing to the
|
|
beginning of the reversed <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reverse_iterator1 rend1 ()</code> </td>
|
|
<td>Returns a <code>reverse_iterator1</code> pointing to the end of
|
|
the reversed <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reverse_iterator2 rbegin2 () const</code></td>
|
|
<td>Returns a <code>const_reverse_iterator2</code> pointing to the
|
|
beginning of the reversed <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reverse_iterator2 rend2 () const</code></td>
|
|
<td>Returns a <code>const_reverse_iterator2</code> pointing to the
|
|
end of the reversed <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reverse_iterator2 rbegin2 ()</code> </td>
|
|
<td>Returns a <code>reverse_iterator2</code> pointing to the
|
|
beginning of the reversed <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reverse_iterator2 rend2 ()</code> </td>
|
|
<td>Returns a <code>reverse_iterator2</code> pointing to the end of
|
|
the reversed <code>compressed_matrix</code>.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h4>Notes</h4>
|
|
|
|
<p><a name="#compressed_matrix_1">[1]</a> Supported parameters for
|
|
the storage organization are <code>row_major</code> and
|
|
<code>column_major</code>.</p>
|
|
|
|
<p><a name="#compressed_matrix_2">[2]</a> Supported parameters for
|
|
the index base are <code>0</code> and <code>1</code> at least.</p>
|
|
|
|
<p><a name="#compressed_matrix_3">[3]</a> Supported parameters for
|
|
the adapted array are <code>unbounded_array<></code> ,
|
|
<code>bounded_array<></code> and
|
|
<code>std::vector<></code> .</p>
|
|
|
|
<h4>Interface</h4>
|
|
|
|
<pre>
|
|
<code>// Array based sparse matrix class<br>
|
|
template<class T, class F, std::size_t IB, class IA, class TA><br>
|
|
class compressed_matrix:<br>
|
|
public matrix_expression<compressed_matrix<T, F, IB, IA, TA> > {<br>
|
|
public: <br>
|
|
typedef std::size_t size_type;<br>
|
|
typedef std::ptrdiff_t difference_type;<br>
|
|
typedef T value_type;<br>
|
|
typedef const T &const_reference;<br>
|
|
typedef T &reference;<br>
|
|
typedef const T *const_pointer;<br>
|
|
typedef T *pointer;<br>
|
|
typedef F functor_type;<br>
|
|
typedef IA index_array_type;<br>
|
|
typedef TA value_array_type;<br>
|
|
typedef const compressed_matrix<T, F, IB, IA, TA> const_self_type;<br>
|
|
typedef compressed_matrix<T, F, IB, IA, TA> self_type;<br>
|
|
typedef const matrix_const_reference<const_self_type> const_closure_type;<br>
|
|
typedef matrix_reference<self_type> closure_type;<br>
|
|
typedef typename A::const_iterator const_iterator_type;<br>
|
|
typedef typename A::iterator iterator_type;<br>
|
|
typedef sparse_tag storage_category;<br>
|
|
typedef typename F::orientation_category orientation_category;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
compressed_matrix ();<br>
|
|
compressed_matrix (size_type size1, size_type size2, size_type non_zeros = 0);<br>
|
|
compressed_matrix (const compressed_matrix &m);<br>
|
|
template<class AE><br>
|
|
compressed_matrix (const matrix_expression<AE> &ae, size_type non_zeros = 0);<br>
|
|
<br>
|
|
// Accessors<br>
|
|
size_type size1 () const;<br>
|
|
size_type size2 () const;<br>
|
|
size_type non_zeros () const;<br>
|
|
static size_type index_base ();<br>
|
|
const index_array_type &index1_data () const;<br>
|
|
index_array_type &index1_data ();<br>
|
|
const index_array_type &index2_data () const;<br>
|
|
index_array_type &index2_data ();<br>
|
|
const value_array_type &value_data () const;<br>
|
|
value_array_type &value_data ();<br>
|
|
<br>
|
|
// Resizing<br>
|
|
void resize (size_type size1, size_type size2, size_type non_zeros = 0);<br>
|
|
<br>
|
|
// Element access<br>
|
|
const_reference operator () (size_type i, size_type j) const;<br>
|
|
reference operator () (size_type i, size_type j);<br>
|
|
<br>
|
|
// Assignment<br>
|
|
compressed_matrix &operator = (const compressed_matrix &m);<br>
|
|
compressed_matrix &assign_temporary (compressed_matrix &m);<br>
|
|
template<class AE><br>
|
|
compressed_matrix &operator = (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
compressed_matrix &reset (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
compressed_matrix &assign (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
compressed_matrix& operator += (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
compressed_matrix &plus_assign (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
compressed_matrix& operator -= (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
compressed_matrix &minus_assign (const matrix_expression<AE> &ae);<br>
|
|
template<class AT><br>
|
|
compressed_matrix& operator *= (const AT &at);<br>
|
|
template<class AT><br>
|
|
compressed_matrix& operator /= (const AT &at);<br>
|
|
<br>
|
|
// Swapping<br>
|
|
void swap (compressed_matrix &m);<br>
|
|
friend void swap (compressed_matrix &m1, compressed_matrix &m2);<br>
|
|
<br>
|
|
// Element insertion and erasure<br>
|
|
void insert (size_type i, size_type j, const_reference t);<br>
|
|
void erase (size_type i, size_type j);<br>
|
|
void clear ();<br>
|
|
<br>
|
|
class const_iterator1;<br>
|
|
class iterator1;<br>
|
|
class const_iterator2;<br>
|
|
class iterator2;<br>
|
|
typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;<br>
|
|
typedef reverse_iterator_base1<iterator1> reverse_iterator1;<br>
|
|
typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;<br>
|
|
typedef reverse_iterator_base2<iterator2> reverse_iterator2;<br>
|
|
<br>
|
|
// Element lookup<br>
|
|
const_iterator1 find1 (int rank, size_type i, size_type j) const;<br>
|
|
iterator1 find1 (int rank, size_type i, size_type j);<br>
|
|
const_iterator2 find2 (int rank, size_type i, size_type j) const;<br>
|
|
iterator2 find2 (int rank, size_type i, size_type j);<br>
|
|
const_iterator1 find_first1 (int rank, size_type i, size_type j) const;<br>
|
|
iterator1 find_first1 (int rank, size_type i, size_type j);<br>
|
|
const_iterator1 find_last1 (int rank, size_type i, size_type j) const;<br>
|
|
iterator1 find_last1 (int rank, size_type i, size_type j);<br>
|
|
const_iterator2 find_first2 (int rank, size_type i, size_type j) const;<br>
|
|
iterator2 find_first2 (int rank, size_type i, size_type j);<br>
|
|
const_iterator2 find_last2 (int rank, size_type i, size_type j) const;<br>
|
|
iterator2 find_last2 (int rank, size_type i, size_type j);<br>
|
|
<br>
|
|
// Iterators simply are pointers.<br>
|
|
<br>
|
|
class const_iterator1:<br>
|
|
public container_const_reference<compressed_matrix>,<br>
|
|
public bidirectional_iterator_base<const_iterator1, value_type> {<br>
|
|
public:<br>
|
|
typedef sparse_bidirectional_iterator_tag iterator_category;<br>
|
|
typedef typename compressed_matrix::difference_type difference_type;<br>
|
|
typedef typename compressed_matrix::value_type value_type;<br>
|
|
typedef typename compressed_matrix::const_reference reference;<br>
|
|
typedef typename compressed_matrix::const_pointer pointer;<br>
|
|
typedef const_iterator2 dual_iterator_type;<br>
|
|
typedef const_reverse_iterator2 dual_reverse_iterator_type;<br>
|
|
typedef typename functor_type::functor1_type functor1_type;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
const_iterator1 ();<br>
|
|
const_iterator1 (const compressed_matrix &m, int rank, size_type i, size_type j, const const_iterator_type &it);<br>
|
|
const_iterator1 (const iterator1 &it);<br>
|
|
<br>
|
|
// Arithmetic<br>
|
|
const_iterator1 &operator ++ ();<br>
|
|
const_iterator1 &operator -- ();<br>
|
|
<br>
|
|
// Dereference<br>
|
|
reference operator * () const;<br>
|
|
<br>
|
|
const_iterator2 begin () const;<br>
|
|
const_iterator2 end () const;<br>
|
|
const_reverse_iterator2 rbegin () const;<br>
|
|
const_reverse_iterator2 rend () const;<br>
|
|
<br>
|
|
// Indices<br>
|
|
size_type index1 () const;<br>
|
|
size_type index2 () const;<br>
|
|
<br>
|
|
// Assignment<br>
|
|
const_iterator1 &operator = (const const_iterator1 &it);<br>
|
|
<br>
|
|
// Comparison<br>
|
|
bool operator == (const const_iterator1 &it) const;<br>
|
|
};<br>
|
|
<br>
|
|
const_iterator1 begin1 () const;<br>
|
|
const_iterator1 end1 () const;<br>
|
|
<br>
|
|
class iterator1:<br>
|
|
public container_reference<compressed_matrix>,<br>
|
|
public bidirectional_iterator_base<iterator1, value_type> {<br>
|
|
public:<br>
|
|
typedef sparse_bidirectional_iterator_tag iterator_category;<br>
|
|
typedef typename compressed_matrix::difference_type difference_type;<br>
|
|
typedef typename compressed_matrix::value_type value_type;<br>
|
|
typedef typename compressed_matrix::reference reference;<br>
|
|
typedef typename compressed_matrix::pointer pointer;<br>
|
|
typedef iterator2 dual_iterator_type;<br>
|
|
typedef reverse_iterator2 dual_reverse_iterator_type;<br>
|
|
typedef typename functor_type::functor1_type functor1_type;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
iterator1 ();<br>
|
|
iterator1 (compressed_matrix &m, int rank, size_type i, size_type j, const iterator_type &it);<br>
|
|
<br>
|
|
// Arithmetic<br>
|
|
iterator1 &operator ++ ();<br>
|
|
iterator1 &operator -- ();<br>
|
|
<br>
|
|
// Dereference<br>
|
|
reference operator * () const;<br>
|
|
<br>
|
|
iterator2 begin () const;<br>
|
|
iterator2 end () const;<br>
|
|
reverse_iterator2 rbegin () const;<br>
|
|
reverse_iterator2 rend () const;<br>
|
|
<br>
|
|
// Indices<br>
|
|
size_type index1 () const;<br>
|
|
size_type index2 () const;<br>
|
|
<br>
|
|
// Assignment<br>
|
|
iterator1 &operator = (const iterator1 &it);<br>
|
|
<br>
|
|
// Comparison<br>
|
|
bool operator == (const iterator1 &it) const;<br>
|
|
};<br>
|
|
<br>
|
|
iterator1 begin1 ();<br>
|
|
iterator1 end1 ();<br>
|
|
<br>
|
|
class const_iterator2:<br>
|
|
public container_const_reference<compressed_matrix>,<br>
|
|
public bidirectional_iterator_base<const_iterator2, value_type> {<br>
|
|
public:<br>
|
|
typedef sparse_bidirectional_iterator_tag iterator_category;<br>
|
|
typedef typename compressed_matrix::difference_type difference_type;<br>
|
|
typedef typename compressed_matrix::value_type value_type;<br>
|
|
typedef typename compressed_matrix::const_reference reference;<br>
|
|
typedef typename compressed_matrix::const_pointer pointer;<br>
|
|
typedef const_iterator1 dual_iterator_type;<br>
|
|
typedef const_reverse_iterator1 dual_reverse_iterator_type;<br>
|
|
typedef typename functor_type::functor2_type functor2_type;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
const_iterator2 ();<br>
|
|
const_iterator2 (const compressed_matrix &m, int rank, size_type i, size_type j, const const_iterator_type &it);<br>
|
|
const_iterator2 (const iterator2 &it);<br>
|
|
<br>
|
|
// Arithmetic<br>
|
|
const_iterator2 &operator ++ ();<br>
|
|
const_iterator2 &operator -- ();<br>
|
|
<br>
|
|
// Dereference<br>
|
|
reference operator * () const;<br>
|
|
<br>
|
|
const_iterator1 begin () const;<br>
|
|
const_iterator1 end () const;<br>
|
|
const_reverse_iterator1 rbegin () const;<br>
|
|
const_reverse_iterator1 rend () const;<br>
|
|
<br>
|
|
// Indices<br>
|
|
size_type index1 () const;<br>
|
|
size_type index2 () const;<br>
|
|
<br>
|
|
// Assignment<br>
|
|
const_iterator2 &operator = (const const_iterator2 &it);<br>
|
|
<br>
|
|
// Comparison<br>
|
|
bool operator == (const const_iterator2 &it) const;<br>
|
|
};<br>
|
|
<br>
|
|
const_iterator2 begin2 () const;<br>
|
|
const_iterator2 end2 () const;<br>
|
|
<br>
|
|
class iterator2:<br>
|
|
public container_reference<compressed_matrix>,<br>
|
|
public bidirectional_iterator_base<iterator2, value_type> {<br>
|
|
public:<br>
|
|
typedef sparse_bidirectional_iterator_tag iterator_category;<br>
|
|
typedef typename compressed_matrix::difference_type difference_type;<br>
|
|
typedef typename compressed_matrix::value_type value_type;<br>
|
|
typedef typename compressed_matrix::reference reference;<br>
|
|
typedef typename compressed_matrix::pointer pointer;<br>
|
|
typedef iterator1 dual_iterator_type;<br>
|
|
typedef reverse_iterator1 dual_reverse_iterator_type;<br>
|
|
typedef typename functor_type::functor2_type functor2_type;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
iterator2 ();<br>
|
|
iterator2 (compressed_matrix &m, int rank, size_type i, size_type j, const iterator_type &it);<br>
|
|
<br>
|
|
// Arithmetic<br>
|
|
iterator2 &operator ++ ();<br>
|
|
iterator2 &operator -- ();<br>
|
|
<br>
|
|
// Dereference<br>
|
|
reference operator * () const;<br>
|
|
<br>
|
|
iterator1 begin () const;<br>
|
|
iterator1 end () const;<br>
|
|
reverse_iterator1 rbegin () const;<br>
|
|
reverse_iterator1 rend () const;<br>
|
|
<br>
|
|
// Indices<br>
|
|
size_type index1 () const;<br>
|
|
size_type index2 () const;<br>
|
|
<br>
|
|
// Assignment<br>
|
|
iterator2 &operator = (const iterator2 &it);<br>
|
|
<br>
|
|
// Comparison<br>
|
|
bool operator == (const iterator2 &it) const;<br>
|
|
};<br>
|
|
<br>
|
|
iterator2 begin2 ();<br>
|
|
iterator2 end2 ();<br>
|
|
<br>
|
|
// Reverse iterators<br>
|
|
<br>
|
|
const_reverse_iterator1 rbegin1 () const;<br>
|
|
const_reverse_iterator1 rend1 () const;<br>
|
|
<br>
|
|
reverse_iterator1 rbegin1 ();<br>
|
|
reverse_iterator1 rend1 ();<br>
|
|
<br>
|
|
const_reverse_iterator2 rbegin2 () const;<br>
|
|
const_reverse_iterator2 rend2 () const;<br>
|
|
<br>
|
|
reverse_iterator2 rbegin2 ();<br>
|
|
reverse_iterator2 rend2 ();<br>
|
|
};</code>
|
|
</pre>
|
|
|
|
<h2><a name="coordinate_matrix"></a> Coordinate Matrix</h2>
|
|
|
|
<h4>Description</h4>
|
|
|
|
<p>The templated class <code>coordinate_matrix<T, F, IB, IA,
|
|
TA></code> is the base container adaptor for compressed
|
|
matrices. For a <em>(m x n</em> )-dimensional sorted coordinate
|
|
matrix and <em>0 <= i < m</em>, <em>0 <= j < n</em> the
|
|
non-zero elements <em>m</em><sub><em>i, j</em></sub> are mapped via
|
|
<em>(i x n + j)</em> for row major orientation or via <em>(i + j x
|
|
m)</em> for column major orientation to consecutive elements of the
|
|
index and value containers, i.e. for elements <em>k</em> =
|
|
<em>m</em><sub><em>i</em></sub><sub><sub><em>1</em></sub></sub><sub>
|
|
<em>,j</em></sub><sub><sub><em>1</em></sub></sub><sub><em></em></sub>and
|
|
<em>k + 1 =
|
|
m</em><sub><em>i</em></sub><sub><sub><em>2</em></sub></sub><sub><em>
|
|
,j</em></sub><sub><sub><em>2</em></sub></sub><sub><em></em></sub>of
|
|
the container holds <em>i</em><sub><em>1</em></sub> <em><
|
|
i</em><sub><em>2</em></sub> or <em>(i</em><sub><em>1</em></sub>
|
|
<em>= i</em><sub><em>2</em></sub> and
|
|
<em>j</em><sub><em>1</em></sub> <em><
|
|
j</em><sub><em>2</em></sub><em>)</em> with row major orientation or
|
|
<em>j</em><sub><em>1</em></sub> <em><
|
|
j</em><sub><em>2</em></sub> or <em>(j</em><sub><em>1</em></sub>
|
|
<em>= j</em><sub><em>2</em></sub> and
|
|
<em>i</em><sub><em>1</em></sub> <em><
|
|
i</em><sub><em>2</em></sub><em>)</em> with column major
|
|
orientation.</p>
|
|
|
|
<h4>Example</h4>
|
|
|
|
<pre>
|
|
#include <boost/numeric/ublas/matrix_sparse.hpp><br>
|
|
#include <boost/numeric/ublas/io.hpp><br>
|
|
<br>
|
|
int main () {<br>
|
|
using namespace boost::numeric::ublas;<br>
|
|
coordinate_matrix<double> m (3, 3, 3 * 3);<br>
|
|
for (unsigned i = 0; i < m.size1 (); ++ i)<br>
|
|
for (unsigned j = 0; j < m.size2 (); ++ j)<br>
|
|
m (i, j) = 3 * i + j;<br>
|
|
std::cout << m << std::endl;<br>
|
|
}<br>
|
|
</pre>
|
|
|
|
<h4>Definition</h4>
|
|
|
|
<p>Defined in the header matrix_sparse.hpp.</p>
|
|
|
|
<h4>Template parameters</h4>
|
|
|
|
<table border="1">
|
|
<tbody>
|
|
<tr>
|
|
<th>Parameter</th>
|
|
<th>Description</th>
|
|
<th>Default</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>T</code> </td>
|
|
<td>The type of object stored in the coordinate matrix.</td>
|
|
<td> </td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>F</code></td>
|
|
<td>Functor describing the storage organization. <a href=
|
|
"#coordinate_matrix_1">[1]</a> </td>
|
|
<td><code>row_major</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>IB</code></td>
|
|
<td>The index base of the coordinate vector. <a href=
|
|
"#coordinate_matrix_2">[2]</a> </td>
|
|
<td><code>0</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>IA</code></td>
|
|
<td>The type of the adapted array for indices. <a href=
|
|
"#coordinate_matrix_3">[3]</a> </td>
|
|
<td><code>unbounded_array<std::size_t></code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>TA</code></td>
|
|
<td>The type of the adapted array for values. <a href=
|
|
"#coordinate_matrix_3">[3]</a> </td>
|
|
<td><code>unbounded_array<T></code></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h4>Model of</h4>
|
|
|
|
<p><a href="container.htm#matrix">Matrix</a> .</p>
|
|
|
|
<h4>Type requirements</h4>
|
|
|
|
<p>None, except for those imposed by the requirements of <a href=
|
|
"container.htm#matrix">Matrix</a> .</p>
|
|
|
|
<h4>Public base classes</h4>
|
|
|
|
<p><code>matrix_expression<coordinate_matrix<T, F, IB, IA,
|
|
TA> ></code></p>
|
|
|
|
<h4>Members</h4>
|
|
|
|
<table border="1">
|
|
<tbody>
|
|
<tr>
|
|
<th>Member</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>coordinate_matrix ()</code> </td>
|
|
<td>Allocates a <code>coordinate_matrix</code> that holds at most
|
|
zero rows of zero elements.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>coordinate_matrix (size_type size1, size_type2, size_type
|
|
non_zeros)</code></td>
|
|
<td>Allocates a <code>coordinate_matrix</code> that holds at most
|
|
<code>size1</code> rows of <code>size2</code> elements.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>coordinate_matrix (const coordinate_matrix
|
|
&m)</code></td>
|
|
<td>The copy constructor.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
coordinate_matrix (size_type non_zeros, const
|
|
matrix_expression<AE> &ae)</code></td>
|
|
<td>The extended copy constructor.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void resize (size_type size1, size_type size2, size_type
|
|
non_zeros)</code></td>
|
|
<td>Reallocates a <code>coordinate_matrix</code> to hold at most
|
|
<code>size1</code> rows of <code>size2</code> elements. The content
|
|
of the <code>coordinate_matrix</code> is preserved.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>size_type size1 () const</code></td>
|
|
<td>Returns the number of rows.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>size_type size2 () const</code></td>
|
|
<td>Returns the number of columns.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reference operator () (size_type i, size_type j)
|
|
const</code></td>
|
|
<td>Returns the value of the <code>j</code>-th element in the
|
|
<code>i</code>-th row.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reference operator () (size_type i, size_type
|
|
j)</code></td>
|
|
<td>Returns a reference of the <code>j</code>-th element in the
|
|
<code>i</code>-th row.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>coordinate_matrix &operator = (const
|
|
coordinate_matrix &m)</code></td>
|
|
<td>The assignment operator.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>coordinate_matrix &assign_temporary
|
|
(coordinate_matrix &m)</code></td>
|
|
<td>Assigns a temporary. May change the coordinate matrix
|
|
<code>m</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
coordinate_matrix &operator = (const
|
|
matrix_expression<AE> &ae)</code></td>
|
|
<td>The extended assignment operator.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
coordinate_matrix &assign (const matrix_expression<AE>
|
|
&ae)</code></td>
|
|
<td>Assigns a matrix expression to the coordinate matrix. Left and
|
|
right hand side of the assignment should be independent.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
coordinate_matrix &operator += (const
|
|
matrix_expression<AE> &ae)</code></td>
|
|
<td>A computed assignment operator. Adds the matrix expression to
|
|
the coordinate matrix.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
coordinate_matrix &plus_assign (const
|
|
matrix_expression<AE> &ae)</code></td>
|
|
<td>Adds a matrix expression to the coordinate matrix. Left and
|
|
right hand side of the assignment should be independent.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
coordinate_matrix &operator -= (const
|
|
matrix_expression<AE> &ae)</code></td>
|
|
<td>A computed assignment operator. Subtracts the matrix expression
|
|
from the coordinate matrix.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AE><br>
|
|
coordinate_matrix &minus_assign (const
|
|
matrix_expression<AE> &ae)</code></td>
|
|
<td>Subtracts a matrix expression from the coordinate matrix. Left
|
|
and right hand side of the assignment should be independent.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AT><br>
|
|
coordinate_matrix &operator *= (const AT &at)</code></td>
|
|
<td>A computed assignment operator. Multiplies the coordinate
|
|
matrix with a scalar.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>template<class AT><br>
|
|
coordinate_matrix &operator /= (const AT &at)</code></td>
|
|
<td>A computed assignment operator. Divides the coordinate matrix
|
|
through a scalar.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void swap (coordinate_matrix &m)</code></td>
|
|
<td>Swaps the contents of the coordinate matrices.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void insert (size_type i, size_type j, const_reference
|
|
t)</code></td>
|
|
<td>Inserts the value <code>t</code> at the <code>j</code>-th
|
|
element of the <code>i</code>-th row.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void erase (size_type i, size_type j)</code></td>
|
|
<td>Erases the value at the <code>j</code>-th element of the
|
|
<code>i</code>-th row.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>void clear ()</code></td>
|
|
<td>Clears the coordinate matrix.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_iterator1 begin1 () const</code></td>
|
|
<td>Returns a <code>const_iterator1</code> pointing to the
|
|
beginning of the <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_iterator1 end1 () const</code></td>
|
|
<td>Returns a <code>const_iterator1</code> pointing to the end of
|
|
the <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>iterator1 begin1 ()</code> </td>
|
|
<td>Returns a <code>iterator1</code> pointing to the beginning of
|
|
the <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>iterator1 end1 ()</code> </td>
|
|
<td>Returns a <code>iterator1</code> pointing to the end of the
|
|
<code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_iterator2 begin2 () const</code></td>
|
|
<td>Returns a <code>const_iterator2</code> pointing to the
|
|
beginning of the <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_iterator2 end2 () const</code></td>
|
|
<td>Returns a <code>const_iterator2</code> pointing to the end of
|
|
the <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>iterator2 begin2 ()</code> </td>
|
|
<td>Returns a <code>iterator2</code> pointing to the beginning of
|
|
the <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>iterator2 end2 ()</code> </td>
|
|
<td>Returns a <code>iterator2</code> pointing to the end of the
|
|
<code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reverse_iterator1 rbegin1 () const</code></td>
|
|
<td>Returns a <code>const_reverse_iterator1</code> pointing to the
|
|
beginning of the reversed <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reverse_iterator1 rend1 () const</code></td>
|
|
<td>Returns a <code>const_reverse_iterator1</code> pointing to the
|
|
end of the reversed <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reverse_iterator1 rbegin1 ()</code> </td>
|
|
<td>Returns a <code>reverse_iterator1</code> pointing to the
|
|
beginning of the reversed <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reverse_iterator1 rend1 ()</code> </td>
|
|
<td>Returns a <code>reverse_iterator1</code> pointing to the end of
|
|
the reversed <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reverse_iterator2 rbegin2 () const</code></td>
|
|
<td>Returns a <code>const_reverse_iterator2</code> pointing to the
|
|
beginning of the reversed <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>const_reverse_iterator2 rend2 () const</code></td>
|
|
<td>Returns a <code>const_reverse_iterator2</code> pointing to the
|
|
end of the reversed <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reverse_iterator2 rbegin2 ()</code> </td>
|
|
<td>Returns a <code>reverse_iterator2</code> pointing to the
|
|
beginning of the reversed <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>reverse_iterator2 rend2 ()</code> </td>
|
|
<td>Returns a <code>reverse_iterator2</code> pointing to the end of
|
|
the reversed <code>coordinate_matrix</code>.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h4>Notes</h4>
|
|
|
|
<p><a name="#coordinate_matrix_1">[1]</a> Supported parameters for
|
|
the storage organization are <code>row_major</code> and
|
|
<code>column_major</code>.</p>
|
|
|
|
<p><a name="#coordinate_matrix_2">[2]</a> Supported parameters for
|
|
the index base are <code>0</code> and <code>1</code> at least.</p>
|
|
|
|
<p><a name="#coordinate_matrix_3">[3]</a> Supported parameters for
|
|
the adapted array are <code>unbounded_array<></code> ,
|
|
<code>bounded_array<></code> and
|
|
<code>std::vector<></code> .</p>
|
|
|
|
<h4>Interface</h4>
|
|
|
|
<pre>
|
|
<code>// Array based sparse matrix class<br>
|
|
template<class T, class F, std::size_t IB, class IA, class TA><br>
|
|
class coordinate_matrix:<br>
|
|
public matrix_expression<coordinate_matrix<T, F, IB, IA, TA> > {<br>
|
|
public: <br>
|
|
typedef std::size_t size_type;<br>
|
|
typedef std::ptrdiff_t difference_type;<br>
|
|
typedef T value_type;<br>
|
|
typedef const T &const_reference;<br>
|
|
typedef T &reference;<br>
|
|
typedef const T *const_pointer;<br>
|
|
typedef T *pointer;<br>
|
|
typedef F functor_type;<br>
|
|
typedef IA index_array_type;<br>
|
|
typedef TA value_array_type;<br>
|
|
typedef const coordinate_matrix<T, F, IB, IA, TA> const_self_type;<br>
|
|
typedef coordinate_matrix<T, F, IB, IA, TA> self_type;<br>
|
|
typedef const matrix_const_reference<const_self_type> const_closure_type;<br>
|
|
typedef matrix_reference<self_type> closure_type;<br>
|
|
typedef typename A::const_iterator const_iterator_type;<br>
|
|
typedef typename A::iterator iterator_type;<br>
|
|
typedef sparse_tag storage_category;<br>
|
|
typedef typename F::orientation_category orientation_category;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
coordinate_matrix ();<br>
|
|
coordinate_matrix (size_type size1, size_type size2, size_type non_zeros = 0);<br>
|
|
coordinate_matrix (const coordinate_matrix &m);<br>
|
|
template<class AE><br>
|
|
coordinate_matrix (const matrix_expression<AE> &ae, size_type non_zeros = 0);<br>
|
|
<br>
|
|
// Accessors<br>
|
|
size_type size1 () const;<br>
|
|
size_type size2 () const;<br>
|
|
size_type non_zeros () const;<br>
|
|
static size_type index_base ();<br>
|
|
const index_array_type &index1_data () const;<br>
|
|
index_array_type &index1_data ();<br>
|
|
const index_array_type &index2_data () const;<br>
|
|
index_array_type &index2_data ();<br>
|
|
const value_array_type &value_data () const;<br>
|
|
value_array_type &value_data ();<br>
|
|
<br>
|
|
// Resizing<br>
|
|
void resize (size_type size1, size_type size2, size_type non_zeros = 0);<br>
|
|
<br>
|
|
// Element access<br>
|
|
const_reference operator () (size_type i, size_type j) const;<br>
|
|
reference operator () (size_type i, size_type j);<br>
|
|
<br>
|
|
// Assignment<br>
|
|
coordinate_matrix &operator = (const coordinate_matrix &m);<br>
|
|
coordinate_matrix &assign_temporary (coordinate_matrix &m);<br>
|
|
template<class AE><br>
|
|
coordinate_matrix &operator = (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
coordinate_matrix &reset (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
coordinate_matrix &assign (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
coordinate_matrix& operator += (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
coordinate_matrix &plus_assign (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
coordinate_matrix& operator -= (const matrix_expression<AE> &ae);<br>
|
|
template<class AE><br>
|
|
coordinate_matrix &minus_assign (const matrix_expression<AE> &ae);<br>
|
|
template<class AT><br>
|
|
coordinate_matrix& operator *= (const AT &at);<br>
|
|
template<class AT><br>
|
|
coordinate_matrix& operator /= (const AT &at);<br>
|
|
<br>
|
|
// Swapping<br>
|
|
void swap (coordinate_matrix &m);<br>
|
|
friend void swap (coordinate_matrix &m1, coordinate_matrix &m2);<br>
|
|
<br>
|
|
// Element insertion and erasure<br>
|
|
void insert (size_type i, size_type j, const_reference t);<br>
|
|
void erase (size_type i, size_type j);<br>
|
|
void clear ();<br>
|
|
<br>
|
|
class const_iterator1;<br>
|
|
class iterator1;<br>
|
|
class const_iterator2;<br>
|
|
class iterator2;<br>
|
|
typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;<br>
|
|
typedef reverse_iterator_base1<iterator1> reverse_iterator1;<br>
|
|
typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;<br>
|
|
typedef reverse_iterator_base2<iterator2> reverse_iterator2;<br>
|
|
<br>
|
|
// Element lookup<br>
|
|
const_iterator1 find1 (int rank, size_type i, size_type j) const;<br>
|
|
iterator1 find1 (int rank, size_type i, size_type j);<br>
|
|
const_iterator2 find2 (int rank, size_type i, size_type j) const;<br>
|
|
iterator2 find2 (int rank, size_type i, size_type j);<br>
|
|
const_iterator1 find_first1 (int rank, size_type i, size_type j) const;<br>
|
|
iterator1 find_first1 (int rank, size_type i, size_type j);<br>
|
|
const_iterator1 find_last1 (int rank, size_type i, size_type j) const;<br>
|
|
iterator1 find_last1 (int rank, size_type i, size_type j);<br>
|
|
const_iterator2 find_first2 (int rank, size_type i, size_type j) const;<br>
|
|
iterator2 find_first2 (int rank, size_type i, size_type j);<br>
|
|
const_iterator2 find_last2 (int rank, size_type i, size_type j) const;<br>
|
|
iterator2 find_last2 (int rank, size_type i, size_type j);<br>
|
|
<br>
|
|
// Iterators simply are pointers.<br>
|
|
<br>
|
|
class const_iterator1:<br>
|
|
public container_const_reference<coordinate_matrix>,<br>
|
|
public bidirectional_iterator_base<const_iterator1, value_type> {<br>
|
|
public:<br>
|
|
typedef sparse_bidirectional_iterator_tag iterator_category;<br>
|
|
typedef typename coordinate_matrix::difference_type difference_type;<br>
|
|
typedef typename coordinate_matrix::value_type value_type;<br>
|
|
typedef typename coordinate_matrix::const_reference reference;<br>
|
|
typedef typename coordinate_matrix::const_pointer pointer;<br>
|
|
typedef const_iterator2 dual_iterator_type;<br>
|
|
typedef const_reverse_iterator2 dual_reverse_iterator_type;<br>
|
|
typedef typename functor_type::functor1_type functor1_type;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
const_iterator1 ();<br>
|
|
const_iterator1 (const coordinate_matrix &m, int rank, size_type i, size_type j, const const_iterator_type &it);<br>
|
|
const_iterator1 (const iterator1 &it);<br>
|
|
<br>
|
|
// Arithmetic<br>
|
|
const_iterator1 &operator ++ ();<br>
|
|
const_iterator1 &operator -- ();<br>
|
|
<br>
|
|
// Dereference<br>
|
|
reference operator * () const;<br>
|
|
<br>
|
|
const_iterator2 begin () const;<br>
|
|
const_iterator2 end () const;<br>
|
|
const_reverse_iterator2 rbegin () const;<br>
|
|
const_reverse_iterator2 rend () const;<br>
|
|
<br>
|
|
// Indices<br>
|
|
size_type index1 () const;<br>
|
|
size_type index2 () const;<br>
|
|
<br>
|
|
// Assignment<br>
|
|
const_iterator1 &operator = (const const_iterator1 &it);<br>
|
|
<br>
|
|
// Comparison<br>
|
|
bool operator == (const const_iterator1 &it) const;<br>
|
|
};<br>
|
|
<br>
|
|
const_iterator1 begin1 () const;<br>
|
|
const_iterator1 end1 () const;<br>
|
|
<br>
|
|
class iterator1:<br>
|
|
public container_reference<coordinate_matrix>,<br>
|
|
public bidirectional_iterator_base<iterator1, value_type> {<br>
|
|
public:<br>
|
|
typedef sparse_bidirectional_iterator_tag iterator_category;<br>
|
|
typedef typename coordinate_matrix::difference_type difference_type;<br>
|
|
typedef typename coordinate_matrix::value_type value_type;<br>
|
|
typedef typename coordinate_matrix::reference reference;<br>
|
|
typedef typename coordinate_matrix::pointer pointer;<br>
|
|
typedef iterator2 dual_iterator_type;<br>
|
|
typedef reverse_iterator2 dual_reverse_iterator_type;<br>
|
|
typedef typename functor_type::functor1_type functor1_type;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
iterator1 ();<br>
|
|
iterator1 (coordinate_matrix &m, int rank, size_type i, size_type j, const iterator_type &it);<br>
|
|
<br>
|
|
// Arithmetic<br>
|
|
iterator1 &operator ++ ();<br>
|
|
iterator1 &operator -- ();<br>
|
|
<br>
|
|
// Dereference<br>
|
|
reference operator * () const;<br>
|
|
<br>
|
|
iterator2 begin () const;<br>
|
|
iterator2 end () const;<br>
|
|
reverse_iterator2 rbegin () const;<br>
|
|
reverse_iterator2 rend () const;<br>
|
|
<br>
|
|
// Indices<br>
|
|
size_type index1 () const;<br>
|
|
size_type index2 () const;<br>
|
|
<br>
|
|
// Assignment<br>
|
|
iterator1 &operator = (const iterator1 &it);<br>
|
|
<br>
|
|
// Comparison<br>
|
|
bool operator == (const iterator1 &it) const;<br>
|
|
};<br>
|
|
<br>
|
|
iterator1 begin1 ()<br>
|
|
iterator1 end1 ();<br>
|
|
<br>
|
|
class const_iterator2:<br>
|
|
public container_const_reference<coordinate_matrix>,<br>
|
|
public bidirectional_iterator_base<const_iterator2, value_type> {<br>
|
|
public:<br>
|
|
typedef sparse_bidirectional_iterator_tag iterator_category;<br>
|
|
typedef typename coordinate_matrix::difference_type difference_type;<br>
|
|
typedef typename coordinate_matrix::value_type value_type;<br>
|
|
typedef typename coordinate_matrix::const_reference reference;<br>
|
|
typedef typename coordinate_matrix::const_pointer pointer;<br>
|
|
typedef const_iterator1 dual_iterator_type;<br>
|
|
typedef const_reverse_iterator1 dual_reverse_iterator_type;<br>
|
|
typedef typename functor_type::functor2_type functor2_type;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
const_iterator2 ();<br>
|
|
const_iterator2 (const coordinate_matrix &m, int rank, size_type i, size_type j, const const_iterator_type &it);<br>
|
|
const_iterator2 (const iterator2 &it);<br>
|
|
<br>
|
|
// Arithmetic<br>
|
|
const_iterator2 &operator ++ ();<br>
|
|
const_iterator2 &operator -- ();<br>
|
|
<br>
|
|
// Dereference<br>
|
|
reference operator * () const;<br>
|
|
<br>
|
|
const_iterator1 begin () const;<br>
|
|
const_iterator1 end () const;<br>
|
|
const_reverse_iterator1 rbegin () const;<br>
|
|
const_reverse_iterator1 rend () const;<br>
|
|
<br>
|
|
// Indices<br>
|
|
size_type index1 () const;<br>
|
|
size_type index2 () const;<br>
|
|
<br>
|
|
// Assignment<br>
|
|
const_iterator2 &operator = (const const_iterator2 &it);<br>
|
|
<br>
|
|
// Comparison<br>
|
|
bool operator == (const const_iterator2 &it) const;<br>
|
|
};<br>
|
|
<br>
|
|
const_iterator2 begin2 () const;<br>
|
|
const_iterator2 end2 () const;<br>
|
|
<br>
|
|
class iterator2:<br>
|
|
public container_reference<coordinate_matrix>,<br>
|
|
public bidirectional_iterator_base<iterator2, value_type> {<br>
|
|
public:<br>
|
|
typedef sparse_bidirectional_iterator_tag iterator_category;<br>
|
|
typedef typename coordinate_matrix::difference_type difference_type;<br>
|
|
typedef typename coordinate_matrix::value_type value_type;<br>
|
|
typedef typename coordinate_matrix::reference reference;<br>
|
|
typedef typename coordinate_matrix::pointer pointer;<br>
|
|
typedef iterator1 dual_iterator_type;<br>
|
|
typedef reverse_iterator1 dual_reverse_iterator_type;<br>
|
|
typedef typename functor_type::functor2_type functor2_type;<br>
|
|
<br>
|
|
// Construction and destruction<br>
|
|
iterator2 ();<br>
|
|
iterator2 (coordinate_matrix &m, int rank, size_type i, size_type j, const iterator_type &it);<br>
|
|
<br>
|
|
// Arithmetic<br>
|
|
iterator2 &operator ++ ();<br>
|
|
iterator2 &operator -- ();<br>
|
|
<br>
|
|
// Dereference<br>
|
|
reference operator * () const;<br>
|
|
<br>
|
|
iterator1 begin () const;<br>
|
|
iterator1 end () const;<br>
|
|
reverse_iterator1 rbegin () const;<br>
|
|
reverse_iterator1 rend () const;<br>
|
|
<br>
|
|
// Indices<br>
|
|
size_type index1 () const;<br>
|
|
size_type index2 () const;<br>
|
|
<br>
|
|
// Assignment<br>
|
|
iterator2 &operator = (const iterator2 &it);<br>
|
|
<br>
|
|
// Comparison<br>
|
|
bool operator == (const iterator2 &it) const;<br>
|
|
};<br>
|
|
<br>
|
|
iterator2 begin2 ();<br>
|
|
iterator2 end2 ();<br>
|
|
<br>
|
|
// Reverse iterators<br>
|
|
<br>
|
|
const_reverse_iterator1 rbegin1 () const;<br>
|
|
const_reverse_iterator1 rend1 () const;<br>
|
|
<br>
|
|
reverse_iterator1 rbegin1 ();<br>
|
|
reverse_iterator1 rend1 ();<br>
|
|
<br>
|
|
const_reverse_iterator2 rbegin2 () const;<br>
|
|
const_reverse_iterator2 rend2 () const;<br>
|
|
<br>
|
|
reverse_iterator2 rbegin2 ();<br>
|
|
reverse_iterator2 rend2 ();<br>
|
|
};</code>
|
|
</pre>
|
|
|
|
<hr>
|
|
<p>Copyright (©) 2000-2002 Joerg Walter, Mathias Koch<br>
|
|
Permission to copy, use, modify, sell and distribute this document
|
|
is granted provided this copyright notice appears in all copies.
|
|
This document is provided ``as is'' without express or implied
|
|
warranty, and with no claim as to its suitability for any
|
|
purpose.</p>
|
|
|
|
<p>Last revised: 1/15/2003</p>
|
|
</body>
|
|
</html>
|
|
|