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>Triangular Matrix
</title>
16 <h1><img src=
"../../../../boost.png" align=
"middle" />Triangular Matrix
</h1>
17 <div class=
"toc" id=
"toc"></div>
18 <h2><a name=
"triangular_matrix"></a>Triangular Matrix
</h2>
20 <p>The templated class
<code>triangular_matrix
<T, F1, F2,
21 A
></code> is the base container adaptor for triangular matrices.
22 For a
<em>(n x n
</em> )-dimensional lower triangular matrix and
23 <em>0 <= i
< n
</em>,
<em>0 <= j
< n
</em> holds
24 <em>t
</em><sub><em>i, j
</em></sub> <em>=
0</em> , if
<em>i
>
25 j
</em>. If furthermore holds t
<sub><em>i, i
</em></sub><em>=
1</em>
26 the matrix is called unit lower triangular. For a
<em>(n x n
</em>
27 )-dimensional lower triangular matrix and
<em>0 <= i
<
28 n
</em>,
<em>0 <= j
< n
</em> holds
<em>t
</em><sub><em>i,
29 j
</em></sub> <em>=
0</em> , if
<em>i
< j
</em>. If furthermore
30 holds t
<sub><em>i, i
</em></sub><em>=
1</em> the matrix is called
31 unit lower triangular. The storage of triangular matrices is
35 #include
<boost/numeric/ublas/triangular.hpp
>
36 #include
<boost/numeric/ublas/io.hpp
>
39 using namespace boost::numeric::ublas;
40 triangular_matrix
<double, lower
> ml (
3,
3);
41 for (unsigned i =
0; i
< ml.size1 (); ++ i)
42 for (unsigned j =
0; j
<= i; ++ j)
43 ml (i, j) =
3 * i + j;
44 std::cout
<< ml
<< std::endl;
45 triangular_matrix
<double, upper
> mu (
3,
3);
46 for (unsigned i =
0; i
< mu.size1 (); ++ i)
47 for (unsigned j = i; j
< mu.size2 (); ++ j)
48 mu (i, j) =
3 * i + j;
49 std::cout
<< mu
<< std::endl;
52 <p>Please read the
<a href=
"samples/ex_triangular.cpp">full triangular example
</a> for more details.
</p>
55 <p>Defined in the header triangular.hpp.
</p>
56 <h4>Template parameters
</h4>
57 <table border=
"1" summary=
"parameters">
65 <td><code>T
</code></td>
66 <td>The type of object stored in the matrix.
</td>
70 <td><code>F1
</code></td>
71 <td>Functor describing the type of the triangular matrix.
<a href=
72 "#triangular_matrix_1">[
1]
</a></td>
73 <td><code>lower
</code></td>
76 <td><code>F2
</code></td>
77 <td>Functor describing the storage organization.
<a href=
78 "#triangular_matrix_2">[
2]
</a></td>
79 <td><code>row_major
</code></td>
82 <td><code>A
</code></td>
83 <td>The type of the adapted array.
<a href=
84 "#triangular_matrix_3">[
3]
</a></td>
85 <td><code>unbounded_array
<T
></code></td>
90 <p><a href=
"container_concept.html#matrix">Matrix
</a> .
</p>
91 <h4>Type requirements
</h4>
92 <p>None, except for those imposed by the requirements of
<a href=
93 "container_concept.html#matrix">Matrix
</a> .
</p>
94 <h4>Public base classes
</h4>
95 <p><code>matrix_container
<triangular_matrix
<T, F1, F2, A
>
98 <table border=
"1" summary=
"members">
105 <td><code>triangular_matrix ()
</code></td>
106 <td>Allocates an uninitialized
<code>triangular_matrix
</code> that
107 holds zero rows of zero elements.
</td>
110 <td><code>triangular_matrix (size_type size1, size_type
112 <td>Allocates an uninitialized
<code>triangular_matrix
</code> that
113 holds
<code>size1
</code> rows of
<code>size2
</code> elements.
</td>
116 <td><code>triangular_matrix (const triangular_matrix
118 <td>The copy constructor.
</td>
121 <td><code>template
<class AE
><br />
122 triangular_matrix (const matrix_expression
<AE
>
124 <td>The extended copy constructor.
</td>
127 <td><code>void resize (size_type size1, size_type size2, bool
128 preserve = true)
</code></td>
129 <td>Reallocates a
<code>triangular_matrix
</code> to hold
130 <code>size1
</code> rows of
<code>size2
</code> elements. The
131 existing elements of the
<code>triangular_matrix
</code> are
132 preseved when specified.
</td>
135 <td><code>size_type size1 () const
</code></td>
136 <td>Returns the number of rows.
</td>
139 <td><code>size_type size2 () const
</code></td>
140 <td>Returns the number of columns.
</td>
143 <td><code>const_reference operator () (size_type i, size_type j)
145 <td>Returns a
<code>const
</code> reference of the
<code>j
</code>
146 -th element in the
<code>i
</code>-th row.
</td>
149 <td><code>reference operator () (size_type i, size_type
151 <td>Returns a reference of the
<code>j
</code>-th element in the
152 <code>i
</code>-th row.
</td>
155 <td><code>triangular_matrix
&operator = (const
156 triangular_matrix
&m)
</code></td>
157 <td>The assignment operator.
</td>
160 <td><code>triangular_matrix
&assign_temporary
161 (triangular_matrix
&m)
</code></td>
162 <td>Assigns a temporary. May change the triangular matrix
166 <td><code>template
<class AE
><br />
167 triangular_matrix
&operator = (const
168 matrix_expression
<AE
> &ae)
</code></td>
169 <td>The extended assignment operator.
</td>
172 <td><code>template
<class AE
><br />
173 triangular_matrix
&assign (const matrix_expression
<AE
>
175 <td>Assigns a matrix expression to the triangular matrix. Left and
176 right hand side of the assignment should be independent.
</td>
179 <td><code>template
<class AE
><br />
180 triangular_matrix
&operator += (const
181 matrix_expression
<AE
> &ae)
</code></td>
182 <td>A computed assignment operator. Adds the matrix expression to
183 the triangular matrix.
</td>
186 <td><code>template
<class AE
><br />
187 triangular_matrix
&plus_assign (const
188 matrix_expression
<AE
> &ae)
</code></td>
189 <td>Adds a matrix expression to the triangular matrix. Left and
190 right hand side of the assignment should be independent.
</td>
193 <td><code>template
<class AE
><br />
194 triangular_matrix
&operator -= (const
195 matrix_expression
<AE
> &ae)
</code></td>
196 <td>A computed assignment operator. Subtracts the matrix expression
197 from the triangular matrix.
</td>
200 <td><code>template
<class AE
><br />
201 triangular_matrix
&minus_assign (const
202 matrix_expression
<AE
> &ae)
</code></td>
203 <td>Subtracts a matrix expression from the triangular matrix. Left
204 and right hand side of the assignment should be independent.
</td>
207 <td><code>template
<class AT
><br />
208 triangular_matrix
&operator *= (const AT
&at)
</code></td>
209 <td>A computed assignment operator. Multiplies the triangular
210 matrix with a scalar.
</td>
213 <td><code>template
<class AT
><br />
214 triangular_matrix
&operator /= (const AT
&at)
</code></td>
215 <td>A computed assignment operator. Divides the triangular matrix
216 through a scalar.
</td>
219 <td><code>void swap (triangular_matrix
&m)
</code></td>
220 <td>Swaps the contents of the triangular matrices.
</td>
223 <td><code>void insert (size_type i, size_type j, const_reference
225 <td>Inserts the value
<code>t
</code> at the
<code>j
</code>-th
226 element of the
<code>i
</code>-th row.
</td>
229 <td><code>void erase (size_type i, size_type j)
</code></td>
230 <td>Erases the value at the
<code>j
</code>-th elemenst of the
231 <code>i
</code>-th row.
</td>
234 <td><code>void clear ()
</code></td>
235 <td>Clears the matrix.
</td>
238 <td><code>const_iterator1 begin1 () const
</code></td>
239 <td>Returns a
<code>const_iterator1
</code> pointing to the
240 beginning of the
<code>triangular_matrix
</code>.
</td>
243 <td><code>const_iterator1 end1 () const
</code></td>
244 <td>Returns a
<code>const_iterator1
</code> pointing to the end of
245 the
<code>triangular_matrix
</code>.
</td>
248 <td><code>iterator1 begin1 ()
</code></td>
249 <td>Returns a
<code>iterator1
</code> pointing to the beginning of
250 the
<code>triangular_matrix
</code>.
</td>
253 <td><code>iterator1 end1 ()
</code></td>
254 <td>Returns a
<code>iterator1
</code> pointing to the end of the
255 <code>triangular_matrix
</code>.
</td>
258 <td><code>const_iterator2 begin2 () const
</code></td>
259 <td>Returns a
<code>const_iterator2
</code> pointing to the
260 beginning of the
<code>triangular_matrix
</code>.
</td>
263 <td><code>const_iterator2 end2 () const
</code></td>
264 <td>Returns a
<code>const_iterator2
</code> pointing to the end of
265 the
<code>triangular_matrix
</code>.
</td>
268 <td><code>iterator2 begin2 ()
</code></td>
269 <td>Returns a
<code>iterator2
</code> pointing to the beginning of
270 the
<code>triangular_matrix
</code>.
</td>
273 <td><code>iterator2 end2 ()
</code></td>
274 <td>Returns a
<code>iterator2
</code> pointing to the end of the
275 <code>triangular_matrix
</code>.
</td>
278 <td><code>const_reverse_iterator1 rbegin1 () const
</code></td>
279 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
280 beginning of the reversed
<code>triangular_matrix
</code>.
</td>
283 <td><code>const_reverse_iterator1 rend1 () const
</code></td>
284 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
285 end of the reversed
<code>triangular_matrix
</code>.
</td>
288 <td><code>reverse_iterator1 rbegin1 ()
</code></td>
289 <td>Returns a
<code>reverse_iterator1
</code> pointing to the
290 beginning of the reversed
<code>triangular_matrix
</code>.
</td>
293 <td><code>reverse_iterator1 rend1 ()
</code></td>
294 <td>Returns a
<code>reverse_iterator1
</code> pointing to the end of
295 the reversed
<code>triangular_matrix
</code>.
</td>
298 <td><code>const_reverse_iterator2 rbegin2 () const
</code></td>
299 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
300 beginning of the reversed
<code>triangular_matrix
</code>.
</td>
303 <td><code>const_reverse_iterator2 rend2 () const
</code></td>
304 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
305 end of the reversed
<code>triangular_matrix
</code>.
</td>
308 <td><code>reverse_iterator2 rbegin2 ()
</code></td>
309 <td>Returns a
<code>reverse_iterator2
</code> pointing to the
310 beginning of the reversed
<code>triangular_matrix
</code>.
</td>
313 <td><code>reverse_iterator2 rend2 ()
</code></td>
314 <td>Returns a
<code>reverse_iterator2
</code> pointing to the end of
315 the reversed
<code>triangular_matrix
</code>.
</td>
320 <p><a name=
"triangular_matrix_1">[
1]
</a>
321 Supported parameters for the type of the triangular matrix are
322 <code>lower
</code> ,
<code>unit_lower
</code>,
<code>upper
</code>
323 and
<code>unit_upper
</code> .
</p>
324 <p><a name=
"triangular_matrix_2">[
2]
</a>
325 Supported parameters for the storage organization are
326 <code>row_major
</code> and
<code>column_major
</code>.
</p>
327 <p><a name=
"triangular_matrix_3">[
3]
</a>
328 Supported parameters for the adapted array are
329 <code>unbounded_array
<T
></code> ,
330 <code>bounded_array
<T
></code> and
331 <code>std::vector
<T
></code> .
</p>
332 <h2><a name=
"triangular_adaptor"></a>Triangular Adaptor
</h2>
334 <p>The templated class
<code>triangular_adaptor
<M, F
></code>
335 is a triangular matrix adaptor for other matrices.
</p>
338 #include
<boost/numeric/ublas/triangular.hpp
>
339 #include
<boost/numeric/ublas/io.hpp
>
342 using namespace boost::numeric::ublas;
343 matrix
<double
> m (
3,
3);
344 triangular_adaptor
<matrix
<double
>, lower
> tal (m);
345 for (unsigned i =
0; i
< tal.size1 (); ++ i)
346 for (unsigned j =
0; j
<= i; ++ j)
347 tal (i, j) =
3 * i + j;
348 std::cout
<< tal
<< std::endl;
349 triangular_adaptor
<matrix
<double
>, upper
> tau (m);
350 for (unsigned i =
0; i
< tau.size1 (); ++ i)
351 for (unsigned j = i; j
< tau.size2 (); ++ j)
352 tau (i, j) =
3 * i + j;
353 std::cout
<< tau
<< std::endl;
356 <p>Please read the
<a href=
"samples/ex_triangular.cpp">full triangular example
</a> for more details.
</p>
359 <p>Defined in the header triangular.hpp.
</p>
360 <h4>Template parameters
</h4>
361 <table border=
"1" summary=
"parameters">
369 <td><code>M
</code></td>
370 <td>The type of the adapted matrix.
</td>
374 <td><code>F
</code></td>
375 <td>Functor describing the type of the triangular adaptor.
<a href=
376 "#triangular_adaptor_1">[
1]
</a></td>
377 <td><code>lower
</code></td>
382 <p><a href=
"expression_concept.html#matrix_expression">Matrix Expression
</a>
384 <h4>Type requirements
</h4>
385 <p>None, except for those imposed by the requirements of
<a href=
386 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</p>
387 <h4>Public base classes
</h4>
388 <p><code>matrix_expression
<triangular_adaptor
<M, F
>
391 <table border=
"1" summary=
"members">
398 <td><code>triangular_adaptor (matrix_type
&data)
</code></td>
399 <td>Constructs a
<code>triangular_adaptor
</code> of a matrix.
</td>
402 <td><code>triangular_adaptor (const triangular_adaptor
404 <td>The copy constructor.
</td>
407 <td><code>template
<class AE
><br />
408 triangular_adaptor (const matrix_expression
<AE
>
410 <td>The extended copy constructor.
</td>
413 <td><code>size_type size1 () const
</code></td>
414 <td>Returns the number of rows.
</td>
417 <td><code>size_type size2 () const
</code></td>
418 <td>Returns the number of columns.
</td>
421 <td><code>const_reference operator () (size_type i, size_type j)
423 <td>Returns a
<code>const
</code> reference of the
<code>j
</code>
424 -th element in the
<code>i
</code>-th row.
</td>
427 <td><code>reference operator () (size_type i, size_type
429 <td>Returns a reference of the
<code>j
</code>-th element in the
430 <code>i
</code>-th row.
</td>
433 <td><code>triangular_adaptor
&operator = (const
434 triangular_adaptor
&m)
</code></td>
435 <td>The assignment operator.
</td>
438 <td><code>triangular_adaptor
&assign_temporary
439 (triangular_adaptor
&m)
</code></td>
440 <td>Assigns a temporary. May change the triangular adaptor
444 <td><code>template
<class AE
><br />
445 triangular_adaptor
&operator = (const
446 matrix_expression
<AE
> &ae)
</code></td>
447 <td>The extended assignment operator.
</td>
450 <td><code>template
<class AE
><br />
451 triangular_adaptor
&assign (const matrix_expression
<AE
>
453 <td>Assigns a matrix expression to the triangular adaptor. Left and
454 right hand side of the assignment should be independent.
</td>
457 <td><code>template
<class AE
><br />
458 triangular_adaptor
&operator += (const
459 matrix_expression
<AE
> &ae)
</code></td>
460 <td>A computed assignment operator. Adds the matrix expression to
461 the triangular adaptor.
</td>
464 <td><code>template
<class AE
><br />
465 triangular_adaptor
&plus_assign (const
466 matrix_expression
<AE
> &ae)
</code></td>
467 <td>Adds a matrix expression to the triangular adaptor. Left and
468 right hand side of the assignment should be independent.
</td>
471 <td><code>template
<class AE
><br />
472 triangular_adaptor
&operator -= (const
473 matrix_expression
<AE
> &ae)
</code></td>
474 <td>A computed assignment operator. Subtracts the matrix expression
475 from the triangular adaptor.
</td>
478 <td><code>template
<class AE
><br />
479 triangular_adaptor
&minus_assign (const
480 matrix_expression
<AE
> &ae)
</code></td>
481 <td>Subtracts a matrix expression from the triangular adaptor. Left
482 and right hand side of the assignment should be independent.
</td>
485 <td><code>template
<class AT
><br />
486 triangular_adaptor
&operator *= (const AT
&at)
</code></td>
487 <td>A computed assignment operator. Multiplies the triangular
488 adaptor with a scalar.
</td>
491 <td><code>template
<class AT
><br />
492 triangular_adaptor
&operator /= (const AT
&at)
</code></td>
493 <td>A computed assignment operator. Divides the triangular adaptor
494 through a scalar.
</td>
497 <td><code>void swap (triangular_adaptor
&m)
</code></td>
498 <td>Swaps the contents of the triangular adaptors.
</td>
501 <td><code>const_iterator1 begin1 () const
</code></td>
502 <td>Returns a
<code>const_iterator1
</code> pointing to the
503 beginning of the
<code>triangular_adaptor
</code>.
</td>
506 <td><code>const_iterator1 end1 () const
</code></td>
507 <td>Returns a
<code>const_iterator1
</code> pointing to the end of
508 the
<code>triangular_adaptor
</code>.
</td>
511 <td><code>iterator1 begin1 ()
</code></td>
512 <td>Returns a
<code>iterator1
</code> pointing to the beginning of
513 the
<code>triangular_adaptor
</code>.
</td>
516 <td><code>iterator1 end1 ()
</code></td>
517 <td>Returns a
<code>iterator1
</code> pointing to the end of the
518 <code>triangular_adaptor
</code>.
</td>
521 <td><code>const_iterator2 begin2 () const
</code></td>
522 <td>Returns a
<code>const_iterator2
</code> pointing to the
523 beginning of the
<code>triangular_adaptor
</code>.
</td>
526 <td><code>const_iterator2 end2 () const
</code></td>
527 <td>Returns a
<code>const_iterator2
</code> pointing to the end of
528 the
<code>triangular_adaptor
</code>.
</td>
531 <td><code>iterator2 begin2 ()
</code></td>
532 <td>Returns a
<code>iterator2
</code> pointing to the beginning of
533 the
<code>triangular_adaptor
</code>.
</td>
536 <td><code>iterator2 end2 ()
</code></td>
537 <td>Returns a
<code>iterator2
</code> pointing to the end of the
538 <code>triangular_adaptor
</code>.
</td>
541 <td><code>const_reverse_iterator1 rbegin1 () const
</code></td>
542 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
543 beginning of the reversed
<code>triangular_adaptor
</code>.
</td>
546 <td><code>const_reverse_iterator1 rend1 () const
</code></td>
547 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
548 end of the reversed
<code>triangular_adaptor
</code>.
</td>
551 <td><code>reverse_iterator1 rbegin1 ()
</code></td>
552 <td>Returns a
<code>reverse_iterator1
</code> pointing to the
553 beginning of the reversed
<code>triangular_adaptor
</code>.
</td>
556 <td><code>reverse_iterator1 rend1 ()
</code></td>
557 <td>Returns a
<code>reverse_iterator1
</code> pointing to the end of
558 the reversed
<code>triangular_adaptor
</code>.
</td>
561 <td><code>const_reverse_iterator2 rbegin2 () const
</code></td>
562 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
563 beginning of the reversed
<code>triangular_adaptor
</code>.
</td>
566 <td><code>const_reverse_iterator2 rend2 () const
</code></td>
567 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
568 end of the reversed
<code>triangular_adaptor
</code>.
</td>
571 <td><code>reverse_iterator2 rbegin2 ()
</code></td>
572 <td>Returns a
<code>reverse_iterator2
</code> pointing to the
573 beginning of the reversed
<code>triangular_adaptor
</code>.
</td>
576 <td><code>reverse_iterator2 rend2 ()
</code></td>
577 <td>Returns a
<code>reverse_iterator2
</code> pointing to the end of
578 the reversed
<code>triangular_adaptor
</code>.
</td>
583 <p><a name=
"triangular_adaptor_1">[
1]
</a>
584 Supported parameters for the type of the triangular adaptor are
585 <code>lower
</code> ,
<code>unit_lower
</code>,
<code>upper
</code>
586 and
<code>unit_upper
</code> .
</p>
588 <p>Copyright (
©)
2000-
2002 Joerg Walter, Mathias Koch
<br />
589 Use, modification and distribution are subject to the
590 Boost Software License, Version
1.0.
591 (See accompanying file LICENSE_1_0.txt
592 or copy at
<a href=
"http://www.boost.org/LICENSE_1_0.txt">
593 http://www.boost.org/LICENSE_1_0.txt
596 <script type=
"text/javascript">