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>Symmetric Matrix</title>
16 <h1><img src="../../../../boost.png" align="middle" />Symmetric Matrix</h1>
17 <div class="toc" id="toc"></div>
18 <h2><a name="symmetric_matrix"></a>Symmetric Matrix</h2>
20 <p>The templated class <code>symmetric_matrix<T, F1, F2,
21 A></code> is the base container adaptor for symmetric matrices.
22 For a <em>(n x n</em> )-dimensional symmetric matrix and <em>0
23 <= i < n</em>, <em>0 <= j < n</em> holds
24 <em>s</em><sub><em>i, j</em></sub> <em>= s</em><sub><em>j,
25 i</em></sub>. The storage of symmetric matrices is packed.</p>
28 #include <boost/numeric/ublas/symmetric.hpp>
29 #include <boost/numeric/ublas/io.hpp>
32 using namespace boost::numeric::ublas;
33 symmetric_matrix<double, lower> ml (3, 3);
34 for (unsigned i = 0; i < ml.size1 (); ++ i)
35 for (unsigned j = 0; j <= i; ++ j)
36 ml (i, j) = 3 * i + j;
37 std::cout << ml << std::endl;
38 symmetric_matrix<double, upper> mu (3, 3);
39 for (unsigned i = 0; i < mu.size1 (); ++ i)
40 for (unsigned j = i; j < mu.size2 (); ++ j)
41 mu (i, j) = 3 * i + j;
42 std::cout << mu << std::endl;
46 <p>Defined in the header symmetric.hpp.</p>
47 <h4>Template parameters</h4>
48 <table border="1" summary="parameters">
56 <td><code>T</code></td>
57 <td>The type of object stored in the matrix.</td>
61 <td><code>F1</code></td>
62 <td>Functor describing the type of the symmetric matrix. <a name=
63 "#symmetric_matrix_1">[1]</a></td>
64 <td><code>lower</code></td>
67 <td><code>F2</code></td>
68 <td>Functor describing the storage organization. <a name=
69 "#symmetric_matrix_2">[2]</a></td>
70 <td><code>row_major</code></td>
73 <td><code>A</code></td>
74 <td>The type of the adapted array. <a name="#symmetric_matrix_3"
76 <td><code>unbounded_array<T></code></td>
81 <p><a href="container_concept.htm#matrix">Matrix</a> .</p>
82 <h4>Type requirements</h4>
83 <p>None, except for those imposed by the requirements of <a href=
84 "container_concept.htm#matrix">Matrix</a> .</p>
85 <h4>Public base classes</h4>
86 <p><code>matrix_container<symmetric_matrix<T, F1, F2, A>
89 <table border="1" summary="members">
96 <td><code>symmetric_matrix (size_type size)</code></td>
97 <td>Allocates an uninitialized <code>symmetric_matrix</code> that
98 holds <code>size</code> rows of <code>size</code> elements.</td>
101 <td><code>symmetric_matrix (const symmetric_matrix
103 <td>The copy constructor.</td>
106 <td><code>template<class AE><br />
107 symmetric_matrix (const matrix_expression<AE>
109 <td>The extended copy constructor.</td>
112 <td><code>void resize (size_type size, bool preserve =
114 <td>Reallocates a <code>symmetric_matrix</code> to hold
115 <code>size</code> rows of <code>size</code> elements. The existing
116 elements of the <code>symmetric_matrix</code> are preseved when
120 <td><code>size_type size1 () const</code></td>
121 <td>Returns the number of rows.</td>
124 <td><code>size_type size2 () const</code></td>
125 <td>Returns the number of columns.</td>
128 <td><code>const_reference operator () (size_type i, size_type j)
130 <td>Returns a <code>const</code> reference of the <code>j</code>
131 -th element in the <code>i</code>-th row.</td>
134 <td><code>reference operator () (size_type i, size_type
136 <td>Returns a reference of the <code>j</code>-th element in the
137 <code>i</code>-th row.</td>
140 <td><code>symmetric_matrix &operator = (const symmetric_matrix
142 <td>The assignment operator.</td>
145 <td><code>symmetric_matrix &assign_temporary (symmetric_matrix
147 <td>Assigns a temporary. May change the symmetric matrix
148 <code>m</code> .</td>
151 <td><code>template<class AE><br />
152 symmetric_matrix &operator = (const matrix_expression<AE>
154 <td>The extended assignment operator.</td>
157 <td><code>template<class AE><br />
158 symmetric_matrix &assign (const matrix_expression<AE>
160 <td>Assigns a matrix expression to the symmetric matrix. Left and
161 right hand side of the assignment should be independent.</td>
164 <td><code>template<class AE><br />
165 symmetric_matrix &operator += (const
166 matrix_expression<AE> &ae)</code></td>
167 <td>A computed assignment operator. Adds the matrix expression to
168 the symmetric matrix.</td>
171 <td><code>template<class AE><br />
172 symmetric_matrix &plus_assign (const
173 matrix_expression<AE> &ae)</code></td>
174 <td>Adds a matrix expression to the symmetric matrix. Left and
175 right hand side of the assignment should be independent.</td>
178 <td><code>template<class AE><br />
179 symmetric_matrix &operator -= (const
180 matrix_expression<AE> &ae)</code></td>
181 <td>A computed assignment operator. Subtracts the matrix expression
182 from the symmetric matrix.</td>
185 <td><code>template<class AE><br />
186 symmetric_matrix &minus_assign (const
187 matrix_expression<AE> &ae)</code></td>
188 <td>Subtracts a matrix expression from the symmetric matrix. Left
189 and right hand side of the assignment should be independent.</td>
192 <td><code>template<class AT><br />
193 symmetric_matrix &operator *= (const AT &at)</code></td>
194 <td>A computed assignment operator. Multiplies the symmetric matrix
198 <td><code>template<class AT><br />
199 symmetric_matrix &operator /= (const AT &at)</code></td>
200 <td>A computed assignment operator. Divides the symmetric matrix
201 through a scalar.</td>
204 <td><code>void swap (symmetric_matrix &m)</code></td>
205 <td>Swaps the contents of the symmetric matrices.</td>
208 <td><code>void insert (size_type i, size_type j, const_reference
210 <td>Inserts the value <code>t</code> at the <code>j</code>-th
211 element of the <code>i</code>-th row.</td>
214 <td><code>void erase (size_type i, size_type j)</code></td>
215 <td>Erases the value at the <code>j</code>-th elemenst of the
216 <code>i</code>-th row.</td>
219 <td><code>void clear ()</code></td>
220 <td>Clears the matrix.</td>
223 <td><code>const_iterator1 begin1 () const</code></td>
224 <td>Returns a <code>const_iterator1</code> pointing to the
225 beginning of the <code>symmetric_matrix</code>.</td>
228 <td><code>const_iterator1 end1 () const</code></td>
229 <td>Returns a <code>const_iterator1</code> pointing to the end of
230 the <code>symmetric_matrix</code>.</td>
233 <td><code>iterator1 begin1 ()</code></td>
234 <td>Returns a <code>iterator1</code> pointing to the beginning of
235 the <code>symmetric_matrix</code>.</td>
238 <td><code>iterator1 end1 ()</code></td>
239 <td>Returns a <code>iterator1</code> pointing to the end of the
240 <code>symmetric_matrix</code>.</td>
243 <td><code>const_iterator2 begin2 () const</code></td>
244 <td>Returns a <code>const_iterator2</code> pointing to the
245 beginning of the <code>symmetric_matrix</code>.</td>
248 <td><code>const_iterator2 end2 () const</code></td>
249 <td>Returns a <code>const_iterator2</code> pointing to the end of
250 the <code>symmetric_matrix</code>.</td>
253 <td><code>iterator2 begin2 ()</code></td>
254 <td>Returns a <code>iterator2</code> pointing to the beginning of
255 the <code>symmetric_matrix</code>.</td>
258 <td><code>iterator2 end2 ()</code></td>
259 <td>Returns a <code>iterator2</code> pointing to the end of the
260 <code>symmetric_matrix</code>.</td>
263 <td><code>const_reverse_iterator1 rbegin1 () const</code></td>
264 <td>Returns a <code>const_reverse_iterator1</code> pointing to the
265 beginning of the reversed <code>symmetric_matrix</code>.</td>
268 <td><code>const_reverse_iterator1 rend1 () const</code></td>
269 <td>Returns a <code>const_reverse_iterator1</code> pointing to the
270 end of the reversed <code>symmetric_matrix</code>.</td>
273 <td><code>reverse_iterator1 rbegin1 ()</code></td>
274 <td>Returns a <code>reverse_iterator1</code> pointing to the
275 beginning of the reversed <code>symmetric_matrix</code>.</td>
278 <td><code>reverse_iterator1 rend1 ()</code></td>
279 <td>Returns a <code>reverse_iterator1</code> pointing to the end of
280 the reversed <code>symmetric_matrix</code>.</td>
283 <td><code>const_reverse_iterator2 rbegin2 () const</code></td>
284 <td>Returns a <code>const_reverse_iterator2</code> pointing to the
285 beginning of the reversed <code>symmetric_matrix</code>.</td>
288 <td><code>const_reverse_iterator2 rend2 () const</code></td>
289 <td>Returns a <code>const_reverse_iterator2</code> pointing to the
290 end of the reversed <code>symmetric_matrix</code>.</td>
293 <td><code>reverse_iterator2 rbegin2 ()</code></td>
294 <td>Returns a <code>reverse_iterator2</code> pointing to the
295 beginning of the reversed <code>symmetric_matrix</code>.</td>
298 <td><code>reverse_iterator2 rend2 ()</code></td>
299 <td>Returns a <code>reverse_iterator2</code> pointing to the end of
300 the reversed <code>symmetric_matrix</code>.</td>
305 <p><a name="symmetric_matrix_1">[1]</a>
306 Supported parameters for the type of the symmetric matrix are
307 <code>lower</code> and <code>upper</code>.</p>
308 <p><a name="symmetric_matrix_2">[2]</a>
309 Supported parameters for the storage organization are
310 <code>row_major</code> and <code>column_major</code>.</p>
311 <p><a name="symmetric_matrix_3">[3]</a>
312 Supported parameters for the adapted array are
313 <code>unbounded_array<T></code> ,
314 <code>bounded_array<T></code> and
315 <code>std::vector<T></code> .</p>
316 <h2><a name="symmetric_adaptor"></a>Symmetric Adaptor</h2>
318 <p>The templated class <code>symmetric_adaptor<M, F></code>
319 is a symmetric matrix adaptor for other matrices.</p>
322 #include <boost/numeric/ublas/symmetric.hpp>
323 #include <boost/numeric/ublas/io.hpp>
326 using namespace boost::numeric::ublas;
327 matrix<double> m (3, 3);
328 symmetric_adaptor<matrix<double>, lower> sal (m);
329 for (unsigned i = 0; i < sal.size1 (); ++ i)
330 for (unsigned j = 0; j <= i; ++ j)
331 sal (i, j) = 3 * i + j;
332 std::cout << sal << std::endl;
333 symmetric_adaptor<matrix<double>, upper> sau (m);
334 for (unsigned i = 0; i < sau.size1 (); ++ i)
335 for (unsigned j = i; j < sau.size2 (); ++ j)
336 sau (i, j) = 3 * i + j;
337 std::cout << sau << std::endl;
341 <p>Defined in the header symmetric.hpp.</p>
342 <h4>Template parameters</h4>
343 <table border="1" summary="parameters">
351 <td><code>M</code></td>
352 <td>The type of the adapted matrix.</td>
356 <td><code>F</code></td>
357 <td>Functor describing the type of the symmetric adaptor. <a href=
358 "#symmetric_adaptor_1">[1]</a></td>
359 <td><code>lower</code></td>
364 <p><a href="expression_concept.htm#matrix_expression">Matrix Expression</a>
366 <h4>Type requirements</h4>
367 <p>None, except for those imposed by the requirements of <a href=
368 "expression_concept.htm#matrix_expression">Matrix Expression</a> .</p>
369 <h4>Public base classes</h4>
370 <p><code>matrix_expression<symmetric_adaptor<M, F>
373 <table border="1" summary="members">
380 <td><code>symmetric_adaptor ()</code></td>
381 <td>Constructs a <code>symmetric_adaptor</code> that holds zero
382 rows of zero elements.</td>
385 <td><code>symmetric_adaptor (matrix_type &data)</code></td>
386 <td>Constructs a <code>symmetric_adaptor</code> of a matrix.</td>
389 <td><code>symmetric_adaptor (const symmetric_adaptor
391 <td>The copy constructor.</td>
394 <td><code>template<class AE><br />
395 symmetric_adaptor (const matrix_expression<AE>
397 <td>The extended copy constructor.</td>
400 <td><code>size_type size1 () const</code></td>
401 <td>Returns the number of rows.</td>
404 <td><code>size_type size2 () const</code></td>
405 <td>Returns the number of columns.</td>
408 <td><code>const_reference operator () (size_type i, size_type j)
410 <td>Returns a <code>const</code> reference of the <code>j</code>
411 -th element in the <code>i</code>-th row.</td>
414 <td><code>reference operator () (size_type i, size_type
416 <td>Returns a reference of the <code>j</code>-th element in the
417 <code>i</code>-th row.</td>
420 <td><code>symmetric_adaptor &operator = (const
421 symmetric_adaptor &m)</code></td>
422 <td>The assignment operator.</td>
425 <td><code>symmetric_adaptor &assign_temporary
426 (symmetric_adaptor &m)</code></td>
427 <td>Assigns a temporary. May change the symmetric adaptor
431 <td><code>template<class AE><br />
432 symmetric_adaptor &operator = (const
433 matrix_expression<AE> &ae)</code></td>
434 <td>The extended assignment operator.</td>
437 <td><code>template<class AE><br />
438 symmetric_adaptor &assign (const matrix_expression<AE>
440 <td>Assigns a matrix expression to the symmetric adaptor. Left and
441 right hand side of the assignment should be independent.</td>
444 <td><code>template<class AE><br />
445 symmetric_adaptor &operator += (const
446 matrix_expression<AE> &ae)</code></td>
447 <td>A computed assignment operator. Adds the matrix expression to
448 the symmetric adaptor.</td>
451 <td><code>template<class AE><br />
452 symmetric_adaptor &plus_assign (const
453 matrix_expression<AE> &ae)</code></td>
454 <td>Adds a matrix expression to the symmetric adaptor. Left and
455 right hand side of the assignment should be independent.</td>
458 <td><code>template<class AE><br />
459 symmetric_adaptor &operator -= (const
460 matrix_expression<AE> &ae)</code></td>
461 <td>A computed assignment operator. Subtracts the matrix expression
462 from the symmetric adaptor.</td>
465 <td><code>template<class AE><br />
466 symmetric_adaptor &minus_assign (const
467 matrix_expression<AE> &ae)</code></td>
468 <td>Subtracts a matrix expression from the symmetric adaptor. Left
469 and right hand side of the assignment should be independent.</td>
472 <td><code>template<class AT><br />
473 symmetric_adaptor &operator *= (const AT &at)</code></td>
474 <td>A computed assignment operator. Multiplies the symmetric
475 adaptor with a scalar.</td>
478 <td><code>template<class AT><br />
479 symmetric_adaptor &operator /= (const AT &at)</code></td>
480 <td>A computed assignment operator. Divides the symmetric adaptor
481 through a scalar.</td>
484 <td><code>void swap (symmetric_adaptor &m)</code></td>
485 <td>Swaps the contents of the symmetric adaptors.</td>
488 <td><code>const_iterator1 begin1 () const</code></td>
489 <td>Returns a <code>const_iterator1</code> pointing to the
490 beginning of the <code>symmetric_adaptor</code>.</td>
493 <td><code>const_iterator1 end1 () const</code></td>
494 <td>Returns a <code>const_iterator1</code> pointing to the end of
495 the <code>symmetric_adaptor</code>.</td>
498 <td><code>iterator1 begin1 ()</code></td>
499 <td>Returns a <code>iterator1</code> pointing to the beginning of
500 the <code>symmetric_adaptor</code>.</td>
503 <td><code>iterator1 end1 ()</code></td>
504 <td>Returns a <code>iterator1</code> pointing to the end of the
505 <code>symmetric_adaptor</code>.</td>
508 <td><code>const_iterator2 begin2 () const</code></td>
509 <td>Returns a <code>const_iterator2</code> pointing to the
510 beginning of the <code>symmetric_adaptor</code>.</td>
513 <td><code>const_iterator2 end2 () const</code></td>
514 <td>Returns a <code>const_iterator2</code> pointing to the end of
515 the <code>symmetric_adaptor</code>.</td>
518 <td><code>iterator2 begin2 ()</code></td>
519 <td>Returns a <code>iterator2</code> pointing to the beginning of
520 the <code>symmetric_adaptor</code>.</td>
523 <td><code>iterator2 end2 ()</code></td>
524 <td>Returns a <code>iterator2</code> pointing to the end of the
525 <code>symmetric_adaptor</code>.</td>
528 <td><code>const_reverse_iterator1 rbegin1 () const</code></td>
529 <td>Returns a <code>const_reverse_iterator1</code> pointing to the
530 beginning of the reversed <code>symmetric_adaptor</code>.</td>
533 <td><code>const_reverse_iterator1 rend1 () const</code></td>
534 <td>Returns a <code>const_reverse_iterator1</code> pointing to the
535 end of the reversed <code>symmetric_adaptor</code>.</td>
538 <td><code>reverse_iterator1 rbegin1 ()</code></td>
539 <td>Returns a <code>reverse_iterator1</code> pointing to the
540 beginning of the reversed <code>symmetric_adaptor</code>.</td>
543 <td><code>reverse_iterator1 rend1 ()</code></td>
544 <td>Returns a <code>reverse_iterator1</code> pointing to the end of
545 the reversed <code>symmetric_adaptor</code>.</td>
548 <td><code>const_reverse_iterator2 rbegin2 () const</code></td>
549 <td>Returns a <code>const_reverse_iterator2</code> pointing to the
550 beginning of the reversed <code>symmetric_adaptor</code>.</td>
553 <td><code>const_reverse_iterator2 rend2 () const</code></td>
554 <td>Returns a <code>const_reverse_iterator2</code> pointing to the
555 end of the reversed <code>symmetric_adaptor</code>.</td>
558 <td><code>reverse_iterator2 rbegin2 ()</code></td>
559 <td>Returns a <code>reverse_iterator2</code> pointing to the
560 beginning of the reversed <code>symmetric_adaptor</code>.</td>
563 <td><code>reverse_iterator2 rend2 ()</code></td>
564 <td>Returns a <code>reverse_iterator2</code> pointing to the end of
565 the reversed <code>symmetric_adaptor</code>.</td>
570 <p><a name="symmetric_adaptor_1">[1]</a>
571 Supported parameters for the type of the symmetric adaptor are
572 <code>lower</code> and <code>upper</code>.</p>
574 <p>Copyright (©) 2000-2002 Joerg Walter, Mathias Koch<br />
575 Use, modification and distribution are subject to the
576 Boost Software License, Version 1.0.
577 (See accompanying file LICENSE_1_0.txt
578 or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
579 http://www.boost.org/LICENSE_1_0.txt
582 <script type="text/javascript">