Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/numeric/ublas/doc/overview.htm @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 32.2 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml">
4<head>
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 href="ublas.css" type="text/css" />
10<title>uBLAS Overview</title>
11</head>
12<body>
13<h1><img src="../../../../boost.png" align="middle" />
14uBLAS Overview</h1>
15<h2><a name="rationale" id="rationale">Rationale</h2>
16<p><cite>It would be nice if every kind of numeric software could
17be written in C++ without loss of efficiency, but unless something
18can be found that achieves this without compromising the C++ type
19system it may be preferable to rely on Fortran, assembler or
20architecture-specific extensions (Bjarne Stroustrup).</cite></p>
21<p>This C++ library is directed towards scientific computing on the
22level of basic linear algebra constructions with matrices and
23vectors and their corresponding abstract operations. The primary
24design goals were:</p>
25<ul type="Disc">
26<li>mathematical notation</li>
27<li>efficiency</li>
28<li>functionality</li>
29<li>compatibility</li>
30</ul>
31<p>Another intention was to evaluate, if the abstraction penalty
32resulting from the use of such matrix and vector classes is
33acceptable.</p>
34<h2>Resources</h2>
35<p>The development of this library was guided by a couple of
36similar efforts:</p>
37<ul type="Disc">
38<li><a href="http://www.netlib.org/blas/index.html">BLAS</a> by
39Jack Dongarra et al.</li>
40<li><a href="http://www.oonumerics.org/blitz/">Blitz++</a> by Todd
41Veldhuizen</li>
42<li><a href="http://acts.nersc.gov/pooma/">POOMA</a> by Scott
43Haney et al.</li>
44<li><a href="http://www.lsc.nd.edu/research/mtl/">MTL</a> by Jeremy
45Siek et al.</li>
46</ul>
47<p>BLAS seems to be the most widely used library for basic linear
48algebra constructions, so it could be called a de-facto standard.
49Its interface is procedural, the individual functions are somewhat
50abstracted from simple linear algebra operations. Due to the fact
51that is has been implemented using Fortran and its optimizations,
52it also seems to be one of the fastest libraries available. As we
53decided to design and implement our library in an object-oriented
54way, the technical approaches are distinct. However anyone should
55be able to express BLAS abstractions in terms of our library
56operators and to compare the efficiency of the implementations.</p>
57<p>Blitz++ is an impressive library implemented in C++. Its main
58design seems to be oriented towards multidimensional arrays and
59their associated operators including tensors. The author of Blitz++
60states, that the library achieves performance on par or better than
61corresponding Fortran code due to his implementation technique
62using expression templates and template metaprograms. However we
63see some reasons, to develop an own design and implementation
64approach. We do not know whether anybody tries to implement
65traditional linear algebra and other numerical algorithms using
66Blitz++. We also presume that even today Blitz++ needs the most
67advanced C++ compiler technology due to its implementation idioms.
68On the other hand, Blitz++ convinced us, that the use of expression
69templates is mandatory to reduce the abstraction penalty to an
70acceptable limit.</p>
71<p>POOMA's design goals seem to parallel Blitz++'s in many parts .
72It extends Blitz++'s concepts with classes from the domains of
73partial differential equations and theoretical physics. The
74implementation supports even parallel architectures.</p>
75<p>MTL is another approach supporting basic linear algebra
76operations in C++. Its design mainly seems to be influenced by BLAS
77and the C++ Standard Template Library. We share the insight that a
78linear algebra library has to provide functionality comparable to
79BLAS. On the other hand we think, that the concepts of the C++
80standard library have not yet been proven to support numerical
81computations as needed. As another difference MTL currently does
82not seem to use expression templates. This may result in one of two
83consequences: a possible loss of expressiveness or a possible loss
84of performance.</p>
85<h2>Concepts</h2>
86<h3>Mathematical Notation</h3>
87<p>The usage of mathematical notation may ease the development of
88scientific algorithms. So a C++ library implementing basic linear
89algebra concepts carefully should overload selected C++ operators
90on matrix and vector classes.</p>
91<p>We decided to use operator overloading for the following
92primitives:</p>
93<table border="1" summary="operators">
94<tbody>
95<tr>
96<th align="left">Description</th>
97<th align="left">Operator</th>
98</tr>
99<tr>
100<td>Indexing of vectors and matrices</td>
101<td><code>vector::operator(size_t i);<br />
102matrix::operator(size_t i, size_t j);</code></td>
103</tr>
104<tr>
105<td>Assignment of vectors and matrices</td>
106<td><code>vector::operator = (const vector_expression &amp;);<br />
107vector::operator += (const vector_expression &amp;);<br />
108vector::operator -= (const vector_expression &amp;);<br />
109vector::operator *= (const scalar_expression &amp;);<br />
110matrix::operator = (const matrix_expression &amp;);<br />
111matrix::operator += (const matrix_expression &amp;);<br />
112matrix::operator -= (const matrix_expression &amp;);<br />
113matrix::operator *= (const scalar_expression &amp;);</code></td>
114</tr>
115<tr>
116<td>Unary operations on vectors and matrices</td>
117<td><code>vector_expression operator - (const vector_expression
118&amp;);<br />
119matrix_expression operator - (const matrix_expression
120&amp;);</code></td>
121</tr>
122<tr>
123<td>Binary operations on vectors and matrices</td>
124<td><code>vector_expression operator + (const vector_expression
125&amp;, const vector_expression &amp;);<br />
126vector_expression operator - (const vector_expression &amp;, const
127vector_expression &amp;);<br />
128matrix_expression operator + (const matrix_expression &amp;, const
129matrix_expression &amp;);<br />
130matrix_expression operator - (const matrix_expression &amp;, const
131matrix_expression &amp;);</code></td>
132</tr>
133<tr>
134<td>Multiplication of vectors and matrices with a scalar</td>
135<td><code>vector_expression operator * (const scalar_expression
136&amp;, const vector_expression &amp;);<br />
137vector_expression operator * (const vector_expression &amp;, const
138scalar_expression &amp;);<br />
139matrix_expression operator * (const scalar_expression &amp;, const
140matrix_expression &amp;);<br />
141matrix_expression operator * (const matrix_expression &amp;, const
142scalar_expression &amp;);</code></td>
143</tr>
144</tbody>
145</table>
146<p>We decided to use no operator overloading for the following
147other primitives:</p>
148<table border="1" summary="functions">
149<tbody>
150<tr>
151<th align="left">Description</th>
152<th align="left">Function</th>
153</tr>
154<tr>
155<td>Left multiplication of vectors with a matrix</td>
156<td><code>vector_expression
157prod&lt;</code><code><em>vector_type</em></code> <code>&gt; (const
158matrix_expression &amp;, const vector_expression &amp;);<br />
159vector_expression prod (const matrix_expression &amp;, const
160vector_expression &amp;);</code></td>
161</tr>
162<tr>
163<td>Right multiplication of vectors with a matrix</td>
164<td><code>vector_expression
165prod&lt;</code><code><em>vector_type</em></code> <code>&gt; (const
166vector_expression &amp;, const matrix_expression &amp;);<br />
167vector_expression prod (const vector_expression &amp;, const
168matrix_expression &amp;);<br /></code></td>
169</tr>
170<tr>
171<td>Multiplication of matrices</td>
172<td><code>matrix_expression
173prod&lt;</code><code><em>matrix_type</em></code> <code>&gt; (const
174matrix_expression &amp;, const matrix_expression &amp;);<br />
175matrix_expression prod (const matrix_expression &amp;, const
176matrix_expression &amp;);</code></td>
177</tr>
178<tr>
179<td>Inner product of vectors</td>
180<td><code>scalar_expression inner_prod (const vector_expression
181&amp;, const vector_expression &amp;);</code></td>
182</tr>
183<tr>
184<td>Outer product of vectors</td>
185<td><code>matrix_expression outer_prod (const vector_expression
186&amp;, const vector_expression &amp;);</code></td>
187</tr>
188<tr>
189<td>Transpose of a matrix</td>
190<td><code>matrix_expression trans (const matrix_expression
191&amp;);</code></td>
192</tr>
193</tbody>
194</table>
195<h3>Efficiency</h3>
196<p>To achieve the goal of efficiency for numerical computing, one
197has to overcome two difficulties in formulating abstractions with
198C++, namely temporaries and virtual function calls. Expression
199templates solve these problems, but tend to slow down compilation
200times.</p>
201<h4>Eliminating Temporaries</h4>
202<p>Abstract formulas on vectors and matrices normally compose a
203couple of unary and binary operations. The conventional way of
204evaluating such a formula is first to evaluate every leaf operation
205of a composition into a temporary and next to evaluate the
206composite resulting in another temporary. This method is expensive
207in terms of time especially for small and space especially for
208large vectors and matrices. The approach to solve this problem is
209to use lazy evaluation as known from modern functional programming
210languages. The principle of this approach is to evaluate a complex
211expression element wise and to assign it directly to the
212target.</p>
213<p>Two interesting and dangerous facts result:</p>
214<h4>Aliases</h4>
215<p>One may get serious side effects using element wise
216evaluation on vectors or matrices. Consider the matrix vector
217product <em>x = A x</em>. Evaluation of
218<em>A</em><sub><em>1</em></sub><em>x</em> and assignment to
219<em>x</em><sub><em>1</em></sub> changes the right hand side, so
220that the evaluation of <em>A</em><sub><em>2</em></sub><em>x</em>
221returns a wrong result. In this case there are <strong>aliases</strong> of the elements
222<em>x</em><sub><em>n</em></sub> on both the left and right hand side of the assignment.</p>
223<p>Our solution for this problem is to
224evaluate the right hand side of an assignment into a temporary and
225then to assign this temporary to the left hand side. To allow
226further optimizations, we provide a corresponding member function
227for every assignment operator and also a
228<a href="operations_overview.htm#noalias"> <code>noalias</code> syntax.</a>
229By using this syntax a programmer can confirm, that the left and right hand sides of an
230assignment are independent, so that element wise evaluation and
231direct assignment to the target is safe.</p>
232<h4>Complexity</h4>
233<p>The computational complexity may be unexpectedly large under certain
234cirumstances. Consider the chained matrix vector product <em>A (B
235x)</em>. Conventional evaluation of <em>A (B x)</em> is quadratic.
236Deferred evaluation of <em>B x</em><sub><em>i</em></sub> is linear.
237As every element <em>B x</em><sub><em>i</em></sub> is needed
238linearly depending of the size, a completely deferred evaluation of
239the chained matrix vector product <em>A (B x)</em> is cubic. In
240such cases one needs to reintroduce temporaries in the
241expression.</p>
242<h4>Eliminating Virtual Function Calls</h4>
243<p>Lazy expression evaluation normally leads to the definition of a
244class hierarchy of terms. This results in the usage of dynamic
245polymorphism to access single elements of vectors and matrices,
246which is also known to be expensive in terms of time. A solution
247was found a couple of years ago independently by David Vandervoorde
248and Todd Veldhuizen and is commonly called expression templates.
249Expression templates contain lazy evaluation and replace dynamic
250polymorphism with static, i.e. compile time polymorphism.
251Expression templates heavily depend on the famous Barton-Nackman
252trick, also coined 'curiously defined recursive templates' by Jim
253Coplien.</p>
254<p>Expression templates form the base of our implementation.</p>
255<h4>Compilation times</h4>
256<p>It is also a well known fact, that expression templates
257challenge currently available compilers. We were able to
258significantly reduce the amount of needed expression templates
259using the Barton-Nackman trick consequently.</p>
260<p>We also decided to support a dual conventional implementation
261(i.e. not using expression templates) with extensive bounds and
262type checking of vector and matrix operations to support the
263development cycle. Switching from debug mode to release mode is
264controlled by the <code>NDEBUG</code> preprocessor symbol of
265<code>&lt;cassert&gt;</code>.</p>
266
267<h2><a name="functionality" id="functionality">Functionality</h2>
268
269<p>Every C++ library supporting linear algebra will be measured
270against the long-standing Fortran package BLAS. We now describe how
271BLAS calls may be mapped onto our classes.</p>
272
273<p>The page <a href="operations_overview.htm">Overview of Matrix and Vector Operations</a>
274gives a short summary of the most used operations on vectors and
275matrices.</p>
276
277<h4>Blas Level 1</h4>
278<table border="1" summary="level 1 blas">
279<tbody>
280<tr>
281<th align="left">BLAS Call</th>
282<th align="left">Mapped Library Expression</th>
283<th align="left">Mathematical Description</th>
284<th align="left">Comment</th>
285</tr>
286<tr>
287<td><code>_asum</code></td>
288<td><code>norm_1 (x)</code></td>
289<td><em>sum |x</em><sub><em>i</em></sub><em>|</em></td>
290<td>Computes the sum norm of a vector.</td>
291</tr>
292<tr>
293<td><code>_nrm2</code></td>
294<td><code>norm_2 (x)</code></td>
295<td><em>sqrt (sum
296|x</em><sub><em>i</em></sub>|<sup><em>2</em></sup> <em>)</em></td>
297<td>Computes the euclidean norm of a vector.</td>
298</tr>
299<tr>
300<td><code>i_amax</code></td>
301<td><code>norm_inf (x)<br />
302norm_inf_index (x)</code></td>
303<td><em>max |x</em><sub><em>i</em></sub><em>|</em></td>
304<td>Computes the maximum norm of a vector.<br />
305BLAS computes the index of the first element having this
306value.</td>
307</tr>
308<tr>
309<td><code>_dot<br />
310_dotu<br />
311_dotc</code></td>
312<td><code>inner_prod (x, y)</code>or<code><br />
313inner_prod (conj (x), y)</code></td>
314<td><em>x</em><sup><em>T</em></sup> <em>y</em> or<br />
315<em>x</em><sup><em>H</em></sup> <em>y</em></td>
316<td>Computes the inner product of two vectors.<br />
317BLAS implements certain loop unrollment.</td>
318</tr>
319<tr>
320<td><code>dsdot<br />
321sdsdot</code></td>
322<td><code>a + prec_inner_prod (x, y)</code></td>
323<td><em>a + x</em><sup><em>T</em></sup> <em>y</em></td>
324<td>Computes the inner product in double precision.</td>
325</tr>
326<tr>
327<td><code>_copy</code></td>
328<td><code>x = y<br />
329y.assign (x)</code></td>
330<td><em>x &lt;- y</em></td>
331<td>Copies one vector to another.<br />
332BLAS implements certain loop unrollment.</td>
333</tr>
334<tr>
335<td><code>_swap</code></td>
336<td><code>swap (x, y)</code></td>
337<td><em>x &lt;-&gt; y</em></td>
338<td>Swaps two vectors.<br />
339BLAS implements certain loop unrollment.</td>
340</tr>
341<tr>
342<td><code>_scal<br />
343csscal<br />
344zdscal</code></td>
345<td><code>x *= a</code></td>
346<td><em>x &lt;- a x</em></td>
347<td>Scales a vector.<br />
348BLAS implements certain loop unrollment.</td>
349</tr>
350<tr>
351<td><code>_axpy</code></td>
352<td><code>y += a * x</code></td>
353<td><em>y &lt;- a x + y</em></td>
354<td>Adds a scaled vector.<br />
355BLAS implements certain loop unrollment.</td>
356</tr>
357<tr>
358<td><code>_rot<br />
359_rotm<br />
360csrot<br />
361zdrot</code></td>
362<td><code>t.assign (a * x + b * y),<br />
363y.assign (- b * x + a * y),<br />
364x.assign (t)</code></td>
365<td><em>(x, y) &lt;- (a x + b y, -b x + a y)</em></td>
366<td>Applies a plane rotation.</td>
367</tr>
368<tr>
369<td><code>_rotg<br />
370_rotmg</code></td>
371<td>&nbsp;</td>
372<td><em>(a, b) &lt;-<br />
373&nbsp; (? a / sqrt (a</em><sup><em>2</em></sup> +
374<em>b</em><sup><em>2</em></sup><em>),<br />
375&nbsp; &nbsp; ? b / sqrt (a</em><sup><em>2</em></sup> +
376<em>b</em><sup><em>2</em></sup><em>))</em> or<em><br />
377(1, 0) &lt;- (0, 0)</em></td>
378<td>Constructs a plane rotation.</td>
379</tr>
380</tbody>
381</table>
382<h4>Blas Level 2</h4>
383<table border="1" summary="level 2 blas">
384<tbody>
385<tr>
386<th align="left">BLAS Call</th>
387<th align="left">Mapped Library Expression</th>
388<th align="left">Mathematical Description</th>
389<th align="left">Comment</th>
390</tr>
391<tr>
392<td><code>_t_mv</code></td>
393<td><code>x = prod (A, x)</code> or<code><br />
394x = prod (trans (A), x)</code> or<code><br />
395x = prod (herm (A), x)</code></td>
396<td><em>x &lt;- A x</em> or<em><br />
397x &lt;- A</em><sup><em>T</em></sup> <em>x</em> or<em><br />
398x &lt;- A</em><sup><em>H</em></sup> <em>x</em></td>
399<td>Computes the product of a matrix with a vector.</td>
400</tr>
401<tr>
402<td><code>_t_sv</code></td>
403<td><code>y = solve (A, x, tag)</code> or<br />
404<code>inplace_solve (A, x, tag)</code> or<br />
405<code>y = solve (trans (A), x, tag)</code> or<br />
406<code>inplace_solve (trans (A), x, tag)</code> or<br />
407<code>y = solve (herm (A), x, tag)</code>or<br />
408<code>inplace_solve (herm (A), x, tag)</code></td>
409<!-- TODO: replace nested sub/sup -->
410<td><em>y &lt;- A</em><sup><em>-1</em></sup> <em>x</em>
411or<em><br />
412x &lt;- A</em><sup><em>-1</em></sup> <em>x</em> or<em><br />
413y &lt;-
414A</em><sup><em>T</em></sup><sup><sup><em>-1</em></sup></sup>
415<em>x</em> or<em><br />
416x &lt;-
417A</em><sup><em>T</em></sup><sup><sup><em>-1</em></sup></sup>
418<em>x</em> or<em><br />
419y &lt;-
420A</em><sup><em>H</em></sup><sup><sup><em>-1</em></sup></sup>
421<em>x</em> or<em><br />
422x &lt;-
423A</em><sup><em>H</em></sup><sup><sup><em>-1</em></sup></sup>
424<em>x</em></td>
425<td>Solves a system of linear equations with triangular form, i.e.
426<em>A</em> is triangular.</td>
427</tr>
428<tr>
429<td><code>_g_mv<br />
430_s_mv<br />
431_h_mv</code></td>
432<td><code>y = a * prod (A, x) + b * y</code> or<code><br />
433y = a * prod (trans (A), x) + b * y</code> or<code><br />
434y = a * prod (herm (A), x) + b * y</code></td>
435<td><em>y &lt;- a A x + b y</em> or<em><br />
436y &lt;- a A</em><sup><em>T</em></sup> <em>x + b y<br />
437y &lt;- a A</em><sup><em>H</em></sup> <em>x + b y</em></td>
438<td>Adds the scaled product of a matrix with a vector.</td>
439</tr>
440<tr>
441<td><code>_g_r<br />
442_g_ru<br />
443_g_rc</code></td>
444<td><code>A += a * outer_prod (x, y)</code> or<code><br />
445A += a * outer_prod (x, conj (y))</code></td>
446<td><em>A &lt;- a x y</em><sup><em>T</em></sup> <em>+ A</em>
447or<em><br />
448A &lt;- a x y</em><sup><em>H</em></sup> <em>+ A</em></td>
449<td>Performs a rank <em>1</em> update.</td>
450</tr>
451<tr>
452<td><code>_s_r<br />
453_h_r</code></td>
454<td><code>A += a * outer_prod (x, x)</code> or<code><br />
455A += a * outer_prod (x, conj (x))</code></td>
456<td><em>A &lt;- a x x</em><sup><em>T</em></sup> <em>+ A</em>
457or<em><br />
458A &lt;- a x x</em><sup><em>H</em></sup> <em>+ A</em></td>
459<td>Performs a symmetric or hermitian rank <em>1</em> update.</td>
460</tr>
461<tr>
462<td><code>_s_r2<br />
463_h_r2</code></td>
464<td><code>A += a * outer_prod (x, y) +<br />
465&nbsp;a * outer_prod (y, x))</code> or<code><br />
466A += a * outer_prod (x, conj (y)) +<br />
467&nbsp;conj (a) * outer_prod (y, conj (x)))</code></td>
468<td><em>A &lt;- a x y</em><sup><em>T</em></sup> <em>+ a y
469x</em><sup><em>T</em></sup> <em>+ A</em> or<em><br />
470A &lt;- a x y</em><sup><em>H</em></sup> <em>+
471a</em><sup><em>-</em></sup> <em>y x</em><sup><em>H</em></sup> <em>+
472A</em></td>
473<td>Performs a symmetric or hermitian rank <em>2</em> update.</td>
474</tr>
475</tbody>
476</table>
477<h4>Blas Level 3</h4>
478<table border="1" summary="level 3 blas">
479<tbody>
480<tr>
481<th align="left">BLAS Call</th>
482<th align="left">Mapped Library Expression</th>
483<th align="left">Mathematical Description</th>
484<th align="left">Comment</th>
485</tr>
486<tr>
487<td><code>_t_mm</code></td>
488<td><code>B = a * prod (A, B)</code> or<br />
489<code>B = a * prod (trans (A), B)</code> or<br />
490<code>B = a * prod (A, trans (B))</code> or<br />
491<code>B = a * prod (trans (A), trans (B))</code> or<br />
492<code>B = a * prod (herm (A), B)</code> or<br />
493<code>B = a * prod (A, herm (B))</code> or<br />
494<code>B = a * prod (herm (A), trans (B))</code> or<br />
495<code>B = a * prod (trans (A), herm (B))</code> or<br />
496<code>B = a * prod (herm (A), herm (B))</code></td>
497<td><em>B &lt;- a op (A) op (B)</em> with<br />
498&nbsp; <em>op (X) = X</em> or<br />
499&nbsp; <em>op (X) = X</em><sup><em>T</em></sup> or<br />
500&nbsp; <em>op (X) = X</em><sup><em>H</em></sup></td>
501<td>Computes the scaled product of two matrices.</td>
502</tr>
503<tr>
504<td><code>_t_sm</code></td>
505<td><code>C = solve (A, B, tag)</code> or<br />
506<code>inplace_solve (A, B, tag)</code> or<br />
507<code>C = solve (trans (A), B, tag)</code> or<code><br />
508inplace_solve (trans (A), B, tag)</code> or<code><br />
509C = solve (herm (A), B, tag)</code> or<code><br />
510inplace_solve (herm (A), B, tag)</code></td>
511<td><em>C &lt;- A</em><sup><em>-1</em></sup> <em>B</em>
512or<em><br />
513B &lt;- A</em><sup><em>-1</em></sup> <em>B</em> or<em><br />
514C &lt;-
515A</em><sup><em>T</em></sup><sup><sup><em>-1</em></sup></sup>
516<em>B</em> or<em><br />
517B &lt;- A</em><sup><em>-1</em></sup> <em>B</em> or<em><br />
518C &lt;-
519A</em><sup><em>H</em></sup><sup><sup><em>-1</em></sup></sup>
520<em>B</em> or<em><br />
521B &lt;-
522A</em><sup><em>H</em></sup><sup><sup><em>-1</em></sup></sup>
523<em>B</em></td>
524<td>Solves a system of linear equations with triangular form, i.e.
525<em>A</em> is triangular.</td>
526</tr>
527<tr>
528<td><code>_g_mm<br />
529_s_mm<br />
530_h_mm</code></td>
531<td><code>C = a * prod (A, B) + b * C</code> or<br />
532<code>C = a * prod (trans (A), B) + b * C</code> or<br />
533<code>C = a * prod (A, trans (B)) + b * C</code> or<br />
534<code>C = a * prod (trans (A), trans (B)) + b * C</code> or<br />
535<code>C = a * prod (herm (A), B) + b * C</code> or<br />
536<code>C = a * prod (A, herm (B)) + b * C</code> or<br />
537<code>C = a * prod (herm (A), trans (B)) + b * C</code> or<br />
538<code>C = a * prod (trans (A), herm (B)) + b * C</code> or<br />
539<code>C = a * prod (herm (A), herm (B)) + b * C</code></td>
540<td><em>C &lt;- a op (A) op (B) + b C</em> with<br />
541&nbsp; <em>op (X) = X</em> or<br />
542&nbsp; <em>op (X) = X</em><sup><em>T</em></sup> or<br />
543&nbsp; <em>op (X) = X</em><sup><em>H</em></sup></td>
544<td>Adds the scaled product of two matrices.</td>
545</tr>
546<tr>
547<td><code>_s_rk<br />
548_h_rk</code></td>
549<td><code>B = a * prod (A, trans (A)) + b * B</code> or<br />
550<code>B = a * prod (trans (A), A) + b * B</code> or<br />
551<code>B = a * prod (A, herm (A)) + b * B</code> or<br />
552<code>B = a * prod (herm (A), A) + b * B</code></td>
553<td><em>B &lt;- a A A</em><sup><em>T</em></sup> <em>+ b B</em>
554or<em><br />
555B &lt;- a A</em><sup><em>T</em></sup> <em>A + b B</em> or<br />
556<em>B &lt;- a A A</em><sup><em>H</em></sup> <em>+ b B</em>
557or<em><br />
558B &lt;- a A</em><sup><em>H</em></sup> <em>A + b B</em></td>
559<td>Performs a symmetric or hermitian rank <em>k</em> update.</td>
560</tr>
561<tr>
562<td><code>_s_r2k<br />
563_h_r2k</code></td>
564<td><code>C = a * prod (A, trans (B)) +<br />
565&nbsp;a * prod (B, trans (A)) + b * C</code> or<br />
566<code>C = a * prod (trans (A), B) +<br />
567&nbsp;a * prod (trans (B), A) + b * C</code> or<br />
568<code>C = a * prod (A, herm (B)) +<br />
569&nbsp;conj (a) * prod (B, herm (A)) + b * C</code> or<br />
570<code>C = a * prod (herm (A), B) +<br />
571&nbsp;conj (a) * prod (herm (B), A) + b * C</code></td>
572<td><em>C &lt;- a A B</em><sup><em>T</em></sup> <em>+ a B
573A</em><sup><em>T</em></sup> <em>+ b C</em> or<em><br />
574C &lt;- a A</em><sup><em>T</em></sup> <em>B + a
575B</em><sup><em>T</em></sup> <em>A + b C</em> or<em><br />
576C &lt;- a A B</em><sup><em>H</em></sup> <em>+
577a</em><sup><em>-</em></sup> <em>B A</em><sup><em>H</em></sup> <em>+
578b C</em> or<em><br />
579C &lt;- a A</em><sup><em>H</em></sup> <em>B +
580a</em><sup><em>-</em></sup> <em>B</em><sup><em>H</em></sup> <em>A +
581b C</em></td>
582<td>Performs a symmetric or hermitian rank <em>2 k</em>
583update.</td>
584</tr>
585</tbody>
586</table>
587
588<h2>Storage Layout</h2>
589
590<p>uBLAS supports may different storage layouts. The full details can be
591found at the <a href="types_overview.htm">Overview of Types</a>. Most types like
592<code>vector&lt;double&gt;</code> and <code>matrix&lt;double&gt;</code> are
593by default compatible to C arrays, but can also be configured to contain
594FORTAN compatible data.
595</p>
596
597<h2>Compatibility</h2>
598<p>For compatibility reasons we provide array like indexing for vectors and matrices. For some types (hermitian, sparse etc) this can be expensive for matrices due to the needed temporary proxy objects.</p>
599<p>uBLAS uses STL compatible allocators for the allocation of the storage required for it's containers.</p>
600<h2>Benchmark Results</h2>
601<p>The following tables contain results of one of our benchmarks.
602This benchmark compares a native C implementation ('C array') and
603some library based implementations. The safe variants based on the
604library assume aliasing, the fast variants do not use temporaries
605and are functionally equivalent to the native C implementation.
606Besides the generic vector and matrix classes the benchmark
607utilizes special classes <code>c_vector</code> and
608<code>c_matrix</code>, which are intended to avoid every overhead
609through genericity.</p>
610<p>The benchmark program <strong>bench1</strong> was compiled with GCC 4.0 and run on an Athlon 64 3000+. Times are scales for reasonable precision by running <strong>bench1 100</strong>.</p>
611<p>First we comment the results for double vectors and matrices of dimension 3 and 3 x 3, respectively.</p>
612<table border="1" summary="1st benchmark">
613<tbody>
614<tr>
615<th align="left">Comment</th>
616</tr>
617<tr>
618<td rowspan="3">inner_prod</td>
619<td>C array</td>
620<td align="right">0.61</td>
621<td align="right">782</td>
622<td rowspan="3">Some abstraction penalty</td>
623</tr>
624<tr>
625<td>c_vector</td>
626<td align="right">0.86</td>
627<td align="right">554</td>
628</tr>
629<tr>
630<td>vector&lt;unbounded_array&gt;</td>
631<td align="right">1.02</td>
632<td align="right">467</td>
633</tr>
634<tr>
635<td rowspan="5">vector + vector</td>
636<td>C array</td>
637<td align="right">0.51</td>
638<td align="right">1122</td>
639<td rowspan="5">Abstraction penalty: factor 2</td>
640</tr>
641<tr>
642<td>c_vector fast</td>
643<td align="right">1.17</td>
644<td align="right">489</td>
645</tr>
646<tr>
647<td>vector&lt;unbounded_array&gt; fast</td>
648<td align="right">1.32</td>
649<td align="right">433</td>
650</tr>
651<tr>
652<td>c_vector safe</td>
653<td align="right">2.02</td>
654<td align="right">283</td>
655</tr>
656<tr>
657<td>vector&lt;unbounded_array&gt; safe</td>
658<td align="right">6.95</td>
659<td align="right">82</td>
660</tr>
661<tr>
662<td rowspan="5">outer_prod</td>
663<td>C array</td>
664<td align="right">0.59</td>
665<td align="right">872</td>
666<td rowspan="5">Some abstraction penalty</td>
667</tr>
668<tr>
669<td>c_matrix, c_vector fast</td>
670<td align="right">0.88</td>
671<td align="right">585</td>
672</tr>
673<tr>
674<td>matrix&lt;unbounded_array&gt;, vector&lt;unbounded_array&gt; fast</td>
675<td align="right">0.90</td>
676<td align="right">572</td>
677</tr>
678<tr>
679<td>c_matrix, c_vector safe</td>
680<td align="right">1.66</td>
681<td align="right">310</td>
682</tr>
683<tr>
684<td>matrix&lt;unbounded_array&gt;, vector&lt;unbounded_array&gt; safe</td>
685<td align="right">2.95</td>
686<td align="right">175</td>
687</tr>
688<tr>
689<td rowspan="5">prod (matrix, vector)</td>
690<td>C array</td>
691<td align="right">0.64</td>
692<td align="right">671</td>
693<td rowspan="5">No significant abstraction penalty</td>
694</tr>
695<tr>
696<td>c_matrix, c_vector fast</td>
697<td align="right">0.70</td>
698<td align="right">613</td>
699</tr>
700<tr>
701<td>matrix&lt;unbounded_array&gt;, vector&lt;unbounded_array&gt; fast</td>
702<td align="right">0.79</td>
703<td align="right">543</td>
704</tr>
705<tr>
706<td>c_matrix, c_vector safe</td>
707<td align="right">0.95</td>
708<td align="right">452</td>
709</tr>
710<tr>
711<td>matrix&lt;unbounded_array&gt;, vector&lt;unbounded_array&gt; safe</td>
712<td align="right">2.61</td>
713<td align="right">164</td>
714</tr>
715<tr>
716<td rowspan="5">matrix + matrix</td>
717<td>C array</td>
718<td align="right">0.75</td>
719<td align="right">686</td>
720<td rowspan="5">No significant abstraction penalty</td>
721</tr>
722<tr>
723<td>c_matrix fast</td>
724<td align="right">0.99</td>
725<td align="right">520</td>
726</tr>
727<tr>
728<td>matrix&lt;unbounded_array&gt; fast</td>
729<td align="right">1.29</td>
730<td align="right">399</td>
731</tr>
732<tr>
733<td>c_matrix safe</td>
734<td align="right">1.7</td>
735<td align="right">303</td>
736</tr>
737<tr>
738<td>matrix&lt;unbounded_array&gt; safe</td>
739<td align="right">3.14</td>
740<td align="right">164</td>
741</tr>
742<tr>
743<td rowspan="5">prod (matrix, matrix)</td>
744<td>C array</td>
745<td align="right">0.94</td>
746<td align="right">457</td>
747<td rowspan="5">No significant abstraction penalty</td>
748</tr>
749<tr>
750<td>c_matrix fast</td>
751<td align="right">1.17</td>
752<td align="right">367</td>
753</tr>
754<tr>
755<td>matrix&lt;unbounded_array&gt; fast</td>
756<td align="right">1.34</td>
757<td align="right">320</td>
758</tr>
759<tr>
760<td>c_matrix safe</td>
761<td align="right">1.56</td>
762<td align="right">275</td>
763</tr>
764<tr>
765<td>matrix&lt;unbounded_array&gt; safe</td>
766<td align="right">2.06</td>
767<td align="right">208</td>
768</tr>
769</tbody>
770</table>
771<p>We notice a two fold performance loss for small vectors and matrices: first the general abstraction penalty for using classes, and then a small loss when using the generic vector and matrix classes. The difference w.r.t. alias assumptions is also significant.</p>
772<p>Next we comment the results for double vectors and matrices of
773dimension 100 and 100 x 100, respectively.</p>
774<table border="1" summary="2nd benchmark">
775<tbody>
776<tr>
777<th align="left">Operation</th>
778<th align="left">Implementation</th>
779<th align="left">Elapsed [s]</th>
780<th align="left">MFLOP/s</th>
781<th align="left">Comment</th>
782</tr>
783<tr>
784<td rowspan="3">inner_prod</td>
785<td>C array</td>
786<td align="right">0.64</td>
787<td align="right">889</td>
788<td rowspan="3">No significant abstraction penalty</td>
789</tr>
790<tr>
791<td>c_vector</td>
792<td align="right">0.66</td>
793<td align="right">862</td>
794</tr>
795<tr>
796<td>vector&lt;unbounded_array&gt;</td>
797<td align="right">0.66</td>
798<td align="right">862</td>
799</tr>
800<tr>
801<td rowspan="5">vector + vector</td>
802<td>C array</td>
803<td align="right">0.64</td>
804<td align="right">894</td>
805<td rowspan="5">No significant abstraction penalty</td>
806</tr>
807<tr>
808<td>c_vector fast</td>
809<td align="right">0.66</td>
810<td align="right">867</td>
811</tr>
812<tr>
813<td>vector&lt;unbounded_array&gt; fast</td>
814<td align="right">0.66</td>
815<td align="right">867</td>
816</tr>
817<tr>
818<td>c_vector safe</td>
819<td align="right">1.14</td>
820<td align="right">501</td>
821</tr>
822<tr>
823<td>vector&lt;unbounded_array&gt; safe</td>
824<td align="right">1.23</td>
825<td align="right">465</td>
826</tr>
827<tr>
828<td rowspan="5">outer_prod</td>
829<td>C array</td>
830<td align="right">0.50</td>
831<td align="right">1144</td>
832<td rowspan="5">No significant abstraction penalty</td>
833</tr>
834<tr>
835<td>c_matrix, c_vector fast</td>
836<td align="right">0.71</td>
837<td align="right">806</td>
838</tr>
839<tr>
840<td>matrix&lt;unbounded_array&gt;, vector&lt;unbounded_array&gt; fast</td>
841<td align="right">0.57</td>
842<td align="right">1004</td>
843</tr>
844<tr>
845<td>c_matrix, c_vector safe</td>
846<td align="right">1.91</td>
847<td align="right">300</td>
848</tr>
849<tr>
850<td>matrix&lt;unbounded_array&gt;, vector&lt;unbounded_array&gt; safe</td>
851<td align="right">0.89</td>
852<td align="right">643</td>
853</tr>
854<tr>
855<td rowspan="5">prod (matrix, vector)</td>
856<td>C array</td>
857<td align="right">0.65</td>
858<td align="right">876</td>
859<td rowspan="5">No significant abstraction penalty</td>
860</tr>
861<tr>
862<td>c_matrix, c_vector fast</td>
863<td align="right">0.65</td>
864<td align="right">876</td>
865</tr>
866<tr>
867<td>matrix&lt;unbounded_array&gt;, vector&lt;unbounded_array&gt;
868fast</td>
869<td align="right">0.66</td>
870<td align="right">863</td>
871</tr>
872<tr>
873<td>c_matrix, c_vector safe</td>
874<td align="right">0.66</td>
875<td align="right">863</td>
876</tr>
877<tr>
878<td>matrix&lt;unbounded_array&gt;, vector&lt;unbounded_array&gt;
879safe</td>
880<td align="right">0.66</td>
881<td align="right">863</td>
882</tr>
883<tr>
884<td rowspan="5">matrix + matrix</td>
885<td>C array</td>
886<td align="right">0.96</td>
887<td align="right">596</td>
888<td rowspan="5">No significant abstraction penalty</td>
889</tr>
890<tr>
891<td>c_matrix fast</td>
892<td align="right">1.21</td>
893<td align="right">473</td>
894</tr>
895<tr>
896<td>matrix&lt;unbounded_array&gt; fast</td>
897<td align="right">1.00</td>
898<td align="right">572</td>
899</tr>
900<tr>
901<td>c_matrix safe</td>
902<td align="right">2.44</td>
903<td align="right">235</td>
904</tr>
905<tr>
906<td>matrix&lt;unbounded_array&gt; safe</td>
907<td align="right">1.30</td>
908<td align="right">440</td>
909</tr>
910<tr>
911<td rowspan="5">prod (matrix, matrix)</td>
912<td>C array</td>
913<td align="right">0.70</td>
914<td align="right">813</td>
915<td rowspan="5">No significant abstraction penalty</td>
916</tr>
917<tr>
918<td>c_matrix fast</td>
919<td align="right">0.73</td>
920<td align="right">780</td>
921</tr>
922<tr>
923<td>matrix&lt;unbounded_array&gt; fast</td>
924<td align="right">0.76</td>
925<td align="right">749</td>
926</tr>
927<tr>
928<td>c_matrix safe</td>
929<td align="right">0.75</td>
930<td align="right">759</td>
931</tr>
932<tr>
933<td>matrix&lt;unbounded_array&gt; safe</td>
934<td align="right">0.76</td>
935<td align="right">749</td>
936</tr>
937</tbody>
938</table>
939<p>For larger vectors and matrices the general abstraction penalty
940for using classes seems to decrease, the small loss when using
941generic vector and matrix classes seems to remain. The difference
942w.r.t. alias assumptions remains visible, too.</p>
943<hr />
944<p>Copyright (&copy;) 2000-2002 Joerg Walter, Mathias Koch<br />
945Permission to copy, use, modify, sell and distribute this document
946is granted provided this copyright notice appears in all copies.
947This document is provided ``as is'' without express or implied
948warranty, and with no claim as to its suitability for any
949purpose.</p>
950</body>
951</html>
Note: See TracBrowser for help on using the repository browser.