1 <!DOCTYPE html PUBLIC
"-//W3C/utf-8XHTML 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>Banded Matrix
</title>
16 <h1><img src=
"../../../../boost.png" align=
"middle" />Banded Matrix
</h1>
17 <div class=
"toc" id=
"toc"></div>
18 <h2><a name=
"banded_matrix"></a>Banded Matrix
</h2>
20 <p>The templated class
<code>banded_matrix
<T, F, A
></code> is
21 the base container adaptor for banded matrices. For a
<em>(m x
22 n
</em>)-dimensional banded matrix with
<em>l
</em> lower and
23 <em>u
</em> upper diagonals and
<em>0 <= i
< m
</em>,
<em>0
24 <= j
< n
</em> holds
<em>b
</em><sub><em>i, j
</em></sub> <em>=
25 0</em>, if
<em>i
> j + l
</em> or
<em>i
< j - u
</em>. The
26 storage of banded matrices is packed.
</p>
29 #include
<boost/numeric/ublas/banded.hpp
>
30 #include
<boost/numeric/ublas/io.hpp
>
33 using namespace boost::numeric::ublas;
34 banded_matrix
<double
> m (
3,
3,
1,
1);
35 for (signed i =
0; i
< signed (m.size1 ()); ++ i)
36 for (signed j = std::max (i -
1,
0); j
< std::min (i +
2, signed (m.size2 ())); ++ j)
38 std::cout
<< m
<< std::endl;
42 <p>Defined in the header banded.hpp.
</p>
43 <h4>Template parameters
</h4>
44 <table border=
"1" summary=
"parameters">
52 <td><code>T
</code></td>
53 <td>The type of object stored in the matrix.
</td>
57 <td><code>F
</code></td>
58 <td>Functor describing the storage organization.
<a href=
59 "#banded_matrix_1">[
1]
</a></td>
60 <td><code>row_major
</code></td>
63 <td><code>A
</code></td>
64 <td>The type of the adapted array.
<a href=
65 "#banded_matrix_2">[
2]
</a></td>
66 <td><code>unbounded_array
<T
></code></td>
71 <p><a href=
"container_concept.html#matrix">Matrix
</a> .
</p>
72 <h4>Type requirements
</h4>
73 <p>None, except for those imposed by the requirements of
<a href=
74 "container_concept.html#matrix">Matrix
</a> .
</p>
75 <h4>Public base classes
</h4>
76 <p><code>matrix_container
<banded_matrix
<T, F, A
>
79 <table border=
"1" summary=
"members">
86 <td><code>banded_matrix ()
</code></td>
87 <td>Allocates an uninitialized
<code>banded_matrix
</code> that
88 holds zero rows of zero elements.
</td>
91 <td><code>banded_matrix (size_type size1, size_type size2,
92 size_type lower =
0, size_type upper =
0)
</code></td>
93 <td>Allocates an uninitialized
<code>banded_matrix
</code> that
94 holds
<code>(lower +
1 + upper)
</code> diagonals around the main
95 diagonal of a matrix with
<code>size1
</code> rows of
96 <code>size2
</code> elements.
</td>
99 <td><code>banded_matrix (const banded_matrix
&m)
</code></td>
100 <td>The copy constructor.
</td>
103 <td><code>template
<class AE
><br />
104 banded_matrix (const matrix_expression
<AE
>
106 <td>The extended copy constructor.
</td>
109 <td><code>void resize (size_type size1, size_type size2, size_type
110 lower =
0, size_type upper =
0, bool preserve = true)
</code></td>
111 <td>Reallocates a
<code>banded_matrix
</code> to hold
<code>(lower +
112 1 + upper)
</code> diagonals around the main diagonal of a matrix
113 with
<code>size1
</code> rows of
<code>size2
</code> elements. The
114 existing elements of the
<code>banded_matrix
</code> are preseved
118 <td><code>size_type size1 () const
</code></td>
119 <td>Returns the number of rows.
</td>
122 <td><code>size_type size2 () const
</code></td>
123 <td>Returns the number of columns.
</td>
126 <td><code>size_type lower () const
</code></td>
127 <td>Returns the number of diagonals below the main diagonal.
</td>
130 <td><code>size_type upper () const
</code></td>
131 <td>Returns the number of diagonals above the main diagonal.
</td>
134 <td><code>const_reference operator () (size_type i, size_type j)
136 <td>Returns a
<code>const
</code> reference of the
<code>j
</code>
137 -th element in the
<code>i
</code>-th row.
</td>
140 <td><code>reference operator () (size_type i, size_type
142 <td>Returns a reference of the
<code>j
</code>-th element in the
143 <code>i
</code>-th row.
</td>
146 <td><code>banded_matrix
&operator = (const banded_matrix
148 <td>The assignment operator.
</td>
151 <td><code>banded_matrix
&assign_temporary (banded_matrix
153 <td>Assigns a temporary. May change the banded matrix
154 <code>m
</code> .
</td>
157 <td><code>template
<class AE
><br />
158 banded_matrix
&operator = (const matrix_expression
<AE
>
160 <td>The extended assignment operator.
</td>
163 <td><code>template
<class AE
><br />
164 banded_matrix
&assign (const matrix_expression
<AE
>
166 <td>Assigns a matrix expression to the banded matrix. Left and
167 right hand side of the assignment should be independent.
</td>
170 <td><code>template
<class AE
><br />
171 banded_matrix
&operator += (const matrix_expression
<AE
>
173 <td>A computed assignment operator. Adds the matrix expression to
174 the banded matrix.
</td>
177 <td><code>template
<class AE
><br />
178 banded_matrix
&plus_assign (const matrix_expression
<AE
>
180 <td>Adds a matrix expression to the banded matrix. Left and right
181 hand side of the assignment should be independent.
</td>
184 <td><code>template
<class AE
><br />
185 banded_matrix
&operator -= (const matrix_expression
<AE
>
187 <td>A computed assignment operator. Subtracts the matrix expression
188 from the banded matrix.
</td>
191 <td><code>template
<class AE
><br />
192 banded_matrix
&minus_assign (const matrix_expression
<AE
>
194 <td>Subtracts a matrix expression from the banded matrix. Left and
195 right hand side of the assignment should be independent.
</td>
198 <td><code>template
<class AT
><br />
199 banded_matrix
&operator *= (const AT
&at)
</code></td>
200 <td>A computed assignment operator. Multiplies the banded matrix
204 <td><code>template
<class AT
><br />
205 banded_matrix
&operator /= (const AT
&at)
</code></td>
206 <td>A computed assignment operator. Divides the banded matrix
207 through a scalar.
</td>
210 <td><code>void swap (banded_matrix
&m)
</code></td>
211 <td>Swaps the contents of the banded matrices.
</td>
214 <td><code>void insert (size_type i, size_type j, const_reference
216 <td>Inserts the value
<code>t
</code> at the
<code>j
</code>-th
217 element of the
<code>i
</code>-th row.
</td>
220 <td><code>void erase (size_type i, size_type j)
</code></td>
221 <td>Erases the value at the
<code>j
</code>-th elemenst of the
222 <code>i
</code>-th row.
</td>
225 <td><code>void clear ()
</code></td>
226 <td>Clears the matrix.
</td>
229 <td><code>const_iterator1 begin1 () const
</code></td>
230 <td>Returns a
<code>const_iterator1
</code> pointing to the
231 beginning of the
<code>banded_matrix
</code>.
</td>
234 <td><code>const_iterator1 end1 () const
</code></td>
235 <td>Returns a
<code>const_iterator1
</code> pointing to the end of
236 the
<code>banded_matrix
</code>.
</td>
239 <td><code>iterator1 begin1 ()
</code></td>
240 <td>Returns a
<code>iterator1
</code> pointing to the beginning of
241 the
<code>banded_matrix
</code>.
</td>
244 <td><code>iterator1 end1 ()
</code></td>
245 <td>Returns a
<code>iterator1
</code> pointing to the end of the
246 <code>banded_matrix
</code>.
</td>
249 <td><code>const_iterator2 begin2 () const
</code></td>
250 <td>Returns a
<code>const_iterator2
</code> pointing to the
251 beginning of the
<code>banded_matrix
</code>.
</td>
254 <td><code>const_iterator2 end2 () const
</code></td>
255 <td>Returns a
<code>const_iterator2
</code> pointing to the end of
256 the
<code>banded_matrix
</code>.
</td>
259 <td><code>iterator2 begin2 ()
</code></td>
260 <td>Returns a
<code>iterator2
</code> pointing to the beginning of
261 the
<code>banded_matrix
</code>.
</td>
264 <td><code>iterator2 end2 ()
</code></td>
265 <td>Returns a
<code>iterator2
</code> pointing to the end of the
266 <code>banded_matrix
</code>.
</td>
269 <td><code>const_reverse_iterator1 rbegin1 () const
</code></td>
270 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
271 beginning of the reversed
<code>banded_matrix
</code>.
</td>
274 <td><code>const_reverse_iterator1 rend1 () const
</code></td>
275 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
276 end of the reversed
<code>banded_matrix
</code>.
</td>
279 <td><code>reverse_iterator1 rbegin1 ()
</code></td>
280 <td>Returns a
<code>reverse_iterator1
</code> pointing to the
281 beginning of the reversed
<code>banded_matrix
</code>.
</td>
284 <td><code>reverse_iterator1 rend1 ()
</code></td>
285 <td>Returns a
<code>reverse_iterator1
</code> pointing to the end of
286 the reversed
<code>banded_matrix
</code>.
</td>
289 <td><code>const_reverse_iterator2 rbegin2 () const
</code></td>
290 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
291 beginning of the reversed
<code>banded_matrix
</code>.
</td>
294 <td><code>const_reverse_iterator2 rend2 () const
</code></td>
295 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
296 end of the reversed
<code>banded_matrix
</code>.
</td>
299 <td><code>reverse_iterator2 rbegin2 ()
</code></td>
300 <td>Returns a
<code>reverse_iterator2
</code> pointing to the
301 beginning of the reversed
<code>banded_matrix
</code>.
</td>
304 <td><code>reverse_iterator2 rend2 ()
</code></td>
305 <td>Returns a
<code>reverse_iterator2
</code> pointing to the end of
306 the reversed
<code>banded_matrix
</code>.
</td>
311 <p><a name=
"banded_matrix_1" id=
"banded_matrix_1">[
1]
</a> Supported
312 parameters for the storage organization are
<code>row_major
</code>
313 and
<code>column_major
</code>.
</p>
314 <p><a name=
"banded_matrix_2" id=
"banded_matrix_2">[
2]
</a> Supported
315 parameters for the adapted array are
316 <code>unbounded_array
<T
></code> ,
317 <code>bounded_array
<T
></code> and
318 <code>std::vector
<T
></code> .
</p>
319 <h2><a name=
"banded_adaptor"></a>Banded Adaptor
</h2>
321 <p>The templated class
<code>banded_adaptor
<M
></code> is a
322 banded matrix adaptor for other matrices.
</p>
325 #include
<boost/numeric/ublas/banded.hpp
>
326 #include
<boost/numeric/ublas/io.hpp
>
329 using namespace boost::numeric::ublas;
330 matrix
<double
> m (
3,
3);
331 banded_adaptor
<matrix
<double
> > ba (m,
1,
1);
332 for (signed i =
0; i
< signed (ba.size1 ()); ++ i)
333 for (signed j = std::max (i -
1,
0); j
< std::min (i +
2, signed (ba.size2 ())); ++ j)
334 ba (i, j) =
3 * i + j;
335 std::cout
<< ba
<< std::endl;
339 <p>Defined in the header banded.hpp.
</p>
340 <h4>Template parameters
</h4>
341 <table border=
"1" summary=
"parameters">
349 <td><code>M
</code></td>
350 <td>The type of the adapted matrix.
</td>
356 <p><a href=
"expression_concept.html#matrix_expression">Matrix Expression
</a>
358 <h4>Type requirements
</h4>
359 <p>None, except for those imposed by the requirements of
<a href=
360 "expression_concept.html#matrix_expression">Matrix Expression
</a> .
</p>
361 <h4>Public base classes
</h4>
362 <p><code>matrix_expression
<banded_adaptor
<M
>
365 <table border=
"1" summary=
"members">
372 <td><code>banded_adaptor (matrix_type
&data, size_type lower =
373 0, size_type upper =
0)
</code></td>
374 <td>Constructs a
<code>banded_adaptor
</code> that holds
375 <code>(lower +
1 + upper)
</code> diagonals around the main diagonal
379 <td><code>banded_adaptor (const banded_adaptor
&m)
</code></td>
380 <td>The copy constructor.
</td>
383 <td><code>template
<class AE
><br />
384 banded_adaptor (const matrix_expression
<AE
>
386 <td>The extended copy constructor.
</td>
389 <td><code>size_type size1 () const
</code></td>
390 <td>Returns the number of rows.
</td>
393 <td><code>size_type size2 () const
</code></td>
394 <td>Returns the number of columns.
</td>
397 <td><code>size_type lower () const
</code></td>
398 <td>Returns the number of diagonals below the main diagonal.
</td>
401 <td><code>size_type upper () const
</code></td>
402 <td>Returns the number of diagonals above the main diagonal.
</td>
405 <td><code>const_reference operator () (size_type i, size_type j)
407 <td>Returns a
<code>const
</code> reference of the
<code>j
</code>
408 -th element in the
<code>i
</code>-th row.
</td>
411 <td><code>reference operator () (size_type i, size_type
413 <td>Returns a reference of the
<code>j
</code>-th element in the
414 <code>i
</code>-th row.
</td>
417 <td><code>banded_adaptor
&operator = (const banded_adaptor
419 <td>The assignment operator.
</td>
422 <td><code>banded_adaptor
&assign_temporary (banded_adaptor
424 <td>Assigns a temporary. May change the banded adaptor
425 <code>m
</code> .
</td>
428 <td><code>template
<class AE
><br />
429 banded_adaptor
&operator = (const matrix_expression
<AE
>
431 <td>The extended assignment operator.
</td>
434 <td><code>template
<class AE
><br />
435 banded_adaptor
&assign (const matrix_expression
<AE
>
437 <td>Assigns a matrix expression to the banded adaptor. Left and
438 right hand side of the assignment should be independent.
</td>
441 <td><code>template
<class AE
><br />
442 banded_adaptor
&operator += (const matrix_expression
<AE
>
444 <td>A computed assignment operator. Adds the matrix expression to
445 the banded adaptor.
</td>
448 <td><code>template
<class AE
><br />
449 banded_adaptor
&plus_assign (const matrix_expression
<AE
>
451 <td>Adds a matrix expression to the banded adaptor. Left and right
452 hand side of the assignment should be independent.
</td>
455 <td><code>template
<class AE
><br />
456 banded_adaptor
&operator -= (const matrix_expression
<AE
>
458 <td>A computed assignment operator. Subtracts the matrix expression
459 from the banded adaptor.
</td>
462 <td><code>template
<class AE
><br />
463 banded_adaptor
&minus_assign (const matrix_expression
<AE
>
465 <td>Subtracts a matrix expression from the banded adaptor. Left and
466 right hand side of the assignment should be independent.
</td>
469 <td><code>template
<class AT
><br />
470 banded_adaptor
&operator *= (const AT
&at)
</code></td>
471 <td>A computed assignment operator. Multiplies the banded adaptor
475 <td><code>template
<class AT
><br />
476 banded_adaptor
&operator /= (const AT
&at)
</code></td>
477 <td>A computed assignment operator. Divides the banded adaptor
478 through a scalar.
</td>
481 <td><code>void swap (banded_adaptor
&m)
</code></td>
482 <td>Swaps the contents of the banded adaptors.
</td>
485 <td><code>const_iterator1 begin1 () const
</code></td>
486 <td>Returns a
<code>const_iterator1
</code> pointing to the
487 beginning of the
<code>banded_adaptor
</code>.
</td>
490 <td><code>const_iterator1 end1 () const
</code></td>
491 <td>Returns a
<code>const_iterator1
</code> pointing to the end of
492 the
<code>banded_adaptor
</code>.
</td>
495 <td><code>iterator1 begin1 ()
</code></td>
496 <td>Returns a
<code>iterator1
</code> pointing to the beginning of
497 the
<code>banded_adaptor
</code>.
</td>
500 <td><code>iterator1 end1 ()
</code></td>
501 <td>Returns a
<code>iterator1
</code> pointing to the end of the
502 <code>banded_adaptor
</code>.
</td>
505 <td><code>const_iterator2 begin2 () const
</code></td>
506 <td>Returns a
<code>const_iterator2
</code> pointing to the
507 beginning of the
<code>banded_adaptor
</code>.
</td>
510 <td><code>const_iterator2 end2 () const
</code></td>
511 <td>Returns a
<code>const_iterator2
</code> pointing to the end of
512 the
<code>banded_adaptor
</code>.
</td>
515 <td><code>iterator2 begin2 ()
</code></td>
516 <td>Returns a
<code>iterator2
</code> pointing to the beginning of
517 the
<code>banded_adaptor
</code>.
</td>
520 <td><code>iterator2 end2 ()
</code></td>
521 <td>Returns a
<code>iterator2
</code> pointing to the end of the
522 <code>banded_adaptor
</code>.
</td>
525 <td><code>const_reverse_iterator1 rbegin1 () const
</code></td>
526 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
527 beginning of the reversed
<code>banded_adaptor
</code>.
</td>
530 <td><code>const_reverse_iterator1 rend1 () const
</code></td>
531 <td>Returns a
<code>const_reverse_iterator1
</code> pointing to the
532 end of the reversed
<code>banded_adaptor
</code>.
</td>
535 <td><code>reverse_iterator1 rbegin1 ()
</code></td>
536 <td>Returns a
<code>reverse_iterator1
</code> pointing to the
537 beginning of the reversed
<code>banded_adaptor
</code>.
</td>
540 <td><code>reverse_iterator1 rend1 ()
</code></td>
541 <td>Returns a
<code>reverse_iterator1
</code> pointing to the end of
542 the reversed
<code>banded_adaptor
</code>.
</td>
545 <td><code>const_reverse_iterator2 rbegin2 () const
</code></td>
546 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
547 beginning of the reversed
<code>banded_adaptor
</code>.
</td>
550 <td><code>const_reverse_iterator2 rend2 () const
</code></td>
551 <td>Returns a
<code>const_reverse_iterator2
</code> pointing to the
552 end of the reversed
<code>banded_adaptor
</code>.
</td>
555 <td><code>reverse_iterator2 rbegin2 ()
</code></td>
556 <td>Returns a
<code>reverse_iterator2
</code> pointing to the
557 beginning of the reversed
<code>banded_adaptor
</code>.
</td>
560 <td><code>reverse_iterator2 rend2 ()
</code></td>
561 <td>Returns a
<code>reverse_iterator2
</code> pointing to the end of
562 the reversed
<code>banded_adaptor
</code>.
</td>
567 <p>Copyright (
©)
2000-
2002 Joerg Walter, Mathias Koch
<br />
568 Use, modification and distribution are subject to the
569 Boost Software License, Version
1.0.
570 (See accompanying file LICENSE_1_0.txt
571 or copy at
<a href=
"http://www.boost.org/LICENSE_1_0.txt">
572 http://www.boost.org/LICENSE_1_0.txt
</a>).
574 <script type=
"text/javascript">