1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <meta name=
"generator" content=
6 "HTML Tidy for Linux/x86 (vers 1st March 2004), see www.w3.org" />
7 <meta http-equiv=
"Content-Type" content=
8 "text/html; charset=us-ascii" />
9 <link rel=
"stylesheet" href=
"../../../../boost.css" type=
"text/css"/>
10 <link rel=
"stylesheet" href=
"ublas.css" type=
"text/css" />
11 <script type=
"text/javascript" src=
"js/jquery-1.3.2.min.js" async=
"async" ></script>
12 <script type=
"text/javascript" src=
"js/jquery.toc-gw.js" async=
"async" ></script>
13 <title>Sparse Matrix
</title>
16 <h1><img src=
"../../../../boost.png" align=
"middle" />Sparse Matricies
</h1>
17 <div class=
"toc" id=
"toc"></div>
18 <h2><a name=
"mapped_matrix"></a>Mapped Matrix
</h2>
20 <p>The templated class
<code>mapped_matrix
<T, F, A
></code> is
21 the base container adaptor for sparse matricies using element maps.
22 For a
<em>(m xn
</em>)-dimensional sparse matrix and
<em>0 <= i
< m
</em>,
23 <em>0 <= j
< n
</em> the non-zero elements
24 <em>m
</em><sub><em>i, j
</em></sub> are mapped via
<em>(i x n +
25 j)
</em> for row major orientation or via
<em>(i + j x m)
</em> for
26 column major orientation to consecutive elements of the associative
27 container, i.e. for elements
<em>k
</em> =
28 <em>m
</em><sub><em>i
</em></sub><sub><sub><em>1</em></sub></sub><sub>
29 <em>,j
</em></sub><sub><sub><em>1</em></sub></sub>and
<em>k +
1 =
30 m
</em><sub><em>i
</em></sub><sub><sub><em>2</em></sub></sub><sub><em>
31 ,j
</em></sub><sub><sub><em>2</em></sub></sub>of the container holds
32 <em>i
</em><sub><em>1</em></sub> <em><
33 i
</em><sub><em>2</em></sub> or
<em>(i
</em><sub><em>1</em></sub>
34 <em>= i
</em><sub><em>2</em></sub> and
35 <em>j
</em><sub><em>1</em></sub> <em><
36 j
</em><sub><em>2</em></sub><em>)
</em> with row major orientation or
37 <em>j
</em><sub><em>1</em></sub> <em><
38 j
</em><sub><em>2</em></sub> or
<em>(j
</em><sub><em>1</em></sub>
39 <em>= j
</em><sub><em>2</em></sub> and
40 <em>i
</em><sub><em>1</em></sub> <em><
41 i
</em><sub><em>2</em></sub><em>)
</em> with column major
45 #include
<boost/numeric/ublas/matrix_sparse.hpp
>
46 #include
<boost/numeric/ublas/io.hpp
>
49 using namespace boost::numeric::ublas;
50 mapped_matrix
<double
> m (
3,
3,
3 *
3);
51 for (unsigned i =
0; i
< m.size1 (); ++ i)
52 for (unsigned j =
0; j
< m.size2 (); ++ j)
54 std::cout
<< m
<< std::endl;
58 <p>Defined in the header matrix_sparse.hpp.
</p>
59 <h4>Template parameters
</h4>
60 <table border=
"1" summary=
"parameters">
68 <td><code>T
</code></td>
69 <td>The type of object stored in the mapped matrix.
</td>
73 <td><code>F
</code></td>
74 <td>Functor describing the storage organization.
<a href=
75 "#mapped_matrix_1">[
1]
</a></td>
76 <td><code>row_major
</code></td>
79 <td><code>A
</code></td>
80 <td>The type of the adapted array.
<a href=
81 "#mapped_matrix_2">[
2]
</a></td>
82 <td><code>map_std
<std::size_t, T
></code></td>
87 <p><a href=
"container_concept.html#matrix">Matrix
</a> .
</p>
88 <h4>Type requirements
</h4>
89 <p>None, except for those imposed by the requirements of
<a href=
90 "container_concept.html#matrix">Matrix
</a> .
</p>
91 <h4>Public base classes
</h4>
92 <p><code>matrix_container
<mapped_matrix
<T, F, A
>
95 <table border=
"1" summary=
"members">
102 <td><code>mapped_matrix ()
</code></td>
103 <td>Allocates a
<code>mapped_matrix
</code> that holds at most zero
104 rows of zero elements.
</td>
107 <td><code>mapped_matrix (size_type size1, size_type2, size_type non_zeros =
0)
</code></td>
108 <td>Allocates a
<code>mapped_matrix
</code> that holds at most
109 <code>size1
</code> rows of
<code>size2
</code> elements.
</td>
112 <td><code>mapped_matrix (const mapped_matrix
&m)
</code></td>
113 <td>The copy constructor.
</td>
116 <td><code>template
<class AE
><br />
117 mapped_matrix (size_type non_zeros, const
118 matrix_expression
<AE
> &ae)
</code></td>
119 <td>The extended copy constructor.
</td>
122 <td><code>void resize (size_type size1, size_type size2, bool preserve = true)
</code></td>
123 <td>Reallocates a
<code>mapped_matrix
</code> to hold at most
124 <code>size1
</code> rows of
<code>size2
</code> elements. The
125 existing elements of the
<code>mapped_matrix
</code> are preseved
129 <td><code>size_type size1 () const
</code></td>
130 <td>Returns the number of rows.
</td>
133 <td><code>size_type size2 () const
</code></td>
134 <td>Returns the number of columns.
</td>
137 <td><code>const_reference operator () (size_type i, size_type j)
139 <td>Returns the value of the
<code>j
</code>-th element in the
140 <code>i
</code>-th row.
</td>
143 <td><code>reference operator () (size_type i, size_type
145 <td>Returns a reference of the
<code>j
</code>-th element in the
146 <code>i
</code>-th row.
</td>
149 <td><code>mapped_matrix
&operator = (const mapped_matrix
151 <td>The assignment operator.
</td>
154 <td><code>mapped_matrix
&assign_temporary (mapped_matrix
156 <td>Assigns a temporary. May change the mapped matrix
157 <code>m
</code> .
</td>
160 <td><code>template
<class AE
><br />
161 mapped_matrix
&operator = (const matrix_expression
<AE
>
163 <td>The extended assignment operator.
</td>
166 <td><code>template
<class AE
><br />
167 mapped_matrix
&assign (const matrix_expression
<AE
>
169 <td>Assigns a matrix expression to the mapped matrix. Left and
170 right hand side of the assignment should be independent.
</td>
173 <td><code>template
<class AE
><br />
174 mapped_matrix
&operator += (const matrix_expression
<AE
>
176 <td>A computed assignment operator. Adds the matrix expression to
177 the mapped matrix.
</td>
180 <td><code>template
<class AE
><br />
181 mapped_matrix
&plus_assign (const matrix_expression
<AE
>
183 <td>Adds a matrix expression to the mapped matrix. Left and right
184 hand side of the assignment should be independent.
</td>
187 <td><code>template
<class AE
><br />
188 mapped_matrix
&operator -= (const matrix_expression
<AE
>
190 <td>A computed assignment operator. Subtracts the matrix expression
191 from the mapped matrix.
</td>
194 <td><code>template
<class AE
><br />
195 mapped_matrix
&minus_assign (const matrix_expression
<AE
>
197 <td>Subtracts a matrix expression from the mapped matrix. Left and
198 right hand side of the assignment should be independent.
</td>
201 <td><code>template
<class AT
><br />
202 mapped_matrix
&operator *= (const AT
&at)
</code></td>
203 <td>A computed assignment operator. Multiplies the mapped matrix
207 <td><code>template
<class AT
><br />
208 mapped_matrix
&operator /= (const AT
&at)
</code></td>
209 <td>A computed assignment operator. Divides the mapped matrix
210 through a scalar.
</td>
213 <td><code>void swap (mapped_matrix
&m)
</code></td>
214 <td>Swaps the contents of the mapped matrices.
</td>
217 <td><code>true_refrence insert_element (size_type i, size_type j, const_reference
219 <td>Inserts the value
<code>t
</code> at the
<code>j
</code>-th
220 element of the
<code>i
</code>-th row. Duplicates elements are not allowed.
</td>
223 <td><code>void erase_element (size_type i, size_type j)
</code></td>
224 <td>Erases the value at the
<code>j
</code>-th element of the
225 <code>i
</code>-th row.
</td>
228 <td><code>void clear ()
</code></td>
229 <td>Clears the mapped matrix.
</td>
232 <td><code>const_iterator1 begin1 () const
</code></td>
233 <td>Returns a
<code>const_iterator1
</code> pointing to the
234 beginning of the
<code>mapped_matrix
</code>.
</td>
237 <td><code>const_iterator1 end1 () const
</code></td>
238 <td>Returns a
<code>const_iterator1
</code> pointing to the end of
239 the
<code>mapped_matrix
</code>.
</td>
242 <td><code>iterator1 begin1 ()
</code></td>
243 <td>Returns a
<code>iterator1
</code> pointing to the beginning of
244 the
<code>mapped_matrix
</code>.
</td>
247 <td><code>iterator1 end1 ()
</code></td>
248 <td>Returns a
<code>iterator1
</code> pointing to the end of the
249 <code>mapped_matrix
</code>.
</td>
252 <td><code>const_iterator2 begin2 () const
</code></td>
253 <td>Returns a
<code>const_iterator2
</code> pointing to the
254 beginning of the
<code>mapped_matrix
</code>.
</td>
257 <td><code>const_iterator2 end2 () const
</code></td>
258 <td>Returns a
<code>const_iterator2
</code> pointing to the end of
259 the
<code>mapped_matrix
</code>.
</td>
262 <td><code>iterator2 begin2 ()
</code></td>
263 <td>Returns a
<code>iterator2
</code> pointing to the beginning of
264 the
<code>mapped_matrix
</code>.
</td>
267 <td><code>iterator2 end2 ()
</code></td>
268 <td>Returns a
<code>iterator2
</code> pointing to the end of the
269 <code>mapped_matrix
</code>.
</td>
272 <td><code>const_reverse_iterator1 rbegin1 () const
</code></td>
273 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
274 beginning of the reversed
<code>mapped_matrix
</code>.
</td>
277 <td><code>const_reverse_iterator1 rend1 () const
</code></td>
278 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
279 end of the reversed
<code>mapped_matrix
</code>.
</td>
282 <td><code>reverse_iterator1 rbegin1 ()
</code></td>
283 <td>Returns a
<code>reverse_iterator1
</code> pointing to the
284 beginning of the reversed
<code>mapped_matrix
</code>.
</td>
287 <td><code>reverse_iterator1 rend1 ()
</code></td>
288 <td>Returns a
<code>reverse_iterator1
</code> pointing to the end of
289 the reversed
<code>mapped_matrix
</code>.
</td>
292 <td><code>const_reverse_iterator2 rbegin2 () const
</code></td>
293 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
294 beginning of the reversed
<code>mapped_matrix
</code>.
</td>
297 <td><code>const_reverse_iterator2 rend2 () const
</code></td>
298 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
299 end of the reversed
<code>mapped_matrix
</code>.
</td>
302 <td><code>reverse_iterator2 rbegin2 ()
</code></td>
303 <td>Returns a
<code>reverse_iterator2
</code> pointing to the
304 beginning of the reversed
<code>mapped_matrix
</code>.
</td>
307 <td><code>reverse_iterator2 rend2 ()
</code></td>
308 <td>Returns a
<code>reverse_iterator2
</code> pointing to the end of
309 the reversed
<code>mapped_matrix
</code>.
</td>
314 <p><a name=
"mapped_matrix_1">[
1]
</a> Supported
315 parameters for the storage organization are
<code>row_major
</code>
316 and
<code>column_major
</code>.
</p>
317 <p><a name=
"mapped_matrix_2">[
2]
</a> Supported
318 parameters for the adapted array are
319 <code>map_array
<std::size_t, T
></code> and
320 <code>map_std
<std::size_t, T
></code>. The latter is
321 equivalent to
<code>std::map
<std::size_t, T
></code>.
</p>
322 <h2><a name=
"compressed_matrix"></a>Compressed Matrix
</h2>
324 <p>The templated class
<code>compressed_matrix
<T, F, IB, IA,
325 TA
></code> is the base container adaptor for compressed
326 matrices. For a
<em>(m x n
</em> )-dimensional compressed matrix and
327 <em>0 <= i
< m
</em>,
<em>0 <= j
< n
</em> the non-zero
328 elements
<em>m
</em><sub><em>i, j
</em></sub> are mapped via
<em>(i x
329 n + j)
</em> for row major orientation or via
<em>(i + j x m)
</em>
330 for column major orientation to consecutive elements of the index
331 and value containers, i.e. for elements
<em>k
</em> =
332 <em>m
</em><sub><em>i
</em></sub><sub><sub><em>1</em></sub></sub><sub>
333 <em>,j
</em></sub><sub><sub><em>1</em></sub></sub>and
<em>k +
1 =
334 m
</em><sub><em>i
</em></sub><sub><sub><em>2</em></sub></sub><sub><em>
335 ,j
</em></sub><sub><sub><em>2</em></sub></sub>of the container holds
336 <em>i
</em><sub><em>1</em></sub> <em><
337 i
</em><sub><em>2</em></sub> or
<em>(i
</em><sub><em>1</em></sub>
338 <em>= i
</em><sub><em>2</em></sub> and
339 <em>j
</em><sub><em>1</em></sub> <em><
340 j
</em><sub><em>2</em></sub><em>)
</em> with row major orientation or
341 <em>j
</em><sub><em>1</em></sub> <em><
342 j
</em><sub><em>2</em></sub> or
<em>(j
</em><sub><em>1</em></sub>
343 <em>= j
</em><sub><em>2</em></sub> and
344 <em>i
</em><sub><em>1</em></sub> <em><
345 i
</em><sub><em>2</em></sub><em>)
</em> with column major
349 #include
<boost/numeric/ublas/matrix_sparse.hpp
>
350 #include
<boost/numeric/ublas/io.hpp
>
353 using namespace boost::numeric::ublas;
354 compressed_matrix
<double
> m (
3,
3,
3 *
3);
355 for (unsigned i =
0; i
< m.size1 (); ++ i)
356 for (unsigned j =
0; j
< m.size2 (); ++ j)
357 m (i, j) =
3 * i + j;
358 std::cout
<< m
<< std::endl;
362 <p>Defined in the header matrix_sparse.hpp.
</p>
363 <h4>Template parameters
</h4>
364 <table border=
"1" summary=
"parameters">
372 <td><code>T
</code></td>
373 <td>The type of object stored in the compressed matrix.
</td>
377 <td><code>F
</code></td>
378 <td>Functor describing the storage organization.
<a href=
379 "#compressed_matrix_1">[
1]
</a></td>
380 <td><code>row_major
</code></td>
383 <td><code>IB
</code></td>
384 <td>The index base of the compressed vector.
<a href=
385 "#compressed_matrix_2">[
2]
</a></td>
386 <td><code>0</code></td>
389 <td><code>IA
</code></td>
390 <td>The type of the adapted array for indices.
<a href=
391 "#compressed_matrix_3">[
3]
</a></td>
392 <td><code>unbounded_array
<std::size_t
></code></td>
395 <td><code>TA
</code></td>
396 <td>The type of the adapted array for values.
<a href=
397 "#compressed_matrix_3">[
3]
</a></td>
398 <td><code>unbounded_array
<T
></code></td>
403 <p><a href=
"container_concept.html#matrix">Matrix
</a> .
</p>
404 <h4>Type requirements
</h4>
405 <p>None, except for those imposed by the requirements of
<a href=
406 "container_concept.html#matrix">Matrix
</a> .
</p>
407 <h4>Public base classes
</h4>
408 <p><code>matrix_container
<compressed_matrix
<T, F, IB, IA,
409 TA
> ></code></p>
411 <table border=
"1" summary=
"members">
418 <td><code>compressed_matrix ()
</code></td>
419 <td>Allocates a
<code>compressed_matrix
</code> that holds at most
420 zero rows of zero elements.
</td>
423 <td><code>compressed_matrix (size_type size1, size_type2, size_type non_zeros =
0)
</code></td>
424 <td>Allocates a
<code>compressed_matrix
</code> that holds at most
425 <code>size1
</code> rows of
<code>size2
</code> elements.
</td>
428 <td><code>compressed_matrix (const compressed_matrix
430 <td>The copy constructor.
</td>
433 <td><code>template
<class AE
><br />
434 compressed_matrix (size_type non_zeros, const
435 matrix_expression
<AE
> &ae)
</code></td>
436 <td>The extended copy constructor.
</td>
439 <td><code>void resize (size_type size1, size_type size2, bool preserve = true)
</code></td>
440 <td>Reallocates a
<code>compressed_matrix
</code> to hold at most
441 <code>size1
</code> rows of
<code>size2
</code> elements. The
442 existing elements of the
<code>compressed_matrix
</code> are
443 preseved when specified.
</td>
446 <td><code>size_type size1 () const
</code></td>
447 <td>Returns the number of rows.
</td>
450 <td><code>size_type size2 () const
</code></td>
451 <td>Returns the number of columns.
</td>
454 <td><code>const_reference operator () (size_type i, size_type j)
456 <td>Returns the value of the
<code>j
</code>-th element in the
457 <code>i
</code>-th row.
</td>
460 <td><code>reference operator () (size_type i, size_type
462 <td>Returns a reference of the
<code>j
</code>-th element in the
463 <code>i
</code>-th row.
</td>
466 <td><code>compressed_matrix
&operator = (const
467 compressed_matrix
&m)
</code></td>
468 <td>The assignment operator.
</td>
471 <td><code>compressed_matrix
&assign_temporary
472 (compressed_matrix
&m)
</code></td>
473 <td>Assigns a temporary. May change the compressed matrix
477 <td><code>template
<class AE
><br />
478 compressed_matrix
&operator = (const
479 matrix_expression
<AE
> &ae)
</code></td>
480 <td>The extended assignment operator.
</td>
483 <td><code>template
<class AE
><br />
484 compressed_matrix
&assign (const matrix_expression
<AE
>
486 <td>Assigns a matrix expression to the compressed matrix. Left and
487 right hand side of the assignment should be independent.
</td>
490 <td><code>template
<class AE
><br />
491 compressed_matrix
&operator += (const
492 matrix_expression
<AE
> &ae)
</code></td>
493 <td>A computed assignment operator. Adds the matrix expression to
494 the compressed matrix.
</td>
497 <td><code>template
<class AE
><br />
498 compressed_matrix
&plus_assign (const
499 matrix_expression
<AE
> &ae)
</code></td>
500 <td>Adds a matrix expression to the compressed matrix. Left and
501 right hand side of the assignment should be independent.
</td>
504 <td><code>template
<class AE
><br />
505 compressed_matrix
&operator -= (const
506 matrix_expression
<AE
> &ae)
</code></td>
507 <td>A computed assignment operator. Subtracts the matrix expression
508 from the compressed matrix.
</td>
511 <td><code>template
<class AE
><br />
512 compressed_matrix
&minus_assign (const
513 matrix_expression
<AE
> &ae)
</code></td>
514 <td>Subtracts a matrix expression from the compressed matrix. Left
515 and right hand side of the assignment should be independent.
</td>
518 <td><code>template
<class AT
><br />
519 compressed_matrix
&operator *= (const AT
&at)
</code></td>
520 <td>A computed assignment operator. Multiplies the compressed
521 matrix with a scalar.
</td>
524 <td><code>template
<class AT
><br />
525 compressed_matrix
&operator /= (const AT
&at)
</code></td>
526 <td>A computed assignment operator. Divides the compressed matrix
527 through a scalar.
</td>
530 <td><code>void swap (compressed_matrix
&m)
</code></td>
531 <td>Swaps the contents of the compressed matrices.
</td>
534 <td><code>true_reference insert_element (size_type i, size_type j, const_reference
536 <td>Inserts the value
<code>t
</code> at the
<code>j
</code>-th
537 element of the
<code>i
</code>-th row. Duplicates elements are not allowed.
</td>
540 <td><code>void erase_element (size_type i, size_type j)
</code></td>
541 <td>Erases the value at the
<code>j
</code>-th element of the
542 <code>i
</code>-th row.
</td>
545 <td><code>void clear ()
</code></td>
546 <td>Clears the compressed matrix.
</td>
549 <td><code>const_iterator1 begin1 () const
</code></td>
550 <td>Returns a
<code>const_iterator1
</code> pointing to the
551 beginning of the
<code>compressed_matrix
</code>.
</td>
554 <td><code>const_iterator1 end1 () const
</code></td>
555 <td>Returns a
<code>const_iterator1
</code> pointing to the end of
556 the
<code>compressed_matrix
</code>.
</td>
559 <td><code>iterator1 begin1 ()
</code></td>
560 <td>Returns a
<code>iterator1
</code> pointing to the beginning of
561 the
<code>compressed_matrix
</code>.
</td>
564 <td><code>iterator1 end1 ()
</code></td>
565 <td>Returns a
<code>iterator1
</code> pointing to the end of the
566 <code>compressed_matrix
</code>.
</td>
569 <td><code>const_iterator2 begin2 () const
</code></td>
570 <td>Returns a
<code>const_iterator2
</code> pointing to the
571 beginning of the
<code>compressed_matrix
</code>.
</td>
574 <td><code>const_iterator2 end2 () const
</code></td>
575 <td>Returns a
<code>const_iterator2
</code> pointing to the end of
576 the
<code>compressed_matrix
</code>.
</td>
579 <td><code>iterator2 begin2 ()
</code></td>
580 <td>Returns a
<code>iterator2
</code> pointing to the beginning of
581 the
<code>compressed_matrix
</code>.
</td>
584 <td><code>iterator2 end2 ()
</code></td>
585 <td>Returns a
<code>iterator2
</code> pointing to the end of the
586 <code>compressed_matrix
</code>.
</td>
589 <td><code>const_reverse_iterator1 rbegin1 () const
</code></td>
590 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
591 beginning of the reversed
<code>compressed_matrix
</code>.
</td>
594 <td><code>const_reverse_iterator1 rend1 () const
</code></td>
595 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
596 end of the reversed
<code>compressed_matrix
</code>.
</td>
599 <td><code>reverse_iterator1 rbegin1 ()
</code></td>
600 <td>Returns a
<code>reverse_iterator1
</code> pointing to the
601 beginning of the reversed
<code>compressed_matrix
</code>.
</td>
604 <td><code>reverse_iterator1 rend1 ()
</code></td>
605 <td>Returns a
<code>reverse_iterator1
</code> pointing to the end of
606 the reversed
<code>compressed_matrix
</code>.
</td>
609 <td><code>const_reverse_iterator2 rbegin2 () const
</code></td>
610 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
611 beginning of the reversed
<code>compressed_matrix
</code>.
</td>
614 <td><code>const_reverse_iterator2 rend2 () const
</code></td>
615 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
616 end of the reversed
<code>compressed_matrix
</code>.
</td>
619 <td><code>reverse_iterator2 rbegin2 ()
</code></td>
620 <td>Returns a
<code>reverse_iterator2
</code> pointing to the
621 beginning of the reversed
<code>compressed_matrix
</code>.
</td>
624 <td><code>reverse_iterator2 rend2 ()
</code></td>
625 <td>Returns a
<code>reverse_iterator2
</code> pointing to the end of
626 the reversed
<code>compressed_matrix
</code>.
</td>
631 <p><a name=
"compressed_matrix_1">[
1]
</a>
632 Supported parameters for the storage organization are
633 <code>row_major
</code> and
<code>column_major
</code>.
</p>
634 <p><a name=
"compressed_matrix_2">[
2]
</a>
635 Supported parameters for the index base are
<code>0</code> and
636 <code>1</code> at least.
</p>
637 <p><a name=
"compressed_matrix_3">[
3]
</a>
638 Supported parameters for the adapted array are
639 <code>unbounded_array
<></code> ,
640 <code>bounded_array
<></code> and
641 <code>std::vector
<></code> .
</p>
642 <h2><a name=
"coordinate_matrix"></a>Coordinate Matrix
</h2>
644 <p>The templated class
<code>coordinate_matrix
<T, F, IB, IA,
645 TA
></code> is the base container adaptor for compressed
646 matrices. For a
<em>(m x n
</em> )-dimensional sorted coordinate
647 matrix and
<em>0 <= i
< m
</em>,
<em>0 <= j
< n
</em> the
648 non-zero elements
<em>m
</em><sub><em>i, j
</em></sub> are mapped via
649 <em>(i x n + j)
</em> for row major orientation or via
<em>(i + j x
650 m)
</em> for column major orientation to consecutive elements of the
651 index and value containers, i.e. for elements
<em>k
</em> =
652 <em>m
</em><sub><em>i
</em></sub><sub><sub><em>1</em></sub></sub><sub>
653 <em>,j
</em></sub><sub><sub><em>1</em></sub></sub>and
<em>k +
1 =
654 m
</em><sub><em>i
</em></sub><sub><sub><em>2</em></sub></sub><sub><em>
655 ,j
</em></sub><sub><sub><em>2</em></sub></sub>of the container holds
656 <em>i
</em><sub><em>1</em></sub> <em><
657 i
</em><sub><em>2</em></sub> or
<em>(i
</em><sub><em>1</em></sub>
658 <em>= i
</em><sub><em>2</em></sub> and
659 <em>j
</em><sub><em>1</em></sub> <em><
660 j
</em><sub><em>2</em></sub><em>)
</em> with row major orientation or
661 <em>j
</em><sub><em>1</em></sub> <em><
662 j
</em><sub><em>2</em></sub> or
<em>(j
</em><sub><em>1</em></sub>
663 <em>= j
</em><sub><em>2</em></sub> and
664 <em>i
</em><sub><em>1</em></sub> <em><
665 i
</em><sub><em>2</em></sub><em>)
</em> with column major
669 #include
<boost/numeric/ublas/matrix_sparse.hpp
>
670 #include
<boost/numeric/ublas/io.hpp
>
673 using namespace boost::numeric::ublas;
674 coordinate_matrix
<double
> m (
3,
3,
3 *
3);
675 for (unsigned i =
0; i
< m.size1 (); ++ i)
676 for (unsigned j =
0; j
< m.size2 (); ++ j)
677 m (i, j) =
3 * i + j;
678 std::cout
<< m
<< std::endl;
682 <p>Defined in the header matrix_sparse.hpp.
</p>
683 <h4>Template parameters
</h4>
684 <table border=
"1" summary=
"parameters">
692 <td><code>T
</code></td>
693 <td>The type of object stored in the coordinate matrix.
</td>
697 <td><code>F
</code></td>
698 <td>Functor describing the storage organization.
<a href=
699 "#coordinate_matrix_1">[
1]
</a></td>
700 <td><code>row_major
</code></td>
703 <td><code>IB
</code></td>
704 <td>The index base of the coordinate vector.
<a href=
705 "#coordinate_matrix_2">[
2]
</a></td>
706 <td><code>0</code></td>
709 <td><code>IA
</code></td>
710 <td>The type of the adapted array for indices.
<a href=
711 "#coordinate_matrix_3">[
3]
</a></td>
712 <td><code>unbounded_array
<std::size_t
></code></td>
715 <td><code>TA
</code></td>
716 <td>The type of the adapted array for values.
<a href=
717 "#coordinate_matrix_3">[
3]
</a></td>
718 <td><code>unbounded_array
<T
></code></td>
723 <p><a href=
"container_concept.html#matrix">Matrix
</a> .
</p>
724 <h4>Type requirements
</h4>
725 <p>None, except for those imposed by the requirements of
<a href=
726 "container_concept.html#matrix">Matrix
</a> .
</p>
727 <h4>Public base classes
</h4>
728 <p><code>matrix_container
<coordinate_matrix
<T, F, IB, IA,
729 TA
> ></code></p>
731 <table border=
"1" summary=
"members">
738 <td><code>coordinate_matrix ()
</code></td>
739 <td>Allocates a
<code>coordinate_matrix
</code> that holds at most
740 zero rows of zero elements.
</td>
743 <td><code>coordinate_matrix (size_type size1, size_type2, size_type non_zeros =
0)
</code></td>
744 <td>Allocates a
<code>coordinate_matrix
</code> that holds at most
745 <code>size1
</code> rows of
<code>size2
</code> elements.
</td>
748 <td><code>coordinate_matrix (const coordinate_matrix
750 <td>The copy constructor.
</td>
753 <td><code>template
<class AE
><br />
754 coordinate_matrix (size_type non_zeros, const
755 matrix_expression
<AE
> &ae)
</code></td>
756 <td>The extended copy constructor.
</td>
759 <td><code>void resize (size_type size1, size_type size2, bool preserve = true)
</code></td>
760 <td>Reallocates a
<code>coordinate_matrix
</code> to hold at most
761 <code>size1
</code> rows of
<code>size2
</code> elements. The
762 existing elements of the
<code>coordinate_matrix
</code> are
763 preseved when specified.
</td>
766 <td><code>size_type size1 () const
</code></td>
767 <td>Returns the number of rows.
</td>
770 <td><code>size_type size2 () const
</code></td>
771 <td>Returns the number of columns.
</td>
774 <td><code>const_reference operator () (size_type i, size_type j)
776 <td>Returns the value of the
<code>j
</code>-th element in the
777 <code>i
</code>-th row.
</td>
780 <td><code>reference operator () (size_type i, size_type
782 <td>Returns a reference of the
<code>j
</code>-th element in the
783 <code>i
</code>-th row.
</td>
786 <td><code>coordinate_matrix
&operator = (const
787 coordinate_matrix
&m)
</code></td>
788 <td>The assignment operator.
</td>
791 <td><code>coordinate_matrix
&assign_temporary
792 (coordinate_matrix
&m)
</code></td>
793 <td>Assigns a temporary. May change the coordinate matrix
797 <td><code>template
<class AE
><br />
798 coordinate_matrix
&operator = (const
799 matrix_expression
<AE
> &ae)
</code></td>
800 <td>The extended assignment operator.
</td>
803 <td><code>template
<class AE
><br />
804 coordinate_matrix
&assign (const matrix_expression
<AE
>
806 <td>Assigns a matrix expression to the coordinate matrix. Left and
807 right hand side of the assignment should be independent.
</td>
810 <td><code>template
<class AE
><br />
811 coordinate_matrix
&operator += (const
812 matrix_expression
<AE
> &ae)
</code></td>
813 <td>A computed assignment operator. Adds the matrix expression to
814 the coordinate matrix.
</td>
817 <td><code>template
<class AE
><br />
818 coordinate_matrix
&plus_assign (const
819 matrix_expression
<AE
> &ae)
</code></td>
820 <td>Adds a matrix expression to the coordinate matrix. Left and
821 right hand side of the assignment should be independent.
</td>
824 <td><code>template
<class AE
><br />
825 coordinate_matrix
&operator -= (const
826 matrix_expression
<AE
> &ae)
</code></td>
827 <td>A computed assignment operator. Subtracts the matrix expression
828 from the coordinate matrix.
</td>
831 <td><code>template
<class AE
><br />
832 coordinate_matrix
&minus_assign (const
833 matrix_expression
<AE
> &ae)
</code></td>
834 <td>Subtracts a matrix expression from the coordinate matrix. Left
835 and right hand side of the assignment should be independent.
</td>
838 <td><code>template
<class AT
><br />
839 coordinate_matrix
&operator *= (const AT
&at)
</code></td>
840 <td>A computed assignment operator. Multiplies the coordinate
841 matrix with a scalar.
</td>
844 <td><code>template
<class AT
><br />
845 coordinate_matrix
&operator /= (const AT
&at)
</code></td>
846 <td>A computed assignment operator. Divides the coordinate matrix
847 through a scalar.
</td>
850 <td><code>void swap (coordinate_matrix
&m)
</code></td>
851 <td>Swaps the contents of the coordinate matrices.
</td>
854 <td><code>true_reference insert_element (size_type i, size_type j, const_reference
856 <td>Inserts the value
<code>t
</code> at the
<code>j
</code>-th
857 element of the
<code>i
</code>-th row. Duplicates elements are not allowed.
</td>
860 <td><code>void append_element (size_type i, size_type j, const_reference t)
</code></td>
861 <td>Appends the value
<code>t
</code> at the
<code>j
</code>-th element of the
<code>i
</code>-th row.
862 Duplicate elements can be appended to a
<code>coordinate_matrix
</code>. They are merged into a single
863 arithmetically summed element by the
<code>sort
</code> function.
</td>
866 <td><code>void erase_element (size_type i, size_type j)
</code></td>
867 <td>Erases the value at the
<code>j
</code>-th element of the
868 <code>i
</code>-th row.
</td>
871 <td><code>void clear ()
</code></td>
872 <td>Clears the coordinate matrix.
</td>
875 <td><code>const_iterator1 begin1 () const
</code></td>
876 <td>Returns a
<code>const_iterator1
</code> pointing to the
877 beginning of the
<code>coordinate_matrix
</code>.
</td>
880 <td><code>const_iterator1 end1 () const
</code></td>
881 <td>Returns a
<code>const_iterator1
</code> pointing to the end of
882 the
<code>coordinate_matrix
</code>.
</td>
885 <td><code>iterator1 begin1 ()
</code></td>
886 <td>Returns a
<code>iterator1
</code> pointing to the beginning of
887 the
<code>coordinate_matrix
</code>.
</td>
890 <td><code>iterator1 end1 ()
</code></td>
891 <td>Returns a
<code>iterator1
</code> pointing to the end of the
892 <code>coordinate_matrix
</code>.
</td>
895 <td><code>const_iterator2 begin2 () const
</code></td>
896 <td>Returns a
<code>const_iterator2
</code> pointing to the
897 beginning of the
<code>coordinate_matrix
</code>.
</td>
900 <td><code>const_iterator2 end2 () const
</code></td>
901 <td>Returns a
<code>const_iterator2
</code> pointing to the end of
902 the
<code>coordinate_matrix
</code>.
</td>
905 <td><code>iterator2 begin2 ()
</code></td>
906 <td>Returns a
<code>iterator2
</code> pointing to the beginning of
907 the
<code>coordinate_matrix
</code>.
</td>
910 <td><code>iterator2 end2 ()
</code></td>
911 <td>Returns a
<code>iterator2
</code> pointing to the end of the
912 <code>coordinate_matrix
</code>.
</td>
915 <td><code>const_reverse_iterator1 rbegin1 () const
</code></td>
916 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
917 beginning of the reversed
<code>coordinate_matrix
</code>.
</td>
920 <td><code>const_reverse_iterator1 rend1 () const
</code></td>
921 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
922 end of the reversed
<code>coordinate_matrix
</code>.
</td>
925 <td><code>reverse_iterator1 rbegin1 ()
</code></td>
926 <td>Returns a
<code>reverse_iterator1
</code> pointing to the
927 beginning of the reversed
<code>coordinate_matrix
</code>.
</td>
930 <td><code>reverse_iterator1 rend1 ()
</code></td>
931 <td>Returns a
<code>reverse_iterator1
</code> pointing to the end of
932 the reversed
<code>coordinate_matrix
</code>.
</td>
935 <td><code>const_reverse_iterator2 rbegin2 () const
</code></td>
936 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
937 beginning of the reversed
<code>coordinate_matrix
</code>.
</td>
940 <td><code>const_reverse_iterator2 rend2 () const
</code></td>
941 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
942 end of the reversed
<code>coordinate_matrix
</code>.
</td>
945 <td><code>reverse_iterator2 rbegin2 ()
</code></td>
946 <td>Returns a
<code>reverse_iterator2
</code> pointing to the
947 beginning of the reversed
<code>coordinate_matrix
</code>.
</td>
950 <td><code>reverse_iterator2 rend2 ()
</code></td>
951 <td>Returns a
<code>reverse_iterator2
</code> pointing to the end of
952 the reversed
<code>coordinate_matrix
</code>.
</td>
957 <p><a name=
"coordinate_matrix_1">[
1]
</a>
958 Supported parameters for the storage organization are
959 <code>row_major
</code> and
<code>column_major
</code>.
</p>
960 <p><a name=
"coordinate_matrix_2">[
2]
</a>
961 Supported parameters for the index base are
<code>0</code> and
962 <code>1</code> at least.
</p>
963 <p><a name=
"coordinate_matrix_3">[
3]
</a>
964 Supported parameters for the adapted array are
965 <code>unbounded_array
<></code> ,
966 <code>bounded_array
<></code> and
967 <code>std::vector
<></code> .
</p>
969 <p>Copyright (
©)
2000-
2002 Joerg Walter, Mathias Koch
<br />
970 Use, modification and distribution are subject to the
971 Boost Software License, Version
1.0.
972 (See accompanying file LICENSE_1_0.txt
973 or copy at
<a href=
"http://www.boost.org/LICENSE_1_0.txt">
974 http://www.boost.org/LICENSE_1_0.txt
977 <script type=
"text/javascript">