comparison armadillo-3.900.4/docs.html @ 49:1ec0e2823891

Switch to using subrepo copies of qm-dsp, nnls-chroma, vamp-plugin-sdk; update Armadillo version; assume build without external BLAS/LAPACK
author Chris Cannam
date Thu, 13 Jun 2013 10:25:24 +0100
parents
children
comparison
equal deleted inserted replaced
48:69251e11a913 49:1ec0e2823891
1 <!-- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -->
2 <html>
3 <head>
4 <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
5 <title>Armadillo: API Reference</title>
6 <link rel="icon" href="armadillo_icon.png" type="image/png">
7 <style type="text/css">
8 <!--
9 body
10 {
11 font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
12 color: #000000;
13 background-color: #FFFFFF;
14 /* font-size: 10pt; */
15 /* line-height: 120%; */
16 height: 110%;
17 }
18
19 pre
20 {
21 font-family: "DejaVu Sans Mono", "Liberation Mono", "Andale Mono", "Bitstream Vera Sans Mono", "Luxi Mono", monospace;
22 font-size: smaller;
23 color: #666666;
24 }
25
26 a
27 {
28 text-decoration: none;
29 color: #498c05;
30 }
31
32 a:hover
33 {
34 text-decoration: underline;
35 color: #498c05;
36 }
37
38 a.menu
39 {
40 text-decoration: none;
41 color: #CCCCCC;
42 }
43
44 a.menu:hover
45 {
46 text-decoration: none;
47 color: #498c05;
48 }
49
50 a.hidden, a.hidden:hover, a.hidden:active, a.hidden:link, a.hidden:visited
51 {
52 text-decoration: none;
53 border-bottom: 0px
54 }
55
56 table
57 {
58 /* border: 1px solid #000; */
59 /* display: block; */
60 border-collapse: collapse;
61 }
62
63 td.line
64 {
65 border-left: 2px solid rgb(204, 204, 204);
66 }
67
68 .footertext
69 {
70 position: relative;
71 bottom: 0px;
72 }
73
74 hr.greyline
75 {
76 color: rgb(204, 204, 204);
77 /* background-color: rgb(204, 204, 204); */
78 }
79
80
81 #nobreak
82 {
83 white-space: nowrap;
84 }
85
86 .noindent
87 {
88 text-indent: 0px;
89 margin-left: 1ex;
90 margin-right: 0ex;
91 margin-top: 0ex;
92 margin-bottom: 0ex;
93 padding-left: 1ex;
94 padding-right: 0ex;
95 padding-top: 0ex;
96 padding-bottom: 0ex;
97 list-style: disc;
98 }
99 -->
100 </style>
101 </head>
102 <body>
103 <center>
104 <table style="text-align: left; width: 80%; margin-left: auto; margin-right: auto;" border="0" cellpadding="0" cellspacing="0">
105 <tbody>
106 <tr>
107 <td style="vertical-align: top;">
108
109 <table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">
110 <tbody>
111 <tr>
112 <td style="text-align: left; vertical-align: top;">
113 <font size=+2><b>Reference for Armadillo 3.900</b></font>
114 <br>
115 <b>(Bavarian Sunflower)</b>
116 </td>
117 <td style="text-align: right; vertical-align: top;">
118 <b><a href="http://arma.sourceforge.net">to Armadillo home page</a></b>
119 <br>
120 <b><a href="http://nicta.com.au">to NICTA home page</a></b>
121 <br>
122 </td>
123 </tr>
124 </tbody>
125 </table>
126 <hr>
127 <br>
128 <br>
129 <a name="top"></a>
130 <a style="display:scroll; position:fixed; bottom:5px; right:5px;" href="#top"><font size=-1>[top]</font></a>
131
132
133 <!-- BEGIN CONTENT -->
134
135
136 <b>Preamble</b>
137 <br>
138 <br>
139 <table border="0" cellpadding="0" cellspacing="0">
140 <tbody>
141 <tr>
142 <td style="text-align: left; vertical-align: top; width: 50%;">
143 <ul>
144 <li>
145 To aid the conversion of Matlab/Octave programs,
146 there is a <a href="#syntax">syntax conversion table</a>
147 </li>
148 <br>
149 <li>
150 First time users may want to have a look at a short <a href="#example_prog">example program</a>
151 </li>
152 <br>
153 <li>
154 If you find any bugs or regressions, please <a href="http://arma.sourceforge.net/faq.html">report them</a>
155 </li>
156 <br>
157 <li>
158 Notes on <a href="#api_additions">API additions</a>
159 </li>
160 </ul>
161 </td>
162 <td>
163 &nbsp;
164 </td>
165 <td class="line" style="vertical-align: top;">
166 <br>
167 </td>
168 <td style="text-align: left; vertical-align: top; width: 45%;">
169 <ul>
170 <li>
171 Please cite the following tech report if you use Armadillo in your research and/or software.
172 Citations are useful for the continued development and maintenance of the library.
173 <br>
174 <br>
175 <font size=-1>
176 Conrad Sanderson.
177 <br>
178 <i><a href="armadillo_nicta_2010.pdf">Armadillo: An Open Source C++ Linear Algebra Library for Fast Prototyping and Computationally Intensive Experiments</a></i>.
179 <br>
180 Technical Report, NICTA, 2010.
181 </font>
182 </li>
183 </ul>
184 </td>
185 </tr>
186 </tbody>
187 </table>
188
189 <br>
190 <br>
191
192 <b>Matrix, Vector, Cube and Field Classes</b>
193 <ul>
194 <a href="#Mat">Mat&lt;<i>type</i>&gt;, mat and cx_mat</a>&nbsp;&middot;
195 <a href="#Col">Col&lt;<i>type</i>&gt;, colvec and vec</a>&nbsp;&middot;
196 <a href="#Row">Row&lt;<i>type</i>&gt;, rowvec</a>&nbsp;&middot;
197 <a href="#Cube">Cube&lt;<i>type</i>&gt;, cube</a>&nbsp;&middot;
198 <a href="#field">field&lt;<i>object&nbsp;type</i>&gt;</a>&nbsp;&middot;
199 <a href="#SpMat">SpMat&lt;<i>type</i>&gt;, sp_mat and sp_cx_mat</a>
200 </ul>
201 <br>
202
203 <b>Member Functions &amp; Variables</b>
204 <ul>
205 <a href="#attributes">attributes</a>&nbsp;&middot;
206 <a href="#colptr">colptr</a>&nbsp;&middot;
207 <a href="#copy_size">copy_size</a>&nbsp;&middot;
208 <a href="#diag">diag</a>&nbsp;&middot;
209 <a href="#each_colrow">each_col/each_row</a>&nbsp;&middot;
210 <a href="#element_access">element&nbsp;access</a>&nbsp;&middot;
211 <a href="#element_initialisation">element&nbsp;initialisation</a>&nbsp;&middot;
212 <a href="#eval_member">eval</a>&nbsp;&middot;
213 <a href="#eye_member">eye</a>&nbsp;&middot;
214 <a href="#fill">fill</a>&nbsp;&middot;
215 <a href="#i_member">i (inverse)</a>&nbsp;&middot;
216 <a href="#imbue">imbue</a>&nbsp;&middot;
217 <a href="#insert">insert rows/cols/slices</a>&nbsp;&middot;
218 <a href="#in_range">in_range</a>&nbsp;&middot;
219 <a href="#is_empty">is_empty</a>&nbsp;&middot;
220 <a href="#is_finite">is_finite</a>&nbsp;&middot;
221 <a href="#is_square">is_square</a>&nbsp;&middot;
222 <a href="#is_vec">is_vec</a>&nbsp;&middot;
223 <a href="#iterators_mat">iterators (matrices)</a>&nbsp;&middot;
224 <a href="#iterators_cube">iterators (cubes)</a>&nbsp;&middot;
225 <a href="#memptr">memptr</a>&nbsp;&middot;
226 <a href="#min_and_max_member">min/max</a>&nbsp;&middot;
227 <a href="#ones_member">ones</a>&nbsp;&middot;
228 <a href="#operators">operators</a>&nbsp;&middot;
229 <a href="#print">print</a>&nbsp;&middot;
230 <a href="#raw_print">raw_print</a>&nbsp;&middot;
231 <a href="#randu_randn_member">randu/randn</a>&nbsp;&middot;
232 <a href="#reset">reset</a>&nbsp;&middot;
233 <a href="#reshape_member">reshape</a>&nbsp;&middot;
234 <a href="#resize_member">resize</a>&nbsp;&middot;
235 <a href="#save_load_mat">save/load (matrices &amp; cubes)</a>&nbsp;&middot;
236 <a href="#save_load_field">save/load (fields)</a>&nbsp;&middot;
237 <a href="#set_imag">set_imag/real</a>&nbsp;&middot;
238 <a href="#set_size">set_size</a>&nbsp;&middot;
239 <a href="#shed">shed rows/cols/slices</a>&nbsp;&middot;
240 <a href="#stl_container_fns">STL container functions</a>&nbsp;&middot;
241 <a href="#submat">submatrix&nbsp;views</a>&nbsp;&middot;
242 <a href="#subcube">subcube&nbsp;views</a>&nbsp;&middot;
243 <a href="#subfield">subfield&nbsp;views</a>&nbsp;&middot;
244 <a href="#swap">swap</a>&nbsp;&middot;
245 <a href="#swap_rows">swap_rows/cols</a>&nbsp;&middot;
246 <a href="#t_st_members">t/st (transpose)</a>&nbsp;&middot;
247 <a href="#transform">transform</a>&nbsp;&middot;
248 <a href="#zeros_member">zeros</a>
249 </ul>
250 <br>
251
252 <b>Other Classes</b>
253 <ul>
254 <a href="#running_stat">running_stat&lt;<i>type</i>&gt;</a>&nbsp;&middot;
255 <a href="#running_stat_vec">running_stat_vec&lt;<i>type</i>&gt;</a>&nbsp;&middot;
256 <a href="#wall_clock">wall_clock</a>
257 </ul>
258 <br>
259
260 <b>Generated Vectors/Matrices/Cubes</b>
261 <ul>
262 <a href="#eye_standalone">eye</a>&nbsp;&middot;
263 <a href="#linspace">linspace</a>&nbsp;&middot;
264 <a href="#ones_standalone">ones</a>&nbsp;&middot;
265 <a href="#randu_randn_standalone">randu/randn</a>&nbsp;&middot;
266 <a href="#repmat">repmat</a>&nbsp;&middot;
267 <a href="#speye">speye</a>&nbsp;&middot;
268 <a href="#sprandu_sprandn">sprandu/sprandn</a>&nbsp;&middot;
269 <a href="#toeplitz">toeplitz/circ_toeplitz</a>&nbsp;&middot;
270 <a href="#zeros_standalone">zeros</a>
271 </ul>
272 <br>
273
274 <b>Functions Individually Applied to Each Element of a Matrix/Cube</b>
275 <ul>
276 <a href="#abs">abs</a>&nbsp;&middot;
277 <a href="#eps">eps</a>&nbsp;&middot;
278 <a href="#misc_fns">misc functions (exp, log, pow, sqrt, ...)</a>&nbsp;&middot;
279 <a href="#trig_fns">trigonometric functions (cos, sin, ...)</a>
280 </ul>
281 <br>
282
283 <b>Scalar Valued Functions of Vectors/Matrices/Cubes</b>
284 <ul>
285 <a href="#accu">accu</a>&nbsp;&middot;
286 <a href="#as_scalar">as_scalar</a>&nbsp;&middot;
287 <a href="#det">det</a>&nbsp;&middot;
288 <a href="#dot">dot/cdot/norm_dot</a>&nbsp;&middot;
289 <a href="#log_det">log_det</a>&nbsp;&middot;
290 <a href="#norm">norm</a>&nbsp;&middot;
291 <a href="#rank">rank</a>&nbsp;&middot;
292 <a href="#trace">trace</a>
293 </ul>
294 <br>
295
296 <b>Scalar/Vector Valued Functions of Vectors/Matrices</b>
297 <ul>
298 <a href="#diagvec">diagvec</a>&nbsp;&middot;
299 <a href="#min_and_max">min/max</a>&nbsp;&middot;
300 <a href="#prod">prod</a>&nbsp;&middot;
301 <a href="#sum">sum</a>&nbsp;&middot;
302 <a href="#stats_fns">statistics (mean, stddev, ...)</a>
303 </ul>
304 <br>
305
306 <b>Vector/Matrix/Cube Valued Functions of Vectors/Matrices/Cubes</b>
307 <ul>
308 <a href="#conv">conv</a>&nbsp;&middot;
309 <a href="#conv_to">conv_to</a>&nbsp;&middot;
310 <a href="#conj">conj</a>&nbsp;&middot;
311 <a href="#cor">cor</a>&nbsp;&middot;
312 <a href="#cov">cov</a>&nbsp;&middot;
313 <a href="#cross">cross</a>&nbsp;&middot;
314 <a href="#cumsum">cumsum</a>&nbsp;&middot;
315 <a href="#diagmat">diagmat</a>&nbsp;&middot;
316 <a href="#find">find</a>&nbsp;&middot;
317 <a href="#flip">fliplr/flipud</a>&nbsp;&middot;
318 <a href="#hist">hist</a>&nbsp;&middot;
319 <a href="#histc">histc</a>&nbsp;&middot;
320 <a href="#imag_real">imag/real</a>&nbsp;&middot;
321 <a href="#join">join&nbsp;rows/cols/slices</a>&nbsp;&middot;
322 <a href="#kron">kron</a>&nbsp;&middot;
323 <a href="#reshape">reshape</a>&nbsp;&middot;
324 <a href="#resize">resize</a>&nbsp;&middot;
325 <a href="#shuffle">shuffle</a>&nbsp;&middot;
326 <a href="#sort">sort</a>&nbsp;&middot;
327 <a href="#sort_index">sort_index</a>&nbsp;&middot;
328 <a href="#symmat">symmatu/symmatl</a>&nbsp;&middot;
329 <a href="#strans">strans</a>&nbsp;&middot;
330 <a href="#trans">trans</a>&nbsp;&middot;
331 <a href="#trimat">trimatu/trimatl</a>&nbsp;&middot;
332 <a href="#unique">unique</a>
333 </ul>
334 <br>
335
336 <b>Decompositions, Factorisations, Inverses and Equation Solvers</b>
337 <ul>
338 <a href="#chol">chol</a>&nbsp;&middot;
339 <a href="#eig_sym">eig_sym</a>&nbsp;&middot;
340 <a href="#eig_gen">eig_gen</a>&nbsp;&middot;
341 <a href="#fft">fft/ifft</a>&nbsp;&middot;
342 <a href="#inv">inv</a>&nbsp;&middot;
343 <a href="#lu">lu</a>&nbsp;&middot;
344 <a href="#pinv">pinv</a>&nbsp;&middot;
345 <a href="#princomp">princomp</a>&nbsp;&middot;
346 <a href="#qr">qr</a>&nbsp;&middot;
347 <a href="#qr_econ">qr_econ</a>&nbsp;&middot;
348 <a href="#solve">solve</a>&nbsp;&middot;
349 <a href="#svd">svd</a>&nbsp;&middot;
350 <a href="#svd_econ">svd_econ</a>&nbsp;&middot;
351 <a href="#syl">syl</a>
352 </ul>
353 <br>
354
355 <b>Miscellaneous</b>
356 <ul>
357 <a href="#is_finite_standalone">is_finite()</a>&nbsp;&middot;
358 <a href="#logging">logging of errors/warnings</a>&nbsp;&middot;
359 <a href="#constants">various constants (pi, inf, speed of light, ...)</a>&nbsp;&middot;
360 <!--<a href="#log_add">log_add</a>&nbsp;&middot;-->
361 <a href="#uword">uword/sword</a>&nbsp;&middot;
362 <a href="#cx_float_double">cx_float/cx_double</a>&nbsp;&middot;
363 <a href="#syntax">Matlab/Armadillo syntax differences</a>&nbsp;&middot;
364 <a href="#example_prog">example program</a>&nbsp;&middot;
365 <!--<a href="#catching_exceptions">catching exceptions</a>&nbsp;&middot;-->
366 <a href="#config_hpp">config.hpp</a>&nbsp;&middot;
367 <a href="#api_additions">API additions</a>
368 </ul>
369 <br>
370
371 <br>
372 <br>
373 <hr class="greyline">
374 <hr class="greyline">
375 <br>
376 <br>
377 <font size=+1><b>Matrix, Vector, Cube and Field Classes</b></font>
378 <br>
379 <br>
380 <hr class="greyline">
381 <br>
382
383 <a name="Mat"></a><b>Mat&lt;</b><i>type</i><b>&gt;</b>
384 <br><b>mat</b>
385 <br><b>cx_mat</b>
386 <ul>
387 <li>
388 The root matrix class is <b>Mat&lt;</b><i>type</i><b>&gt;</b>, where <i>type</i> can be one of:
389 <ul>
390 <li>
391 <i>float</i>, <i>double</i>, <i>std::complex&lt;float&gt;</i>, <i>std::complex&lt;double&gt;</i>,
392 <i>char</i>, <i>short</i>, <i>int</i>, and unsigned versions of <i>char</i>, <i>short</i>, <i>int</i>.
393 </li>
394 </ul>
395 </li>
396 <br>
397 <li>
398 For convenience the following typedefs have been defined:
399 <ul>
400 <table style="text-align: left;" border="0" cellpadding="2" cellspacing="2">
401 <tbody>
402 <tr>
403 <td style="vertical-align: top;">
404 mat
405 </td>
406 <td style="vertical-align: top;">
407 &nbsp;=&nbsp;
408 </td>
409 <td style="vertical-align: top;">
410 Mat&lt;double&gt;
411 </td>
412 </tr>
413 <tr>
414 <td style="vertical-align: top;">
415 fmat
416 </td>
417 <td style="vertical-align: top;">
418 &nbsp;=&nbsp;
419 </td>
420 <td style="vertical-align: top;">
421 Mat&lt;float&gt;
422 </td>
423 </tr>
424 <tr>
425 <td style="vertical-align: top;">
426 cx_mat
427 </td>
428 <td style="vertical-align: top;">
429 &nbsp;=&nbsp;
430 </td>
431 <td style="vertical-align: top;">
432 Mat&lt;<a href="#cx_float_double">cx_double</a>&gt;
433 </td>
434 </tr>
435 <tr>
436 <td style="vertical-align: top;">
437 cx_fmat
438 </td>
439 <td style="vertical-align: top;">
440 &nbsp;=&nbsp;
441 </td>
442 <td style="vertical-align: top;">
443 Mat&lt;<a href="#cx_float_double">cx_float</a>&gt;
444 </td>
445 </tr>
446 <tr>
447 <td style="vertical-align: top;">
448 umat
449 </td>
450 <td style="vertical-align: top;">
451 &nbsp;=&nbsp;
452 </td>
453 <td style="vertical-align: top;">
454 Mat&lt;<a href="#uword">uword</a>&gt;
455 </td>
456 </tr>
457 <tr>
458 <td style="vertical-align: top;">
459 imat
460 </td>
461 <td style="vertical-align: top;">
462 &nbsp;=&nbsp;
463 </td>
464 <td style="vertical-align: top;">
465 Mat&lt;<a href="#uword">sword</a>&gt;
466 </td>
467 </tr>
468 </tbody>
469 </table>
470 </ul>
471 </li>
472 <br>
473 <li>
474 In this documentation the <i>mat</i> type is used for convenience;
475 it is possible to use other types instead, eg. <i>fmat</i>
476 </li>
477 <br>
478 <li>
479 Functions which are wrappers for LAPACK or ATLAS functions (generally matrix decompositions) are only valid for the following types:
480 <i>fmat</i>, <i>mat</i>, <i>cx_fmat</i>, <i>cx_mat</i>
481 </li>
482 <br>
483 <li>
484 Elements are stored with column-major ordering (ie. column by column)
485 </li>
486 <br>
487 <a name="constructors_mat"></a>
488 <li>
489 Constructors:
490 <ul>
491 <li>mat()</li>
492 <li>mat(n_rows, n_cols)</li>
493 <li>mat(mat)</li>
494 <li>mat(vec)</li>
495 <li>mat(rowvec)</li>
496 <li>mat(string)</li>
497 <li>mat(std::vector) &nbsp; (treated as a column vector)</li>
498 <li>mat(initialiser_list) &nbsp; (C++11 only)</li>
499 <li>cx_mat(mat,mat) &nbsp; (for constructing a complex matrix out of two real matrices)</li>
500 </ul>
501 </li>
502 <br>
503 <li>
504 The string format for the constructor is elements separated by spaces, and rows denoted by semicolons.
505 For example, the 2x2 identity matrix can be created using the format string <code>"1 0; 0 1"</code>.
506 While string based initialisation is compact,
507 directly <a href="#element_access">setting the elements</a>
508 or using <a href="#element_initialisation">element initialisation</a> is considerably faster.
509 </li>
510 <br>
511 <a name="adv_constructors_mat"></a>
512 <li>
513 Advanced constructors:
514 <br>
515 <br>
516 <ul>
517 <li>mat(aux_mem*, n_rows, n_cols, copy_aux_mem = true, strict = true)
518 <br>
519 <br>
520 <ul>
521 Create a matrix using data from writeable auxiliary memory.
522 By default the matrix allocates its own memory and copies data from the auxiliary memory (for safety).
523 However, if <i>copy_aux_mem</i> is set to <i>false</i>,
524 the matrix will instead directly use the auxiliary memory (ie. no copying).
525 This is faster, but can be dangerous unless you know what you're doing!
526 <br>
527 <br>
528 The <i>strict</i> variable comes into effect only if <i>copy_aux_mem</i> is set to <i>false</i>
529 (ie. the matrix is directly using auxiliary memory).
530 If <i>strict</i> is set to <i>true</i>,
531 the matrix will be bound to the auxiliary memory for its lifetime;
532 the number of elements in the matrix can't be changed (directly or indirectly).
533 If <i>strict</i> is set to <i>false</i>, the matrix will not be bound to the auxiliary memory for its lifetime,
534 ie., the size of the matrix can be changed.
535 If the requested number of elements is different to the size of the auxiliary memory,
536 new memory will be allocated and the auxiliary memory will no longer be used.
537 </ul>
538 </li>
539 <br>
540 <li>mat(const aux_mem*, n_rows, n_cols)
541 <br>
542 <br>
543 <ul>
544 Create a matrix by copying data from read-only auxiliary memory.
545 </ul>
546 </li>
547 <a name="adv_constructors_mat_fixed"></a>
548 <br>
549 <li>mat::fixed&lt;n_rows, n_cols&gt;
550 <br>
551 <br>
552 <ul>
553 Create a fixed size matrix, with the size specified via template arguments.
554 Memory for the matrix is allocated at compile time.
555 This is generally faster than dynamic memory allocation, but the size of the matrix can't be changed afterwards (directly or indirectly).
556 <br>
557 <br>
558 For convenience, there are several pre-defined typedefs for each matrix type
559 (where the types are: <i>umat</i>, <i>imat</i>, <i>fmat</i>, <i>mat</i>, <i>cx_fmat</i>, <i>cx_mat</i>).
560 The typedefs specify a square matrix size, ranging from 2x2 to 9x9.
561 The typedefs were defined by simply appending a two digit form of the size to the matrix type
562 -- for example, <i>mat33</i> is equivalent to <i>mat::fixed&lt;3,3&gt;</i>,
563 while <i>cx_mat44</i> is equivalent to <i>cx_mat::fixed&lt;4,4&gt;</i>.
564 </ul>
565 </li>
566 <br>
567 <li>mat::fixed&lt;n_rows, n_cols&gt;(const aux_mem*)
568 <br>
569 <br>
570 <ul>
571 Create a fixed size matrix, with the size specified via template arguments,
572 and copying data from auxiliary memory.
573 </ul>
574 </li>
575 </ul>
576 </li>
577 <br>
578 <br>
579 <li>
580 Examples:
581 <ul>
582 <pre>
583 mat A = randu&lt;mat&gt;(5,5);
584 double x = A(1,2);
585
586 mat B = A + A;
587 mat C = A * B;
588 mat D = A % B;
589
590 cx_mat X(A,B);
591
592 B.zeros();
593 B.set_size(10,10);
594 B.zeros(5,6);
595
596 //
597 // fixed size matrices:
598
599 mat::fixed&lt;5,6&gt; F;
600 F.ones();
601
602 mat44 G;
603 G.randn();
604
605 cout &lt;&lt; mat22().randu() &lt;&lt; endl;
606
607 //
608 // constructing matrices from
609 // auxiliary (external) memory:
610
611 double aux_mem[24];
612 mat H(aux_mem, 4, 6, false);
613 </pre>
614 </ul>
615 </li>
616 <br>
617 <li><b>Caveat:</b>
618 For mathematical correctness, scalars are treated as 1x1 matrices during initialisation.
619 As such, the code below <b>will not</b> generate a 5x5 matrix with every element equal to 123.0:
620 <ul>
621 <pre>
622 mat A(5,5); A = 123.0;
623 </pre>
624 </ul>
625 Use the following code instead:
626 <ul>
627 <pre>
628 mat A(5,5); A.fill(123.0);
629 </pre>
630 </ul>
631 <br>
632 <li>
633 See also:
634 <ul>
635 <li><a href="#attributes">matrix attributes</a></li>
636 <li><a href="#element_access">accessing elements</a></li>
637 <li><a href="#element_initialisation">initialising elements</a></li>
638 <li><a href="#operators">math &amp; relational operators</a></li>
639 <li><a href="#submat">submatrix views</a></li>
640 <li><a href="#save_load_mat">saving &amp; loading matrices</a></li>
641 <li><a href="#print">printing matrices</a></li>
642 <li><a href="#iterators_mat">STL-style element iterators</a></li>
643 <li><a href="#eval_member">.eval()</a></li>
644 <li><a href="#conv_to">conv_to()</a> (convert between matrix types)</li>
645 <li><a href="http://www.cplusplus.com/doc/tutorial/other_data_types/">explanation of <i>typedef</i></a> (cplusplus.com)
646 <li><a href="#Col">Col class</a></li>
647 <li><a href="#Row">Row class</a></li>
648 <li><a href="#Cube">Cube class</a></li>
649 <li><a href="#SpMat">SpMat class</a> (sparse matrix)</li>
650 <li><a href="#config_hpp">config.hpp</a></li>
651 </ul>
652 </li>
653 <br>
654 </ul>
655 <hr class="greyline">
656 <br>
657
658 <a name="Col"></a><b>Col&lt;</b><i>type</i><b>&gt;</b>
659 <br><b>colvec</b>
660 <br><b>vec</b>
661 <ul>
662 <li>
663 Classes for column vectors (matrices with one column)
664 </li>
665 <br>
666 <li>The <b>Col&lt;</b><i>type</i><b>&gt;</b> class is derived from the <b>Mat&lt;</b><i>type</i><b>&gt;</b> class
667 and inherits most of the member functions
668 </li>
669 <br>
670 <li>
671 For convenience the following typedefs have been defined:
672 <ul>
673 <table style="text-align: left;" border="0" cellpadding="2" cellspacing="2">
674 <tbody>
675 <tr>
676 <td style="vertical-align: top;">
677 vec, colvec
678 </td>
679 <td style="vertical-align: top;">
680 &nbsp;=&nbsp;
681 </td>
682 <td style="vertical-align: top;">
683 Col&lt;double&gt;
684 </td>
685 </tr>
686 <tr>
687 <td style="vertical-align: top;">
688 fvec, fcolvec
689 </td>
690 <td style="vertical-align: top;">
691 &nbsp;=&nbsp;
692 </td>
693 <td style="vertical-align: top;">
694 Col&lt;float&gt;
695 </td>
696 </tr>
697 <tr>
698 <td style="vertical-align: top;">
699 cx_vec, cx_colvec
700 </td>
701 <td style="vertical-align: top;">
702 &nbsp;=&nbsp;
703 </td>
704 <td style="vertical-align: top;">
705 Col&lt;<a href="#cx_float_double">cx_double</a>&gt;
706 </td>
707 </tr>
708 <tr>
709 <td style="vertical-align: top;">
710 cx_fvec, cx_fcolvec
711 </td>
712 <td style="vertical-align: top;">
713 &nbsp;=&nbsp;
714 </td>
715 <td style="vertical-align: top;">
716 Col&lt;<a href="#cx_float_double">cx_float</a>&gt;
717 </td>
718 </tr>
719 <tr>
720 <td style="vertical-align: top;">
721 uvec, ucolvec
722 </td>
723 <td style="vertical-align: top;">
724 &nbsp;=&nbsp;
725 </td>
726 <td style="vertical-align: top;">
727 Col&lt;<a href="#uword">uword</a>&gt;
728 </td>
729 </tr>
730 <tr>
731 <td style="vertical-align: top;">
732 ivec, icolvec
733 </td>
734 <td style="vertical-align: top;">
735 &nbsp;=&nbsp;
736 </td>
737 <td style="vertical-align: top;">
738 Col&lt;<a href="#uword">sword</a>&gt;
739 </td>
740 </tr>
741 </tbody>
742 </table>
743 </ul>
744 </li>
745 <br>
746 <li>
747 In this documentation, the <b><i>vec</i></b> and <b><i>colvec</i></b> types have the <b>same meaning</b> and are used <b>interchangeably</b>
748 </li>
749 <br>
750 <li>
751 In this documentation, the types <i>vec</i> or <i>colvec</i> are used for convenience; it is possible to use other types instead, eg.&nbsp;<i>fvec</i>, <i>fcolvec</i>
752 </li>
753 <br>
754 <li>
755 Functions which take <i>Mat</i> as input can generally also take <i>Col</i> as input.
756 Main exceptions are functions which require square matrices
757 </li>
758 <br>
759 <li>
760 Constructors
761 <ul>
762 <li>vec(n_elem=0)</li>
763 <li>vec(vec)</li>
764 <li>vec(mat) &nbsp; (a <i>std::logic_error</i> exception is thrown if the given matrix has more than one column)</li>
765 <li>vec(string) &nbsp; (elements separated by spaces)</li>
766 <li>vec(std::vector)</li>
767 <li>vec(initialiser_list) &nbsp; (C++11 only)</li>
768 </ul>
769 </li>
770 <br>
771 <a name="adv_constructors_col"></a>
772 <li>
773 Advanced constructors:
774 <br>
775 <br>
776 <ul>
777 <li>vec(aux_mem*, number_of_elements, copy_aux_mem = true, strict = true)
778 <br>
779 <br>
780 <ul>
781 Create a column vector using data from writeable auxiliary memory.
782 By default the vector allocates its own memory and copies data from the auxiliary memory (for safety).
783 However, if <i>copy_aux_mem</i> is set to <i>false</i>,
784 the vector will instead directly use the auxiliary memory (ie. no copying).
785 This is faster, but can be dangerous unless you know what you're doing!
786 <br>
787 <br>
788 The <i>strict</i> variable comes into effect only if <i>copy_aux_mem</i> is set to <i>false</i>
789 (ie. the vector is directly using auxiliary memory).
790 If <i>strict</i> is set to <i>true</i>,
791 the vector will be bound to the auxiliary memory for its lifetime;
792 the number of elements in the vector can't be changed (directly or indirectly).
793 If <i>strict</i> is set to <i>false</i>, the vector will not be bound to the auxiliary memory for its lifetime,
794 ie., the vector's size can be changed.
795 If the requested number of elements is different to the size of the auxiliary memory,
796 new memory will be allocated and the auxiliary memory will no longer be used.
797 </ul>
798 </li>
799 <br>
800 <li>vec(const aux_mem*, number_of_elements)
801 <br>
802 <br>
803 <ul>
804 Create a column vector by copying data from read-only auxiliary memory.
805 </ul>
806 </li>
807 <a name="adv_constructors_col_fixed"></a>
808 <br>
809 <li>vec::fixed&lt;number_of_elements&gt;
810 <br>
811 <br>
812 <ul>
813 Create a fixed size column vector, with the size specified via the template argument.
814 Memory for the vector is allocated at compile time.
815 This is generally faster than dynamic memory allocation, but the size of the vector can't be changed afterwards (directly or indirectly).
816 <br>
817 <br>
818 For convenience, there are several pre-defined typedefs for each vector type
819 (where the types are: <i>uvec</i>, <i>ivec</i>, <i>fvec</i>, <i>vec</i>, <i>cx_fvec</i>, <i>cx_vec</i> as well as the corresponding <i>colvec</i> versions).
820 The pre-defined typedefs specify vector sizes ranging from 2 to 9.
821 The typedefs were defined by simply appending a single digit form of the size to the vector type
822 -- for example, <i>vec3</i> is equivalent to <i>vec::fixed&lt;3&gt;</i>,
823 while <i>cx_vec4</i> is equivalent to <i>cx_vec::fixed&lt;4&gt;</i>.
824 </ul>
825 </li>
826 <br>
827 <li>vec::fixed&lt;number_of_elements&gt;(const aux_mem*)
828 <br>
829 <br>
830 <ul>
831 Create a fixed size column vector, with the size specified via the template argument,
832 and copying data from auxiliary memory.
833 </ul>
834 </li>
835 </ul>
836 </li>
837 <br>
838 <br>
839 <li>
840 Examples:
841 <ul>
842 <pre>
843 vec x(10);
844 vec y = zeros&lt;vec&gt;(10,1);
845
846 mat A = randu&lt;mat&gt;(10,10);
847 vec z = A.col(5); // extract a column vector
848 </pre>
849 </ul>
850 </li>
851 <br>
852 <li><b>Caveat:</b>
853 For mathematical correctness, scalars are treated as 1x1 matrices during initialisation.
854 As such, the code below <b>will not</b> generate a column vector with every element equal to 123.0:
855 <ul>
856 <pre>
857 vec a(5); a = 123.0;
858 </pre>
859 </ul>
860 Use the following code instead:
861 <ul>
862 <pre>
863 vec a(5); a.fill(123.0);
864 </pre>
865 </ul>
866 </li>
867 <br>
868 <li>See also:
869 <ul>
870 <li><a href="#Mat">Mat class</a></li>
871 <li><a href="#Row">Row class</a></li>
872 </ul>
873 </li>
874 <br>
875 </ul>
876 <hr class="greyline"><br>
877
878 <a name="Row"></a>
879 <b>Row&lt;</b><i>type</i><b>&gt;</b>
880 <br><b>rowvec</b>
881 <ul>
882 <li>
883 Classes for row vectors (matrices with one row)
884 </li>
885 <br>
886 <li>The template <b>Row&lt;</b><i>type</i><b>&gt;</b> class is derived from the <b>Mat&lt;</b><i>type</i><b>&gt;</b> class
887 and inherits most of the member functions
888 </li>
889 <br>
890 <li>
891 For convenience the following typedefs have been defined:
892 <ul>
893 <table style="text-align: left;" border="0" cellpadding="2" cellspacing="2">
894 <tbody>
895 <tr>
896 <td style="vertical-align: top;">
897 rowvec
898 </td>
899 <td style="vertical-align: top;">
900 &nbsp;=&nbsp;
901 </td>
902 <td style="vertical-align: top;">
903 Row&lt;double&gt;
904 </td>
905 </tr>
906 <tr>
907 <td style="vertical-align: top;">
908 frowvec
909 </td>
910 <td style="vertical-align: top;">
911 &nbsp;=&nbsp;
912 </td>
913 <td style="vertical-align: top;">
914 Row&lt;float&gt;
915 </td>
916 </tr>
917 <tr>
918 <td style="vertical-align: top;">
919 cx_rowvec
920 </td>
921 <td style="vertical-align: top;">
922 &nbsp;=&nbsp;
923 </td>
924 <td style="vertical-align: top;">
925 Row&lt;<a href="#cx_float_double">cx_double</a>&gt;
926 </td>
927 </tr>
928 <tr>
929 <td style="vertical-align: top;">
930 cx_frowvec
931 </td>
932 <td style="vertical-align: top;">
933 &nbsp;=&nbsp;
934 </td>
935 <td style="vertical-align: top;">
936 Row&lt;<a href="#cx_float_double">cx_float</a>&gt;
937 </td>
938 </tr>
939 <tr>
940 <td style="vertical-align: top;">
941 urowvec
942 </td>
943 <td style="vertical-align: top;">
944 &nbsp;=&nbsp;
945 </td>
946 <td style="vertical-align: top;">
947 Row&lt;<a href="#uword">uword</a>&gt;
948 </td>
949 </tr>
950 <tr>
951 <td style="vertical-align: top;">
952 irowvec
953 </td>
954 <td style="vertical-align: top;">
955 &nbsp;=&nbsp;
956 </td>
957 <td style="vertical-align: top;">
958 Row&lt;<a href="#uword">sword</a>&gt;
959 </td>
960 </tr>
961 </tbody>
962 </table>
963 </ul>
964 </li>
965 <br>
966 <li>
967 In this documentation, the <i>rowvec</i> type is used for convenience;
968 it is possible to use other types instead, eg. <i>frowvec</i>
969 </li>
970 <br>
971 <li>
972 Functions which take <i>Mat</i> as input can generally also take <i>Row</i> as input.
973 Main exceptions are functions which require square matrices
974 </li>
975 <br>
976 <li>
977 Constructors
978 <ul>
979 <li>rowvec(n_elem=0)</li>
980 <li>rowvec(rowvec)</li>
981 <li>rowvec(mat) &nbsp; (a <i>std::logic_error</i> exception is thrown if the given matrix has more than one row)</li>
982 <li>rowvec(string) &nbsp; (elements separated by spaces)</li>
983 <li>rowvec(std::vector)</li>
984 <li>rowvec(initialiser_list) &nbsp; (C++11 only)</li>
985 </ul>
986 </li>
987 <br>
988 <a name="adv_constructors_row"></a>
989 <li>
990 Advanced constructors:
991 <br>
992 <br>
993 <ul>
994 <li>rowvec(aux_mem*, number_of_elements, copy_aux_mem = true, strict = true)
995 <br>
996 <br>
997 <ul>
998 Create a row vector using data from writeable auxiliary memory.
999 By default the vector allocates its own memory and copies data from the auxiliary memory (for safety).
1000 However, if <i>copy_aux_mem</i> is set to <i>false</i>,
1001 the vector will instead directly use the auxiliary memory (ie. no copying).
1002 This is faster, but can be dangerous unless you know what you're doing!
1003 <br>
1004 <br>
1005 The <i>strict</i> variable comes into effect only if <i>copy_aux_mem</i> is set to <i>false</i>
1006 (ie. the vector is directly using auxiliary memory).
1007 If <i>strict</i> is set to <i>true</i>,
1008 the vector will be bound to the auxiliary memory for its lifetime;
1009 the number of elements in the vector can't be changed (directly or indirectly).
1010 If <i>strict</i> is set to <i>false</i>, the vector will not be bound to the auxiliary memory for its lifetime,
1011 ie., the vector's size can be changed.
1012 If the requested number of elements is different to the size of the auxiliary memory,
1013 new memory will be allocated and the auxiliary memory will no longer be used.
1014 </ul>
1015 </li>
1016 <br>
1017 <li>rowvec(const aux_mem*, number_of_elements)
1018 <br>
1019 <br>
1020 <ul>
1021 Create a row vector by copying data from read-only auxiliary memory.
1022 </ul>
1023 </li>
1024 <br>
1025 <li>rowvec::fixed&lt;number_of_elements&gt;
1026 <br>
1027 <br>
1028 <ul>
1029 Create a fixed size row vector, with the size specified via the template argument.
1030 Memory for the vector is allocated at compile time.
1031 This is generally faster than dynamic memory allocation, but the size of the vector can't be changed afterwards (directly or indirectly).
1032 <br>
1033 <br>
1034 For convenience, there are several pre-defined typedefs for each vector type
1035 (where the types are: <i>urowvec</i>, <i>irowvec</i>, <i>frowvec</i>, <i>rowvec</i>, <i>cx_frowvec</i>, <i>cx_rowvec</i>).
1036 The pre-defined typedefs specify vector sizes ranging from 2 to 9.
1037 The typedefs were defined by simply appending a single digit form of the size to the vector type
1038 -- for example, <i>rowvec3</i> is equivalent to <i>rowvec::fixed&lt;3&gt;</i>,
1039 while <i>cx_rowvec4</i> is equivalent to <i>cx_rowvec::fixed&lt;4&gt;</i>.
1040 </ul>
1041 </li>
1042 <br>
1043 <li>rowvec::fixed&lt;number_of_elements&gt;(const aux_mem*)
1044 <br>
1045 <br>
1046 <ul>
1047 Create a fixed size row vector, with the size specified via the template argument,
1048 and copying data from auxiliary memory.
1049 </ul>
1050 </li>
1051 </ul>
1052 </li>
1053 <br>
1054 <br>
1055 <li>
1056 Examples:
1057 <ul>
1058 <pre>
1059 rowvec x(10);
1060 rowvec y = zeros&lt;mat&gt;(1,10);
1061
1062 mat A = randu&lt;mat&gt;(10,10);
1063 rowvec z = A.row(5); // extract a row vector
1064 </pre>
1065 </ul>
1066 </li>
1067 <br>
1068 <li>
1069 <b>Caveat:</b>
1070 For mathematical correctness, scalars are treated as 1x1 matrices during initialisation.
1071 As such, the code below <b>will not</b> generate a row vector with every element equal to 123.0:
1072 <ul>
1073 <pre>
1074 rowvec r(5); r = 123.0;
1075 </pre>
1076 </ul>
1077 Use the following code instead:
1078 <ul>
1079 <pre>
1080 rowvec r(5); r.fill(123.0);
1081 </pre>
1082 </ul>
1083 <br>
1084 <li>See also:
1085 <ul>
1086 <li><a href="#Mat">Mat class</a></li>
1087 <li><a href="#Col">Col class</a></li>
1088 </ul>
1089 </li>
1090 <br>
1091 </ul>
1092 <hr class="greyline">
1093 <br>
1094
1095 <a name="Cube"></a>
1096 <b>Cube&lt;</b><i>type</i><b>&gt;</b>
1097 <br><b>cube</b>
1098 <br><b>cx_cube</b>
1099 <ul>
1100 <li>
1101 Classes for cubes, also known as "3D matrices" or 3rd order tensors
1102 </li>
1103 <br>
1104 <li>
1105 The cube class is <b>Cube&lt;</b><i>type</i><b>&gt;</b>, where <i>type</i> can be one of:
1106 <i>char</i>, <i>int</i>, <i>float</i>, <i>double</i>, <i>std::complex&lt;double&gt;</i>, etc
1107 </li>
1108 <br>
1109 <li>
1110 For convenience the following typedefs have been defined:
1111 <ul>
1112 <table style="text-align: left;" border="0" cellpadding="2" cellspacing="2">
1113 <tbody>
1114 <tr>
1115 <td style="vertical-align: top;">
1116 cube
1117 </td>
1118 <td style="vertical-align: top;">
1119 &nbsp;=&nbsp;
1120 </td>
1121 <td style="vertical-align: top;">
1122 Cube&lt;double&gt;
1123 </td>
1124 </tr>
1125 <tr>
1126 <td style="vertical-align: top;">
1127 fcube
1128 </td>
1129 <td style="vertical-align: top;">
1130 &nbsp;=&nbsp;
1131 </td>
1132 <td style="vertical-align: top;">
1133 Cube&lt;float&gt;
1134 </td>
1135 </tr>
1136 <tr>
1137 <td style="vertical-align: top;">
1138 cx_cube
1139 </td>
1140 <td style="vertical-align: top;">
1141 &nbsp;=&nbsp;
1142 </td>
1143 <td style="vertical-align: top;">
1144 Cube&lt;<a href="#cx_float_double">cx_double</a>&gt;
1145 </td>
1146 </tr>
1147 <tr>
1148 <td style="vertical-align: top;">
1149 cx_fcube
1150 </td>
1151 <td style="vertical-align: top;">
1152 &nbsp;=&nbsp;
1153 </td>
1154 <td style="vertical-align: top;">
1155 Cube&lt;<a href="#cx_float_double">cx_float</a>&gt;
1156 </td>
1157 </tr>
1158 <tr>
1159 <td style="vertical-align: top;">
1160 ucube
1161 </td>
1162 <td style="vertical-align: top;">
1163 &nbsp;=&nbsp;
1164 </td>
1165 <td style="vertical-align: top;">
1166 Cube&lt;<a href="#uword">uword</a>&gt;
1167 </td>
1168 </tr>
1169 <tr>
1170 <td style="vertical-align: top;">
1171 icube
1172 </td>
1173 <td style="vertical-align: top;">
1174 &nbsp;=&nbsp;
1175 </td>
1176 <td style="vertical-align: top;">
1177 Cube&lt;<a href="#uword">sword</a>&gt;
1178 </td>
1179 </tr>
1180 </tbody>
1181 </table>
1182 </ul>
1183 </li>
1184 <br>
1185 <li>
1186 In this documentation the <i>cube</i> type is used for convenience;
1187 it is possible to use other types instead, eg. <i>fcube</i>
1188 </li>
1189 <br>
1190 <li>
1191 Cube data is stored as a set of slices (matrices) stored contiguously within memory.
1192 Within each slice, elements are stored with column-major ordering (ie. column by column)
1193 </li>
1194 <br>
1195 <li>
1196 Each slice can be interpreted as a matrix, hence functions which take <i>Mat</i> as input can generally also take cube slices as input
1197 </li>
1198 <br>
1199 <a name="constructors_cube"></a>
1200 <li>
1201 Constructors:
1202 <ul>
1203 cube()
1204 <br>cube(cube)
1205 <br>cube(n_rows, n_cols, n_slices)
1206 <br>cx_cube(cube, cube) (for constructing a complex cube out of two real cubes)
1207 </ul>
1208 </li>
1209 <br>
1210
1211 <a name="adv_constructors_cube"></a>
1212 <li>
1213 Advanced constructors:
1214 <br>
1215 <br>
1216 <ul>
1217 <li>
1218 cube::fixed&lt;n_rows, n_cols, n_slices&gt;
1219 <br>
1220 <br>
1221 <ul>
1222 Create a fixed size cube, with the size specified via template arguments.
1223 Memory for the cube is allocated at compile time.
1224 This is generally faster than dynamic memory allocation, but the size of the cube can't be changed afterwards (directly or indirectly).
1225 </ul>
1226 </li>
1227 <br>
1228 <li>cube(aux_mem*, n_rows, n_cols, n_slices, copy_aux_mem = true, strict = true)
1229 <br>
1230 <br>
1231 <ul>
1232 Create a cube using data from writeable auxiliary memory.
1233 By default the cube allocates its own memory and copies data from the auxiliary memory (for safety).
1234 However, if <i>copy_aux_mem</i> is set to <i>false</i>,
1235 the cube will instead directly use the auxiliary memory (ie. no copying).
1236 This is faster, but can be dangerous unless you know what you're doing!
1237 <br>
1238 <br>
1239 The <i>strict</i> variable comes into effect only if <i>copy_aux_mem</i> is set to <i>false</i>
1240 (ie. the cube is directly using auxiliary memory).
1241 If <i>strict</i> is set to <i>true</i>,
1242 the cube will be bound to the auxiliary memory for its lifetime;
1243 the number of elements in the cube can't be changed (directly or indirectly).
1244 If <i>strict</i> is set to <i>false</i>, the cube will not be bound to the auxiliary memory for its lifetime,
1245 ie., the size of the cube can be changed.
1246 If the requested number of elements is different to the size of the auxiliary memory,
1247 new memory will be allocated and the auxiliary memory will no longer be used.
1248 </ul>
1249 </li>
1250 <br>
1251 <li>cube(const aux_mem*, n_rows, n_cols, n_slices)
1252 <br>
1253 <br>
1254 <ul>
1255 Create a cube by copying data from read-only auxiliary memory.
1256 </ul>
1257 </li>
1258 </ul>
1259 </li>
1260 <br>
1261 <br>
1262 <li>
1263 Examples:
1264 <ul>
1265 <pre>
1266 cube x(1,2,3);
1267 cube y = randu&lt;cube&gt;(4,5,6);
1268
1269 mat A = y.slice(1); // extract a slice from the cube
1270 // (each slice is a matrix)
1271
1272 mat B = randu&lt;mat&gt;(4,5);
1273 y.slice(2) = B; // set a slice in the cube
1274
1275 cube q = y + y; // cube addition
1276 cube r = y % y; // element-wise cube multiplication
1277
1278 cube::fixed&lt;4,5,6&gt; f;
1279 f.ones();
1280 </pre>
1281 </ul>
1282 </li>
1283 <br>
1284 <li>
1285 <b>Caveats</b>
1286 <br>
1287 <br>
1288 <ul>
1289 <li>
1290 The size of individual slices can't be changed.
1291 For example, the following <b>will not</b> work:
1292 <ul>
1293 <pre>
1294 cube c(5,6,7);
1295 c.slice(0) = randu&lt;mat&gt;(10,20); // wrong size
1296 </pre>
1297 </ul>
1298 </li>
1299 <li>
1300 For mathematical correctness, scalars are treated as 1x1x1 cubes during initialisation.
1301 As such, the code below <b>will not</b> generate a cube with every element equal to 123.0:
1302 <ul>
1303 <pre>
1304 cube c(5,6,7); c = 123.0;
1305 </pre>
1306 </ul>
1307 Use the following code instead:
1308 <ul>
1309 <pre>
1310 cube c(5,6,7); c.fill(123.0);
1311 </pre>
1312 </ul>
1313 <br>
1314 </ul>
1315 <li>
1316 See also:
1317 <ul>
1318 <li><a href="#attributes">cube attributes</a></li>
1319 <li><a href="#element_access">accessing elements</a></li>
1320 <li><a href="#operators">math &amp; relational operators</a></li>
1321 <li><a href="#subcube">subcube views and slices</a></li>
1322 <li><a href="#save_load_mat">saving &amp; loading cubes</a></li>
1323 <li><a href="#iterators_cube">STL-style element iterators</a></li>
1324 <li><a href="#Mat">Mat class</a></li>
1325 </ul>
1326 </li>
1327 <br>
1328 </ul>
1329 <hr class="greyline">
1330 <br>
1331
1332 <a name="field"></a>
1333 <b>field&lt;</b><i>object type</i><b>&gt;</b>
1334 <ul>
1335 <li>
1336 Class for one and two dimensional fields of arbitrary objects
1337 </li>
1338 <br>
1339 <li>
1340 Constructors (where <i>object type</i> is another class, eg. <i>std::string</i>, <i>mat</i>, <i>vec</i>, <i>rowvec</i>, etc):
1341 <ul>
1342 field&lt;<i>object type</i>&gt;(n_elem=0)
1343 <br>field&lt;<i>object type</i>&gt;(n_rows, n_cols)
1344 <br>field&lt;<i>object type</i>&gt;(field&lt;<i>object type</i>&gt;)
1345 </ul>
1346 </li>
1347 <br>
1348 <li>
1349 Examples:
1350 <ul>
1351 <pre>
1352 // create a field of strings
1353 field&lt;std::string&gt; S(3,2);
1354
1355 S(0,0) = "hello";
1356 S(1,0) = "there";
1357
1358 // string fields can be saved as plain text files
1359 S.save("string_field");
1360
1361 // create a vec field with 3 rows and 2 columns
1362 field&lt;vec&gt; F(3,2);
1363
1364 // access components of the field
1365 F(0,0) = vec(5);
1366 F(1,1) = randu&lt;vec&gt;(6);
1367 F(2,0).set_size(7);
1368
1369 // access element 1 of the vec stored at 2,0
1370 double x = F(2,0)(1);
1371
1372 // copy rows
1373 F.row(0) = F.row(2);
1374
1375 // extract a row of vecs from F
1376 field&lt;vec&gt; G = F.row(1);
1377
1378 // print the field to the standard output
1379 G.print("G =");
1380
1381 // save the field to a binary file
1382 G.save("vec_field");
1383 </pre>
1384 </ul>
1385 </li>
1386 <br>
1387 <li>See also:
1388 <ul>
1389 <li><a href="#attributes">field attributes</a></li>
1390 <li><a href="#subfield">subfield views</a></li>
1391 <li><a href="#save_load_field">saving/loading fields</a></li>
1392 <li><a href="http://cplusplus.com/reference/string/string/">string class in the standard C++ library</a> (cplusplus.com)</li>
1393 </ul>
1394 </li>
1395 <br>
1396 </ul>
1397 <hr class="greyline">
1398 <br>
1399
1400
1401 <a name="SpMat"></a><b>SpMat&lt;</b><i>type</i><b>&gt;</b>
1402 <br><b>sp_mat</b>
1403 <br><b>sp_cx_mat</b>
1404 <ul>
1405 <li>
1406 The root sparse matrix class is <b>SpMat&lt;</b><i>type</i><b>&gt;</b>, where <i>type</i> can be one of:
1407 <i>char</i>, <i>int</i>, <i>float</i>, <i>double</i>, <i>std::complex&lt;double&gt;</i>, etc.
1408 </li>
1409 <br>
1410 <li>
1411 For convenience the following typedefs have been defined:
1412 <ul>
1413 <table style="text-align: left;" border="0" cellpadding="2" cellspacing="2">
1414 <tbody>
1415 <tr>
1416 <td style="vertical-align: top;">
1417 sp_mat
1418 </td>
1419 <td style="vertical-align: top;">
1420 &nbsp;=&nbsp;
1421 </td>
1422 <td style="vertical-align: top;">
1423 SpMat&lt;double&gt;
1424 </td>
1425 </tr>
1426 <tr>
1427 <td style="vertical-align: top;">
1428 sp_fmat
1429 </td>
1430 <td style="vertical-align: top;">
1431 &nbsp;=&nbsp;
1432 </td>
1433 <td style="vertical-align: top;">
1434 SpMat&lt;float&gt;
1435 </td>
1436 </tr>
1437 <tr>
1438 <td style="vertical-align: top;">
1439 sp_cx_mat
1440 </td>
1441 <td style="vertical-align: top;">
1442 &nbsp;=&nbsp;
1443 </td>
1444 <td style="vertical-align: top;">
1445 SpMat&lt;<a href="#cx_float_double">cx_double</a>&gt;
1446 </td>
1447 </tr>
1448 <tr>
1449 <td style="vertical-align: top;">
1450 sp_cx_fmat
1451 </td>
1452 <td style="vertical-align: top;">
1453 &nbsp;=&nbsp;
1454 </td>
1455 <td style="vertical-align: top;">
1456 SpMat&lt;<a href="#cx_float_double">cx_float</a>&gt;
1457 </td>
1458 </tr>
1459 <tr>
1460 <td style="vertical-align: top;">
1461 sp_umat
1462 </td>
1463 <td style="vertical-align: top;">
1464 &nbsp;=&nbsp;
1465 </td>
1466 <td style="vertical-align: top;">
1467 SpMat&lt;<a href="#uword">uword</a>&gt;
1468 </td>
1469 </tr>
1470 <tr>
1471 <td style="vertical-align: top;">
1472 sp_imat
1473 </td>
1474 <td style="vertical-align: top;">
1475 &nbsp;=&nbsp;
1476 </td>
1477 <td style="vertical-align: top;">
1478 SpMat&lt;<a href="#uword">sword</a>&gt;
1479 </td>
1480 </tr>
1481 </tbody>
1482 </table>
1483 </ul>
1484 </li>
1485 <br>
1486 <li>
1487 In this documentation the <i>sp_mat</i> type is used for convenience;
1488 it is possible to use other types instead, eg. <i>sp_fmat</i>
1489 </li>
1490 <br>
1491 <a name="constructors_sp_mat"></a>
1492 <li>
1493 Constructors:
1494 <ul>
1495 <li>sp_mat()</li>
1496 <li>sp_mat(n_rows, n_cols)</li>
1497 <li>sp_mat(sp_mat)</li>
1498 <li>sp_mat(string)</li>
1499 <li>sp_cx_mat(sp_mat,sp_mat) &nbsp; (for constructing a complex matrix out of two real matrices)</li>
1500 </ul>
1501 <br>
1502 <li>
1503 <a name="batch_constructors_sp_mat"></a>
1504 Batch insertion constructors:
1505 <ul>
1506 <li>sp_mat(locations, values, n_rows, n_cols, sort_locations = true)</li>
1507 <li>sp_mat(locations, values, sort_locations = true)</li>
1508 </ul>
1509 <br>
1510 <li>
1511 Elements are stored in the <i>compressed sparse column</i> (CSC) format
1512 </li>
1513 <br>
1514 <li>
1515 All elements are treated as zero by default
1516 </li>
1517 <br>
1518 <li>
1519 This class behaves in a similar manner to the <a href="#Mat">Mat</a> class,
1520 however, member functions which set all elements to non-zero values (and hence do not make sense for sparse matrices) have been deliberately omitted;
1521 examples of omitted functions: <a href="#fill">.fill()</a>, <a href="#ones_member">.ones()</a>, +=&nbsp;scalar, etc.
1522 </li>
1523 <br>
1524
1525 <li>Batch insertion of values:
1526 <ul>
1527 <li>
1528 Using batch insertion constructors is generally much faster than consecutively inserting values using <a href="#element_access">element access operators</a>
1529 </li>
1530 <br>
1531 <li>
1532 <i>locations</i> is a dense matrix of type <i>umat</i>, with a size of <i>2</i>&nbsp;x&nbsp;<i>N</i>, where <i>N</i> is the number of values to be inserted.
1533 The row and column of the <i>i</i>-th element are specified as <i>locations(0,i)</i> and <i>locations(1,i)</i>, respectively.
1534 </li>
1535 <br>
1536 <li>
1537 <i>values</i> is a dense column vector containing the values to be inserted.
1538 It must have the same element type as the sparse matrix.
1539 The value in <i>values[i]</i> will be inserted at the location specified by the <i>i</i>-th column of the <i>locations</i> matrix.
1540 </li>
1541 <br>
1542 <li>
1543 The size of the constructed matrix is either manually specified via <i>n_rows</i> and <i>n_cols</i>,
1544 or automatically determined from the maximal locations in the <i>locations</i> matrix.
1545 </li>
1546 <br>
1547 <li>
1548 If <i>sort_locations</i> is set to <i>false</i>, the <i>locations</i> matrix is assumed to contain locations that are already sorted according to column-major ordering.
1549 </li>
1550 </ul>
1551 </li>
1552 <br>
1553
1554 <li>
1555 <b>Caveat:</b>
1556 support for sparse matrices in this version is <b>preliminary</b>;
1557 it is not yet fully optimised, and sparse matrix decompositions/factorisations are not yet implemented.
1558 The following subset of operations currently works with sparse matrices:
1559 <ul>
1560 <li>element access</li>
1561 <li>fundamental arithmetic operations (such as addition and multiplication)</li>
1562 <li>submatrix views</li>
1563 <li>saving and loading (in <i>arma_binary</i> format)</li>
1564 <li>
1565 <a href="#abs">abs()</a>,
1566 <a href="#accu">accu()</a>,
1567 <a href="#as_scalar">as_scalar()</a>,
1568 <a href="#dot">dot()</a>,
1569 <a href="#stats_fns">mean()</a>,
1570 <a href="#min_and_max">min()</a>,
1571 <a href="#min_and_max">max()</a>,
1572 <a href="#norm">norm()</a>,
1573 <a href="#print">print()</a>,
1574 <a href="#speye">speye()</a>,
1575 <a href="#sprandu_sprandn">sprandu()/sprandn()</a>,
1576 <a href="#misc_fns">square()</a>,
1577 <a href="#misc_fns">sqrt()</a>,
1578 <a href="#sum">sum()</a>,
1579 <a href="#trace">trace()</a>,
1580 <a href="#trans">trans()</a>,
1581 <a href="#stats_fns">var()</a>
1582 </li>
1583 </ul>
1584 </li>
1585 <br>
1586
1587 <li>
1588 Examples:
1589 <ul>
1590 <pre>
1591 sp_mat A(5,6);
1592 sp_mat B(6,5);
1593
1594 A(0,0) = 1;
1595 A(1,0) = 2;
1596
1597 B(0,0) = 3;
1598 B(0,1) = 4;
1599
1600 sp_mat C = 2*B;
1601
1602 sp_mat D = A*C;
1603
1604
1605 // batch insertion of two values at (5, 6) and (9, 9)
1606 umat locations;
1607 locations &lt;&lt; 5 &lt;&lt; 9 &lt;&lt; endr
1608 &lt;&lt; 6 &lt;&lt; 9 &lt;&lt; endr;
1609
1610 vec values;
1611 values &lt;&lt; 1.5 &lt;&lt; 3.2 &lt;&lt; endr;
1612
1613 sp_mat X(locations, values);
1614 </pre>
1615 </ul>
1616 </li>
1617 <br>
1618 <li>
1619 See also:
1620 <ul>
1621 <li><a href="#element_access">accessing elements</a></li>
1622 <li><a href="#print">printing matrices</a></li>
1623 <!--
1624 <li><a href="#SpCol">SpCol class</a> (TODO: add to documentation)</li>
1625 <li><a href="#SpRow">SpRow class</a> (TODO: add to documentation)</li>
1626 -->
1627 <li><a href="http://en.wikipedia.org/wiki/Sparse_matrix">Sparse Matrix in Wikipedia</a></li>
1628 <li><a href="#Mat">Mat class</a> (dense matrix)</li>
1629 </ul>
1630 </li>
1631 <br>
1632 </ul>
1633 <hr class="greyline">
1634 <hr class="greyline">
1635 <br>
1636 <br>
1637 <font size=+1><b>Member Functions &amp; Variables</b></font>
1638 <br>
1639 <br>
1640 <hr class="greyline">
1641 <br>
1642
1643 <a name="attributes"></a>
1644
1645 <b>attributes</b>
1646 <ul>
1647 <table style="text-align: left;" border="0" cellpadding="0" cellspacing="0">
1648 <tbody>
1649 <tr>
1650 <td>
1651 <b>.n_rows</b>
1652 </td>
1653 <td>&nbsp;&nbsp;</td>
1654 <td>
1655 (number of rows)
1656 </td>
1657 </tr>
1658 <tr>
1659 <td>
1660 <b>.n_cols</b>
1661 </td>
1662 <td>&nbsp;&nbsp;</td>
1663 <td>
1664 (number of columns)
1665 </td>
1666 </tr>
1667 <tr>
1668 <td>
1669 <b>.n_elem</b>
1670 </td>
1671 <td>&nbsp;&nbsp;</td>
1672 <td>
1673 (total number of elements)
1674 </td>
1675 </tr>
1676 <tr>
1677 <td>
1678 <b>.n_slices</b>
1679 </td>
1680 <td>&nbsp;&nbsp;</td>
1681 <td>
1682 (number of slices)
1683 </td>
1684 </tr>
1685 <tr>
1686 <td>
1687 <b>.n_nonzero</b>
1688 </td>
1689 <td>&nbsp;&nbsp;</td>
1690 <td>
1691 (number of nonzero elements)
1692 </td>
1693 </tr>
1694 </tbody>
1695 </table>
1696 </ul>
1697 <br>
1698 <ul>
1699 <li>
1700 Member variables which are read-only;
1701 to change the size, use
1702 <a href="#set_size">.set_size()</a>,
1703 <a href="#copy_size">.copy_size()</a>,
1704 <a href="#zeros_member">.zeros()</a>,
1705 <a href="#ones_member">.ones()</a>,
1706 or
1707 <a href="#reset">.reset()</a>
1708 </li>
1709 <br>
1710 <li><i>n_rows</i>, <i>n_cols</i> and <i>n_elem</i> are applicable to <i>Mat</i>, <i>SpMat</i>, <i>Col</i>, <i>Row</i>, <i>Cube</i> and <i>field</i> classes</li>
1711 <br>
1712 <li><i>n_slices</i> is applicable only to the <i>Cube</i> class</li>
1713 <br>
1714 <li><i>n_nonzero</i> is applicable only to the <i>SpMat</i> class</li>
1715 <br>
1716 <li>
1717 For the <i>Col</i> and <i>Row</i> classes, <i>n_elem</i> also indicates vector length</li>
1718 <br>
1719 <li>The variables are of type <a href="#uword">uword</a></li>
1720 <br>
1721 <li>
1722 Examples:
1723 <ul>
1724 <pre>
1725 mat X(4,5);
1726 cout &lt;&lt; "X has " &lt;&lt; X.n_cols &lt;&lt; " columns" &lt;&lt; endl;
1727 </pre>
1728 </ul>
1729 </li>
1730 <br>
1731 <li>
1732 See also:
1733 <ul>
1734 <li><a href="#set_size">.set_size()</a></li>
1735 <li><a href="#copy_size">.copy_size()</a></li>
1736 <li><a href="#zeros_member">.zeros()</a></li>
1737 <li><a href="#ones_member">.ones()</a></li>
1738 <li><a href="#reset">.reset()</a></li>
1739 </ul>
1740 </li>
1741 <br>
1742 </ul>
1743 <hr class="greyline"><br>
1744
1745 <a name="colptr"></a>
1746 <b>.colptr(col_number)</b>
1747 <ul>
1748 <li>
1749 Member function of <i>Mat</i>
1750 </li>
1751 <br>
1752 <li>
1753 Obtain a raw pointer to the memory used by the specified column
1754 </li>
1755 <br>
1756 <li>
1757 As soon as the size of the matrix is changed, the pointer is no longer valid
1758 </li>
1759 <br>
1760 <li>This function is not recommended for use unless you know what you're doing
1761 -- you may wish to use <a href="#submat">submatrix views</a> instead
1762 </li>
1763 <br>
1764 <li>
1765 Examples:
1766 <ul>
1767 <pre>
1768 mat A = randu&lt;mat&gt;(5,5);
1769
1770 double* mem = A.colptr(2);
1771 </pre>
1772 </ul>
1773 </li>
1774 <br>
1775 <li>
1776 See also:
1777 <ul>
1778 <li><a href="#memptr">.memptr()</a></li>
1779 <li><a href="#submat">submatrix views</a></li>
1780 <li><a href="#element_access">element access</a></li>
1781 <li><a href="#iterators_mat">iterators (matrices)</a></li>
1782 <li><a href="#adv_constructors_mat">advanced constructors (matrices)</a></li>
1783 </ul>
1784 </li>
1785 <br>
1786 </ul>
1787 <hr class="greyline"><br>
1788
1789 <a name="copy_size"></a>
1790 <b>.copy_size(A)</b>
1791 <ul>
1792 <li>
1793 Member function of <i>Mat</i>, <i>Col</i>, <i>Row</i>, <i>Cube</i> and <i>field</i>
1794 </li>
1795 <br>
1796 <li>
1797 Set the size to be the same as object <i>A</i>
1798 </li>
1799 <br>
1800 <li>
1801 Object <i>A</i> must be of the same root type as the object being modified
1802 (eg. you can't set the size of a matrix by providing a cube)
1803 </li>
1804 <br>
1805 <li>
1806 Examples:
1807 <ul>
1808 <pre>
1809 mat A = randu&lt;mat&gt;(5,6);
1810 mat B;
1811 B.copy_size(A);
1812
1813 cout &lt;&lt; B.n_rows &lt;&lt; endl;
1814 cout &lt;&lt; B.n_cols &lt;&lt; endl;
1815 </pre>
1816 </ul>
1817 </li>
1818 <br>
1819 <li>
1820 See also:
1821 <ul>
1822 <li><a href="#reset">.reset()</a></li>
1823 <li><a href="#set_size">.set_size()</a></li>
1824 <li><a href="#reshape_member">.reshape()</a></li>
1825 <li><a href="#resize_member">.resize()</a></li>
1826 <li><a href="#zeros_member">.zeros()</a></li>
1827 </ul>
1828 </li>
1829 </ul>
1830 <br>
1831 <hr class="greyline"><br>
1832
1833 <a name="diag"></a>
1834 <b>.diag(</b><i>k=0</i><b>)</b>
1835 <ul>
1836 <li>
1837 Member function of <i>Mat</i>
1838 </li>
1839 <br>
1840 <li>
1841 Read/write access to the <i>k</i>-th diagonal in a matrix
1842 </li>
1843 <br>
1844 <li>The argument <i>k</i> is optional -- by default the main diagonal is accessed (<i>k=0</i>)</li>
1845 <br>
1846 <li>For <i>k &gt; 0</i>, the <i>k</i>-th super-diagonal is accessed (top-right corner)</li>
1847 <br>
1848 <li>For <i>k &lt; 0</i>, the <i>k</i>-th sub-diagonal is accessed (bottom-left corner)</li>
1849 <br>
1850 <li>
1851 An extracted diagonal is interpreted as a column vector
1852 </li>
1853 <br>
1854 <li>
1855 Examples:
1856 <ul>
1857 <pre>
1858 mat X = randu&lt;mat&gt;(5,5);
1859
1860 vec a = X.diag();
1861 vec b = X.diag(1);
1862 vec c = X.diag(-2);
1863
1864 X.diag() = randu&lt;vec&gt;(5);
1865 X.diag() += 6;
1866 </pre>
1867 </ul>
1868 </li>
1869 <br>
1870 <li>
1871 See also:
1872 <ul>
1873 <li><a href="#eye_member">.eye()</a></li>
1874 <li><a href="#diagvec">diagvec()</a></li>
1875 <li><a href="#diagmat">diagmat()</a></li>
1876 <li><a href="#submat">submatrix views</a></li>
1877 <li><a href="#each_colrow">.each_col() &amp; .each_row()</a></li>
1878 <li><a href="#trace">trace()</a></li>
1879 </ul>
1880 </li>
1881 </ul>
1882 <br>
1883 <hr class="greyline"><br>
1884
1885 <a name="each_colrow"></a>
1886 <b>.each_col()</b>
1887 <br>
1888 <b>.each_row()</b>
1889 <br>
1890 <br>
1891 <b>.each_col(</b><i>vector_of_indices</i><b>)</b>
1892 <br>
1893 <b>.each_row(</b><i>vector_of_indices</i><b>)</b>
1894 <ul>
1895 <li>
1896 Member functions of <i>Mat</i>
1897 </li>
1898 <br>
1899 <li>
1900 Write access to each column or row of a matrix/submatrix,
1901 allowing a vector operation to be repeated on each column or row
1902 </li>
1903 <br>
1904 <li>
1905 The operation can be in-place vector addition, subtraction, element-wise multiplication, element-wise division, or simply vector copy
1906 </li>
1907 <br>
1908 <li>The argument <i>vector_of_indices</i> is optional -- by default all columns or rows are accessed</li>
1909 <br>
1910 <li>
1911 If the argument <i>vector_of_indices</i> is used, it must evaluate to be a vector of type <i><a href="#Col">uvec</a></i>;
1912 the vector contains a list of indices of the columns or rows to be accessed
1913 </li>
1914 <br>
1915 <li>
1916 These functions were added in version 3.4
1917 </li>
1918 <br>
1919 <li>
1920 Examples:
1921 <ul>
1922 <pre>
1923 mat X = ones&lt;mat&gt;(6,5);
1924 vec v = linspace&lt;vec&gt;(10,15,6);
1925
1926 // add v to each column in X
1927 X.each_col() += v;
1928
1929 // subtract v from columns 0 through to 3 in X
1930 X.cols(0,3).each_col() -= v;
1931
1932 uvec indices(2);
1933 indices(0) = 2;
1934 indices(1) = 4;
1935
1936 // copy v to columns 2 and 4 in X
1937 X.each_col(indices) = v;
1938 </pre>
1939 </ul>
1940 </li>
1941 <br>
1942 <li>
1943 See also:
1944 <ul>
1945 <li><a href="#diag">diagonal views</a></li>
1946 <li><a href="#submat">submatrix views</a></li>
1947 </ul>
1948 </li>
1949 </ul>
1950 <br>
1951 <hr class="greyline"><br>
1952
1953 <a name="element_access"></a>
1954 <b>element/object access via (), [] and .at()</b>
1955 <ul>
1956 <li>
1957 Provide access to individual elements or objects stored in a container object
1958 (ie., <i>Mat</i>, <i>Col</i>, <i>Row</i>, <i>Cube</i>, <i>field</i>)<br>
1959 <br>
1960 <ul>
1961 <table style="text-align: left; width: 100%;"
1962 border="0" cellpadding="2" cellspacing="2">
1963 <tbody>
1964 <tr>
1965 <td style="vertical-align: top;">
1966 <pre>(n)</pre>
1967 </td>
1968 <td style="vertical-align: top;">&nbsp;<br>
1969 </td>
1970 <td style="vertical-align: top;">
1971 For <i>vec</i> and <i>rowvec</i>, access the <i>n</i>-th element.
1972 For <i>mat</i>, <i>cube</i> and <i>field</i>, access the <i>n</i>-th element/object under the assumption of a flat layout,
1973 with column-major ordering of data (ie. column by column).
1974 A <i>std::logic_error</i> exception is thrown if the requested element is out of bounds.
1975 The bounds check can be <a href="#element_access_bounds_check_note">optionally disabled</a> at compile-time to get more speed.
1976 </td>
1977 </tr>
1978 <tr>
1979 <td>&nbsp;</td>
1980 <td>&nbsp;</td>
1981 <td>&nbsp;</td>
1982 </tr>
1983 <tr>
1984 <td style="vertical-align: top;">
1985 <pre>.at(n) and [n]</pre>
1986 </td>
1987 <td style="vertical-align: top;"><br>
1988 </td>
1989 <td style="vertical-align: top;">
1990 As for <i>(n)</i>, but without a bounds check.
1991 Not recommended for use unless your code has been thoroughly debugged.
1992 </td>
1993 </tr>
1994 <tr>
1995 <td>&nbsp;</td>
1996 <td>&nbsp;</td>
1997 <td>&nbsp;</td>
1998 </tr>
1999 <tr>
2000 <td style="vertical-align: top;">
2001 <pre>(i,j)</pre>
2002 </td>
2003 <td style="vertical-align: top;"><br>
2004 </td>
2005 <td style="vertical-align: top;">
2006 For <i>mat</i> and <i>field</i> classes, access the element/object stored at the <i>i</i>-th row and <i>j</i>-th column.
2007 A <i>std::logic_error</i> exception is thrown if the requested element is out of bounds.
2008 The bounds check can be <a href="#element_access_bounds_check_note">optionally disabled</a> at compile-time to get more speed.
2009 </td>
2010 </tr>
2011 <tr>
2012 <td>&nbsp;</td>
2013 <td>&nbsp;</td>
2014 <td>&nbsp;</td>
2015 </tr>
2016 <tr>
2017 <td style="vertical-align: top;">
2018 <pre>.at(i,j)</pre>
2019 </td>
2020 <td style="vertical-align: top;"><br>
2021 </td>
2022 <td style="vertical-align: top;">
2023 As for <i>(i,j)</i>, but without a bounds check.
2024 Not recommended for use unless your code has been thoroughly debugged.
2025 </td>
2026 <td style="vertical-align: top;"><br>
2027 </td>
2028 </tr>
2029 <tr>
2030 <td>&nbsp;</td>
2031 <td>&nbsp;</td>
2032 <td>&nbsp;</td>
2033 </tr>
2034 <tr>
2035 <td style="vertical-align: top;">
2036 <pre>(i,j,k)</pre>
2037 </td>
2038 <td style="vertical-align: top;"><br>
2039 </td>
2040 <td style="vertical-align: top;">
2041 Cube only: access the element stored at the <i>i</i>-th row, <i>j</i>-th column and <i>k</i>-th slice.
2042 A <i>std::logic_error</i> exception is thrown if the requested element is out of bounds.
2043 The bounds check can be <a href="#element_access_bounds_check_note">optionally disabled</a> at compile-time to get more speed.
2044 </td>
2045 </tr>
2046 <tr>
2047 <td>&nbsp;</td>
2048 <td>&nbsp;</td>
2049 <td>&nbsp;</td>
2050 </tr>
2051 <tr>
2052 <td style="vertical-align: top;">
2053 <pre>.at(i,j,k)</pre>
2054 </td>
2055 <td style="vertical-align: top;"><br>
2056 </td>
2057 <td style="vertical-align: top;">
2058 As for <i>(i,j,k)</i>, but without a bounds check.
2059 Not recommended for use unless your code has been thoroughly debugged.</td>
2060 </tr>
2061 </tbody>
2062 </table>
2063 </ul>
2064 </li>
2065 <br>
2066 <a name="element_access_bounds_check_note"></a>
2067 <li>
2068 The bounds checks used by the <i>(n)</i>, <i>(i,j)</i> and <i>(i,j,k)</i> access forms
2069 can be disabled by defining <a href="#config_hpp_arma_no_debug"><i>ARMA_NO_DEBUG</i></a> or <i>NDEBUG</i> macros
2070 before including the <i>armadillo</i> header file (eg. <i>#define ARMA_NO_DEBUG</i>).
2071 Disabling the bounds checks is not recommended until your code has been thoroughly debugged
2072 -- it's better to write correct code first, and then maximise its speed.
2073 </li>
2074 <br>
2075 <li>
2076 <b>Note</b>: for <a href="#SpMat">sparse matrices</a>, using element access operators to insert values via loops can be inefficient;
2077 you may wish to use <a href="#batch_constructors_sp_mat">batch insertion constructors</a> instead
2078 </li>
2079 <br>
2080 <li>
2081 Examples:
2082 <ul>
2083 <pre>
2084 mat A = randu&lt;mat&gt;(10,10);
2085 A(9,9) = 123.0;
2086 double x = A.at(9,9);
2087 double y = A[99];
2088
2089 vec p = randu&lt;vec&gt;(10,1);
2090 p(9) = 123.0;
2091 double z = p[9];
2092 </pre>
2093 </ul>
2094 </li>
2095 <br>
2096 <li>See also:
2097 <ul>
2098 <li><a href="#in_range">.in_range()</a></li>
2099 <li><a href="#element_initialisation">element initialisation</a></li>
2100 <li><a href="#submat">submatrix views</a></li>
2101 <li><a href="#memptr">.memptr()</a></li>
2102 <li><a href="#iterators_mat">iterators (matrices)</a></li>
2103 <li><a href="#iterators_cube">iterators (cubes)</a></li>
2104 <li><a href="#config_hpp">config.hpp</a></li>
2105 </ul>
2106 </li>
2107 <br>
2108 </ul>
2109 <hr class="greyline"><br>
2110
2111 <a name="element_initialisation"></a>
2112 <b>element initialisation</b>
2113 <ul>
2114 <li>
2115 Instances of <i>Mat</i>, <i>Col</i>, <i>Row</i> and <i>field</i> classes can be initialised via repeated use of the &lt;&lt; operator
2116 </li>
2117 <br>
2118 <li>
2119 Special element <i>endr</i> indicates "end of row" (conceptually similar to <i>std::endl</i>)
2120 </li>
2121 <br>
2122 <li>
2123 Setting elements via &lt;&lt; is a bit slower than directly <a href="#element_access">accessing</a> the elements,
2124 but code using &lt;&lt; is generally more readable as well as being easier to write
2125 </li>
2126 <br>
2127 <li>
2128 If you have a C++11 compiler, instances of <i>Mat</i>, <i>Col</i> and <i>Row</i> classes can be also initialised via initialiser lists;
2129 this requires support for the C++11 standard to be <a href="#config_hpp_arma_use_cxx11">explicitly enabled</a>
2130 </li>
2131 <br>
2132 <li>
2133 Examples:
2134 <ul>
2135 <pre>
2136 mat A;
2137
2138 A &lt;&lt; 1 &lt;&lt; 2 &lt;&lt; 3 &lt;&lt; endr
2139 &lt;&lt; 4 &lt;&lt; 5 &lt;&lt; 6 &lt;&lt; endr;
2140
2141 mat B = { 1, 2, 3, 4, 5, 6 }; // C++11 only
2142 B.reshape(2,3);
2143 </pre>
2144 </ul>
2145 </li>
2146 <br>
2147 <li>
2148 See also:
2149 <ul>
2150 <li><a href="#element_access">element access</a></li>
2151 <li><a href="#print">.print()</a></li>
2152 <li><a href="#save_load_mat">saving &amp; loading matrices</a></li>
2153 <li><a href="#adv_constructors_mat">advanced constructors (matrices)</a></li>
2154 </ul>
2155 </li>
2156 <br>
2157 </ul>
2158 <hr class="greyline"><br>
2159
2160 <a name="eval_member"></a>
2161 <b>.eval()</b>
2162 <br>
2163 <ul>
2164 <li>
2165 Member function of any matrix or vector expression
2166 </li>
2167 <br>
2168 <li>
2169 Explicitly forces the evaluation of a delayed expression and outputs a matrix
2170 </li>
2171 <br>
2172 <li>
2173 This function should be used sparingly and only in cases where it is absolutely necessary; indiscriminate use can cause slow downs
2174 </li>
2175 <br>
2176 <li>
2177 This function was added in version 3.2
2178 </li>
2179 <br>
2180 <li>
2181 Examples:
2182 <ul>
2183 <pre>
2184 cx_mat A( randu&lt;mat&gt;(4,4), randu&lt;mat&gt;(4,4) );
2185
2186 real(A).eval().save("A_real.dat", raw_ascii);
2187 imag(A).eval().save("A_imag.dat", raw_ascii);
2188 </pre>
2189 </ul>
2190 </li>
2191 <br>
2192 <li>See also:
2193 <ul>
2194 <li><a href="#Mat">Mat class</a></li>
2195 </ul>
2196 </li>
2197 <br>
2198 </ul>
2199 <hr class="greyline"><br>
2200
2201 <a name="eye_member"></a>
2202 <b>.eye()</b>
2203 <br>
2204 <b>.eye(n_rows, n_cols)</b>
2205 <ul>
2206 <li>
2207 Set the elements along the main diagonal to one and off-diagonal elements set to zero,
2208 optionally first resizing to specified dimensions
2209 </li>
2210 <br>
2211 <li>
2212 An identity matrix is generated when <i>n_rows</i> = <i>n_cols</i>
2213 </li>
2214 <br>
2215 <li>
2216 Examples:
2217 <ul>
2218 <pre>
2219 mat A(5,5);
2220 A.eye();
2221
2222 mat B;
2223 B.eye(5,5);
2224 </pre>
2225 </ul>
2226 </li>
2227 <br>
2228 <li>See also:
2229 <ul>
2230 <li><a href="#ones_member">.ones()</a></li>
2231 <li><a href="#diag">.diag()</a></li>
2232 <li><a href="#diagmat">diagmat()</a></li>
2233 <li><a href="#diagvec">diagvec()</a></li>
2234 <li><a href="#eye_standalone">eye()</a> (standalone function)</li>
2235 </ul>
2236 </li>
2237 <br>
2238 </ul>
2239 <hr class="greyline"><br>
2240
2241 <a name="fill"></a>
2242 <b>.fill(</b>value<b>)</b>
2243 <ul>
2244 <li>
2245 Member function of <i>Mat</i>, <i>Col</i>, <i>Row</i> and <i>Cube</i> classes.
2246 </li>
2247 <br>
2248 <li>Sets the elements to a specified value</li>
2249 <br>
2250 <li>the type of value must match the type of elements used by the container object (eg. for <i>mat</i> the type is double)
2251 </li>
2252 <br>
2253 <li>
2254 Examples:
2255 <ul>
2256 <pre>
2257 mat A(5,5);
2258 A.fill(123.0);
2259 </pre>
2260 </ul>
2261 </li>
2262 <br>
2263 <li>
2264 See also:
2265 <ul>
2266 <li><a href="#imbue">.imbue()</a></li>
2267 <li><a href="#ones_member">.ones()</a></li>
2268 <li><a href="#zeros_member">.zeros()</a></li>
2269 <li><a href="#randu_randn_member">.randu() &amp; .randn()</a></li>
2270 </ul>
2271 </li>
2272 <br>
2273 </ul>
2274 <hr class="greyline"><br>
2275
2276 <a name="i_member"></a>
2277 <b>.i(</b> <i>slow=false</i> <b>)</b>
2278 <ul>
2279 <li>
2280 Member function of any matrix expression
2281 </li>
2282 <br>
2283 <li>
2284 Provides an inverse of the matrix expression
2285 </li>
2286 <br>
2287 <li>the <i>slow</i> argument is optional</li>
2288 <br>
2289 <li>
2290 If the matrix expression is not square, a <i>std::logic_error</i> exception is thrown
2291 </li>
2292 <br>
2293 <li>
2294 If the matrix expression appears to be singular, the output matrix is reset and a <i>std::runtime_error</i> exception is thrown
2295 </li>
2296 <br>
2297 <li>
2298 For matrix sizes &le; 4x4, a fast inverse algorithm is used by default.
2299 In rare instances, the fast algorithm might be less precise than the standard algorithm.
2300 To force the use of the standard algorithm, set the <i>slow</i> argument to <i>true</i>
2301 </li>
2302 <br>
2303 <li>
2304 <b>NOTE:</b> in many cases it is more efficient/faster to use the <a href="#solve">solve()</a> function instead of performing a matrix inverse
2305 </li>
2306 <br>
2307 <li>
2308 This function was added in version 3.0
2309 </li>
2310 <br>
2311 <li>
2312 Examples:
2313 <ul>
2314 <pre>
2315 mat A = randu&lt;mat&gt;(4,4);
2316
2317 mat X = A.i();
2318 mat Y = (A+A).i();
2319
2320 mat B = randu&lt;mat&gt;(4,1);
2321 mat Z = A.i() * B; // automatically converted to Z=solve(A,B)
2322
2323 </pre>
2324 </ul>
2325 </li>
2326 <li>
2327 See also:
2328 <ul>
2329 <li><a href="#inv">inv()</a></li>
2330 <li><a href="#pinv">pinv()</a></li>
2331 <li><a href="#solve">solve()</a></li>
2332 </ul>
2333 </li>
2334 <br>
2335 </ul>
2336 <hr class="greyline"><br>
2337
2338 <a name="in_range"></a>
2339 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
2340 <tbody>
2341 <tr>
2342 <td style="vertical-align: top;"><b>.in_range(</b> i <b>)</b></td>
2343 <td style="vertical-align: top;"><br>
2344 </td>
2345 <td style="vertical-align: top;">(member of <i>Mat</i>, <i>Col</i>, <i>Row</i>, <i>Cube</i> and <i>field</i>)
2346 </td>
2347 </tr>
2348 <tr>
2349 <td style="vertical-align: top;"><b>.in_range( span(</b>start<b>,</b> end<b>) )</b></td>
2350 <td style="vertical-align: top;"><br>
2351 </td>
2352 <td style="vertical-align: top;">(member of <i>Mat</i>, <i>Col</i>, <i>Row</i>, <i>Cube</i> and <i>field</i>)
2353 </td>
2354 </tr>
2355 <tr>
2356 <td>
2357 &nbsp;
2358 </td>
2359 </tr>
2360 <tr>
2361 <td style="vertical-align: top;"><b>.in_range(</b> row<b>,</b> col <b>)</b></td>
2362 <td style="vertical-align: top;"><br>
2363 </td>
2364 <td style="vertical-align: top;">(member of <i>Mat</i>, <i>Col</i>, <i>Row</i> and <i>field</i>)
2365 </td>
2366 </tr>
2367 <tr>
2368 <td style="vertical-align: top;"><b>.in_range( <font size=-1>span(</b>start_row<b>,</b> end_row<b>), span(</b>start_col<b>,</b> end_col<b>)</font> )</b></td>
2369 <td style="vertical-align: top;"><br>
2370 </td>
2371 <td style="vertical-align: top;">(member of <i>Mat</i>, <i>Col</i>, <i>Row</i> and <i>field</i>)
2372 </td>
2373 </tr>
2374 <tr>
2375 <td>
2376 &nbsp;
2377 </td>
2378 </tr>
2379 <tr>
2380 <td style="vertical-align: top;"><b>.in_range(</b> row<b>,</b> col<b>,</b> slice <b>)</b></td>
2381 <td style="vertical-align: top;"><br>
2382 </td>
2383 <td style="vertical-align: top;">(member of <i>Cube</i>)
2384 </td>
2385 </tr>
2386 <tr>
2387 <td style="vertical-align: top;"><b>.in_range( <font size=-1>span(</b>start_row<b>,</b> end_row<b>), span(</b>start_col<b>,</b> end_col<b>), span(</b>start_slice<b>,</b> end_slice<b>)</font> )</b></td>
2388 <td style="vertical-align: top;"><br>
2389 </td>
2390 <td style="vertical-align: top;">(member of <i>Cube</i>)
2391 </td>
2392 </tr>
2393 </tbody>
2394 </table>
2395 <br>
2396 <ul>
2397 <li>Returns <i>true</i> if the given location or span is currently valid
2398 </li>
2399 <br>
2400 <li>Returns <i>false</i> if the object is empty, the location is out of bounds, or the span is out of bounds
2401 </li>
2402 <br>
2403 <li>
2404 Instances of <i>span(a,b)</i> can be replaced by:
2405 <ul>
2406 <li><i>span()</i> or <i>span::all</i>, to indicate the entire range</li>
2407 <li><i>span(a)</i>, to indicate a particular row, column or slice</li>
2408 </ul>
2409 </li>
2410 <br>
2411 <li>
2412 Examples:
2413 <ul>
2414 <pre>
2415 mat A = randu&lt;mat&gt;(4,5);
2416
2417 cout &lt;&lt; A.in_range(0,0) &lt;&lt; endl; // true
2418 cout &lt;&lt; A.in_range(3,4) &lt;&lt; endl; // true
2419 cout &lt;&lt; A.in_range(4,5) &lt;&lt; endl; // false
2420 </pre>
2421 </ul>
2422 </li>
2423 <br>
2424 <li>
2425 See also:
2426 <ul>
2427 <li><a href="#element_access">element access</a></li>
2428 <li><a href="#submat">submatrix views</a></li>
2429 <li><a href="#subcube">subcube views</a></li>
2430 <li><a href="#subfield">subfield views</a></li>
2431 <li><a href="#set_size">.set_size()</a></li>
2432 </ul>
2433 </li>
2434 <br>
2435 </ul>
2436 <hr class="greyline"><br>
2437
2438 <a name="is_empty"></a>
2439 <b>.is_empty()</b>
2440 <ul>
2441 <li>
2442 Member function of <i>Mat</i>, <i>Col</i>, <i>Row</i>, <i>Cube</i> and <i>field</i> classes
2443 </li>
2444 <br>
2445 <li>Returns true if the object has no elements
2446 </li>
2447 <br>
2448 <li>Returns false if the object has one or more elements
2449 </li>
2450 <br>
2451 <li>
2452 Examples:
2453 <ul>
2454 <pre>
2455 mat A = randu&lt;mat&gt;(5,5);
2456 cout &lt;&lt; A.is_empty() &lt;&lt; endl;
2457
2458 A.reset();
2459 cout &lt;&lt; A.is_empty() &lt;&lt; endl;
2460 </pre>
2461 </ul>
2462 </li>
2463 <br>
2464 <li>
2465 See also:
2466 <ul>
2467 <li><a href="#is_square">.is_square()</a></li>
2468 <li><a href="#is_vec">.is_vec()</a></li>
2469 <li><a href="#is_finite">.is_finite()</a></li>
2470 <li><a href="#reset">.reset()</a></li>
2471 </ul>
2472 </li>
2473 <br>
2474 </ul>
2475 <hr class="greyline"><br>
2476
2477 <a name="is_finite"></a>
2478 <b>.is_finite()</b>
2479 <ul>
2480 <li>
2481 Member function of <i>Mat</i>, <i>Col</i>, <i>Row</i> and <i>Cube</i> classes
2482 </li>
2483 <br>
2484 <li>Returns <i>true</i> if all elements of the object are finite
2485 </li>
2486 <br>
2487 <li>Returns <i>false</i> if at least one of the elements of the object is non-finite (&plusmn;infinity or NaN)
2488 </li>
2489 <br>
2490 <li>
2491 Examples:
2492 <ul>
2493 <pre>
2494 mat A = randu&lt;mat&gt;(5,5);
2495 mat B = randu&lt;mat&gt;(5,5);
2496
2497 B(1,1) = datum::nan;
2498
2499 cout &lt;&lt; A.is_finite() &lt;&lt; endl;
2500 cout &lt;&lt; B.is_finite() &lt;&lt; endl;
2501 </pre>
2502 </ul>
2503 </li>
2504 <br>
2505 <li>
2506 See also:
2507 <ul>
2508 <li><a href="#constants">datum::nan</a></li>
2509 <li><a href="#constants">datum::inf</a></li>
2510 <li><a href="#is_finite_standalone">is_finite()</a> (standalone function)</li>
2511 </ul>
2512 </li>
2513 <br>
2514 </ul>
2515 <hr class="greyline"><br>
2516
2517 <a name="is_square"></a>
2518 <b>.is_square()</b>
2519 <ul>
2520 <li>
2521 Member function of the <i>Mat</i> class
2522 </li>
2523 <br>
2524 <li>Returns <i>true</i> if the matrix is square, ie., number of rows is equal to the number of columns
2525 </li>
2526 <br>
2527 <li>Returns <i>false</i> if the matrix is not square
2528 </li>
2529 <br>
2530 <li>
2531 Examples:
2532 <ul>
2533 <pre>
2534 mat A = randu&lt;mat&gt;(5,5);
2535 mat B = randu&lt;mat&gt;(6,7);
2536
2537 cout &lt;&lt; A.is_square() &lt;&lt; endl;
2538 cout &lt;&lt; B.is_square() &lt;&lt; endl;
2539 </pre>
2540 </ul>
2541 </li>
2542 <br>
2543 <li>
2544 See also:
2545 <ul>
2546 <li><a href="#is_empty">.is_empty()</a></li>
2547 <li><a href="#is_vec">.is_vec()</a></li>
2548 <li><a href="#is_finite">.is_finite()</a></li>
2549 </ul>
2550 </li>
2551 </ul>
2552 <br>
2553 <hr class="greyline"><br>
2554
2555 <a name="is_vec"></a>
2556 <b>.is_vec()</b>
2557 <br><b>.is_colvec()</b>
2558 <br><b>.is_rowvec()</b>
2559 <ul>
2560 <li>
2561 Member functions of the <i>Mat</i> class
2562 </li>
2563 <br>
2564
2565 <li>.is_vec():
2566 <ul>
2567 <li>Returns <i>true</i> if the matrix can be interpreted as a vector (either column or row vector)
2568 </li>
2569 <li>Returns <i>false</i> if the matrix does not have exactly one column or one row
2570 </li>
2571 </ul>
2572 </li>
2573 <br>
2574
2575 <li>.is_colvec():
2576 <ul>
2577 <li>Returns <i>true</i> if the matrix can be interpreted as a column vector
2578 </li>
2579 <li>Returns <i>false</i> if the matrix does not have exactly one column
2580 </li>
2581 </ul>
2582 </li>
2583 <br>
2584
2585 <li>.is_rowvec():
2586 <ul>
2587 <li>Returns <i>true</i> if the matrix can be interpreted as a row vector
2588 </li>
2589 <li>Returns <i>false</i> if the matrix does not have exactly one row
2590 </li>
2591 </ul>
2592 </li>
2593 <br>
2594
2595 <li><b>Caveat:</b> do not assume that the vector has elements if these functions return <i>true</i> -- it is possible to have an empty vector (eg. 0x1)
2596 </li>
2597 <br>
2598 <li>
2599 Examples:
2600 <ul>
2601 <pre>
2602 mat A = randu&lt;mat&gt;(1,5);
2603 mat B = randu&lt;mat&gt;(5,1);
2604 mat C = randu&lt;mat&gt;(5,5);
2605
2606 cout &lt;&lt; A.is_vec() &lt;&lt; endl;
2607 cout &lt;&lt; B.is_vec() &lt;&lt; endl;
2608 cout &lt;&lt; C.is_vec() &lt;&lt; endl;
2609 </pre>
2610 </ul>
2611 </li>
2612 <br>
2613 <li>
2614 See also:
2615 <ul>
2616 <li><a href="#is_empty">.is_empty()</a></li>
2617 <li><a href="#is_square">.is_square()</a></li>
2618 <li><a href="#is_finite">.is_finite()</a></li>
2619 </ul>
2620 </li>
2621 </ul>
2622 <br>
2623 <hr class="greyline"><br>
2624
2625 <a name="imbue"></a>
2626 <b>.imbue(&nbsp;</b>functor<b>&nbsp;)</b>
2627 <br>
2628 <b>.imbue(&nbsp;</b>lambda function<b>&nbsp;)</b>&nbsp;&nbsp;&nbsp;<i>(C++11 only)</i>
2629 <br>
2630 <ul>
2631 <li>
2632 Imbue (fill) with values provided by a functor or lambda function
2633 </li>
2634 <br>
2635 <li>
2636 For matrices, filling is done column-by-column (ie. column 0 is filled, then column 1, ...)
2637 </li>
2638 <br>
2639 <li>
2640 For cubes, filling is done slice-by-slice; each slice is filled column-by-column
2641 </li>
2642 <br>
2643 <li>
2644 This function was added in version 3.800
2645 </li>
2646 <br>
2647 <li>
2648 Examples:
2649 <ul>
2650 <pre>
2651 // C++11 only example
2652 // need to include &lt;random&gt;
2653
2654 std::mt19937 engine; // Mersenne twister random number engine
2655
2656 std::uniform_real_distribution&lt;double&gt; distr(0.0, 1.0);
2657
2658 mat A(4,5);
2659
2660 A.imbue( [&amp;]() { return distr(engine); } );
2661 </pre>
2662 </ul>
2663 </li>
2664 <br>
2665 <li>
2666 See also:
2667 <ul>
2668 <li><a href="#fill">.fill()</a></li>
2669 <li><a href="#transform">.transform()</a></li>
2670 <li><a href="http://en.wikipedia.org/wiki/Function_object">function object</a> at Wikipedia</li>
2671 <li><a href="http://en.wikipedia.org/wiki/C%2B%2B11#Lambda_functions_and_expressions">C++11 lambda functions</a> at Wikipedia</li>
2672 <li><a href="http://www.cprogramming.com/c++11/c++11-lambda-closures.html">lambda function</a> at cprogramming.com</li>
2673 </ul>
2674 </li>
2675 <br>
2676 </ul>
2677 <hr class="greyline"><br>
2678
2679 <a name="insert"></a>
2680 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
2681 <tbody>
2682 <tr>
2683 <td style="vertical-align: top;">
2684 <b>.insert_rows(&nbsp;</b>row_number, X<b>&nbsp;)</b>
2685 <br>
2686 <b>.insert_rows(&nbsp;</b>row_number, number_of_rows, set_to_zero&nbsp;=&nbsp;true<b>&nbsp;)</b>
2687 </td>
2688 <td style="vertical-align: top;"><br></td>
2689 <td style="vertical-align: top;">(member functions of <i>Mat</i> and <i>Col</i>)
2690 </td>
2691 </tr>
2692 <tr>
2693 <td>&nbsp;</td>
2694 </tr>
2695 <tr>
2696 <td style="vertical-align: top;">
2697 <b>.insert_cols(&nbsp;</b>col_number, X<b>&nbsp;)</b>
2698 <br>
2699 <b>.insert_cols(&nbsp;</b>col_number, number_of_cols, set_to_zero&nbsp;=&nbsp;true<b>&nbsp;)</b>
2700 </td>
2701 <td style="vertical-align: top;"><br></td>
2702 <td style="vertical-align: top;">(member functions of <i>Mat</i> and <i>Row</i>)
2703 </td>
2704 </tr>
2705 <tr>
2706 <td>&nbsp;</td>
2707 </tr>
2708 <tr>
2709 <td style="vertical-align: top;">
2710 <b>.insert_slices(&nbsp;</b>slice_number, X<b>&nbsp;)</b>
2711 <br>
2712 <b>.insert_slices(&nbsp;</b>slice_number, number_of_slices, set_to_zero&nbsp;=&nbsp;true<b>&nbsp;)</b>
2713 </td>
2714 <td style="vertical-align: top;"><br></td>
2715 <td style="vertical-align: top;">(member functions of <i>Cube</i>)
2716 </td>
2717 </tr>
2718 </tbody>
2719 </table>
2720 <br>
2721 <ul>
2722 <li>
2723 Functions with the <i>X</i> argument: insert a copy of X at the specified row/column/slice
2724 <ul>
2725 <li>if inserting rows, X must have the same number of columns as the recipient object</li>
2726 <li>if inserting columns, X must have the same number of rows as the recipient object</li>
2727 <li>if inserting slices, X must have the same number of rows and columns as the recipient object (ie. all slices must have the same size)</li>
2728 </ul>
2729 </li>
2730 <br>
2731 <li>
2732 Functions with the <i>number_of_...</i> argument: expand the object by creating new rows/columns/slices.
2733 By default, the new rows/columns/slices are set to zero.
2734 If <i>set_to_zero</i> is <i>false</i>, the memory used by the new rows/columns/slices will not be initialised.
2735 </li>
2736 <br>
2737 <li>
2738 Examples:
2739 <ul>
2740 <pre>
2741 mat A = randu&lt;mat&gt;(5,10);
2742 mat B = ones&lt;mat&gt;(5,2);
2743
2744 // at column 2, insert a copy of B;
2745 // A will now have 12 columns
2746 A.insert_cols(2, B);
2747
2748 // at column 1, insert 5 zeroed columns;
2749 // B will now have 7 columns
2750 B.insert_cols(1, 5);
2751 </pre>
2752 </ul>
2753 </li>
2754 <br>
2755 <li>
2756 See also:
2757 <ul>
2758 <li><a href="#shed">shed rows/columns/slices</a></li>
2759 <li><a href="#join">join rows/columns/slices</a></li>
2760 <li><a href="#resize_member">.resize()</a></li>
2761 <li><a href="#submat">submatrix views</a></li>
2762 <li><a href="#subcube">subcube views</a></li>
2763 </ul>
2764 </li>
2765 <br>
2766 </ul>
2767 <hr class="greyline"><br>
2768
2769 <a name="iterators_mat"></a>
2770 <b>iterators (matrices &amp; vectors)</b>
2771 <ul>
2772 <li>
2773 STL-style iterators and associated member functions of the <i>Mat</i>, <i>Col</i> and <i>Row</i> classes
2774 </li>
2775 <br>
2776 <li>
2777 iterator types:
2778 <br>
2779 <br>
2780 <ul>
2781 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
2782 <tbody>
2783 <tr>
2784 <td style="vertical-align: top;">
2785 <b>mat::iterator</b>
2786 <br>
2787 <b>vec::iterator</b>
2788 <br>
2789 <b>rowvec::iterator</b>
2790 </td>
2791 <td style="vertical-align: top;">&nbsp;<br>
2792 </td>
2793 <td style="vertical-align: top;">
2794 random access iterators, for read/write access to elements
2795 (which are stored column by column)
2796 </td>
2797 </tr>
2798 <tr>
2799 <td style="vertical-align: top;">
2800 &nbsp;
2801 </td>
2802 <td style="vertical-align: top;">&nbsp;<br>
2803 </td>
2804 <td style="vertical-align: top;">
2805 &nbsp;
2806 </td>
2807 </tr>
2808 <tr>
2809 <td style="vertical-align: top;">
2810 <b>mat::const_iterator</b>
2811 <br>
2812 <b>vec::const_iterator</b>
2813 <br>
2814 <b>rowvec::const_iterator</b>
2815 </td>
2816 <td style="vertical-align: top;">&nbsp;<br>
2817 </td>
2818 <td style="vertical-align: top;">
2819 random access iterators, for read-only access to elements
2820 (which are stored column by column)
2821 </td>
2822 </tr>
2823 <tr>
2824 <td style="vertical-align: top;">
2825 &nbsp;
2826 </td>
2827 <td style="vertical-align: top;">&nbsp;<br>
2828 </td>
2829 <td style="vertical-align: top;">
2830 &nbsp;
2831 </td>
2832 </tr>
2833 <tr>
2834 <td style="vertical-align: top;">
2835 <b>mat::col_iterator</b>
2836 <br>
2837 <b>vec::col_iterator</b>
2838 <br>
2839 <b>rowvec::col_iterator</b>
2840 </td>
2841 <td style="vertical-align: top;">&nbsp;<br>
2842 </td>
2843 <td style="vertical-align: top;">
2844 random access iterators, for read/write access to the elements of a specific column
2845 </td>
2846 </tr>
2847 <tr>
2848 <td style="vertical-align: top;">
2849 &nbsp;
2850 </td>
2851 <td style="vertical-align: top;">&nbsp;<br>
2852 </td>
2853 <td style="vertical-align: top;">
2854 &nbsp;
2855 </td>
2856 </tr>
2857 <tr>
2858 <td style="vertical-align: top;">
2859 <b>mat::const_col_iterator</b>
2860 <br>
2861 <b>vec::const_col_iterator</b>
2862 <br>
2863 <b>rowvec::const_col_iterator</b>
2864 </td>
2865 <td style="vertical-align: top;">&nbsp;<br>
2866 </td>
2867 <td style="vertical-align: top;">
2868 random access iterators, for read-only access to the elements of a specific column
2869 </td>
2870 </tr>
2871 <tr>
2872 <td style="vertical-align: top;">
2873 &nbsp;
2874 </td>
2875 <td style="vertical-align: top;">&nbsp;<br>
2876 </td>
2877 <td style="vertical-align: top;">
2878 &nbsp;
2879 </td>
2880 </tr>
2881 <tr>
2882 <td style="vertical-align: top;">
2883 <b>mat::row_iterator</b>
2884 </td>
2885 <td style="vertical-align: top;">&nbsp;<br>
2886 </td>
2887 <td style="vertical-align: top;">
2888 rudimentary forward iterator, for read/write access to the elements of a specific row
2889 </td>
2890 </tr>
2891 <tr>
2892 <td style="vertical-align: top;">
2893 &nbsp;
2894 </td>
2895 <td style="vertical-align: top;">&nbsp;<br>
2896 </td>
2897 <td style="vertical-align: top;">
2898 &nbsp;
2899 </td>
2900 </tr>
2901 <tr>
2902 <td style="vertical-align: top;">
2903 <b>mat::const_row_iterator</b>
2904 </td>
2905 <td style="vertical-align: top;">&nbsp;<br>
2906 </td>
2907 <td style="vertical-align: top;">
2908 rudimentary forward iterator, for read-only access to the elements of a specific row
2909 </td>
2910 </tr>
2911 <tr>
2912 <td style="vertical-align: top;">
2913 &nbsp;
2914 </td>
2915 <td style="vertical-align: top;">&nbsp;<br>
2916 </td>
2917 <td style="vertical-align: top;">
2918 &nbsp;
2919 </td>
2920 </tr>
2921 <tr>
2922 <td style="vertical-align: top;">
2923 <b>vec::row_iterator</b>
2924 <br>
2925 <b>rowvec::row_iterator</b>
2926 </td>
2927 <td style="vertical-align: top;">&nbsp;<br>
2928 </td>
2929 <td style="vertical-align: top;">
2930 random access iterators, for read/write access to the elements of a specific row
2931 </td>
2932 </tr>
2933 <tr>
2934 <td style="vertical-align: top;">
2935 &nbsp;
2936 </td>
2937 <td style="vertical-align: top;">&nbsp;<br>
2938 </td>
2939 <td style="vertical-align: top;">
2940 &nbsp;
2941 </td>
2942 </tr>
2943 <tr>
2944 <td style="vertical-align: top;">
2945 <b>vec::const_row_iterator</b>
2946 <br>
2947 <b>rowvec::const_row_iterator</b>
2948 </td>
2949 <td style="vertical-align: top;">&nbsp;<br>
2950 </td>
2951 <td style="vertical-align: top;">
2952 random access iterators, for read-only access to the elements of a specific row
2953 </td>
2954 </tr>
2955 </tbody>
2956 </table>
2957 </ul>
2958 </li>
2959 <br>
2960 <br>
2961 <li>
2962 Member functions:
2963 <br>
2964 <br>
2965 <ul>
2966 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
2967 <tbody>
2968 <tr>
2969 <td style="vertical-align: top;">
2970 <b>.begin()</b>
2971 </td>
2972 <td style="vertical-align: top;">&nbsp;<br>
2973 </td>
2974 <td style="vertical-align: top;">
2975 iterator referring to the first element
2976 </td>
2977 </tr>
2978 <tr>
2979 <td style="vertical-align: top;">
2980 <b>.end()</b>
2981 </td>
2982 <td style="vertical-align: top;">&nbsp;<br>
2983 </td>
2984 <td style="vertical-align: top;">
2985 iterator referring to the <i>past-the-end</i> element
2986 </td>
2987 </tr>
2988 <tr>
2989 <td>
2990 &nbsp;
2991 </td>
2992 </tr>
2993 <tr>
2994 <td style="vertical-align: top;">
2995 <b>.begin_row(</b><i>row_number</i><b>)</b>
2996 </td>
2997 <td style="vertical-align: top;">&nbsp;<br>
2998 </td>
2999 <td style="vertical-align: top;">
3000 iterator referring to the first element of the specified row
3001 </td>
3002 </tr>
3003 <tr>
3004 <td style="vertical-align: top;">
3005 <b>.end_row(</b><i>row_number</i><b>)</b>
3006 </td>
3007 <td style="vertical-align: top;">&nbsp;<br>
3008 </td>
3009 <td style="vertical-align: top;">
3010 iterator referring to the <i>past-the-end</i> element of the specified row
3011 </td>
3012 </tr>
3013 <tr>
3014 <td>
3015 &nbsp;
3016 </td>
3017 </tr>
3018 <tr>
3019 <td style="vertical-align: top;">
3020 <b>.begin_col(</b><i>col_number</i><b>)</b>
3021 </td>
3022 <td style="vertical-align: top;">&nbsp;<br>
3023 </td>
3024 <td style="vertical-align: top;">
3025 iterator referring to the first element of the specified column
3026 </td>
3027 </tr>
3028 <tr>
3029 <td style="vertical-align: top;">
3030 <b>.end_col(</b><i>col_number</i><b>)</b>
3031 </td>
3032 <td style="vertical-align: top;">&nbsp;<br>
3033 </td>
3034 <td style="vertical-align: top;">
3035 iterator referring to the <i>past-the-end</i> element of the specified column
3036 </td>
3037 </tr>
3038 </tbody>
3039 </table>
3040 </ul>
3041 </li>
3042 <br>
3043 <br>
3044 <li>
3045 Examples:
3046 <ul>
3047 <pre>
3048 mat X = randu&lt;mat&gt;(5,5);
3049
3050
3051 mat::iterator a = X.begin();
3052 mat::iterator b = X.end();
3053
3054 for(mat::iterator i=a; i!=b; ++i)
3055 {
3056 cout &lt;&lt; *i &lt;&lt; endl;
3057 }
3058
3059
3060 mat::col_iterator c = X.begin_col(1); // start of column 1
3061 mat::col_iterator d = X.end_col(3); // end of column 3
3062
3063 for(mat::col_iterator i=c; i!=d; ++i)
3064 {
3065 cout &lt;&lt; *i &lt;&lt; endl;
3066 (*i) = 123.0;
3067 }
3068 </pre>
3069 </ul>
3070 </li>
3071 <br>
3072 <li>
3073 See also:
3074 <ul>
3075 <li><a href="#stl_container_fns">STL container functions</a></li>
3076 <li><a href="http://cplusplus.com/reference/std/iterator/">iterator at cplusplus.com</a></li>
3077 <li><a href="#element_access">element access</a></li>
3078 <li><a href="#memptr">.memptr()</a></li>
3079 <li><a href="#colptr">.colptr()</a></li>
3080 <li><a href="#submat">submatrix views</a></li>
3081 </ul>
3082 </li>
3083 <br>
3084 </ul>
3085 <hr class="greyline"><br>
3086
3087 <a name="iterators_cube"></a>
3088 <b>iterators (cubes)</b>
3089 <ul>
3090 <li>
3091 STL-style iterators and associated member functions of the <i>Cube</i> class
3092 </li>
3093 <br>
3094 <li>
3095 iterator types:
3096 <br>
3097 <br>
3098 <ul>
3099 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
3100 <tbody>
3101 <tr>
3102 <td style="vertical-align: top;">
3103 <b>cube::iterator</b>
3104 </td>
3105 <td style="vertical-align: top;">&nbsp;<br>
3106 </td>
3107 <td style="vertical-align: top;">
3108 random access iterator, for read/write access to elements;
3109 the elements are ordered slice by slice;
3110 the elements within each slice are ordered column by column
3111 </td>
3112 </tr>
3113 <tr>
3114 <td style="vertical-align: top;">
3115 &nbsp;
3116 </td>
3117 <td style="vertical-align: top;">&nbsp;<br>
3118 </td>
3119 <td style="vertical-align: top;">
3120 &nbsp;
3121 </td>
3122 </tr>
3123 <tr>
3124 <td style="vertical-align: top;">
3125 <b>cube::const_iterator</b>
3126 </td>
3127 <td style="vertical-align: top;">&nbsp;<br>
3128 </td>
3129 <td style="vertical-align: top;">
3130 random access iterators, for read-only access to elements
3131 </td>
3132 </tr>
3133 <tr>
3134 <td style="vertical-align: top;">
3135 &nbsp;
3136 </td>
3137 <td style="vertical-align: top;">&nbsp;<br>
3138 </td>
3139 <td style="vertical-align: top;">
3140 &nbsp;
3141 </td>
3142 </tr>
3143 <tr>
3144 <td style="vertical-align: top;">
3145 <b>cube::slice_iterator</b>
3146 </td>
3147 <td style="vertical-align: top;">&nbsp;<br>
3148 </td>
3149 <td style="vertical-align: top;">
3150 random access iterator, for read/write access to the elements of a particular slice;
3151 the elements are ordered column by column
3152 </td>
3153 </tr>
3154 <tr>
3155 <td style="vertical-align: top;">
3156 &nbsp;
3157 </td>
3158 <td style="vertical-align: top;">&nbsp;<br>
3159 </td>
3160 <td style="vertical-align: top;">
3161 &nbsp;
3162 </td>
3163 </tr>
3164 <tr>
3165 <td style="vertical-align: top;">
3166 <b>cube::const_slice_iterator</b>
3167 </td>
3168 <td style="vertical-align: top;">&nbsp;<br>
3169 </td>
3170 <td style="vertical-align: top;">
3171 random access iterators, for read-only access to the elements of a particular slice
3172 </td>
3173 </tr>
3174 </tbody>
3175 </table>
3176 </ul>
3177 </li>
3178 <br>
3179 <br>
3180 <li>
3181 Member functions:
3182 <br>
3183 <br>
3184 <ul>
3185 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
3186 <tbody>
3187 <tr>
3188 <td style="vertical-align: top;">
3189 <b>.begin()</b>
3190 </td>
3191 <td style="vertical-align: top;">&nbsp;<br>
3192 </td>
3193 <td style="vertical-align: top;">
3194 iterator referring to the first element
3195 </td>
3196 </tr>
3197 <tr>
3198 <td style="vertical-align: top;">
3199 <b>.end()</b>
3200 </td>
3201 <td style="vertical-align: top;">&nbsp;<br>
3202 </td>
3203 <td style="vertical-align: top;">
3204 iterator referring to the <i>past-the-end</i> element
3205 </td>
3206 </tr>
3207 <tr>
3208 <td>
3209 &nbsp;
3210 </td>
3211 </tr>
3212 <tr>
3213 <td style="vertical-align: top;">
3214 <b>.begin_slice(</b><i>slice_number</i><b>)</b>
3215 </td>
3216 <td style="vertical-align: top;">&nbsp;<br>
3217 </td>
3218 <td style="vertical-align: top;">
3219 iterator referring to the first element of the specified slice
3220 </td>
3221 </tr>
3222 <tr>
3223 <td style="vertical-align: top;">
3224 <b>.end_slice(</b><i>slice_number</i><b>)</b>
3225 </td>
3226 <td style="vertical-align: top;">&nbsp;<br>
3227 </td>
3228 <td style="vertical-align: top;">
3229 iterator referring to the <i>past-the-end</i> element of the specified slice
3230 </td>
3231 </tr>
3232 </tbody>
3233 </table>
3234 </ul>
3235 </li>
3236 <br>
3237 <br>
3238 <li>
3239 Examples:
3240 <ul>
3241 <pre>
3242 cube X = randu&lt;cube&gt;(2,3,4);
3243
3244
3245 cube::iterator a = X.begin();
3246 cube::iterator b = X.end();
3247
3248 for(cube::iterator i=a; i!=b; ++i)
3249 {
3250 cout &lt;&lt; *i &lt;&lt; endl;
3251 }
3252
3253
3254 cube::slice_iterator c = X.begin_slice(1); // start of slice 1
3255 cube::slice_iterator d = X.end_slice(2); // end of slice 2
3256
3257 for(cube::slice_iterator i=c; i!=d; ++i)
3258 {
3259 cout &lt;&lt; *i &lt;&lt; endl;
3260 (*i) = 123.0;
3261 }
3262 </pre>
3263 </ul>
3264 </li>
3265 <br>
3266 <li>
3267 See also:
3268 <ul>
3269 <li><a href="http://cplusplus.com/reference/std/iterator/">iterator at cplusplus.com</a></li>
3270 <li><a href="#element_access">element access</a></li>
3271 </ul>
3272 </li>
3273 <br>
3274 </ul>
3275 <hr class="greyline"><br>
3276
3277 <a name="memptr"></a>
3278 <b>.memptr()</b>
3279 <ul>
3280 <li>
3281 Member function of <i>Mat</i>, <i>Col</i>, <i>Row</i> and <i>Cube</i> classes
3282 </li>
3283 <br>
3284 <li>
3285 Obtain a raw pointer to the memory used for storing elements. Not recommended for use unless you know what you're doing!
3286 </li>
3287 <br>
3288 <li>
3289 The function can be used for interfacing with libraries such as <a href="http://www.fftw.org/">FFTW</a>
3290 </li>
3291 <br>
3292 <li>
3293 As soon as the size of the matrix/vector/cube is changed, the pointer is no longer valid
3294 </li>
3295 <br>
3296 <li>
3297 Data for matrices is stored in a column-by-column order
3298 </li>
3299 <br>
3300 <li>
3301 Data for cubes is stored in a slice-by-slice (matrix-by-matrix) order
3302 </li>
3303 <br>
3304 <li>
3305 Examples:
3306 <ul>
3307 <pre>
3308 mat A = randu&lt;mat&gt;(5,5);
3309 const mat B = randu&lt;mat&gt;(5,5);
3310
3311 double* A_mem = A.memptr();
3312 const double* B_mem = B.memptr();
3313 </pre>
3314 </ul>
3315 </li>
3316 <br>
3317 <li>
3318 See also:
3319 <ul>
3320 <li><a href="#colptr">.colptr()</a></li>
3321 <li><a href="#element_access">element_access</a></li>
3322 <li><a href="#iterators_mat">iterators (matrices)</a></li>
3323 <li><a href="#iterators_cube">iterators (cubes)</a></li>
3324 <li><a href="#adv_constructors_mat">advanced constructors (matrices)</a></li>
3325 <li><a href="#adv_constructors_cube">advanced constructors (cubes)</a></li>
3326 </ul>
3327 </li>
3328 <br>
3329 </ul>
3330 <hr class="greyline"><br>
3331
3332 <a name="min_and_max_member"></a>
3333 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
3334 <tbody>
3335 <tr>
3336 <td style="vertical-align: top;"><b>.min()</b></td>
3337 <td style="vertical-align: top;"><br>
3338 </td>
3339 <td style="vertical-align: top;">(member functions of <i>Mat</i>, <i>Col</i>, <i>Row</i>, <i>Cube</i>)
3340 </td>
3341 </tr>
3342 <tr>
3343 <td style="vertical-align: top;"><b>.max()</b></td>
3344 <td style="vertical-align: top;"><br>
3345 </td>
3346 <td style="vertical-align: top;">&nbsp;
3347 </td>
3348 </tr>
3349 <tr>
3350 <td style="vertical-align: top;">&nbsp;</td>
3351 <td style="vertical-align: top;"><br>
3352 </td>
3353 <td style="vertical-align: top;">&nbsp;
3354 </td>
3355 </tr>
3356 <tr>
3357 <td style="vertical-align: top;"><b>.min(</b>&nbsp;index_of_min_val&nbsp;<b>)</b></td>
3358 <td style="vertical-align: top;"><br>
3359 </td>
3360 <td style="vertical-align: top;">(member functions of <i>Mat</i>, <i>Col</i>, <i>Row</i>, <i>Cube</i>)
3361 </td>
3362 </tr>
3363 <tr>
3364 <td style="vertical-align: top;"><b>.max(</b>&nbsp;index_of_max_val&nbsp;<b>)</b></td>
3365 <td style="vertical-align: top;"><br>
3366 </td>
3367 <td style="vertical-align: top;">&nbsp;
3368 </td>
3369 </tr>
3370 <tr>
3371 <td style="vertical-align: top;">&nbsp;</td>
3372 <td style="vertical-align: top;"><br>
3373 </td>
3374 <td style="vertical-align: top;">&nbsp;
3375 </td>
3376 </tr>
3377 <tr>
3378 <td style="vertical-align: top;"><b>.min(</b>&nbsp;row_of_min_val<b>,</b> col_of_min_val&nbsp;<b>)</b></td>
3379 <td style="vertical-align: top;"><br>
3380 </td>
3381 <td style="vertical-align: top;">(member functions of <i>Mat</i>)
3382 </td>
3383 </tr>
3384 <tr>
3385 <td style="vertical-align: top;"><b>.max(</b>&nbsp;row_of_max_val<b>,</b> col_of_max_val&nbsp;<b>)</b></td>
3386 <td style="vertical-align: top;"><br>
3387 </td>
3388 <td style="vertical-align: top;">&nbsp;
3389 </td>
3390 </tr>
3391 <tr>
3392 <td style="vertical-align: top;">&nbsp;</td>
3393 <td style="vertical-align: top;"><br>
3394 </td>
3395 <td style="vertical-align: top;">&nbsp;
3396 </td>
3397 </tr>
3398 <tr>
3399 <td style="vertical-align: top;"><b>.min(</b>&nbsp;row_of_min_val<b>,</b> col_of_min_val<b>,</b> slice_of_min_val&nbsp;<b>)</b></td>
3400 <td style="vertical-align: top;"><br>
3401 </td>
3402 <td style="vertical-align: top;">(member functions of <i>Cube</i>)
3403 </td>
3404 </tr>
3405 <tr>
3406 <td style="vertical-align: top;"><b>.max(</b>&nbsp;row_of_max_val<b>,</b> col_of_max_val<b>,</b> slice_of_max_val&nbsp;<b>)</b></td>
3407 <td style="vertical-align: top;"><br>
3408 </td>
3409 <td style="vertical-align: top;">&nbsp;
3410 </td>
3411 </tr>
3412 </tbody>
3413 </table>
3414 <ul>
3415 <br>
3416 <li>
3417 Without arguments: return the extremum value of an object
3418 </li>
3419 <br>
3420 <li>
3421 With one or more arguments: return the extremum value of an object and store the location of the extremum value in the provided variable(s)
3422 </li>
3423 <br>
3424 <li>
3425 The provided variables must be of type <a href="#uword">uword</a>.
3426 </li>
3427 <br>
3428 <li>
3429 Examples:
3430 <ul>
3431 <pre>
3432 vec v = randu&lt;vec&gt;(10);
3433
3434 cout &lt;&lt; "min value is " &lt;&lt; v.min() &lt;&lt; endl;
3435
3436
3437 uword index;
3438 double min_val = v.min(index);
3439
3440 cout &lt;&lt; "index of min value is " &lt;&lt; index &lt;&lt; endl;
3441
3442
3443 mat A = randu&lt;mat&gt;(5,5);
3444
3445 uword row;
3446 uword col;
3447 double min_val2 = A.max(row,col);
3448
3449 cout &lt;&lt; "max value is at " &lt;&lt; row &lt;&lt; ',' &lt;&lt; col &lt;&lt; endl;
3450 </pre>
3451 </ul>
3452 </li>
3453 <br>
3454 <li>
3455 See also:
3456 <ul>
3457 <li><a href="#min_and_max">min() &amp; max()</a> (standalone functions)</li>
3458 <li><a href="#running_stat">running_stat</a></li>
3459 <li><a href="#running_stat_vec">running_stat_vec</a></li>
3460 </ul>
3461 </li>
3462 <br>
3463 </ul>
3464 <hr class="greyline"><br>
3465
3466 <a name="ones_member"></a>
3467 <b>.ones()</b>
3468 <br><b>.ones(n_elem)</b>
3469 <br><b>.ones(n_rows, n_cols)</b>
3470 <br><b>.ones(n_rows, n_cols, n_slices)</b>
3471 <ul>
3472 <li>
3473 Set the elements of an object to one, optionally first resizing to specified dimensions
3474 </li>
3475 <br>
3476 <li>
3477 <i>.ones()</i> and <i>.ones(n_elem)</i> are member functions of <i>Col</i> and <i>Row</i>
3478 </li>
3479 <br>
3480 <li>
3481 <i>.ones()</i> and <i>.ones(n_rows, n_cols)</i> are member functions of <i>Mat</i>
3482 </li>
3483 <br>
3484 <li>
3485 <i>.ones()</i> and <i>.ones(n_rows, n_cols, n_slices)</i> are member functions of <i>Cube</i>
3486 </li>
3487 <br>
3488 <li>
3489 Examples:
3490 <ul>
3491 <pre>
3492 mat A = randu&lt;mat&gt;(5,10);
3493 A.ones(); // sets all elements to one
3494 A.ones(10,20); // sets the size to 10 rows and 20 columns
3495 // followed by setting all elements to one
3496 </pre>
3497 </ul>
3498 </li>
3499 <br>
3500 <li>
3501 See also:
3502 <ul>
3503 <li><a href="#ones_standalone">ones()</a> (standalone function)</li>
3504 <li><a href="#eye_member">.eye()</a></li>
3505 <li><a href="#zeros_member">.zeros()</a></li>
3506 <li><a href="#fill">.fill()</a></li>
3507 <li><a href="#imbue">.imbue()</a></li>
3508 <li><a href="#randu_randn_member">.randu()</a></li>
3509 </ul>
3510 </li>
3511 <br>
3512 </ul>
3513 <hr class="greyline"><br>
3514
3515 <a name="operators"></a>
3516 <b>operators: &nbsp; + &nbsp; - &nbsp; * &nbsp; / &nbsp; % &nbsp; == &nbsp; != &nbsp; &lt;= &nbsp; &gt;= &nbsp; &lt; &nbsp; &gt;</b>
3517 <ul>
3518 <li>
3519 Overloaded operators for <i>mat</i>, <i>vec</i>, <i>rowvec</i> and <i>cube</i> classes
3520 </li>
3521 <br>
3522 <li>
3523 Meanings:
3524 <br>
3525 <br>
3526 <ul>
3527 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
3528 <tbody>
3529 <tr>
3530 <td style="vertical-align: top;"><b>+</b></td>
3531 <td style="vertical-align: top;">&nbsp;&nbsp;&nbsp;<br>
3532 </td>
3533 <td style="vertical-align: top;">Addition of two objects</td>
3534 </tr>
3535 <tr>
3536 <td style="vertical-align: top;"><b>-</b></td>
3537 <td style="vertical-align: top;"><br>
3538 </td>
3539 <td style="vertical-align: top;">Subtraction of one object from another or negation of an object</td>
3540 </tr>
3541 <tr>
3542 <td style="vertical-align: top;"><b>/</b></td>
3543 <td style="vertical-align: top;"><br>
3544 </td>
3545 <td style="vertical-align: top;">Element-wise division of an object by another object or a scalar</td>
3546 </tr>
3547 <tr>
3548 <td style="vertical-align: top;"><b>*</b></td>
3549 <td style="vertical-align: top;"><br>
3550 </td>
3551 <td style="vertical-align: top;">Matrix multiplication of two objects; not applicable to the <i>cube</i> class unless multiplying a cube by a scalar</td>
3552 </tr>
3553 <tr>
3554 <td style="vertical-align: top;"><b>%</b></td>
3555 <td style="vertical-align: top;"><br>
3556 </td>
3557 <td style="vertical-align: top;"><a name="schur_product"></a>Schur product: element-wise multiplication of two objects</td>
3558 </tr>
3559 <tr>
3560 <td style="vertical-align: top;"><b>==</b></td>
3561 <td style="vertical-align: top;"><br>
3562 </td>
3563 <td style="vertical-align: top;">Element-wise equality evaluation of two objects; generates a matrix of type <i>umat</i> with entries that indicate whether at a given position the two elements from the two objects are equal (1) or not equal (0)</td>
3564 </tr>
3565 <tr>
3566 <td style="vertical-align: top;"><b>!=</b></td>
3567 <td style="vertical-align: top;"><br>
3568 </td>
3569 <td style="vertical-align: top;">Element-wise non-equality evaluation of two objects</td>
3570 </tr>
3571 <tr>
3572 <td style="vertical-align: top;"><b>&gt;=</b></td>
3573 <td style="vertical-align: top;"><br>
3574 </td>
3575 <td style="vertical-align: top;">As for ==, but the check is for "greater than or equal to"</td>
3576 </tr>
3577 <tr>
3578 <td style="vertical-align: top;"><b>&lt;=</b></td>
3579 <td style="vertical-align: top;"><br>
3580 </td>
3581 <td style="vertical-align: top;">As for ==, but the check is for "less than or equal to"</td>
3582 </tr>
3583 <tr>
3584 <td style="vertical-align: top;"><b>&gt;</b></td>
3585 <td style="vertical-align: top;"><br>
3586 </td>
3587 <td style="vertical-align: top;">As for ==, but the check is for "greater than"</td>
3588 </tr>
3589 <tr>
3590 <td style="vertical-align: top;"><b>&lt;</b></td>
3591 <td style="vertical-align: top;"><br>
3592 </td>
3593 <td style="vertical-align: top;">As for ==, but the check is for "less than"</td>
3594 </tr>
3595 </tbody>
3596 </table>
3597 </ul>
3598 </li>
3599 <br>
3600 <li>
3601 A <i>std::logic_error</i> exception is thrown if incompatible object sizes are used
3602 </li>
3603 <br>
3604 <li>
3605 If the +, - and % operators are chained, Armadillo will try to avoid the generation of temporaries;
3606 no temporaries are generated if all given objects are of the same type and size
3607 </li>
3608 <br>
3609 <li>
3610 If the * operator is chained, Armadillo will try to find an efficient ordering of the matrix multiplications
3611 </li>
3612 <br>
3613 <li>
3614 <b>Caveat:</b> operators involving an equality comparison (ie., ==, !=, &gt;=, &lt;=)
3615 may not work as expected for floating point element types (ie., <i>float</i>, <i>double</i>)
3616 due to the necessarily limited precision of these types;
3617 in other words, these operators are (in general) not recommended for matrices of type <i>mat</i> or <i>fmat</i>
3618 </li>
3619 <br>
3620 <br>
3621 <li>
3622 Examples:
3623 <ul>
3624 <pre>
3625 mat A = randu&lt;mat&gt;(5,10);
3626 mat B = randu&lt;mat&gt;(5,10);
3627 mat C = randu&lt;mat&gt;(10,5);
3628
3629 mat P = A + B;
3630 mat Q = A - B;
3631 mat R = -B;
3632 mat S = A / 123.0;
3633 mat T = A % B;
3634 mat U = A * C;
3635
3636 // V is constructed without temporaries
3637 mat V = A + B + A + B;
3638
3639 imat AA = "1 2 3; 4 5 6; 7 8 9;";
3640 imat BB = "3 2 1; 6 5 4; 9 8 7;";
3641
3642 // compare elements
3643 umat ZZ = (AA >= BB);
3644 </pre>
3645 </ul>
3646 </li>
3647 <br>
3648 <li>
3649 See also:
3650 <ul>
3651 <li><a href="#accu">accu()</a></li>
3652 <li><a href="#as_scalar">as_scalar()</a></li>
3653 <li><a href="#find">find()</a></li>
3654 <li><a href="#transform">.transform()</a></li>
3655 </ul>
3656 </li>
3657 <br>
3658 </ul>
3659 <hr class="greyline"><br>
3660
3661 <a name="print"></a>
3662 <b>.print(header="")</b>
3663 <br><b>.print(stream, header="")</b>
3664 <ul>
3665 <li>
3666 Member function of <i>Mat</i>, <i>Col</i>, <i>Row</i>, <i>Cube</i> and <i>field</i>
3667 </li>
3668 <br>
3669 <li>
3670 The first form prints the contents of an object to the <i>std::cout</i> stream, with an optional header line
3671 </li>
3672 <br>
3673 <li>
3674 The second form prints to a user specified stream
3675 </li>
3676 <br>
3677 <li>
3678 It's also possible to print objects using the &lt;&lt; stream operator
3679 </li>
3680 <br>
3681 <li>
3682 Elements of a field can only be printed if there is an associated <i>operator&lt;&lt;</i> function defined
3683 </li>
3684 <br>
3685 <li>
3686 Examples:
3687 <ul>
3688 <pre>
3689 mat A = randu&lt;mat&gt;(5,5);
3690 mat B = randu&lt;mat&gt;(6,6);
3691
3692 A.print();
3693
3694 // print a transposed version of A
3695 A.t().print();
3696
3697 // "B:" is the optional header line
3698 B.print("B:");
3699
3700 cout &lt;&lt; A &lt;&lt; endl;
3701 cout &lt;&lt; "B:" &lt;&lt; endl &lt;&lt; B &lt;&lt; endl;
3702 </pre>
3703 </ul>
3704 </li>
3705 <br>
3706 <li>
3707 See also:
3708 <ul>
3709 <li><a href="#raw_print">.raw_print()</a></li>
3710 <li><a href="#save_load_mat">saving &amp; loading matrices</a></li>
3711 <li><a href="#element_initialisation">initialising elements</a></li>
3712 <li><a href="#logging">logging of errors and warnings</a></li>
3713 </ul>
3714 </li>
3715 <br>
3716 </ul>
3717 <hr class="greyline"><br>
3718
3719 <a name="raw_print"></a>
3720 <b>.raw_print(header="")</b>
3721 <br><b>.raw_print(stream, header="")</b>
3722 <ul>
3723 <li>
3724 Member function of <i>Mat</i>, <i>Col</i>, <i>Row</i> and <i>Cube</i>
3725 </li>
3726 <br>
3727 <li>
3728 Similar to the <a href="#print">.print()</a> member function,
3729 with the difference being that no formatting of the output is done -- ie. the user can set the stream's parameters such as precision, cell width, etc.
3730 </li>
3731 <br>
3732 <li>
3733 If the cell width is set to zero, a space is printed between the elements
3734 </li>
3735 <br>
3736 <li>
3737 Examples:
3738 <ul>
3739 <pre>
3740 mat A = randu&lt;mat&gt;(5,5);
3741
3742 cout.precision(11);
3743 cout.setf(ios::fixed);
3744
3745 A.raw_print(cout, "A =");
3746 </pre>
3747 </ul>
3748 </li>
3749 </ul>
3750 <br>
3751 <hr class="greyline"><br>
3752
3753 <a name="randu_randn_member"></a>
3754 <b>.randu()</b>
3755 <br><b>.randu(n_elem)</b>
3756 <br><b>.randu(n_rows, n_cols)</b>
3757 <br><b>.randu(n_rows, n_cols, n_slices)</b>
3758 <br>
3759 <br>
3760 <b>.randn()</b>
3761 <br><b>.randn(n_elem)</b>
3762 <br><b>.randn(n_rows, n_cols)</b>
3763 <br><b>.randn(n_rows, n_cols, n_slices)</b>
3764 <ul>
3765 <li>
3766 Fill an object with random values, optionally first resizing to specified dimensions
3767 </li>
3768 <br>
3769 <li><i>.randu()</i> uses a uniform distribution in the [0,1] interval
3770 </li>
3771 <br>
3772 <li><i>.randn()</i> uses a normal/Gaussian distribution with zero mean and unit variance
3773 </li>
3774 <br>
3775 <li>
3776 To change the seed, use the <a href="http://cplusplus.com/reference/clibrary/cstdlib/srand/">std::srand()</a> function
3777 </li>
3778 <br>
3779 <li>
3780 Examples:
3781 <ul>
3782 <pre>
3783 mat A(4,5);
3784 A.randu();
3785
3786 mat B;
3787 B.randu(6,7);
3788 </pre>
3789 </ul>
3790 </li>
3791 <br>
3792 <li>
3793 See also:
3794 <ul>
3795 <li><a href="#randu_randn_standalone">randu() &amp; randn()</a> (standalone functions)</li>
3796 <li><a href="#fill">.fill()</a></li>
3797 <li><a href="#imbue">.imbue()</a></li>
3798 <li><a href="#ones_member">.ones()</a></li>
3799 <li><a href="#zeros_member">.zeros()</a></li>
3800 <li><a href="http://cplusplus.com/reference/clibrary/cstdlib/srand/">std::srand()</a></li>
3801 </ul>
3802 </li>
3803 <br>
3804 </ul>
3805 <hr class="greyline"><br>
3806
3807 <a name="reset"></a>
3808 <b>
3809 .reset()
3810 </b>
3811 <ul>
3812 <li>
3813 Member function of <i>Mat</i>, <i>Col</i>, <i>Row</i>, <i>Cube</i> and <i>field</i>
3814 </li>
3815 <br>
3816 <li>
3817 Causes an object to have no elements
3818 </li>
3819 <br>
3820 <li>
3821 Examples:
3822 <ul>
3823 <pre>
3824 mat A = randu&lt;mat&gt;(5, 5);
3825 A.reset();
3826 </pre>
3827 </ul>
3828 </li>
3829 <br>
3830 <li>See also:
3831 <ul>
3832 <li><a href="#set_size">.set_size()</a></li>
3833 <li><a href="#is_empty">.is_empty()</a></li>
3834 <li><a href="#zeros_member">.zeros()</a></li>
3835 </ul>
3836 </li>
3837 </ul>
3838 <br>
3839 <hr class="greyline"><br>
3840
3841 <a name="reshape_member"></a>
3842 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
3843 <tbody>
3844 <tr>
3845 <td style="vertical-align: top;"><b>.reshape(n_rows, n_cols, dim=0)</b></td>
3846 <td style="vertical-align: top;"><br>
3847 </td>
3848 <td style="vertical-align: top;">(member function of <i>Mat</i>, <i>Col</i>, <i>Row</i>)
3849 </td>
3850 </tr>
3851 <tr>
3852 <td style="vertical-align: top;"><b>.reshape(n_rows, n_cols, n_slices, dim=0)</b></td>
3853 <td style="vertical-align: top;"><br>
3854 </td>
3855 <td style="vertical-align: top;">(member function of <i>Cube</i>)
3856 </td>
3857 </tr>
3858 </tbody>
3859 </table>
3860 <br>
3861 <ul>
3862 <li>
3863 Recreate the object according to given size specifications,
3864 with the elements taken from the previous version of the object,
3865 either column-wise (dim=0) or row-wise (dim=1);
3866 the elements in the generated object are placed column-wise (ie. the first column is filled up before filling the second column)
3867 </li>
3868 <br>
3869 <li>
3870 The layout of the elements in the recreated object will be different to the layout in the previous version of the object
3871 </li>
3872 <br>
3873 <li>
3874 This function can be used to vectorise a matrix (ie. concatenate all the columns or rows)
3875 </li>
3876 <br>
3877 <li>
3878 The new total number of elements (according to the specified size) doesn't have to be the same as the previous total number of elements in the object
3879 </li>
3880 <br>
3881 <li>
3882 If the total number of elements in the previous version of the object is less than the specified size,
3883 the extra elements in the recreated object are set to zero
3884 </li>
3885 <br>
3886 <li>
3887 If the total number of elements in the previous version of the object is greater than the specified size,
3888 only a subset of the elements is taken
3889 </li>
3890 <br>
3891 <li>
3892 <b>Caveat:</b>
3893 .reshape() is slower than <a href="#set_size">.set_size()</a>, which doesn't preserve data
3894 </li>
3895 <br>
3896 <li>
3897 <b>Caveat:</b>
3898 if you wish to grow/shrink the object while preserving the elements <b>as well as</b> the layout of the elements,
3899 use <a href="#resize_member">.resize()</a> instead
3900 </li>
3901 <br>
3902 <li>
3903 Examples:
3904 <ul>
3905 <pre>
3906 mat A = randu&lt;mat&gt;(4,5);
3907 A.reshape(5,4);
3908
3909 // vectorise A into a column vector:
3910 A.reshape(A.n_elem, 1);
3911 </pre>
3912 </ul>
3913 </li>
3914 <br>
3915 <li>See also:
3916 <ul>
3917 <li><a href="#resize_member">.resize()</a></li>
3918 <li><a href="#set_size">.set_size()</a></li>
3919 <li><a href="#copy_size">.copy_size()</a></li>
3920 <li><a href="#zeros_member">.zeros()</a></li>
3921 <li><a href="#reset">.reset()</a></li>
3922 <li><a href="#reshape">reshape()</a> (standalone function)</li>
3923 </ul>
3924 </li>
3925 </ul>
3926 <br>
3927 <hr class="greyline"><br>
3928
3929 <a name="resize_member"></a>
3930 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
3931 <tbody>
3932 <tr>
3933 <td style="vertical-align: top;"><b>.resize(n_elem)</b></td>
3934 <td style="vertical-align: top;"><br>
3935 </td>
3936 <td style="vertical-align: top;">(member function of <i>Col</i>, <i>Row</i>)
3937 </td>
3938 </tr>
3939 <tr>
3940 <td style="vertical-align: top;"><b>.resize(n_rows, n_cols)</b></td>
3941 <td style="vertical-align: top;"><br>
3942 </td>
3943 <td style="vertical-align: top;">(member function of <i>Mat</i>)
3944 </td>
3945 </tr>
3946 <tr>
3947 <td style="vertical-align: top;"><b>.resize(n_rows, n_cols, n_slices)</b></td>
3948 <td style="vertical-align: top;"><br>
3949 </td>
3950 <td style="vertical-align: top;">(member function of <i>Cube</i>)
3951 </td>
3952 </tr>
3953 </tbody>
3954 </table>
3955 <br>
3956 <ul>
3957 <li>
3958 Recreate the object according to given size specifications, while preserving the elements as well as the layout of the elements
3959 </li>
3960 <br>
3961 <li>
3962 Can be used for growing or shrinking an object (ie. adding/removing rows, and/or columns, and/or slices)
3963 </li>
3964 <br>
3965 <li>
3966 <b>Caveat:</b>
3967 .resize() is slower than <a href="#set_size">.set_size()</a>, which doesn't preserve data
3968 </li>
3969 <br>
3970 <li>
3971 Examples:
3972 <ul>
3973 <pre>
3974 mat A = randu&lt;mat&gt;(4,5);
3975 A.resize(7,6);
3976 </pre>
3977 </ul>
3978 </li>
3979 <br>
3980 <li>
3981 This function was added in version 2.4
3982 </li>
3983 <br>
3984 <li>See also:
3985 <ul>
3986 <li><a href="#reshape_member">.reshape()</a></li>
3987 <li><a href="#set_size">.set_size()</a></li>
3988 <li><a href="#copy_size">.copy_size()</a></li>
3989 <li><a href="#zeros_member">.zeros()</a></li>
3990 <li><a href="#reset">.reset()</a></li>
3991 <li><a href="#insert">insert rows/cols/slices</a></li>
3992 <li><a href="#shed">shed rows/cols/slices</a></li>
3993 <li><a href="#resize">resize()</a> (standalone function)</li>
3994 </ul>
3995 </li>
3996 </ul>
3997 <br>
3998 <hr class="greyline"><br>
3999
4000 <a name="save_load_mat"></a>
4001 <b>
4002 .save(name, file_type = arma_binary)
4003 <br>
4004 .save(stream, file_type = arma_binary)
4005 <br>
4006 <br>
4007 .load(name, file_type = auto_detect)
4008 <br>
4009 .load(stream, file_type = auto_detect)
4010 <br>
4011 <br>
4012 .quiet_save(name, file_type = arma_binary)
4013 <br>
4014 .quiet_save(stream, file_type = arma_binary)
4015 <br>
4016 <br>
4017 .quiet_load(name, file_type = auto_detect)
4018 <br>
4019 .quiet_load(stream, file_type = auto_detect)
4020 </b>
4021 <ul>
4022 <li>Member functions of <i>Mat</i>, <i>Col</i>, <i>Row</i> and <i>Cube</i> classes</li>
4023 <br>
4024 <li>Store/retrieve data in files or streams</li>
4025 <br>
4026 <li>On success, <i>save()</i>, <i>load()</i>, <i>quiet_save()</i>, and <i>quite_load()</i> will return a <i>bool</i> set to <i>true</i></li>
4027 <br>
4028 <li><i>save()</i> and <i>quiet_save()</i> will return a <i>bool</i> set to <i>false</i> if the saving process fails</li>
4029 <br>
4030 <li>
4031 <i>load()</i> and <i>quiet_load()</i> will return a <i>bool</i> set to <i>false</i> if the loading process fails;
4032 additionally, the object will be reset so it has no elements
4033 </li>
4034 <br>
4035 <li><i>load()</i> and <i>save()</i> will print warning messages if any problems are encountered</li>
4036 <br>
4037 <li><i>quiet_load()</i> and <i>quiet_save()</i> do not print any error messages</li>
4038 <br>
4039 <li>
4040 The following file formats are supported:
4041 <br>
4042 <br>
4043 <ul>
4044 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
4045 <tbody>
4046 <tr>
4047 <td style="vertical-align: top;"><b>auto_detect</b></td>
4048 <td style="vertical-align: top;"><br>
4049 </td>
4050 <td style="vertical-align: top;">
4051 for <i>load()</i> and <i>quiet_load()</i>:
4052 try to automatically detect the file type as one of the formats described below.
4053 This is the default operation.
4054 <br>
4055 <br>
4056 </td>
4057 </tr>
4058 <tr>
4059 <td style="vertical-align: top;"><b>raw_ascii</b></td>
4060 <td style="vertical-align: top;"><br>
4061 </td>
4062 <td style="vertical-align: top;">
4063 Numerical data stored in raw ASCII format, without a header.
4064 The numbers are separated by whitespace.
4065 The number of columns must be the same in each row.
4066 Cubes are loaded as one slice.
4067 Data which was saved in Matlab/Octave using the <i>-ascii</i> option can be read in Armadillo, except for complex numbers.
4068 Complex numbers are stored in standard C++ notation, which is a tuple surrounded by brackets: eg. (1.23,4.56) indicates 1.24&nbsp;+&nbsp;4.56i.
4069 <br>
4070 <br>
4071 </td>
4072 </tr>
4073 <tr>
4074 <td style="vertical-align: top;"><b>raw_binary</b></td>
4075 <td style="vertical-align: top;"><br>
4076 </td>
4077 <td style="vertical-align: top;">
4078 Numerical data stored in machine dependent raw binary format, without a header.
4079 Matrices are loaded to have one column,
4080 while cubes are loaded to have one slice with one column.
4081 The <a href="#reshape_member">.reshape()</a> function can be used to alter the size of the loaded matrix/cube without losing data.
4082 <br>
4083 <br>
4084 </td>
4085 </tr>
4086 <tr>
4087 <td style="vertical-align: top;"><b>arma_ascii</b></td>
4088 <td style="vertical-align: top;"><br>
4089 </td>
4090 <td style="vertical-align: top;">
4091 Numerical data stored in human readable text format, with a simple header to speed up loading.
4092 The header indicates the type of matrix as well as the number of rows and columns.
4093 For cubes, the header additionally specifies the number of slices.
4094 <br>
4095 <br>
4096 </td>
4097 </tr>
4098 <tr>
4099 <td style="vertical-align: top;"><b>arma_binary</b></td>
4100 <td style="vertical-align: top;"><br>
4101 </td>
4102 <td style="vertical-align: top;">
4103 Numerical data stored in machine dependent binary format, with a simple header to speed up loading.
4104 The header indicates the type of matrix as well as the number of rows and columns.
4105 For cubes, the header additionally specifies the number of slices.
4106 <br>
4107 <br>
4108 </td>
4109 </tr>
4110 <tr>
4111 <td style="vertical-align: top;"><b>csv_ascii</b></td>
4112 <td style="vertical-align: top;"><br>
4113 </td>
4114 <td style="vertical-align: top;">
4115 Numerical data stored in comma separated value (CSV) text format, without a header.
4116 Applicable to <i>Mat</i> only.
4117 <br>
4118 <br>
4119 </td>
4120 </tr>
4121 <tr>
4122 <td style="vertical-align: top;"><b>hdf5_binary</b></td>
4123 <td style="vertical-align: top;"><br>
4124 </td>
4125 <td style="vertical-align: top;">
4126 Numerical data stored in portable HDF5 binary format.
4127 <br>
4128 <b>Caveat</b>:
4129 support for HDF5 must be enabled within Armadillo's <a href="#config_hpp">configuration</a>;
4130 the <i>hdf5.h</i> header file must be available on your system and you will need to link with the hdf5 library (eg. -lhdf5).
4131 Support for saving &amp; loading of <i>Cube</i> objects was added in version 3.830.
4132 <br>
4133 <br>
4134 </td>
4135 </tr>
4136 <tr>
4137 <td style="vertical-align: top;"><b>pgm_binary</b></td>
4138 <td style="vertical-align: top;"><br>
4139 </td>
4140 <td style="vertical-align: top;">
4141 Image data stored in Portable Gray Map (PGM) format.
4142 Applicable to <i>Mat</i> only.
4143 Saving <i>int</i>, <i>float</i> or <i>double</i> matrices is a lossy operation, as each element is copied and converted to an 8 bit representation.
4144 As such the matrix should have values in the [0,255] interval, otherwise the resulting image may not display correctly.
4145 <br>
4146 <br>
4147 </td>
4148 </tr>
4149 <tr>
4150 <td style="vertical-align: top;"><b>ppm_binary</b></td>
4151 <td style="vertical-align: top;"><br>
4152 </td>
4153 <td style="vertical-align: top;">
4154 Image data stored in Portable Pixel Map (PPM) format.
4155 Applicable to <i>Cube</i> only.
4156 Saving <i>int</i>, <i>float</i> or <i>double</i> matrices is a lossy operation, as each element is copied and converted to an 8 bit representation.
4157 As such the cube/field should have values in the [0,255] interval, otherwise the resulting image may not display correctly.
4158 </td>
4159 </tr>
4160 </tbody>
4161 </table>
4162 </ul>
4163 </li>
4164 <br>
4165 <br>
4166 <li>
4167 Examples:
4168 <ul>
4169 <pre>
4170 mat A = randu&lt;mat&gt;(5,5);
4171
4172 A.save("A1.mat"); // default save format is arma_binary
4173 A.save("A2.mat", arma_ascii);
4174
4175 mat B;
4176 // automatically detect format type
4177 B.load("A1.mat");
4178
4179 mat C;
4180 // force loading in the arma_ascii format
4181 C.load("A2.mat", arma_ascii);
4182
4183
4184 // example of saving/loading using a stream
4185 std::stringstream s;
4186 A.save(s);
4187
4188 mat D;
4189 D.load(s);
4190
4191
4192 // example of testing for success
4193 mat E;
4194 bool status = E.load("A2.mat");
4195
4196 if(status == true)
4197 {
4198 cout &lt;&lt; "loaded okay" &lt;&lt; endl;
4199 }
4200 else
4201 {
4202 cout &lt;&lt; "problem with loading" &lt;&lt; endl;
4203 }
4204 </pre>
4205 </ul>
4206 </li>
4207 <br>
4208 <li>See also:
4209 <ul>
4210 <li><a href="#save_load_field">saving/loading fields</a></li>
4211 </ul>
4212 </li>
4213 <br>
4214 </ul>
4215 <hr class="greyline"><br>
4216
4217 <a name="save_load_field"></a>
4218 <b>
4219 .save(name, file_type = arma_binary)
4220 <br>
4221 .save(stream, file_type = arma_binary)
4222 <br>
4223 <br>
4224 .load(name, file_type = auto_detect)
4225 <br>
4226 .load(stream, file_type = auto_detect)
4227 <br>
4228 <br>
4229 .quiet_save(name, file_type = arma_binary)
4230 <br>
4231 .quiet_save(stream, file_type = arma_binary)
4232 <br>
4233 <br>
4234 .quiet_load(name, file_type = auto_detect)
4235 <br>
4236 .quiet_load(stream, file_type = auto_detect)
4237 </b>
4238 <ul>
4239 <li>Member functions of the <i>field</i> class</li>
4240 <br>
4241 <li>Store/retrieve fields in files or stream</li>
4242 <br>
4243 <li>On success, save(), load(), quiet_save(), and quite_load() will return a <i>bool</i> set to <i>true</i></li>
4244 <br>
4245 <li>save() and quiet_save() will return a <i>bool</i> set to <i>false</i> if the saving process fails</li>
4246 <br>
4247 <li>
4248 load() and quiet_load() will return a <i>bool</i> set to <i>false</i> if the loading process fails;
4249 additionally, the field will be reset so it has no elements
4250 </li>
4251 <br>
4252 <li>load() and save() will print warning messages if any problems are encountered</li>
4253 <br>
4254 <li>quiet_load() and quiet_save() do not print any error messages</li>
4255 <br>
4256 <li>
4257 Fields with objects of type <i>std::string</i> are saved and loaded as raw text files.
4258 The text files do not have a header.
4259 Each string is separated by a whitespace.
4260 load() and quiet_load() will only accept text files that have the same number of strings on each line.
4261 The strings can have variable lengths.
4262 </li>
4263 <br>
4264 <li>
4265 Other than storing string fields as text files, the following file formats are supported:
4266 <br>
4267 <br>
4268 <ul>
4269 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
4270 <tbody>
4271 <tr>
4272 <td style="vertical-align: top;"><b>auto_detect</b></td>
4273 <td style="vertical-align: top;"><br>
4274 </td>
4275 <td style="vertical-align: top;">
4276 <br>
4277 <li>
4278 load(): try to automatically detect the field format type as one of the formats described below.
4279 This is the default operation.
4280 </li>
4281 <br>
4282 </td>
4283 </tr>
4284 <tr>
4285 <td style="vertical-align: top;"><b>arma_binary</b></td>
4286 <td style="vertical-align: top;"><br>
4287 </td>
4288 <td style="vertical-align: top;">
4289 <br>
4290 <li>
4291 Objects are stored in machine dependent binary format.
4292 <li>
4293 Default type for fields of type <i>Mat</i>, <i>Col</i> or <i>Row</i>.
4294 </li>
4295 <li>
4296 Only applicable to fields of type <i>Mat</i>, <i>Col</i> or <i>Row</i>.
4297 </li>
4298 <br>
4299 </td>
4300 </tr>
4301 <tr>
4302 <td style="vertical-align: top;"><b>ppm_binary</b></td>
4303 <td style="vertical-align: top;"><br>
4304 </td>
4305 <td style="vertical-align: top;">
4306 <br>
4307 <li>
4308 Image data stored in Portable Pixmap Map (PPM) format.
4309 </li>
4310 <li>
4311 Only applicable to fields of type <i>Mat</i>, <i>Col</i> or <i>Row</i>.
4312 </li>
4313 <li>
4314 .load(): Loads the specified image and stores the red, green and blue components as three separate matrices.
4315 The resulting field is comprised of the three matrices,
4316 with the red, green and blue components in the first, second and third matrix, respectively.
4317 </li>
4318 <li>
4319 .save(): Saves a field with exactly three matrices of equal size as an image.
4320 It is assumed that the red, green and blue components are stored in the first, second and third matrix, respectively.
4321 Saving <i>int</i>, <i>float</i> or <i>double</i> matrices is a lossy operation,
4322 as each matrix element is copied and converted to an 8 bit representation.
4323 </li>
4324
4325 </td>
4326 </tr>
4327 </tbody>
4328 </table>
4329 </ul>
4330 </li>
4331 <br>
4332 <li>See also:
4333 <ul>
4334 <li><a href="#save_load_mat">saving/loading matrices and cubes</a></li>
4335 </ul>
4336 </li>
4337 <br>
4338 </ul>
4339 <hr class="greyline"><br>
4340
4341 <a name="set_imag"></a>
4342 <b>.set_imag(X)</b>
4343 <br>
4344 <b>.set_real(X)</b>
4345 <br>
4346 <ul>
4347 <li>Member functions of Mat, Col, Row and Cube</li>
4348 <br>
4349 <li>
4350 Set the imaginary/real part of an object
4351 </li>
4352 <br>
4353 <li>
4354 <i>X</i> must have the same size as the recipient object
4355 </li>
4356 <br>
4357 <li>
4358 Examples:
4359 <ul>
4360 <pre>
4361 mat A = randu&lt;mat&gt;(4,5);
4362 mat B = randu&lt;mat&gt;(4,5);
4363
4364 cx_mat C = zeros&lt;cx_mat&gt;(4,5);
4365
4366 C.set_real(A);
4367 C.set_imag(B);
4368 </pre>
4369 </ul>
4370 </li>
4371 <br>
4372 <li>
4373 <b>Caveat:</b>
4374 if you want to directly construct a complex matrix out of two real matrices,
4375 the following code is faster:
4376 <ul>
4377 <pre>
4378 mat A = randu&lt;mat&gt;(4,5);
4379 mat B = randu&lt;mat&gt;(4,5);
4380
4381 cx_mat C = cx_mat(A,B);
4382 </pre>
4383 </ul>
4384 </li>
4385 <br>
4386 <li>See also:
4387 <ul>
4388 <li><a href="#constructors_mat">matrix constructors</a></li>
4389 <li><a href="#constructors_cube">cube constructors</a></li>
4390 <li><a href="#imag_real">imag()&nbsp;/&nbsp;real()</a></li>
4391 </ul>
4392 </li>
4393 <br>
4394 </ul>
4395 <hr class="greyline"><br>
4396
4397 <a name="set_size"></a>
4398 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
4399 <tbody>
4400 <tr>
4401 <td style="vertical-align: top;"><b>.set_size(n_elem)</b></td>
4402 <td style="vertical-align: top;"><br>
4403 </td>
4404 <td style="vertical-align: top;">(member function of <i>Col</i>, <i>Row</i>, and <i>field</i>)
4405 </td>
4406 </tr>
4407 <tr>
4408 <td style="vertical-align: top;"><b>.set_size(n_rows, n_cols)</b></td>
4409 <td style="vertical-align: top;"><br>
4410 </td>
4411 <td style="vertical-align: top;">(member function of <i>Mat</i> and <i>field</i>)
4412 </td>
4413 </tr>
4414 <tr>
4415 <td style="vertical-align: top;"><b>.set_size(n_rows, n_cols, n_slices)</b></td>
4416 <td style="vertical-align: top;"><br>
4417 </td>
4418 <td style="vertical-align: top;">(member function of <i>Cube</i>)
4419 </td>
4420 </tr>
4421 </tbody>
4422 </table>
4423 <br>
4424 <ul>
4425 <li>Changes the size of an object</li>
4426 <br>
4427 <li>
4428 If the requested number of elements is equal to the old number of elements, existing memory is reused
4429 </li>
4430 <br>
4431 <li>
4432 If the requested number of elements is not equal to the old number of elements, new memory is used;
4433 the memory is uninitilised
4434 </li>
4435 <br>
4436 <li>
4437 If you need to initialise the memory, use <a href="#zeros_member">.zeros()</a> instead
4438 </li>
4439 <br>
4440 <li>
4441 If you need to explicitly preserve data, use <a href="#reshape_member">.reshape()</a> or <a href="#resize_member">.resize()</a>
4442 </li>
4443 <br>
4444 <li>
4445 Examples:
4446 <ul>
4447 <pre>
4448 mat A;
4449 A.set_size(5,10);
4450
4451 vec q;
4452 q.set_size(100);
4453 </pre>
4454 </ul>
4455 </li>
4456 <br>
4457 <li>See also:
4458 <ul>
4459 <li><a href="#reset">.reset()</a></li>
4460 <li><a href="#copy_size">.copy_size()</a></li>
4461 <li><a href="#reshape_member">.reshape()</a></li>
4462 <li><a href="#resize_member">.resize()</a></li>
4463 <li><a href="#zeros_member">.zeros()</a></li>
4464 </ul>
4465 </li>
4466 </ul>
4467 <br>
4468 <hr class="greyline"><br>
4469
4470 <a name="shed"></a>
4471 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
4472 <tbody>
4473 <tr>
4474 <td style="vertical-align: top;">
4475 <b>.shed_row(&nbsp;</b>row_number<b>&nbsp;)</b>
4476 <br>
4477 <b>.shed_rows(&nbsp;</b>first_row, last_row<b>&nbsp;)</b>
4478 </td>
4479 <td style="vertical-align: top;"><br></td>
4480 <td style="vertical-align: top;">(member functions of <i>Mat</i> and <i>Col</i>)
4481 </td>
4482 </tr>
4483 <tr>
4484 <td>&nbsp;</td>
4485 </tr>
4486 <tr>
4487 <td style="vertical-align: top;">
4488 <b>.shed_col(&nbsp;</b>column_number<b>&nbsp;)</b>
4489 <br>
4490 <b>.shed_cols(&nbsp;</b>first_column, last_column<b>&nbsp;)</b>
4491 </td>
4492 <td style="vertical-align: top;"><br></td>
4493 <td style="vertical-align: top;">(member functions of <i>Mat</i> and <i>Row</i>)
4494 </td>
4495 </tr>
4496 <tr>
4497 <td>&nbsp;</td>
4498 </tr>
4499 <tr>
4500 <td style="vertical-align: top;">
4501 <b>.shed_slice(&nbsp;</b>slice_number<b>&nbsp;)</b>
4502 <br>
4503 <b>.shed_slices(&nbsp;</b>first_slice, last_slice<b>&nbsp;)</b>
4504 </td>
4505 <td style="vertical-align: top;"><br></td>
4506 <td style="vertical-align: top;">(member functions of <i>Cube</i>)
4507 </td>
4508 </tr>
4509 </tbody>
4510 </table>
4511 <br>
4512 <ul>
4513 <li>
4514 Single argument functions:
4515 remove the specified row/column/slice
4516 </li>
4517 <br>
4518 <li>
4519 Two argument functions:
4520 remove the specified range of rows/columns/slices
4521 </li>
4522 <br>
4523 <li>
4524 Examples:
4525 <ul>
4526 <pre>
4527 mat A = randu&lt;mat&gt;(5,10);
4528
4529 A.shed_row(2);
4530 A.shed_cols(2,4);
4531 </pre>
4532 </ul>
4533 </li>
4534 <br>
4535 <li>
4536 See also:
4537 <ul>
4538 <li><a href="#insert">insert rows/columns/slices</a></li>
4539 <li><a href="#join">join rows/columns/slices</a></li>
4540 <li><a href="#resize_member">.resize()</a></li>
4541 <li><a href="#submat">submatrix views</a></li>
4542 <li><a href="#subcube">subcube views</a></li>
4543 <li><a href="http://thesaurus.com/browse/shed"><i>shed</i> in thesaurus.com</a></li>
4544 </ul>
4545 </li>
4546 <br>
4547 </ul>
4548 <hr class="greyline"><br>
4549
4550 <a name="stl_container_fns"></a>
4551 <b>STL container functions</b>
4552 <ul>
4553 <li><i>Mat</i>, <i>Col</i> and <i>Row</i> classes provide the following member functions that mimic the containers in the C++ Standard Template Library:<br>
4554 <br>
4555
4556 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
4557 <tbody>
4558 <tr>
4559 <td style="vertical-align: top;">
4560 <b>.clear()</b>
4561 </td>
4562 <td style="vertical-align: top;">&nbsp;<br>
4563 </td>
4564 <td style="vertical-align: top;">
4565 causes an object to have no elements
4566 </td>
4567 </tr>
4568 <tr>
4569 <td style="vertical-align: top;">
4570 &nbsp;
4571 </td>
4572 <td style="vertical-align: top;">&nbsp;<br>
4573 </td>
4574 <td style="vertical-align: top;">
4575 &nbsp;
4576 </td>
4577 </tr>
4578 <tr>
4579 <td style="vertical-align: top;">
4580 <b>.empty()</b>
4581 </td>
4582 <td style="vertical-align: top;">&nbsp;<br>
4583 </td>
4584 <td style="vertical-align: top;">
4585 returns true if the object has no elements; returns false if the object has one or more elements
4586 </td>
4587 </tr>
4588 <tr>
4589 <td style="vertical-align: top;">
4590 &nbsp;
4591 </td>
4592 <td style="vertical-align: top;">&nbsp;<br>
4593 </td>
4594 <td style="vertical-align: top;">
4595 &nbsp;
4596 </td>
4597 </tr>
4598 <tr>
4599 <td style="vertical-align: top;">
4600 <b>.size()</b>
4601 </td>
4602 <td style="vertical-align: top;">&nbsp;<br>
4603 </td>
4604 <td style="vertical-align: top;">
4605 returns the total number of elements
4606 </td>
4607 </tr>
4608 </tbody>
4609 </table>
4610 </li>
4611 <br>
4612 <li>
4613 Examples:
4614 <ul>
4615 <pre>
4616 mat A = randu&lt;mat&gt;(5,5);
4617 cout &lt;&lt; A.size() &lt;&lt; endl;
4618
4619 A.clear();
4620 cout &lt;&lt; A.empty() &lt;&lt; endl;
4621 </pre>
4622 </ul>
4623 </li>
4624 <br>
4625 <li>
4626 See also:
4627 <ul>
4628 <li><a href="#iterators_mat">iterators (matrices)</a></li>
4629 <li><a href="#attributes">matrix and vector attributes</a></li>
4630 <li><a href="#is_empty">.is_empty()</a></li>
4631 <li><a href="#reset">.reset()</a></li>
4632 </ul>
4633 </li>
4634 <br>
4635 </ul>
4636 <hr class="greyline"><br>
4637
4638 <a name="submat"></a>
4639 <b>submatrix views</b>
4640 <ul>
4641 <li>A collection of member functions of <i>Mat</i>, <i>Col</i> and <i>Row</i> classes that provide read/write access to submatrix views<br>
4642 <br>
4643 <li>For a matrix or vector <i>X</i>, the subviews are accessed as:</li>
4644 <br>
4645 <ul>
4646 <li>contiguous views:
4647 <ul>
4648 <br>
4649 X.<b>col(&nbsp;</b>col_number<b>&nbsp;)</b><br>
4650 X.<b>row(&nbsp;</b>row_number<b>&nbsp;)</b><br>
4651 <br>
4652 X.<b>cols(&nbsp;</b>first_col<b>,</b> last_col<b>&nbsp;)</b><br>
4653 X.<b>rows(&nbsp;</b>first_row<b>,</b> last_row<b>&nbsp;)</b><br>
4654 <br>
4655 X<b>(</b>&nbsp;<b>span::all,</b> col_number&nbsp;<b>)</b><br>
4656 X<b>(</b>&nbsp;<b>span(</b>first_row<b>,</b> last_row<b>),</b> col_number&nbsp;<b>)</b><br>
4657 <br>
4658 X<b>(</b>&nbsp;row_number<b>,</b> <b>span::all</b>&nbsp;<b>)</b><br>
4659 X<b>(</b>&nbsp;row_number<b>,</b> <b>span(</b>first_col<b>,</b> last_col<b>)&nbsp;)</b><br>
4660 <br>
4661 X.<b>submat(&nbsp;</b>first_row<b>,</b> first_col<b>,</b> last_row<b>,</b> last_col<b>&nbsp;)</b><br>
4662 X.<b>submat(&nbsp;span(</b>first_row<b>,</b> last_row<b>), span(</b>first_col<b>,</b> last_col<b>)&nbsp;)</b><br>
4663 <br>
4664 X<b>(&nbsp;span(</b>first_row<b>,</b> last_row<b>), span(</b>first_col<b>,</b> last_col<b>)&nbsp;)</b><br>
4665 <br>
4666 X.<b>unsafe_col(&nbsp;</b>col_number<b>&nbsp;)</b><br>
4667 <br>
4668 V.<b>subvec(&nbsp;</b>first_index<b>,</b> last_index<b>&nbsp;)</b> &nbsp;&nbsp;&nbsp; <i>(for vectors only)</i><br>
4669 V<b>(&nbsp;span(</b>first_index<b>,</b> last_index<b>)&nbsp;)</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <i>(for vectors only)</i><br>
4670 </ul>
4671 </li>
4672 <br>
4673 <li>non-contiguous views (added in version 3.0):
4674 <ul>
4675 <br>
4676 X.<b>elem(</b>&nbsp;vector_of_indices&nbsp;<b>)</b><br>
4677 X<b>(</b>&nbsp;vector_of_indices&nbsp;<b>)</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <i>(added in version 3.810)</i><br>
4678 <br>
4679 X.<b>cols(&nbsp;</b>vector_of_column_indices<b>&nbsp;)</b><br>
4680 X.<b>rows(&nbsp;</b>vector_of_row_indices<b>&nbsp;)</b><br>
4681 <br>
4682 X<b>(</b>&nbsp;vector_of_row_indices<b>,</b>&nbsp;vector_of_column_indices&nbsp;<b>)</b><br>
4683 X.<b>submat(</b>&nbsp;vector_of_row_indices<b>,</b>&nbsp;vector_of_column_indices&nbsp;<b>)</b><br>
4684 <!--X.<b>elem(</b>&nbsp;vector_of_row_indices<b>,</b>&nbsp;vector_of_column_indices&nbsp;<b>)</b><br>-->
4685 </ul>
4686 </li>
4687 </ul>
4688 <br>
4689 <li>
4690 Instances of <i>span::all</i>, to indicate an entire range, can be replaced by <i>span()</i>, where no number is specified
4691 </li>
4692 <br>
4693 <li>
4694 For functions requiring one or more vector of indices,
4695 eg. <i>X.submat(vector_of_row_indices,vector_of_column_indices)</i>,
4696 each vector of indices must be of type <i><a href="#Col">uvec</a></i>.
4697 </li>
4698 <br>
4699 <li>
4700 In the function <i>X.elem(vector_of_indices)</i>,
4701 elements specified in <i>vector_of_indices</i> are accessed.
4702 <i>X</i> is interpreted as one long vector,
4703 with column-by-column ordering of the elements of <i>X</i>.
4704 The <i>vector_of_indices</i> must evaluate to be a vector of type <i><a href="#Col">uvec</a></i>
4705 (eg., generated by <i><a href="#find">find()</a></i>).
4706 The aggregate set of the specified elements is treated as a column vector
4707 (eg., the output of <i>X.elem()</i> is always a column vector).
4708 </li>
4709 <br>
4710 <li>
4711 The function <i>.unsafe_col()</i> is provided for speed reasons and should be used only if you know what you're doing.
4712 The function creates a seemingly independent <i>Col</i> vector object (eg. <i>vec</i>),
4713 but the vector actually uses memory from the existing matrix object.
4714 As such, the created <i>Col</i> vector is currently not alias safe
4715 and does not take into account that the parent matrix object could be deleted.
4716 If deleted memory is accessed through the created <i>Col</i> vector,
4717 it will cause memory corruption and/or a crash.
4718 </li>
4719 <br>
4720 <li>
4721 Examples:
4722 <ul>
4723 <pre>
4724 mat A = zeros&lt;mat&gt;(5,10);
4725
4726 A.submat(0,1,2,3) = randu&lt;mat&gt;(3,3);
4727
4728 // the following three statements
4729 // access the same part of A
4730 mat B = A.submat(0,1,2,3);
4731 mat C = A.submat( span(0,2), span(1,3) );
4732 mat D = A( span(0,2), span(1,3) );
4733
4734 // the following two statements
4735 // access the same part of A
4736 A.col(1) = randu&lt;mat&gt;(5,1);
4737 A(span::all, 1) = randu&lt;mat&gt;(5,1);
4738
4739 mat X = randu&lt;mat&gt;(5,5);
4740
4741 // get all elements of X that are greater than 0.5
4742 vec q = X.elem( find(X > 0.5) );
4743
4744 // set four specific elements of X to 1
4745 uvec indices;
4746 indices &lt;&lt; 2 &lt;&lt; 3 &lt;&lt; 6 &lt;&lt; 8;
4747
4748 X.elem(indices) = ones&lt;vec&gt;(4);
4749 </pre>
4750 </ul>
4751 </li>
4752 <br>
4753 <li>
4754 See also:
4755 <ul>
4756 <li><a href="#diag">diagonal views</a> &nbsp;&nbsp; (read/write access to diagonals)</li>
4757 <li><a href="#each_colrow">.each_col() &amp; .each_row()</a> &nbsp;&nbsp; (vector operations repeated on each column or row)</li>
4758 <li><a href="#colptr">.colptr()</a></li>
4759 <li><a href="#in_range">.in_range()</a></li>
4760 <li><a href="#find">find()</a></li>
4761 <li><a href="#join">join rows/columns/slices</a></li>
4762 <li><a href="#shed">shed rows/columns/slices</a></li>
4763 <li><a href="#insert">insert rows/columns/slices</a></li>
4764 <li><a href="#subcube">subcube views</a></li>
4765 </ul>
4766 </li>
4767 <br>
4768 </ul>
4769 <hr class="greyline"><br>
4770
4771 <a name="subcube"></a>
4772 <b>subcube views and slices</b>
4773 <ul>
4774 <li>A collection of member functions of the <i>Cube</i> class that provide subcube views<br>
4775 <br>
4776 <li>For a cube <i>Q</i>, the subviews are accessed as:</li>
4777 <br>
4778 <ul>
4779 Q.<b>slice(&nbsp;</b>slice_number&nbsp;<b>)</b><br>
4780 Q.<b>slices(&nbsp;</b>first_slice<b>,</b> last_slice&nbsp;<b>)</b><br>
4781 <br>
4782 Q.<b>subcube(&nbsp;</b>first_row<b>,</b> first_col<b>,</b> first_slice<b>, </b>last_row<b>,</b> last_col<b>, </b>last_slice&nbsp;<b>)</b><br>
4783 Q.<b>subcube(&nbsp;span(</b>first_row<b>,</b> last_row<b>), span(</b>first_col<b>,</b> last_col<b>), span(</b>first_slice<b>,</b> last_slice<b>)&nbsp;)</b><br>
4784 <br>
4785 Q<b>(&nbsp;span(</b>first_row<b>,</b> last_row<b>), span(</b>first_col<b>,</b> last_col<b>), span(</b>first_slice<b>,</b> last_slice<b>)&nbsp;)</b><br>
4786 </ul>
4787 </li>
4788 <br>
4789 <li>
4790 Instances of <i>span(a,b)</i> can be replaced by:
4791 <ul>
4792 <li><i>span()</i> or <i>span::all</i>, to indicate the entire range</li>
4793 <li><i>span(a)</i>, to indicate a particular row, column or slice</li>
4794 </ul>
4795 </li>
4796 <br>
4797 <li>
4798 An individual slice, accessed via <i>.slice()</i>, is an instance of the <i>Mat</i> class
4799 (a reference to a matrix is provided)
4800 </li>
4801 <br>
4802 <li>
4803 Examples:
4804 <ul>
4805 <pre>
4806 cube A = randu&lt;cube&gt;(2,3,4);
4807 mat B = A.slice(1);
4808
4809 A.slice(0) = randu&lt;mat&gt;(2,3);
4810 A.slice(0)(1,2) = 99.0;
4811
4812 A.subcube(0,0,1, 1,1,2) = randu&lt;cube&gt;(2,2,2);
4813 A( span(0,1), span(0,1), span(1,2) ) = randu&lt;cube&gt;(2,2,2);
4814
4815 </pre>
4816 </ul>
4817 </li>
4818 <br>
4819 <li>
4820 See also:
4821 <ul>
4822 <li><a href="#in_range">.in_range()</a></li>
4823 <li><a href="#join">join slices</a></li>
4824 <li><a href="#shed">shed slices</a></li>
4825 <li><a href="#insert">insert slices</a></li>
4826 <li><a href="#submat">submatrix views</a></li>
4827 </ul>
4828 </li>
4829 <br>
4830 </ul>
4831 <hr class="greyline"><br>
4832
4833 <a name="subfield"></a>
4834 <b>subfield views</b>
4835 <ul>
4836 <li>A collection of member functions of the <i>field</i> class that provide subfield views<br>
4837 <br>
4838 <li>For a field <i>F</i>, the subfields are accessed as:</li>
4839 <br>
4840 <ul>
4841 F.<b>row(&nbsp;</b>row_number&nbsp;<b>)</b><br>
4842 F.<b>col(&nbsp;</b>col_number&nbsp;<b>)</b><br>
4843 <br>
4844 F.<b>rows(&nbsp;</b>first_row<b>,</b> last_row&nbsp;<b>)</b><br>
4845 F.<b>cols(&nbsp;</b>first_col<b>,</b> last_col&nbsp;<b>)</b><br>
4846 <br>
4847 F.<b>subfield(&nbsp;</b>first_row<b>,</b>&nbsp;first_col<b>,</b> last_row<b>,</b>&nbsp;last_col <b>)</b><br>
4848 F.<b>subfield(&nbsp;span(</b>first_row<b>,</b>&nbsp;last_row<b>), span(</b>first_col<b>,</b>&nbsp;last_col<b>) )</b><br>
4849 <br>
4850 F<b>(&nbsp;span(</b>first_row<b>,</b> last_row<b>), span(</b>first_col<b>,</b>&nbsp;last_col<b>) )</b><br>
4851 </ul>
4852 </li>
4853 <br>
4854 <li>
4855 Instances of <i>span(a,b)</i> can be replaced by:
4856 <ul>
4857 <li><i>span()</i> or <i>span::all</i>, to indicate the entire range</li>
4858 <li><i>span(a)</i>, to indicate a particular row or column</li>
4859 </ul>
4860 </li>
4861 <br>
4862 <li>
4863 See also:
4864 <ul>
4865 <li><a href="#in_range">.in_range()</a></li>
4866 <li><a href="#submat">submatrix views</a></li>
4867 <li><a href="#subcube">subcube views</a></li>
4868 </ul>
4869 </li>
4870 <br>
4871 </ul>
4872 <hr class="greyline"><br>
4873
4874 <a name="swap"></a>
4875 <b>.swap(</b>X<b>)</b>
4876 <ul>
4877 <li>
4878 Swap contents with matrix <i>X</i>
4879 </li>
4880 <br>
4881 <li>
4882 This function was added in version 3.800
4883 </li>
4884 <br>
4885 <li>
4886 Examples:
4887 <ul>
4888 <pre>
4889 mat A = zeros&lt;mat&gt;(4,5);
4890 mat B = ones&lt;mat&gt;(6,7);
4891
4892 A.swap(B);
4893 </pre>
4894 </ul>
4895 </li>
4896 <br>
4897 <li>
4898 See also:
4899 <ul>
4900 <li><a href="#swap_rows">.swap_rows() &amp; .swap_cols()</a></li>
4901 </ul>
4902 </li>
4903 <br>
4904 </ul>
4905 <hr class="greyline"><br>
4906
4907 <a name="swap_rows"></a>
4908 <b>
4909 .swap_rows(row1, row2)
4910 <br>.swap_cols(col1, col2)
4911 </b>
4912 <ul>
4913 <li>
4914 Member functions of <i>Mat</i>, <i>Col</i> and <i>Row</i> classes
4915 </li>
4916 <br>
4917 <li>
4918 Swap the contents of specified rows or columns
4919 </li>
4920 <br>
4921 <li>
4922 Examples:
4923 <ul>
4924 <pre>
4925 mat X = randu&lt;mat&gt;(5,5);
4926 X.swap_rows(0,4);
4927 </pre>
4928 </ul>
4929 </li>
4930 <br>
4931 <li>
4932 See also:
4933 <ul>
4934 <li><a href="#flip">fliplr() &amp; flipud()</a></li>
4935 <li><a href="#swap">.swap()</a></li>
4936 </ul>
4937 </li>
4938 <br>
4939 </ul>
4940 <hr class="greyline"><br>
4941
4942 <a name="t_st_members"></a>
4943 <b>
4944 .t()
4945 <br>.st()
4946 </b>
4947 <ul>
4948 <li>
4949 Member functions of any matrix or vector expression
4950 </li>
4951 <br>
4952 <li>
4953 <i>.t()</i> provides a transposed copy of the object; if a given object has complex elements, a Hermitian transpose is done (ie. the conjugate of the elements is taken during the transpose operation)
4954 </li>
4955 <br>
4956 <li>
4957 <i>.st()</i> provides a transposed copy of the object, without taking the conjugate of the elements (complex matrices)
4958 </li>
4959 <br>
4960 <li>
4961 For non-complex objects, the <i>.t()</i> and <i>.st()</i> functions are equivalent
4962 </li>
4963 <br>
4964 <li>
4965 Examples:
4966 <ul>
4967 <pre>
4968 mat A = randu&lt;mat&gt;(4,5);
4969 mat B = A.t();
4970 </pre>
4971 </ul>
4972 </li>
4973 <br>
4974 <li>
4975 The <i>.t()</i> and <i>.st()</i> functions were added in version 2.4
4976 </li>
4977 <br>
4978 <li>
4979 See also:
4980 <ul>
4981 <li><a href="#trans">trans()</a></li>
4982 <li><a href="#strans">strans()</a></li>
4983 </ul>
4984 </li>
4985 <br>
4986 </ul>
4987 <hr class="greyline"><br>
4988
4989 <a name="transform"></a>
4990 <b>.transform(&nbsp;</b>functor<b>&nbsp;)</b>
4991 <br>
4992 <b>.transform(&nbsp;</b>lambda function<b>&nbsp;)</b>&nbsp;&nbsp;&nbsp;<i>(C++11 only)</i>
4993 <br>
4994 <ul>
4995 <li>
4996 Transform each element using a functor or lambda function
4997 </li>
4998 <br>
4999 <li>
5000 For matrices, transformation is done column-by-column (ie. column 0 is transformed, then column 1, ...)
5001 </li>
5002 <br>
5003 <li>
5004 For cubes, transformation is done slice-by-slice; each slice is transformed column-by-column
5005 </li>
5006 <br>
5007 <li>
5008 This function was added in version 3.800
5009 </li>
5010 <br>
5011 <li>
5012 Examples:
5013 <ul>
5014 <pre>
5015 // C++11 only example
5016
5017 mat A = ones&lt;mat&gt;(4,5);
5018
5019 // add 123 to every element
5020 A.transform( [](double val) { return (val + 123.0); } );
5021 </pre>
5022 </ul>
5023 </li>
5024 <br>
5025 <li>
5026 See also:
5027 <ul>
5028 <li><a href="#operators">overloaded operators</a></li>
5029 <li><a href="#imbue">.imbue()</a></li>
5030 <li><a href="#fill">.fill()</a></li>
5031 <li><a href="http://en.wikipedia.org/wiki/Function_object">function object</a> at Wikipedia</li>
5032 <li><a href="http://en.wikipedia.org/wiki/C%2B%2B11#Lambda_functions_and_expressions">C++11 lambda functions</a> at Wikipedia</li>
5033 <li><a href="http://www.cprogramming.com/c++11/c++11-lambda-closures.html">lambda function</a> at cprogramming.com</li>
5034 </ul>
5035 </li>
5036 <br>
5037 </ul>
5038 <hr class="greyline"><br>
5039
5040 <a name="zeros_member"></a>
5041 <b>.zeros()</b>
5042 <br><b>.zeros(n_elem)</b>
5043 <br><b>.zeros(n_rows, n_cols)</b>
5044 <br><b>.zeros(n_rows, n_cols, n_slices)</b>
5045 <ul>
5046 <li>
5047 Set the elements of an object to zero, optionally first resizing to specified dimensions
5048 </li>
5049 <br>
5050 <li>
5051 <i>.zeros()</i> and <i>.zeros(n_elem)</i> are member function of <i>Col</i> and <i>Row</i>
5052 </li>
5053 <br>
5054 <li>
5055 <i>.zeros()</i> and <i>.zeros(n_rows, n_cols)</i> are member functions of <i>Mat</i>
5056 </li>
5057 <br>
5058 <li>
5059 <i>.zeros()</i> and <i>.zeros(n_rows, n_cols, n_slices)</i> are member functions of <i>Cube</i>
5060 </li>
5061 <br>
5062 <li>
5063 Examples:
5064 <ul>
5065 <pre>
5066 mat A = randu&lt;mat&gt;(5,10);
5067 A.zeros(); // sets all elements to zero
5068 A.zeros(10,20); // sets the size to 10 rows and 20 columns
5069 // followed by setting all elements to zero
5070 </pre>
5071 </ul>
5072 </li>
5073 <br>
5074 <li>
5075 See also:
5076 <ul>
5077 <li><a href="#zeros_standalone">zeros()</a> (standalone function)</li>
5078 <li><a href="#ones_member">.ones()</a></li>
5079 <li><a href="#randu_randn_member">.randu()</a></li>
5080 <li><a href="#fill">.fill()</a></li>
5081 <li><a href="#imbue">.imbue()</a></li>
5082 <li><a href="#reset">.reset()</a></li>
5083 <li><a href="#set_size">.set_size()</a></li>
5084 </ul>
5085 </li>
5086 <br>
5087 </ul>
5088 <hr class="greyline">
5089
5090
5091 <hr class="greyline">
5092 <br>
5093 <br>
5094 <font size=+1><b>Other Classes</b></font>
5095 <br>
5096 <br>
5097 <hr class="greyline">
5098 <br>
5099
5100 <a name="running_stat"></a>
5101 <b>running_stat&lt;</b><i>type</i><b>&gt;</b>
5102 <ul>
5103 <li>
5104 Class for keeping statistics of a continuously sampled one dimensional process/signal.
5105 Useful if the storage of individual samples (scalars) is not necessary or desired.
5106 Also useful if the number of samples is not known beforehand or exceeds available memory.
5107 </li>
5108 <br>
5109 <li>
5110 <i>type</i> should be one of: <i>float</i>, <i>double</i>, <i><a href="#cx_float_double">cx_float</a></i>, <i><a href="#cx_float_double">cx_double</a></i>
5111 </li>
5112 <br>
5113 <li>
5114 Member functions:
5115 <ul>
5116 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
5117 <tbody>
5118 <tr>
5119 <td style="vertical-align: top;">
5120 <b>.operator()(</b>scalar<b>)</b>
5121 </td>
5122 <td style="vertical-align: top;">&nbsp;<br>
5123 </td>
5124 <td style="vertical-align: top;">
5125 update the statistics so far using the given scalar
5126 </td>
5127 </tr>
5128 <tr>
5129 <td style="vertical-align: top;">
5130 <b>.mean()</b>
5131 </td>
5132 <td style="vertical-align: top;">&nbsp;<br>
5133 </td>
5134 <td style="vertical-align: top;">
5135 get the mean or average value so far
5136 </td>
5137 </tr>
5138 <tr>
5139 <td style="vertical-align: top;">
5140 <b>.var(</b>norm_type=0<b>)</b>
5141 </td>
5142 <td style="vertical-align: top;">&nbsp;<br>
5143 </td>
5144 <td style="vertical-align: top;">
5145 get the variance so far
5146 </td>
5147 </tr>
5148 <tr>
5149 <td style="vertical-align: top;">
5150 <b>.stddev(</b>norm_type=0<b>)</b>
5151 </td>
5152 <td style="vertical-align: top;">&nbsp;<br>
5153 </td>
5154 <td style="vertical-align: top;">
5155 get the standard deviation so far
5156 </td>
5157 </tr>
5158 <tr>
5159 <td style="vertical-align: top;">
5160 <b>.min()</b>
5161 </td>
5162 <td style="vertical-align: top;">&nbsp;<br>
5163 </td>
5164 <td style="vertical-align: top;">
5165 get the minimum value so far
5166 </td>
5167 </tr>
5168 <tr>
5169 <td style="vertical-align: top;">
5170 <b>.max()</b>
5171 </td>
5172 <td style="vertical-align: top;">&nbsp;<br>
5173 </td>
5174 <td style="vertical-align: top;">
5175 get the maximum value so far
5176 </td>
5177 </tr>
5178 <tr>
5179 <td style="vertical-align: top;">
5180 <b>.reset()</b>
5181 </td>
5182 <td style="vertical-align: top;">&nbsp;<br>
5183 </td>
5184 <td style="vertical-align: top;">
5185 reset all statistics and set the number of samples to zero
5186 </td>
5187 </tr>
5188 <tr>
5189 <td style="vertical-align: top;">
5190 <b>.count()</b>
5191 </td>
5192 <td style="vertical-align: top;">&nbsp;<br>
5193 </td>
5194 <td style="vertical-align: top;">
5195 get the number of samples so far
5196 </td>
5197 </tr>
5198 </tbody>
5199 </table>
5200 </ul>
5201 </li>
5202 <br>
5203 <li>
5204 For the .var() and .stddev() functions, the default <i>norm_type=0</i> performs normalisation using <i>N-1</i>
5205 (where <i>N</i> is the number of samples so far),
5206 providing the best unbiased estimator.
5207 Using <i>norm_type=1</i> causes normalisation to be done using <i>N</i>, which provides the second moment around the mean.
5208 </li>
5209 <br>
5210 <li>
5211 The return type of .count() depends on the underlying form of <i>type</i>: it is either <i>float</i> or <i>double</i>.
5212 </li>
5213 <br>
5214 <li>
5215 Examples:
5216 <ul>
5217 <pre>
5218 running_stat&lt;double&gt; stats;
5219
5220 for(uword i=0; i&lt;10000; ++i)
5221 {
5222 double sample = double(rand())/RAND_MAX;
5223 stats(sample);
5224 }
5225
5226 cout &lt;&lt; "mean = " &lt;&lt; stats.mean() &lt;&lt; endl;
5227 cout &lt;&lt; "var = " &lt;&lt; stats.var() &lt;&lt; endl;
5228 cout &lt;&lt; "min = " &lt;&lt; stats.min() &lt;&lt; endl;
5229 cout &lt;&lt; "max = " &lt;&lt; stats.max() &lt;&lt; endl;
5230 </pre>
5231 </ul>
5232 </li>
5233 <br>
5234 <li>See also:
5235 <ul>
5236 <li><a href="#stats_fns">statistics functions</a></li>
5237 <li><a href="#running_stat_vec">running_stat_vec</a></li>
5238 </ul>
5239 </li>
5240 </ul>
5241 <br>
5242 <hr class="greyline"><br>
5243
5244 <a name="running_stat_vec"></a>
5245 <b>running_stat_vec&lt;</b><i>type</i><b>&gt;(calc_cov = false)</b>
5246 <ul>
5247 <li>
5248 Class for keeping statistics of a continuously sampled multi-dimensional process/signal.
5249 Useful if the storage of individual samples is not necessary or desired.
5250 Also useful if the number of samples is not known beforehand or exceeds available memory.
5251 </li>
5252 <br>
5253 <li>
5254 This class is similar to <i>running_stat</i>, with the difference being that vectors are processed instead of single values.
5255 </li>
5256 <br>
5257 <li>
5258 <i>type</i> must match the element type used by the sample vectors
5259 (ie. it must be one of <i>float</i>, <i>double</i>, <i><a href="#cx_float_double">cx_float</a></i>, <i><a href="#cx_float_double">cx_double</a></i>)
5260 </li>
5261 <br>
5262 <li>
5263 <i>type</i> can be inferred via the use of the <i>elem_type</i> member typedef of a vector class.
5264 For example, <i>fvec::elem_type</i> will be interpreted as <i>float</i>,
5265 while <i>cx_vec::elem_type</i> will be interpreted as <i><a href="#cx_float_double">cx_double</a></i>.
5266 </li>
5267 <br>
5268 <li>
5269 Member functions:
5270 <ul>
5271 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
5272 <tbody>
5273 <tr>
5274 <td style="vertical-align: top;">
5275 <b>.operator()(</b>vector<b>)</b>
5276 </td>
5277 <td style="vertical-align: top;">&nbsp;<br>
5278 </td>
5279 <td style="vertical-align: top;">
5280 update the statistics so far using the given vector
5281 </td>
5282 </tr>
5283 <tr>
5284 <td style="vertical-align: top;">
5285 <b>.mean()</b>
5286 </td>
5287 <td style="vertical-align: top;">&nbsp;<br>
5288 </td>
5289 <td style="vertical-align: top;">
5290 get the mean vector so far
5291 </td>
5292 </tr>
5293 <tr>
5294 <td style="vertical-align: top;">
5295 <b>.var(</b>norm_type=0<b>)</b>
5296 </td>
5297 <td style="vertical-align: top;">&nbsp;<br>
5298 </td>
5299 <td style="vertical-align: top;">
5300 get the vector of variances so far
5301 </td>
5302 </tr>
5303 <tr>
5304 <td style="vertical-align: top;">
5305 <b>.stddev(</b>norm_type=0<b>)</b>
5306 </td>
5307 <td style="vertical-align: top;">&nbsp;<br>
5308 </td>
5309 <td style="vertical-align: top;">
5310 get the vector of standard deviations so far
5311 </td>
5312 </tr>
5313 <tr>
5314 <td style="vertical-align: top;">
5315 <b>.min()</b>
5316 </td>
5317 <td style="vertical-align: top;">&nbsp;<br>
5318 </td>
5319 <td style="vertical-align: top;">
5320 get the vector of minimum values so far
5321 </td>
5322 </tr>
5323 <tr>
5324 <td style="vertical-align: top;">
5325 <b>.max()</b>
5326 </td>
5327 <td style="vertical-align: top;">&nbsp;<br>
5328 </td>
5329 <td style="vertical-align: top;">
5330 get the vector of maximum values so far
5331 </td>
5332 </tr>
5333 <tr>
5334 <td style="vertical-align: top;">
5335 <b>.cov(</b>norm_type=0<b>)</b>
5336 </td>
5337 <td style="vertical-align: top;">&nbsp;<br>
5338 </td>
5339 <td style="vertical-align: top;">
5340 get the covariance matrix so far
5341 <br>NOTE: this only works if <i>calc_cov</i> is set to <i>true</i> during the construction of the class
5342 </td>
5343 </tr>
5344 <tr>
5345 <td style="vertical-align: top;">
5346 <b>.reset()</b>
5347 </td>
5348 <td style="vertical-align: top;">&nbsp;<br>
5349 </td>
5350 <td style="vertical-align: top;">
5351 reset all statistics and set the number of samples to zero
5352 </td>
5353 </tr>
5354 <tr>
5355 <td style="vertical-align: top;">
5356 <b>.count()</b>
5357 </td>
5358 <td style="vertical-align: top;">&nbsp;<br>
5359 </td>
5360 <td style="vertical-align: top;">
5361 get the number of samples so far
5362 </td>
5363 </tr>
5364 </tbody>
5365 </table>
5366 </ul>
5367 </li>
5368 <br>
5369 <li>
5370 For the .var() and .stddev() functions, the default <i>norm_type=0</i> performs normalisation using <i>N-1</i>
5371 (where <i>N</i> is the number of samples so far),
5372 providing the best unbiased estimator.
5373 Using <i>norm_type=1</i> causes normalisation to be done using <i>N</i>, which provides the second moment around the mean.
5374 </li>
5375 <br>
5376 <li>
5377 The return type of .count() depends on the underlying form of <i>type</i>: it is either <i>float</i> or <i>double</i>.
5378 </li>
5379 <br>
5380 <li>
5381 Examples:
5382 <ul>
5383 <pre>
5384 running_stat_vec&lt;rowvec::elem_type&gt; stats;
5385
5386 rowvec sample;
5387
5388 for(uword i=0; i&lt;10000; ++i)
5389 {
5390 sample = randu&lt;rowvec&gt;(5);
5391 stats(sample);
5392 }
5393
5394 cout &lt;&lt; "mean = " &lt;&lt; stats.mean() &lt;&lt; endl;
5395 cout &lt;&lt; "var = " &lt;&lt; stats.var() &lt;&lt; endl;
5396 cout &lt;&lt; "min = " &lt;&lt; stats.min() &lt;&lt; endl;
5397 cout &lt;&lt; "max = " &lt;&lt; stats.max() &lt;&lt; endl;
5398
5399 //
5400 //
5401
5402 running_stat_vec&lt;rowvec::elem_type&gt; more_stats(true);
5403
5404 for(uword i=0; i&lt;20; ++i)
5405 {
5406 sample = randu&lt;rowvec&gt;(3);
5407
5408 sample(1) -= sample(0);
5409 sample(2) += sample(1);
5410
5411 more_stats(sample);
5412 }
5413
5414 cout &lt;&lt; "covariance matrix = " &lt;&lt; endl;
5415 cout &lt;&lt; more_stats.cov() &lt;&lt; endl;
5416
5417 rowvec sd = more_stats.stddev();
5418
5419 cout &lt;&lt; "correlations = " &lt;&lt; endl;
5420 cout &lt;&lt; more_stats.cov() / (sd.t() * sd);
5421 </pre>
5422 </ul>
5423 </li>
5424 <br>
5425 <li>See also:
5426 <ul>
5427 <li><a href="#cov">cov()</a></li>
5428 <li><a href="#cor">cor()</a></li>
5429 <li><a href="#running_stat">running_stat</a></li>
5430 <li><a href="#stats_fns">statistics functions</a></li>
5431 </ul>
5432 </li>
5433 </ul>
5434 <br>
5435 <hr class="greyline"><br>
5436
5437 <a name="wall_clock"></a>
5438 <b>wall_clock</b>
5439 <ul>
5440 <li>
5441 Simple wall clock timer class, for measuring the number of elapsed seconds between two intervals
5442 </li>
5443 <br>
5444 <li>
5445 Examples:
5446 <ul>
5447 <pre>
5448 wall_clock timer;
5449
5450 mat A = randu&lt;mat&gt;(4,4);
5451 mat B = randu&lt;mat&gt;(4,4);
5452 mat C;
5453
5454 timer.tic();
5455 for(uword i=0; i&lt;100000; ++i)
5456 C = A + B + A + B;
5457
5458 double n_secs = timer.toc();
5459 cout &lt;&lt; "took " &lt;&lt; n_secs &lt;&lt; " seconds" &lt;&lt; endl;
5460 </pre>
5461 </ul>
5462 </li>
5463 </ul>
5464 <br>
5465 <hr class="greyline">
5466
5467 <hr class="greyline">
5468 <br>
5469 <br>
5470 <font size=+1><b>Generated Vectors/Matrices</b></font>
5471 <br>
5472 <br>
5473 <hr class="greyline">
5474 <br>
5475
5476 <a name="eye_standalone"></a>
5477 <b>eye(n_rows, n_cols)</b>
5478 <ul>
5479 <li>
5480 Generate a matrix with the elements along the main diagonal set to one
5481 and off-diagonal elements set to zero
5482 </li>
5483 <br>
5484 <li>
5485 An identity matrix is generated when <i>n_rows</i> = <i>n_cols</i>
5486 </li>
5487 <br>
5488 <li>
5489 Usage:
5490 <ul>
5491 <li>
5492 <i>matrix_type</i> X = eye&lt;<i>matrix_type</i>&gt;(n_rows, n_cols)
5493 </li>
5494 </ul>
5495 </li>
5496 <br>
5497 <li>
5498 Examples:
5499 <ul>
5500 <pre>
5501 mat A = eye&lt;mat&gt;(5,5);
5502 mat B = 123.0 * eye&lt;mat&gt;(5,5);
5503 </pre>
5504 </ul>
5505 </li>
5506 <br>
5507 <li>See also:
5508 <ul>
5509 <li><a href="#eye_member">.eye()</a> (member function of Mat)</li>
5510 <li><a href="#diag">.diag()</a></li>
5511 <li><a href="#ones_standalone">ones()</a></li>
5512 <li><a href="#diagmat">diagmat()</a></li>
5513 <li><a href="#diagvec">diagvec()</a></li>
5514 </ul>
5515 </li>
5516 <br>
5517 </ul>
5518 <hr class="greyline"><br>
5519
5520 <a name="linspace"></a>
5521 <b>linspace(start, end, N=100)</b>
5522 <ul>
5523 <li>
5524 Generate a vector with <i>N</i> elements;
5525 the values of the elements linearly increase from <i>start</i> upto (and including) <i>end</i>
5526 <br>
5527 </li>
5528 <br>
5529 <li>
5530 Usage:
5531 <ul>
5532 <li><i>vector_type</i> v = linspace&lt;<i>vector_type</i>&gt;(start, end, N)</li>
5533 <li><i>matrix_type</i> X = linspace&lt;<i>matrix_type</i>&gt;(start, end, N)</li>
5534 </ul>
5535 </li>
5536 <br>
5537 <li>
5538 If a <i>matrix_type</i> is specified, the resultant matrix will have one column
5539 </li>
5540 <br>
5541 <li>
5542 Examples:
5543 <ul>
5544 <pre>
5545 vec v = linspace&lt;vec&gt;(10, 20, 5);
5546 mat X = linspace&lt;mat&gt;(10, 20, 5);
5547 </pre>
5548 </ul>
5549 </li>
5550 <br>
5551 <li>
5552 See also:
5553 <ul>
5554 <li><a href="#ones_standalone">ones()</a></li>
5555 </ul>
5556 </li>
5557 </ul>
5558 <br>
5559 <hr class="greyline"><br>
5560
5561
5562
5563 <a name="ones_standalone"></a>
5564 <b>
5565 ones(n_elem)
5566 <br>ones(n_rows, n_cols)
5567 <br>ones(n_rows, n_cols, n_slices)
5568 </b>
5569 <ul>
5570 <li>
5571 Generate a vector, matrix or cube with all elements set to one
5572 </li>
5573 <br>
5574 <li>
5575 Usage:
5576 <ul>
5577 <li><i>vector_type</i> v = ones&lt;<i>vector_type</i>&gt;(n_elem)</li>
5578 <li><i>matrix_type</i> X = ones&lt;<i>matrix_type</i>&gt;(n_rows, n_cols)</li>
5579 <li><i>cube_type</i> Q = ones&lt;<i>cube_type</i>&gt;(n_rows, n_cols, n_slices)</li>
5580 </ul>
5581 </li>
5582 <br>
5583 <li>
5584 Examples:
5585 <ul>
5586 <pre>
5587 vec v = ones&lt;vec&gt;(10);
5588 uvec u = ones&lt;uvec&gt;(11);
5589 mat A = ones&lt;mat&gt;(5,6);
5590 cube Q = ones&lt;cube&gt;(5,6,7);
5591
5592 mat B = 123.0 * ones&lt;mat&gt;(5,6);
5593 </pre>
5594 </ul>
5595 </li>
5596 <br>
5597 <li>
5598 See also:
5599 <ul>
5600 <li><a href="#ones_member">.ones()</a> (member function of <i>Mat</i>, <i>Col</i>, <i>Row</i> and <i>Cube</i>)</li>
5601 <li><a href="#eye_standalone">eye()</a></li>
5602 <li><a href="#linspace">linspace()</a></li>
5603 <li><a href="#zeros_standalone">zeros()</a></li>
5604 </ul>
5605 </li>
5606 </ul>
5607 <br>
5608 <hr class="greyline"><br>
5609
5610 <a name="randu_randn_standalone"></a>
5611 <b>randu(n_elem)</b>
5612 <br><b>randu(n_rows, n_cols)</b>
5613 <br><b>randu(n_rows, n_cols, n_slices)</b>
5614 <br>
5615 <br><b>randn(n_elem)</b>
5616 <br><b>randn(n_rows, n_cols)</b>
5617 <br><b>randn(n_rows, n_cols, n_slices)</b>
5618 <ul>
5619 <li>
5620 Generate a vector, matrix or cube with the elements set to random values
5621 </li>
5622 <br>
5623 <li><i>randu()</i> uses a uniform distribution in the [0,1] interval
5624 </li>
5625 <br>
5626 <li><i>randn()</i> uses a normal/Gaussian distribution with zero mean and unit variance
5627 </li>
5628 <br>
5629 <li>
5630 Usage:
5631 <ul>
5632 <li><i>vector_type</i> v = randu&lt;<i>vector_type</i>&gt;(n_elem)</li>
5633 <li><i>matrix_type</i> X = randu&lt;<i>matrix_type</i>&gt;(n_rows, n_cols)</li>
5634 <li><i>cube_type</i> Q = randu&lt;<i>cube_type</i>&gt;(n_rows, n_cols, n_slices)</li>
5635 </ul>
5636 </li>
5637 <br>
5638 <li>
5639 To change the seed, use the <a href="http://cplusplus.com/reference/clibrary/cstdlib/srand/">std::srand()</a> function.
5640 </li>
5641 <br>
5642 <li>
5643 Examples:
5644 <ul>
5645 <pre>
5646 vec v = randu&lt;vec&gt;(5);
5647 mat A = randu&lt;mat&gt;(5,6);
5648 cube Q = randu&lt;cube&gt;(5,6,7);
5649 </pre>
5650 </ul>
5651 </li>
5652 <li>See also:
5653 <ul>
5654 <li><a href="#randu_randn_member">.randu() &amp; .randn()</a> (member functions)</li>
5655 <li><a href="#imbue">.imbue()</a></li>
5656 <li><a href="#ones_standalone">ones()</a></li>
5657 <li><a href="#zeros_standalone">zeros()</a></li>
5658 <li><a href="#shuffle">shuffle()</a></li>
5659 <li><a href="http://cplusplus.com/reference/clibrary/cstdlib/srand/">std::srand()</a></li>
5660 </ul>
5661 </li>
5662 <br>
5663 </ul>
5664 <hr class="greyline"><br>
5665
5666 <a name="repmat"></a>
5667 <b>repmat(A, num_copies_per_row, num_copies_per_col)</b>
5668 <ul>
5669 <li>Generate a matrix by replicating matrix A in a block-like fashion</li>
5670 <br>
5671 <li>The generated matrix has the following size:
5672 <ul>
5673 rows = num_copies_per_row * A.n_rows
5674 <br>
5675 cols = num_copies_per_col * A.n_cols
5676 </ul>
5677 </li>
5678 <br>
5679 <li>
5680 Examples:
5681 <ul>
5682 <pre>
5683 mat A = randu&lt;mat&gt;(2, 3);
5684
5685 mat B = repmat(A, 4, 5);
5686 </pre>
5687 </ul>
5688 </li>
5689 <br>
5690 </ul>
5691 <hr class="greyline">
5692 <br>
5693
5694 <a name="speye"></a>
5695 <b>speye(n_rows, n_cols)</b>
5696 <ul>
5697 <li>
5698 Generate a sparse matrix with the elements along the main diagonal set to one
5699 and off-diagonal elements set to zero
5700 </li>
5701 <br>
5702 <li>
5703 An identity matrix is generated when <i>n_rows</i> = <i>n_cols</i>
5704 </li>
5705 <br>
5706 <li>
5707 Usage:
5708 <ul>
5709 <li>
5710 <i>sparse_matrix_type</i> X = speye&lt;<i>sparse_matrix_type</i>&gt;(n_rows, n_cols)
5711 </li>
5712 </ul>
5713 </li>
5714 <br>
5715 <li>
5716 Examples:
5717 <ul>
5718 <pre>
5719 sp_mat A = speye&lt;sp_mat&gt;(5,5);
5720 </pre>
5721 </ul>
5722 </li>
5723 <br>
5724 <li>See also:
5725 <ul>
5726 <li><a href="#sprandu_sprandn">sprandu()/sprandn()</a></li>
5727 </ul>
5728 </li>
5729 <br>
5730 </ul>
5731 <hr class="greyline"><br>
5732
5733 <a name="sprandu_sprandn"></a>
5734 <b>sprandu(n_rows, n_cols, density)</b>
5735 <br><b>sprandn(n_rows, n_cols, density)</b>
5736 <ul>
5737 <li>
5738 Generate a sparse matrix with the non-zero elements set to random values
5739 </li>
5740 <br>
5741 <li>
5742 The <i>density</i> argument specifies the percentage of non-zero elements; it must be in the [0,1] interval
5743 </li>
5744 <br>
5745 <li><i>sprandu()</i> uses a uniform distribution in the [0,1] interval
5746 </li>
5747 <br>
5748 <li><i>sprandn()</i> uses a normal/Gaussian distribution with zero mean and unit variance
5749 </li>
5750 <br>
5751 <li>
5752 Usage:
5753 <ul>
5754 <li><i>sparse_matrix_type</i> X = sprandu&lt;<i>sparse_matrix_type</i>&gt;(n_rows, n_cols, density)</li>
5755 </ul>
5756 </li>
5757 <br>
5758 <li>
5759 To change the seed, use the <a href="http://cplusplus.com/reference/clibrary/cstdlib/srand/">std::srand()</a> function.
5760 </li>
5761 <br>
5762 <li>
5763 Examples:
5764 <ul>
5765 <pre>
5766 sp_mat A = sprandu&lt;sp_mat&gt;(100, 200, 0.1);
5767 </pre>
5768 </ul>
5769 </li>
5770 <li>See also:
5771 <ul>
5772 <li><a href="#speye">speye()</a></li>
5773 <li><a href="http://cplusplus.com/reference/clibrary/cstdlib/srand/">std::srand()</a></li>
5774 </ul>
5775 </li>
5776 <br>
5777 </ul>
5778 <hr class="greyline"><br>
5779
5780 <a name="toeplitz"></a>
5781 <b>toeplitz(A)</b>
5782 <br><b>toeplitz(A,B)</b>
5783 <br><b>circ_toeplitz(A)</b>
5784 <ul>
5785 <li>
5786 toeplitz(): generate a Toeplitz matrix, with the first column specified by <i>A</i>, and (optionally) the first row specified by <i>B</i>
5787 </li>
5788 <br>
5789 <li>
5790 circ_toeplitz(): generate a circulant Toeplitz matrix
5791 </li>
5792 <br>
5793 <li>
5794 A and B must be vectors
5795 </li>
5796 <br>
5797 <li>
5798 Examples:
5799 <ul>
5800 <pre>
5801 vec A = randu&lt;vec&gt;(5);
5802 mat X = toeplitz(A);
5803 mat Y = circ_toeplitz(A);
5804 </pre>
5805 </ul>
5806 </li>
5807 <br>
5808 <li>See also:
5809 <ul>
5810 <li><a href="http://mathworld.wolfram.com/ToeplitzMatrix.html">Toeplitz matrix in MathWorld</a></li>
5811 <li><a href="http://en.wikipedia.org/wiki/Toeplitz_matrix">Toeplitz matrix in Wikipedia</a></li>
5812 <li><a href="http://en.wikipedia.org/wiki/Circulant_matrix">Circulant matrix in Wikipedia</a></li>
5813 </ul>
5814 </li>
5815 <br>
5816 </ul>
5817 <hr class="greyline">
5818 <br>
5819
5820 <a name="zeros_standalone"></a>
5821 <b>zeros(n_elem)</b>
5822 <br><b>zeros(n_rows, n_cols)</b>
5823 <br><b>zeros(n_rows, n_cols, n_slices)</b>
5824 <ul>
5825 <li>
5826 Generate a vector, matrix or cube with the elements set to zero
5827 </li>
5828 <br>
5829 <li>
5830 Usage:
5831 <ul>
5832 <li><i>vector_type</i> v = zeros&lt;<i>vector_type</i>&gt;(n_elem)</li>
5833 <li><i>matrix_type</i> X = zeros&lt;<i>matrix_type</i>&gt;(n_rows, n_cols)</li>
5834 <li><i>cube_type</i> X = zeros&lt;<i>cube_type</i>&gt;(n_rows, n_cols, n_slices)</li>
5835 </ul>
5836 </li>
5837 <br>
5838 <li>
5839 Examples:
5840 <ul>
5841 <pre>
5842 vec v = zeros&lt;vec&gt;(10);
5843 uvec u = zeros&lt;uvec&gt;(11);
5844 mat A = zeros&lt;mat&gt;(5,6);
5845 cube Q = zeros&lt;cube&gt;(5,6,7);
5846 </pre>
5847 </ul>
5848 </li>
5849 <br>
5850 <li>
5851 See also:
5852 <ul>
5853 <li><a href="#zeros_member">.zeros()</a> (member function of <i>Mat</i>, <i>Col</i>, <i>Row</i> and <i>Cube</i>)</li>
5854 <li><a href="#ones_member">.ones()</a> (member function of <i>Mat</i>, <i>Col</i>, <i>Row</i> and <i>Cube</i>)</li>
5855 <li><a href="#ones_standalone">ones()</a></li>
5856 </ul>
5857 </li>
5858 </ul>
5859 <br>
5860 <hr class="greyline">
5861
5862 <hr class="greyline">
5863 <br>
5864 <br>
5865 <font size=+1><b>Functions Individually Applied to Each Element of a Matrix/Cube</b></font>
5866 <br>
5867 <br>
5868 <hr class="greyline">
5869 <br>
5870
5871 <a name="abs"></a>
5872 <b>abs(mat)</b>
5873 <br><b>abs(cube)</b>
5874 <br><b>abs(cx_mat)</b>
5875 <br><b>abs(cx_cube)</b>
5876 <ul>
5877 <li>
5878 Obtain the magnitude of each element
5879 </li>
5880 <br>
5881 <li>
5882 Usage for non-complex matrices:
5883 <ul>
5884 <li><i>matrix_type</i> Y = abs(X)</li>
5885 <li>X and Y must have the same <i>matrix_type</i></li>
5886 </ul>
5887 </li>
5888 <br>
5889 <li>
5890 Usage for non-complex cubes:
5891 <ul>
5892 <li><i>cube_type</i> Y = abs(X)</li>
5893 <li>X and Y must have the same <i>cube_type</i></li>
5894 </ul>
5895 </li>
5896 <br>
5897 <li>
5898 Usage for complex matrices:
5899 <ul>
5900 <li><i>non_complex_matrix_type</i> Y = abs(X)</li>
5901 <li>X must be a have complex matrix type, eg., <i>cx_mat</i> or <i>cx_fmat</i></li>
5902 <li>The type of Y must be related to the type of X,
5903 eg., if X has the type <i>cx_mat</i>, then the type of Y must be <i>mat</i>
5904 </ul>
5905 </li>
5906 <br>
5907 <li>
5908 Usage for complex cubes:
5909 <ul>
5910 <li><i>non_complex_cube_type</i> Y = abs(X)</li>
5911 <li>X must be a have complex cube type, eg., <i>cx_cube</i> or <i>cx_fcube</i></li>
5912 <li>The type of Y must be related to the type of X,
5913 eg., if X has the type <i>cx_cube</i>, then the type of Y must be <i>cube</i>
5914 </ul>
5915 </li>
5916 <br>
5917 <li>
5918 Examples:
5919 <ul>
5920 <pre>
5921 mat A = randu&lt;mat&gt;(5,5);
5922 mat B = abs(A);
5923
5924 cx_mat X = randu&lt;cx_mat&gt;(5,5);
5925 mat Y = abs(X);
5926 </pre>
5927 </ul>
5928 </li>
5929 </ul>
5930 <br>
5931 <hr class="greyline"><br>
5932
5933 <a name="eps"></a>
5934 <b>eps(X)</b>
5935 <ul>
5936 <li>
5937 Obtain the positive distance of the absolute value of each element of <i>X</i> to the next largest representable floating point number
5938 </li>
5939 <br>
5940 <li>
5941 <i>X</i> can be a scalar (eg. <i>double</i>), vector or matrix
5942 </li>
5943 <br>
5944 <li>
5945 Examples:
5946 <ul>
5947 <pre>
5948 mat A = randu&lt;mat&gt;(4,5);
5949 mat B = eps(A);
5950 </pre>
5951 </ul>
5952 </li>
5953 <br>
5954 <li>
5955 See also:
5956 <ul>
5957 <li><a href="#constants">datum::eps</a></li>
5958 <li><a href="http://mathworld.wolfram.com/Floating-PointArithmetic.html">Floating-Point Arithmetic in MathWorld</a></li>
5959 <li><a href="http://en.wikipedia.org/wiki/IEEE_754-2008">IEEE Standard for Floating-Point Arithmetic in Wikipedia</a></li>
5960
5961 </ul>
5962 </li>
5963 </ul>
5964 <br>
5965 <hr class="greyline"><br>
5966
5967 <a name="misc_fns"></a>
5968 <b>
5969 miscellaneous functions:
5970 <br>&nbsp; exp, exp2, exp10, trunc_exp,
5971 <br>&nbsp; log, log2, log10, trunc_log,
5972 <br>&nbsp; pow, sqrt, square
5973 <br>&nbsp; floor, ceil, round
5974 </b>
5975 <br>
5976 <ul>
5977 <li>
5978 Apply a function to each element
5979 </li>
5980 <br>
5981 <li>
5982 Usage:
5983 <ul>
5984 <li>
5985 <i>matrix_type</i> B = misc_fn(A)
5986 </li>
5987 <li>
5988 <i>cube_type</i> B = misc_fn(A)
5989 </li>
5990 <li>
5991 A and B must have the same <i>matrix_type/cube_type</i>
5992 </li>
5993 <li>
5994 misc_fn(A) is one of:
5995 <ul>
5996
5997 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
5998 <tbody>
5999 <tr>
6000 <td style="vertical-align: top;">
6001 exp(A)<sup>&nbsp;</sup>
6002 </td>
6003 <td style="vertical-align: top;">
6004 &nbsp;
6005 </td>
6006 <td style="vertical-align: top;">
6007 base-e exponential, <i>e<sup>x</sup></i>
6008 </td>
6009 </tr>
6010 <tr>
6011 <td style="vertical-align: top;">
6012 exp2(A)<sup>&nbsp;</sup>
6013 </td>
6014 <td style="vertical-align: top;">
6015 &nbsp;
6016 </td>
6017 <td style="vertical-align: top;">
6018 base-2 exponential, <i>2<sup>x</sup></i>
6019 </td>
6020 </tr>
6021 <tr>
6022 <td style="vertical-align: top;">
6023 exp10(A)<sup>&nbsp;</sup>
6024 </td>
6025 <td style="vertical-align: top;">
6026 &nbsp;
6027 </td>
6028 <td style="vertical-align: top;">
6029 base-10 exponential, <i>10<sup>x</sup></i>
6030 </td>
6031 </tr>
6032 <tr>
6033 <td style="vertical-align: top;">
6034 trunc_exp(A)
6035 </td>
6036 <td style="vertical-align: top;">
6037 &nbsp;
6038 </td>
6039 <td style="vertical-align: top;">
6040 base-e exponential,
6041 truncated to avoid infinity
6042 <br>
6043 <font size=-1>(only for elements with type <i>float</i> or <i>double</i>)</font>
6044 </td>
6045 </tr>
6046 <tr>
6047 <td style="vertical-align: top;">
6048 log(A)<sub>&nbsp;</sub>
6049 </td>
6050 <td style="vertical-align: top;">
6051 &nbsp;
6052 </td>
6053 <td style="vertical-align: top;">
6054 natural log, <i>log<sub>e</sub>&nbsp;x</i>
6055 </td>
6056 </tr>
6057 <tr>
6058 <td style="vertical-align: top;">
6059 log2(A)<sub>&nbsp;</sub>
6060 </td>
6061 <td style="vertical-align: top;">
6062 &nbsp;
6063 </td>
6064 <td style="vertical-align: top;">
6065 base-2 log, <i>log<sub>2</sub>&nbsp;x</i>
6066 </td>
6067 </tr>
6068 <tr>
6069 <td style="vertical-align: top;">
6070 log10(A)<sub>&nbsp;</sub>
6071 </td>
6072 <td style="vertical-align: top;">
6073 &nbsp;
6074 </td>
6075 <td style="vertical-align: top;">
6076 base-10 log, <i>log<sub>10</sub>&nbsp;x</i>
6077 </td>
6078 </tr>
6079 <tr>
6080 <td style="vertical-align: top;">
6081 trunc_log(A)
6082 </td>
6083 <td style="vertical-align: top;">
6084 &nbsp;
6085 </td>
6086 <td style="vertical-align: top;">
6087 natural log,
6088 truncated to avoid &plusmn;infinity
6089 <br>
6090 <font size=-1>(only for elements with type <i>float</i> or <i>double</i>)</font>
6091 </td>
6092 </tr>
6093 <tr>
6094 <td style="vertical-align: top;">
6095 pow(A, p)<sup>&nbsp;</sup>
6096 </td>
6097 <td style="vertical-align: top;">
6098 &nbsp;
6099 </td>
6100 <td style="vertical-align: top;">
6101 raise to the power of p, <i>x<sup>p</sup></i>
6102 </td>
6103 </tr>
6104 <tr>
6105 <td style="vertical-align: top;">
6106 sqrt(A)<sup>&nbsp;</sup>
6107 </td>
6108 <td style="vertical-align: top;">
6109 &nbsp;
6110 </td>
6111 <td style="vertical-align: top;">
6112 square root, <i>x<sup>&frac12;</sup></i>
6113 </td>
6114 </tr>
6115 <tr>
6116 <td style="vertical-align: top;">
6117 square(A)<sup>&nbsp;</sup>
6118 </td>
6119 <td style="vertical-align: top;">
6120 &nbsp;
6121 </td>
6122 <td style="vertical-align: top;">
6123 square, <i>x<sup>2</sup></i>
6124 </td>
6125 </tr>
6126 <tr>
6127 <td style="vertical-align: top;">
6128 floor(A)
6129 </td>
6130 <td style="vertical-align: top;">
6131 &nbsp;
6132 </td>
6133 <td style="vertical-align: top;">
6134 largest integral value that is not greater than the input value
6135 </td>
6136 </tr>
6137 <tr>
6138 <td style="vertical-align: top;">
6139 ceil(A)
6140 </td>
6141 <td style="vertical-align: top;">
6142 &nbsp;
6143 </td>
6144 <td style="vertical-align: top;">
6145 smallest integral value that is not less than the input value
6146 </td>
6147 </tr>
6148 <tr>
6149 <td style="vertical-align: top;">
6150 round(A)
6151 </td>
6152 <td style="vertical-align: top;">
6153 &nbsp;
6154 </td>
6155 <td style="vertical-align: top;">
6156 round to nearest integer, away from zero
6157 </td>
6158 </tr>
6159 </tbody>
6160 </table>
6161
6162
6163 </ul>
6164 </li>
6165
6166 </ul>
6167 </li>
6168 <br>
6169 <li>
6170 Examples:
6171 <ul>
6172 <pre>
6173 mat A = randu&lt;mat&gt;(5,5);
6174 mat B = exp(A);
6175 </pre>
6176 </ul>
6177 </li>
6178 </ul>
6179 <br>
6180 <hr class="greyline"><br>
6181
6182 <a name="trig_fns"></a>
6183 <b>trigonometric functions (cos, sin, tan, ...)</b>
6184 <ul>
6185 <li>
6186 Apply a trigonometric function to each element
6187 </li>
6188 <br>
6189 <li>
6190 Usage:
6191 <ul>
6192 <li>
6193 <i>matrix_type</i> Y = trig_fn(X)
6194 </li>
6195 <li>
6196 <i>cube_type</i> Y = trig_fn(X)
6197 </li>
6198 <li>
6199 X and Y must have the same <i>matrix_type/cube_type</i>
6200 </li>
6201 <li>
6202 trig_fn is one of:
6203 <ul>
6204 <li>
6205 cos family: <i>cos</i>, <i>acos</i>, <i>cosh</i>, <i>acosh</i>
6206 </li>
6207 <li>
6208 sin family: <i>sin</i>, <i>asin</i>, <i>sinh</i>, <i>asinh</i>
6209 </li>
6210 <li>
6211 tan family: <i>tan</i>, <i>atan</i>, <i>tanh</i>, <i>atanh</i>
6212 </li>
6213 </ul>
6214 </li>
6215
6216 </ul>
6217 </li>
6218 <br>
6219 <li>
6220 Examples:
6221 <ul>
6222 <pre>
6223 mat X = randu&lt;mat&gt;(5,5);
6224 mat Y = cos(X);
6225 </pre>
6226 </ul>
6227 </li>
6228 </ul>
6229 <br>
6230 <hr class="greyline">
6231
6232 <hr class="greyline">
6233 <br>
6234 <br>
6235 <font size=+1><b>Scalar Valued Functions of Vectors/Matrices/Cubes</b></font>
6236 <br>
6237 <br>
6238 <hr class="greyline">
6239 <br>
6240
6241 <a name="accu"></a>
6242 <b>accu(mat)</b>
6243 <br><b>accu(cube)</b>
6244 <ul>
6245 <li>
6246 Accumulate (sum) all elements
6247 </li>
6248 <br>
6249 <li>
6250 Examples:
6251 <ul>
6252 <pre>
6253 mat A = randu&lt;mat&gt;(5,5);
6254 double x = accu(A);
6255
6256 mat B = randu&lt;mat&gt;(5,5);
6257 double y = accu(A % B);
6258
6259 // operator % performs element-wise multiplication,
6260 // hence accu(A % B) is a "multiply-and-accumulate"
6261 // operation
6262 </pre>
6263 </ul>
6264 </li>
6265 <br>
6266 <li>
6267 See also:
6268 <ul>
6269 <li><a href="#sum">sum()</a></li>
6270 <li><a href="#cumsum">cumsum()</a></li>
6271 <li><a href="#as_scalar">as_scalar()</a></li>
6272 <li><a href="#trace">trace()</a></li>
6273 </ul>
6274 </li>
6275 <br>
6276 </ul>
6277 <hr class="greyline"><br>
6278
6279 <a name="as_scalar"></a>
6280 <b>as_scalar(expression)</b>
6281 <ul>
6282 <li>
6283 Evaluate an expression that results in a 1x1 matrix,
6284 followed by converting the 1x1 matrix to a pure scalar
6285 </li>
6286 <br>
6287 <li>
6288 If a binary or trinary expression is given (ie. 2 or 3 terms),
6289 the function will try to exploit the fact that the result is a 1x1 matrix
6290 by using optimised expression evaluations
6291 </li>
6292 <br>
6293 <li>
6294 Examples:
6295 <ul>
6296 <pre>
6297 rowvec r = randu&lt;rowvec&gt;(5);
6298 colvec q = randu&lt;colvec&gt;(5);
6299 mat X = randu&lt;mat&gt;(5,5);
6300
6301 // examples of some expressions
6302 // for which optimised implementations exist
6303
6304 double a = as_scalar(r*q);
6305 double b = as_scalar(r*X*q);
6306 double c = as_scalar(r*diagmat(X)*q);
6307 double d = as_scalar(r*inv(diagmat(X))*q);
6308 </pre>
6309 </ul>
6310 </li>
6311 <br>
6312 <li>
6313 See also:
6314 <ul>
6315 <li><a href="#accu">accu()</a></li>
6316 <li><a href="#conv_to">conv_to()</a></li>
6317 <li><a href="#dot">dot()</a></li>
6318 <li><a href="#norm">norm()</a></li>
6319 <li><a href="#reshape">reshape()</a></li>
6320 <li><a href="#resize">resize()</a></li>
6321 <li><a href="#trace">trace()</a></li>
6322 </ul>
6323 </li>
6324 <br>
6325 </ul>
6326 <hr class="greyline"><br>
6327
6328 <a name="det"></a>
6329 <b>det(A, </b><i>slow=false</i><b>)</b>
6330 <ul>
6331 <li>
6332 Determinant of square matrix <i>A</i>
6333 </li>
6334 <br>
6335 <li>
6336 If <i>A</i> is not square, a <i>std::logic_error</i> exception is thrown
6337 </li>
6338 <br>
6339 <li>
6340 <b>Caveat</b>: for large matrices you may want to use <a href="#log_det">log_det()</a> instead
6341 </li>
6342 <br>
6343 <li>
6344 For matrix sizes &le; 4x4, a fast algorithm is used by default.
6345 In rare instances, the fast algorithm might be less precise than the standard algorithm.
6346 To force the use of the standard algorithm, set the <i>slow</i> argument to <i>true</i>
6347 </li>
6348 <br>
6349 <li>
6350 Examples:
6351 <ul>
6352 <pre>
6353 mat A = randu&lt;mat&gt;(5,5);
6354 double x = det(A);
6355
6356 mat44 B = randu&lt;mat&gt;(4,4);
6357
6358 double y = det(B); // use fast algorithm by default
6359 double z = det(B, true); // use slow algorithm
6360 </pre>
6361 </ul>
6362 </li>
6363 <br>
6364 <li>
6365 See also:
6366 <ul>
6367 <li><a href="#log_det">log_det()</a></li>
6368 <li><a href="http://mathworld.wolfram.com/Determinant.html">determinant in MathWorld</a></li>
6369 <li><a href="http://en.wikipedia.org/wiki/Determinant">determinant in Wikipedia</a></li>
6370 </ul>
6371 </li>
6372 <br>
6373 </ul>
6374 <hr class="greyline"><br>
6375
6376 <a name="dot"></a>
6377 <b>dot(A, B)</b>
6378 <br><b>cdot(A, B)</b>
6379 <br><b>norm_dot(A, B)</b>
6380 <ul>
6381 <li>
6382 <i>dot(A,B)</i>: dot product of <i>A</i> and <i>B</i>, under the assumption that <i>A</i> and <i>B</i> are vectors with the same number of elements
6383 </li>
6384 <br>
6385 <li>
6386 <i>cdot(A,B)</i>: as per <i>dot(A,B)</i>, but the complex conjugate of <i>A</i> is used
6387 </li>
6388 <br>
6389 <li>
6390 <i>norm_dot(A,B)</i>: normalised version of <i>dot(A,B)</i>
6391 </li>
6392 <br>
6393 <li>
6394 Examples:
6395 <ul>
6396 <pre>
6397 vec a = randu&lt;vec&gt;(10);
6398 vec b = randu&lt;vec&gt;(10);
6399
6400 double x = dot(a,b);
6401 </pre>
6402 </ul>
6403 </li>
6404 <br>
6405 <li>See also:
6406 <ul>
6407 <li><a href="#as_scalar">as_scalar()</a></li>
6408 <li><a href="#cross">cross()</a></li>
6409 <li><a href="#conj">conj()</a></li>
6410 <li><a href="#norm">norm()</a></li>
6411 </ul>
6412 </li>
6413 <br>
6414 </ul>
6415 <hr class="greyline"><br>
6416
6417 <a name="log_det"></a>
6418 <b>log_det(val, sign, A)</b>
6419 <ul>
6420 <li>
6421 Log determinant of square matrix <i>A</i>, such that the determinant is equal to <i>exp(val)*sign</i>
6422 </li>
6423 <br>
6424 <li>
6425 If <i>A</i> is not square, a <i>std::logic_error</i> exception is thrown
6426 </li>
6427 <br>
6428 <li>
6429 Examples:
6430 <ul>
6431 <pre>
6432 mat A = randu&lt;mat&gt;(5,5);
6433
6434 double val;
6435 double sign;
6436
6437 log_det(val, sign, A);
6438 </pre>
6439 </ul>
6440 </li>
6441 <br>
6442 <li>
6443 See also:
6444 <ul>
6445 <li><a href="#det">det()</a></li>
6446 <li><a href="http://mathworld.wolfram.com/Determinant.html">determinant in MathWorld</a></li>
6447 <li><a href="http://en.wikipedia.org/wiki/Determinant">determinant in Wikipedia</a></li>
6448 </ul>
6449 </li>
6450 <br>
6451 </ul>
6452 <hr class="greyline"><br>
6453
6454 <a name="norm"></a>
6455 <b>
6456 norm(X, p)
6457 </b>
6458 <ul>
6459 <li>
6460 Compute the <i>p</i>-norm of <i>X</i>, where <i>X</i> can be a vector or a matrix
6461 </li>
6462 <br>
6463 <li>
6464 For vectors, <i>p</i> is an integer &ge;1, or one of: "-inf", "inf", "fro"
6465 </li>
6466 <br>
6467 <li>
6468 For matrices, <i>p</i> is one of: 1, 2, "inf", "fro"; the calculated norm is the <i>induced norm</i> (not entrywise norm)
6469 </li>
6470 <br>
6471 <li>
6472 "-inf" is the minimum norm, "inf" is the maximum norm, while "fro" is the Frobenius norm
6473 </li>
6474 <br>
6475 <li>
6476 To obtain the zero norm or Hamming norm (ie. the number of non-zero elements),
6477 you may want to use this expression: <a href="#accu">accu</a>(X&nbsp;!=&nbsp;0).
6478 </li>
6479 <br>
6480 <li>
6481 Examples:
6482 <ul>
6483 <pre>
6484 vec q = randu&lt;vec&gt;(5);
6485 double x = norm(q, 2);
6486 double y = norm(q, "inf");
6487 </pre>
6488 </ul>
6489 </li>
6490 <br>
6491 <li>
6492 See also:
6493 <ul>
6494 <li><a href="#dot">dot()</a></li>
6495 <li><a href="http://en.wikipedia.org/wiki/Norm_(mathematics)">Vector Norm in Wikipedia</a></li>
6496 <li><a href="http://mathworld.wolfram.com/VectorNorm.html">Vector Norm in MathWorld</a></li>
6497 <li><a href="http://en.wikipedia.org/wiki/Matrix_norm">Matrix Norm in Wikipedia</a></li>
6498 <li><a href="http://mathworld.wolfram.com/MatrixNorm.html">Matrix Norm in MathWorld</a></li>
6499 </ul>
6500 </li>
6501 <br>
6502 </ul>
6503 <hr class="greyline"><br>
6504
6505 <a name="rank"></a>
6506 <b>rank(X, tolerance = default)</b>
6507
6508 <ul>
6509 <li>Returns the rank of matrix <i>X</i></li><br>
6510 <li>Any singular values less than default tolerance are treated as zero</li><br>
6511 <li>The default tolerance is <i>max(X.n_rows, X.n_cols)*eps(sigma)</i>,
6512 where <i>sigma</i> is the largest singular value of <i>X</i>
6513 </li><br>
6514 <li>The computation is based on singular value decomposition;
6515 if the decomposition fails, a <i>std::runtime_error</i> exception is thrown</li><br>
6516 <li>
6517 Examples:
6518 <ul>
6519 <pre>
6520 mat A = randu&lt;mat&gt;(4,5);
6521 uword r = rank(A);
6522 </pre>
6523 </ul>
6524 </li>
6525 <br>
6526 <li>
6527 See also:
6528 <ul>
6529 <li><a href="#eps">eps()</a></li>
6530 <li><a href="http://mathworld.wolfram.com/MatrixRank.html">Rank in MathWorld</a></li>
6531 <li><a href="http://en.wikipedia.org/wiki/Rank_(linear_algebra)">Rank in Wikipedia</a></li>
6532 </ul>
6533 </li>
6534 </ul>
6535 <br>
6536 <hr class="greyline"><br>
6537
6538 <a name="trace"></a>
6539 <b>trace(X)</b>
6540 <ul>
6541 <li>
6542 Sum of the diagonal elements of square matrix <i>X</i>
6543 </li>
6544 <br>
6545 <li>
6546 If <i>X</i> is an expression,
6547 the function will try to use optimised expression evaluations to calculate only the diagonal elements
6548 </li>
6549 <br>
6550 <li>
6551 A <i>std::logic_error</i> exception is thrown if <i>X</i> does not evaluate to a square matrix
6552 </li>
6553 <br>
6554 <li>
6555 Examples:
6556 <ul>
6557 <pre>
6558 mat A = randu&lt;mat&gt;(5,5);
6559 double x = trace(A);
6560 </pre>
6561 </ul>
6562 </li>
6563 <br>
6564 <li>
6565 See also:
6566 <ul>
6567 <li><a href="#accu">accu()</a></li>
6568 <li><a href="#as_scalar">as_scalar()</a></li>
6569 <li><a href="#diag">.diag()</a></li>
6570 <li><a href="#diagvec">diagvec()</a></li>
6571 <li><a href="#sum">sum()</a></li>
6572 </ul>
6573 </li>
6574 <br>
6575 </ul>
6576 <hr class="greyline">
6577
6578 <hr class="greyline">
6579 <br>
6580 <br>
6581 <font size=+1><b>Scalar/Vector Valued Functions of Vectors/Matrices</b></font>
6582 <br>
6583 <br>
6584 <hr class="greyline">
6585 <br>
6586
6587 <a name="diagvec"></a>
6588 <b>diagvec(A, k=0)</b>
6589 <ul>
6590 <li>
6591 Extract the <i>k</i>-th diagonal from matrix <i>A</i>
6592 </li>
6593 <br>
6594 <li>
6595 The argument <i>k</i> is optional -- by default the main diagonal is extracted (<i>k=0</i>)
6596 </li>
6597 <br>
6598 <li>For <i>k &gt; 0</i>, the <i>k</i>-th super-diagonal is extracted (top-right corner)</li>
6599 <br>
6600 <li>For <i>k &lt; 0</i>, the <i>k</i>-th sub-diagonal is extracted (bottom-left corner)</li>
6601 <br>
6602 <li>
6603 An extracted a diagonal is interpreted as a column vector
6604 </li>
6605 <br>
6606 <li>
6607 Examples:
6608 <ul>
6609 <pre>
6610 mat A = randu&lt;mat&gt;(5,5);
6611 vec d = diagvec(A);
6612 </pre>
6613 </ul>
6614 </li>
6615 <br>
6616 <li>See also:
6617 <ul>
6618 <li><a href="#diag">.diag()</a></li>
6619 <li><a href="#diagmat">diagmat()</a></li>
6620 <li><a href="#trace">trace()</a></li>
6621 </ul>
6622 </li>
6623 <br>
6624 </ul>
6625 <hr class="greyline">
6626 <br>
6627
6628 <a name="min_and_max"></a>
6629 <b>min(mat, dim=0)</b>
6630 <br><b>min(rowvec)</b>
6631 <br><b>min(colvec)</b>
6632 <br>
6633 <br><b>max(mat, dim=0)</b>
6634 <br><b>max(rowvec)</b>
6635 <br><b>max(colvec)</b>
6636 <ul>
6637 <li>
6638 For a matrix argument, return the extremum value for each column (dim=0), or each row (dim=1)
6639 </li>
6640 <br>
6641 <li>
6642 For a vector argument, return the extremum value
6643 </li>
6644 <br>
6645 <li>
6646 Examples:
6647 <ul>
6648 <pre>
6649 colvec q = randu&lt;colvec&gt;(10,1);
6650 double x = max(q);
6651
6652 mat A = randu&lt;mat&gt;(10,10);
6653 rowvec b = max(A);
6654
6655 // same result as max(A)
6656 // the 0 explicitly indicates
6657 // "traverse across rows"
6658 rowvec c = max(A,0);
6659
6660 // the 1 explicitly indicates
6661 // "traverse across columns"
6662 colvec d = max(A,1);
6663
6664 // find the overall maximum value
6665 double y = max(max(A));
6666 </pre>
6667 </ul>
6668 </li>
6669 <br>
6670 <li>
6671 See also:
6672 <ul>
6673 <li><a href="#min_and_max_member">.min() &amp; .max()</a> (member functions of Mat and Cube)</li>
6674 <li><a href="#running_stat">running_stat</a></li>
6675 <li><a href="#running_stat_vec">running_stat_vec</a></li>
6676 </ul>
6677 </li>
6678 <br>
6679 </ul>
6680 <hr class="greyline"><br>
6681
6682 <a name="prod"></a>
6683 <b>prod(mat, dim=0)</b>
6684 <br><b>prod(rowvec)</b>
6685 <br><b>prod(colvec)</b>
6686 <ul>
6687 <li>
6688 For a matrix argument, return the product of elements in each column (dim=0), or each row (dim=1)
6689 </li>
6690 <br>
6691 <li>
6692 For a vector argument, return the product of all elements
6693 </li>
6694 <br>
6695 <li>
6696 Examples:
6697 <ul>
6698 <pre>
6699 colvec q = randu&lt;colvec&gt;(10,1);
6700 double x = prod(q);
6701
6702 mat A = randu&lt;mat&gt;(10,10);
6703 rowvec b = prod(A);
6704
6705 // same result as prod(A)
6706 // the 0 explicitly indicates
6707 // "traverse across rows"
6708 rowvec c = prod(A,0);
6709
6710 // the 1 explicitly indicates
6711 // "traverse across columns"
6712 colvec d = prod(A,1);
6713
6714 // find the overall product
6715 double y = prod(prod(A));
6716 </pre>
6717 </ul>
6718 </li>
6719 <br>
6720 <li>
6721 See also:
6722 <ul>
6723 <li><a href="#schur_product">Schur product</a></li>
6724 </ul>
6725 </li>
6726 </ul>
6727 <br>
6728 <hr class="greyline"><br>
6729
6730
6731 <a name="sum"></a>
6732 <b>sum(mat, dim=0)</b>
6733 <br><b>sum(rowvec)</b>
6734 <br><b>sum(colvec)</b>
6735 <ul>
6736 <li>
6737 For a matrix argument, return the sum of elements in each column (dim=0), or each row (dim=1)
6738 </li>
6739 <br>
6740 <li>
6741 For a vector argument, return the sum of all elements
6742 </li>
6743 <br>
6744 <li>
6745 To get a sum of all the elements regardless of the argument type (ie. matrix or vector),
6746 you may wish to use <a href="#accu">accu()</a> instead
6747 </li>
6748 <br>
6749 <li>
6750 Examples:
6751 <ul>
6752 <pre>
6753 colvec q = randu&lt;colvec&gt;(10,1);
6754 double x = sum(q);
6755
6756 mat A = randu&lt;mat&gt;(10,10);
6757 rowvec b = sum(A);
6758
6759 // same result as sum(A)
6760 // the 0 explicitly indicates
6761 // "traverse across rows"
6762 rowvec c = sum(A,0);
6763
6764 // the 1 explicitly indicates
6765 // "traverse across columns"
6766 colvec d = sum(A,1);
6767
6768 // find the overall sum
6769 double y = sum(sum(A));
6770 </pre>
6771 </ul>
6772 </li>
6773 <br>
6774 <li>
6775 See also:
6776 <ul>
6777 <li><a href="#accu">accu()</a></li>
6778 <li><a href="#cumsum">cumsum()</a></li>
6779 <li><a href="#trace">trace()</a></li>
6780 <li><a href="#as_scalar">as_scalar()</a></li>
6781 </ul>
6782 </li>
6783 <br>
6784 </ul>
6785 <hr class="greyline"><br>
6786
6787
6788 <a name="stats_fns"></a>
6789 <b>statistics: mean, median, stddev, var</b>
6790
6791 <ul>
6792 <table style="text-align: left;" border="0" cellpadding="2" cellspacing="2">
6793 <tbody>
6794 <tr>
6795 <td style="vertical-align: top;">
6796 <b>mean(mat, dim=0)</b>
6797 <br><b>mean(colvec)</b>
6798 <br><b>mean(rowvec)</b>
6799 <br>
6800 <br>
6801 </td>
6802 <td style="vertical-align: top;">
6803 &nbsp;
6804 </td>
6805 <td style="vertical-align: top;">
6806 mean (average value)
6807 </td>
6808 </tr>
6809 <tr>
6810 <td style="vertical-align: top;">
6811 <b>median(mat, dim=0)</b>
6812 <br><b>median(colvec)</b>
6813 <br><b>median(rowvec)</b>
6814 <br>
6815 <br>
6816 </td>
6817 <td style="vertical-align: top;">
6818 &nbsp;
6819 </td>
6820 <td style="vertical-align: top;">
6821 median
6822 </td>
6823 </tr>
6824 <tr>
6825 <td style="vertical-align: top;">
6826 <b>stddev(mat, norm_type=0, dim=0)</b>
6827 <br><b>stddev(colvec, norm_type=0)</b>
6828 <br><b>stddev(rowvec, norm_type=0)</b>
6829 <br>
6830 <br>
6831 </td>
6832 <td style="vertical-align: top;">
6833 &nbsp;
6834 </td>
6835 <td style="vertical-align: top;">
6836 standard deviation
6837 </td>
6838 </tr>
6839 <tr>
6840 <td style="vertical-align: top;">
6841 <b>var(mat, norm_type=0, dim=0)</b>
6842 <br><b>var(colvec, norm_type=0)</b>
6843 <br><b>var(rowvec, norm_type=0)</b>
6844 <br>
6845 <br>
6846 </td>
6847 <td style="vertical-align: top;">
6848 &nbsp;
6849 </td>
6850 <td style="vertical-align: top;">
6851 variance
6852 </td>
6853 </tr>
6854 </tbody>
6855 </table>
6856 <br>
6857 <li>
6858 For a matrix argument, find a particular statistic for each column (<i>dim=0</i>), or each row (<i>dim=1</i>)
6859 </li>
6860 <br>
6861 <li>
6862 For a vector argument, return a particular statistic calculated using all the elements of the vector
6863 </li>
6864 <br>
6865 <li>
6866 For the var() and stddev() functions, the default <i>norm_type=0</i> performs normalisation using <i>N-1</i> (where <i>N</i> is the number of samples),
6867 providing the best unbiased estimator.
6868 Using <i>norm_type=1</i> causes normalisation to be done using <i>N</i>, which provides the second moment around the mean
6869 </li>
6870 <br>
6871 <li>
6872 Examples:
6873 <ul>
6874 <pre>
6875 mat A = randu&lt;mat&gt;(5,5);
6876 mat B = mean(A);
6877 mat C = var(A);
6878 double m = mean(mean(A));
6879
6880 vec q = randu&lt;vec&gt;(5);
6881 double v = var(q);
6882 </pre>
6883 </ul>
6884 </li>
6885 <br>
6886 <li>
6887 See also:
6888 <ul>
6889 <li><a href="#cov">cov()</a></li>
6890 <li><a href="#cor">cor()</a></li>
6891 <li><a href="#running_stat">running_stat</a></li>
6892 <li><a href="#running_stat_vec">running_stat_vec</a></li>
6893 <li><a href="#hist">hist()</a></li>
6894 <li><a href="#histc">histc()</a></li>
6895 </ul>
6896 </li>
6897 </ul>
6898 <br>
6899 <hr class="greyline">
6900
6901 <hr class="greyline">
6902 <br>
6903 <br>
6904 <font size=+1><b>Vector/Matrix/Cube Valued Functions of Vectors/Matrices/Cubes</b></font>
6905 <br>
6906 <br>
6907 <hr class="greyline">
6908 <br>
6909
6910 <a name="conv"></a>
6911 <b>
6912 C = conv(A, B)
6913 </b>
6914 <ul>
6915 <li>
6916 Convolution of vectors <i>A</i> and <i>B</i>
6917 </li>
6918 <br>
6919 <li>
6920 If <i>A</i> and <i>B</i> are polynomial coefficient vectors, convolving them is equivalent to multiplying the two polynomials
6921 </li>
6922 <br>
6923 <li>
6924 The convolution operation is also equivalent to FIR filtering
6925 </li>
6926 <br>
6927 <li>
6928 The orientation of the result vector is the same as the orientation of <i>A</i> (ie. column or row vector)
6929 </li>
6930 <br>
6931 <li>
6932 Examples:
6933 <ul>
6934 <pre>
6935 vec A = randu&lt;vec&gt;(128) - 0.5;
6936 vec B = randu&lt;vec&gt;(128) - 0.5;
6937
6938 vec C = conv(A,B);
6939 </pre>
6940 </ul>
6941 </li>
6942 <br>
6943 <li>
6944 See also:
6945 <ul>
6946 <li><a href="#fft">fft()</a></li>
6947 <li><a href="#cor">cor()</a></li>
6948 <li><a href="http://mathworld.wolfram.com/Convolution.html">Convolution in MathWorld</a></li>
6949 <li><a href="http://en.wikipedia.org/wiki/Convolution">Convolution in Wikipedia</a></li>
6950 <li><a href="http://en.wikipedia.org/wiki/Finite_impulse_response">FIR filter in Wikipedia</a></li>
6951 </ul>
6952 </li>
6953 </ul>
6954 <br>
6955 <hr class="greyline"><br>
6956
6957 <a name="conv_to"></a>
6958 <b>
6959 conv_to&lt;<i>type</i>&gt;::from(X)
6960 </b>
6961 <ul>
6962 <li>
6963 A form of casting
6964 </li>
6965 <br>
6966 <li>
6967 Convert between matrix/vector types (eg. <i>mat</i> to <i>fmat</i>), as well as cube types (eg. <i>cube</i> to <i>fcube</i>)
6968 </li>
6969 <br>
6970 <li>
6971 Conversion between <i>std::vector</i> and Armadillo matrices/vectors is also possible
6972 </li>
6973 <br>
6974 <li>
6975 Conversion of a <i>mat</i> object into <i>colvec</i>, <i>rowvec</i> or <i>std::vector</i> is possible if the object can be interpreted as a vector
6976 </li>
6977 <br>
6978 <li>
6979 Examples:
6980 <ul>
6981 <pre>
6982 mat A = randu&lt;mat&gt;(5,5);
6983 fmat B = conv_to&lt;fmat&gt;::from(A);
6984
6985 typedef std::vector&lt;double&gt; stdvec;
6986
6987 stdvec x(3);
6988 x[0] = 0.0; x[1] = 1.0; x[2] = 2.0;
6989
6990 colvec y = conv_to&lt; colvec &gt;::from(x);
6991 stdvec z = conv_to&lt; stdvec &gt;::from(y);
6992 </pre>
6993 </ul>
6994 </li>
6995 <br>
6996 <li>
6997 See also:
6998 <ul>
6999 <li><a href="#as_scalar">as_scalar()</a></li>
7000 <li><a href="#reshape">reshape()</a></li>
7001 <li><a href="#resize">resize()</a></li>
7002 <li><a href="#adv_constructors_mat">advanced constructors (matrices)</a></li>
7003 <li><a href="#adv_constructors_cube">advanced constructors (cubes)</a></li>
7004 </ul>
7005 </li>
7006 <br>
7007 </ul>
7008 <hr class="greyline"><br>
7009
7010 <a name="conj"></a>
7011 <b>conj(cx_mat)</b>
7012 <br><b>conj(cx_cube)</b>
7013 <ul>
7014 <li>
7015 Obtain the complex conjugate of each element in a complex matrix/cube
7016 </li>
7017 <br>
7018 <li>
7019 Examples:
7020 <ul>
7021 <pre>
7022 cx_mat X = randu&lt;cx_mat&gt;(5,5);
7023 cx_mat Y = conj(X);
7024 </pre>
7025 </ul>
7026 </li>
7027 <br>
7028 <li>See also:
7029 <ul>
7030 <li><a href="#trans">trans()</a></li>
7031 </ul>
7032 </li>
7033 <br>
7034 </ul>
7035 <hr class="greyline"><br>
7036
7037 <a name="cor"></a>
7038 <b>cor(X, Y, norm_type=0)</b>
7039 <br><b>cor(X, norm_type=0)</b>
7040 <ul>
7041 <li>
7042 For two matrix arguments <i>X</i> and <i>Y</i>,
7043 if each row of <i>X</i> and <i>Y</i> is an observation and each column is a variable,
7044 the <i>(i,j)</i>-th entry of <i>cor(X,Y)</i> is the correlation coefficient between the <i>i</i>-th variable in <i>X</i> and the <i>j</i>-th variable in <i>Y</i>
7045 </li>
7046 <br>
7047 <li>
7048 For vector arguments, the type of vector is ignored and each element in the vector is treated as an observation
7049 </li>
7050 <br>
7051 <li>
7052 For matrices, <i>X</i> and <i>Y</i> must have the same dimensions
7053 </li>
7054 <br>
7055 <li>
7056 For vectors, <i>X</i> and <i>Y</i> must have the same number of elements
7057 </li>
7058 <br>
7059 <li>
7060 <i>cor(X)</i> is equivalent to <i>cor(X, X)</i>, also called autocorrelation
7061 </li>
7062 <br>
7063 <li>
7064 The default <i>norm_type=0</i> performs normalisation of the correlation matrix using <i>N-1</i> (where <i>N</i> is the number of observations).
7065 Using <i>norm_type=1</i> causes normalisation to be done using <i>N</i>
7066 </li>
7067 <br>
7068 <li>
7069 Examples:
7070 <ul>
7071 <pre>
7072 mat X = randu&lt;mat&gt;(4,5);
7073 mat Y = randu&lt;mat&gt;(4,5);
7074
7075 mat R = cor(X,Y);
7076 </pre>
7077 </ul>
7078 </li>
7079 <br>
7080 <li>
7081 See also:
7082 <ul>
7083 <li><a href="http://mathworld.wolfram.com/Correlation.html">Correlation in MathWorld</a></li>
7084 <li><a href="http://mathworld.wolfram.com/Autocorrelation.html">Autocorrelation in MathWorld</a></li>
7085 <li><a href="#cov">cov()</a></li>
7086 <li><a href="#conv">conv()</a></li>
7087 </ul>
7088 </li>
7089 </ul>
7090 <br>
7091 <hr class="greyline"><br>
7092
7093 <a name="cov"></a>
7094 <b>cov(X, Y, norm_type=0)</b>
7095 <br><b>cov(X, norm_type=0)</b>
7096 <ul>
7097 <li>
7098 For two matrix arguments <i>X</i> and <i>Y</i>,
7099 if each row of <i>X</i> and <i>Y</i> is an observation and each column is a variable,
7100 the <i>(i,j)</i>-th entry of <i>cov(X,Y)</i> is the covariance between the <i>i</i>-th variable in <i>X</i> and the <i>j</i>-th variable in <i>Y</i>
7101 </li>
7102 <br>
7103 <li>
7104 For vector arguments, the type of vector is ignored and each element in the vector is treated as an observation
7105 </li>
7106 <br>
7107 <li>
7108 For matrices, <i>X</i> and <i>Y</i> must have the same dimensions
7109 </li>
7110 <br>
7111 <li>
7112 For vectors, <i>X</i> and <i>Y</i> must have the same number of elements
7113 </li>
7114 <br>
7115 <li>
7116 <i>cov(X)</i> is equivalent to <i>cov(X, X)</i>
7117 </li>
7118 <br>
7119 <li>
7120 The default <i>norm_type=0</i> performs normalisation using <i>N-1</i> (where <i>N</i> is the number of observations),
7121 providing the best unbiased estimation of the covariance matrix (if the observations are from a normal distribution).
7122 Using <i>norm_type=1</i> causes normalisation to be done using <i>N</i>, which provides the second moment matrix of the observations about their mean
7123 </li>
7124 <br>
7125 <li>
7126 Examples:
7127 <ul>
7128 <pre>
7129 mat X = randu&lt;mat&gt;(4,5);
7130 mat Y = randu&lt;mat&gt;(4,5);
7131
7132 mat C = cov(X,Y);
7133 </pre>
7134 </ul>
7135 </li>
7136 <br>
7137 <li>
7138 See also:
7139 <ul>
7140 <li><a href="#running_stat_vec">running_stat_vec</a></li>
7141 <li><a href="#stats_fns">statistics functions</a></li>
7142 <li><a href="http://mathworld.wolfram.com/Covariance.html">Covariance in MathWorld</a></li>
7143 <li><a href="#cor">cor()</a></li>
7144 </ul>
7145 </li>
7146 </ul>
7147 <br>
7148 <hr class="greyline"><br>
7149
7150 <a name="cross"></a>
7151 <b>cross(A, B)</b>
7152 <ul>
7153 <li>
7154 Calculate the cross product between A and B, under the assumption that A and B are 3 dimensional vectors
7155 </li>
7156 <br>
7157 <li>
7158 Examples:
7159 <ul>
7160 <pre>
7161 vec a = randu&lt;vec&gt;(3);
7162 vec b = randu&lt;vec&gt;(3);
7163
7164 vec c = cross(a,b);
7165 </pre>
7166 </ul>
7167 </li>
7168 <br>
7169 <li>
7170 See also:
7171 <ul>
7172 <li><a href="#dot">dot()</a></li>
7173 <li><a href="http://en.wikipedia.org/wiki/Cross_product">Cross product in Wikipedia</a></li>
7174 <li><a href="http://mathworld.wolfram.com/CrossProduct.html">Cross product in MathWorld</a></li>
7175 </ul>
7176 </li>
7177 </ul>
7178 <br>
7179 <hr class="greyline"><br>
7180
7181 <a name="cumsum"></a>
7182 <b>cumsum(mat, dim=0)</b>
7183 <br><b>cumsum(rowvec)</b>
7184 <br><b>cumsum(colvec)</b>
7185 <ul>
7186 <li>
7187 For a matrix argument, return a matrix containing the cumulative sum of elements in each column (dim=0, the default), or each row (dim=1)
7188 </li>
7189 <br>
7190 <li>
7191 For a vector argument, return a vector of the same orientation, containing the cumulative sum of elements
7192 </li>
7193 <br>
7194 <li>
7195 Examples:
7196 <ul>
7197 <pre>
7198 mat A = randu&lt;mat&gt;(5,5);
7199 mat B = cumsum(A);
7200
7201 vec x = randu&lt;vec&gt;(10);
7202 vec y = cumsum(x);
7203 </pre>
7204 </ul>
7205 </li>
7206 <br>
7207 <li>
7208 See also:
7209 <ul>
7210 <li><a href="#accu">accu()</a></li>
7211 <li><a href="#sum">sum()</a></li>
7212 </ul>
7213 </li>
7214 <br>
7215 </ul>
7216 <hr class="greyline"><br>
7217
7218 <a name="diagmat"></a>
7219 <b>diagmat(X)</b>
7220 <ul>
7221 <li>
7222 Interpret a matrix or vector <i>X</i> as a diagonal matrix
7223 </li>
7224 <br>
7225 <li>
7226 If <i>X</i> is a matrix, the matrix must be square; the main diagonal is copied and all other elements in the generated matrix are set to zero
7227 </li>
7228 <br>
7229 <li>
7230 If <i>X</i> is a vector, elements of the vector are placed on the main diagonal in the generated matrix and all other elements are set to zero
7231 </li>
7232 <br>
7233 <li>
7234 Examples:
7235 <ul>
7236 <pre>
7237 mat A = randu&lt;mat&gt;(5,5);
7238 mat B = diagmat(A);
7239 mat C = A*diagmat(A);
7240
7241 rowvec q = randu&lt;rowvec&gt;(5);
7242 colvec r = randu&lt;colvec&gt;(5);
7243 mat X = diagmat(q)*diagmat(r);
7244 </pre>
7245 </ul>
7246 </li>
7247 <br>
7248 <li>
7249 See also:
7250 <ul>
7251 <li><a href="#diagvec">diagvec()</a></li>
7252 <li><a href="#diag">.diag()</a></li>
7253 <li><a href="#trimat">trimatu() / trimatl()</a></li>
7254 <li><a href="#symmat">symmatu() / symmatl()</a></li>
7255 <li><a href="#reshape">reshape()</a></li>
7256 </ul>
7257 </li>
7258 <br>
7259 </ul>
7260 <hr class="greyline">
7261 <br>
7262
7263 <a name="find"></a>
7264 <b>find(X, k=0, s="first")</b>
7265 <ul>
7266 <li>Return a column vector of the indices of non-zero elements of <i>X</i></li>
7267 <br>
7268 <li>The output vector must have the type <a href="#Col">uvec</a> or <a href="#Mat">umat</a>
7269 (ie. the indices are stored as unsigned integers of type <a href="#uword">uword</a>)
7270 </li>
7271 <br>
7272 <li>
7273 The input matrix <i>X</i> is interpreted as a vector, with column-by-column ordering of the elements of <i>X</i>
7274 </li>
7275 <br>
7276 <li>Relational operators can be used instead of <i>X</i>, eg.&nbsp;<i>A&nbsp;&gt;&nbsp;0.5</i>
7277 </li>
7278 <br>
7279 <li>If <i>k=0</i> (default), return the indices of all non-zero elements, otherwise return at most <i>k</i> of their indices</li>
7280 <br>
7281 <li>If <i>s="first"</i> (default), return at most the first <i>k</i> indices of the non-zero elements
7282 </li>
7283 <br>
7284 <li>If <i>s="last"</i>, return at most the last <i>k</i> indices of the non-zero elements
7285 </li>
7286 <br>
7287 <li>
7288 Examples:
7289 <ul>
7290 <pre>
7291 mat A = randu&lt;mat&gt;(5,5);
7292 mat B = randu&lt;mat&gt;(5,5);
7293
7294 uvec q1 = find(A &gt; B);
7295 uvec q2 = find(A &gt; 0.5);
7296 uvec q3 = find(A &gt; 0.5, 3, "last");
7297 </pre>
7298 </ul>
7299 </li>
7300 <br>
7301 <li>
7302 See also:
7303 <ul>
7304 <li><a href="#unique">unique()</a></li>
7305 <li><a href="#conv_to">conv_to()</a> (convert between matrix/vector types)</li>
7306 <li><a href="#submat">submatrix views</a></li>
7307 <li><a href="#sort_index">sort_index()</a></li>
7308 </ul>
7309 </li>
7310 <br>
7311 </ul>
7312 <hr class="greyline">
7313 <br>
7314
7315 <a name="flip"></a>
7316 <b>fliplr(mat)</b>
7317 <br><b>flipud(mat)</b>
7318 <ul>
7319 <li>
7320 fliplr(): generate a copy of the input matrix, with the order of the columns reversed
7321 </li>
7322 <br>
7323 <li>
7324 flipud(): generate a copy of the input matrix, with the order of the rows reversed
7325 </li>
7326 <br>
7327 <li>
7328 Examples:
7329 <ul>
7330 <pre>
7331 mat A = randu&lt;mat&gt;(5,5);
7332
7333 mat B = fliplr(A);
7334 mat C = flipud(A);
7335 </pre>
7336 </ul>
7337 </li>
7338 <br>
7339 <li>
7340 See also:
7341 <ul>
7342 <li><a href="#swap_rows">.swap_rows() &amp; .swap_cols()</a> (member functions of <i>Mat</i>, <i>Col</i> and <i>Row</i> classes)</li>
7343 </ul>
7344 </li>
7345 <br>
7346 </ul>
7347 <hr class="greyline"><br>
7348
7349 <a name="hist"></a>
7350 <b>hist(V, n_bins=10)</b>
7351 <br><b>hist(X, n_bins=10, dim=0)</b>
7352 <br>
7353 <br><b>hist(V, centers)</b>
7354 <br><b>hist(X, centers, dim=0)</b>
7355 <ul>
7356 <li>
7357 For vector <i>V</i>,
7358 produce an unsigned vector of the same orientation as <i>V</i> (ie. either <a href="#Col">uvec</a> or <a href="#Row">urowvec</a>)
7359 that represents a histogram of counts
7360 </li>
7361 <br>
7362 <li>
7363 For matrix <i>X</i>,
7364 produce a <a href="#Mat">umat</a> matrix containing either
7365 column histogram counts (for <i>dim=0</i>, default),
7366 or
7367 row histogram counts (for <i>dim=1</i>)
7368 </li>
7369 <br>
7370 <li>
7371 The bin centers can be automatically determined from the data, with the number of bins specified via <i>n_bins</i> (default is 10);
7372 the range of the bins is determined by the range of the data
7373 </li>
7374 <br>
7375 <li>
7376 The bin centers can also be explicitly specified via the <i>centers</i> vector;
7377 the vector must contain monotonically increasing values (eg. 0.1, 0.2, 0.3, ...)
7378 </li>
7379 <br>
7380 <li>
7381 This function was added in version 3.0
7382 </li>
7383 <br>
7384 <li>
7385 Examples:
7386 <ul>
7387 <pre>
7388 vec v = randn&lt;vec&gt;(1000); // Gaussian distribution
7389
7390 uvec h1 = hist(v, 11);
7391 uvec h2 = hist(v, linspace&lt;vec&gt;(-2,2,11));
7392 </pre>
7393 </ul>
7394 </li>
7395 <br>
7396 <li>See also:
7397 <ul>
7398 <li><a href="#histc">histc()</a></li>
7399 <li><a href="#stats_fns">statistics functions</a></li>
7400 <li><a href="#conv_to">conv_to()</a></li>
7401 </ul>
7402 </li>
7403 <br>
7404 </ul>
7405 <hr class="greyline"><br>
7406
7407 <a name="histc"></a>
7408 <b>histc(V, edges)</b>
7409 <br><b>histc(X, edges, dim=0)</b>
7410 <ul>
7411 <li>
7412 For vector <i>V</i>,
7413 produce an unsigned vector of the same orientation as <i>V</i> (ie. either <a href="#Col">uvec</a> or <a href="#Row">urowvec</a>)
7414 that contains the counts of the number of values that fall between the elements in the <i>edges</i> vector
7415 </li>
7416 <br>
7417 <li>
7418 For matrix <i>X</i>,
7419 produce a <i>umat</i> matrix containing either
7420 column histogram counts (for <i>dim=0</i>, default),
7421 or
7422 row histogram counts (for <i>dim=1</i>)
7423 </li>
7424 <br>
7425 <li>
7426 The <i>edges</i> vector must contain monotonically increasing values (eg. 0.1, 0.2, 0.3, ...)
7427 </li>
7428 <br>
7429 <li>
7430 This function was added in version 3.0
7431 </li>
7432 <br>
7433 <li>
7434 Examples:
7435 <ul>
7436 <pre>
7437 vec v = randn&lt;vec&gt;(1000); // Gaussian distribution
7438
7439 uvec h = histc(v, linspace&lt;vec&gt;(-2,2,11));
7440 </pre>
7441 </ul>
7442 </li>
7443 <br>
7444 <li>See also:
7445 <ul>
7446 <li><a href="#hist">hist()</a></li>
7447 <li><a href="#stats_fns">statistics functions</a></li>
7448 <li><a href="#conv_to">conv_to()</a></li>
7449 </ul>
7450 </li>
7451 <br>
7452 </ul>
7453 <hr class="greyline"><br>
7454
7455 <a name="imag_real"></a>
7456 <b>imag(cx_mat)</b>
7457 <br><b>imag(cx_cube)</b>
7458 <br>
7459 <br><b>real(cx_mat)</b>
7460 <br><b>real(cx_cube)</b>
7461 <ul>
7462 <li>
7463 Extract the imaginary/real part of a complex matrix/cube
7464 </li>
7465 <br>
7466 <li>
7467 Examples:
7468 <ul>
7469 <pre>
7470 cx_mat C = randu&lt;cx_mat&gt;(5,5);
7471
7472 mat A = imag(C);
7473 mat B = real(C);
7474 </pre>
7475 </ul>
7476 </li>
7477 <br>
7478 <li><b>Caveat:</b> versions 4.4, 4.5 and 4.6 of the GCC C++ compiler have a bug when using the <i>-std=c++0x</i> compiler option (ie. experimental support for C++11);
7479 to work around this bug, preface Armadillo's imag() and real() with the <i>arma</i> namespace qualification, eg. arma::imag(C)
7480 </li>
7481 <br>
7482 <li>See also:
7483 <ul>
7484 <li><a href="#set_imag">set_imag()&nbsp;/&nbsp;set_real()</a></li>
7485 </ul>
7486 </li>
7487 <br>
7488 </ul>
7489 <hr class="greyline"><br>
7490
7491 <a name="join"></a>
7492 <b>join_rows(mat A, mat B)</b>
7493 <br><b>join_cols(mat A, mat B)</b>
7494 <br><b>join_slices(cube A, cube B)</b>
7495 <ul>
7496 <li>
7497 join_rows():
7498 for two matrices A and B, append each row of B to its respective row of A;
7499 matrices A and B must have the same number of rows
7500 </li>
7501 <br>
7502 <li>
7503 join_cols():
7504 for two matrices A and B, append each column of B to its respective column of A;
7505 matrices A and B must have the same number of columns
7506 </li>
7507 <br>
7508 <li>
7509 join_slices():
7510 for two cubes A and B, append the slices of B to the slices of A;
7511 cubes A and B have the same number of rows and columns (ie. all slices must have the same size)
7512 </li>
7513 <br>
7514 <li>
7515 Examples:
7516 <ul>
7517 <pre>
7518 mat A = randu&lt;mat&gt;(4,5);
7519 mat B = randu&lt;mat&gt;(4,6);
7520 mat C = randu&lt;mat&gt;(6,5);
7521
7522 mat X = join_rows(A,B);
7523 mat Y = join_cols(A,C);
7524 </pre>
7525 </ul>
7526 </li>
7527 <br>
7528 <li>
7529 See also:
7530 <ul>
7531 <li><a href="#shed">shed rows/columns/slices</a></li>
7532 <li><a href="#insert">insert rows/columns/slices</a></li>
7533 <li><a href="#submat">submatrix views</a></li>
7534 <li><a href="#subcube">subcube views</a></li>
7535 </ul>
7536 </li>
7537 <br>
7538 </ul>
7539 <hr class="greyline"><br>
7540
7541 <a name="kron"></a>
7542 <b>kron(A,B)</b>
7543
7544 <ul>
7545 <li>Kronecker tensor product.</li>
7546 <br>
7547 <li>Using matrix <i>A</i> (with <i>n</i> rows and <i>p</i> columns) and matrix <i>B</i> (with <i>m</i> rows and <i>q</i> columns),
7548 <i>kron(A,B)</i> returns a matrix (with <i>nm</i> rows and <i>pq</i> columns) which denotes the tensor product of <i>A</i> and <i>B</i>
7549 </li>
7550 <br>
7551 <li>
7552 Examples:
7553 <ul>
7554 <pre>
7555 mat A = randu&lt;mat&gt;(4,5);
7556 mat B = randu&lt;mat&gt;(5,4);
7557
7558 mat K = kron(A,B);
7559 </pre>
7560 </ul>
7561 </li>
7562 <br>
7563 <li>
7564 See also:
7565 <ul>
7566 <li><a href="http://mathworld.wolfram.com/KroneckerProduct.html">Kronecker Product in MathWorld</a></li>
7567 </ul>
7568 </li>
7569 </ul>
7570 <br>
7571 <hr class="greyline"><br>
7572
7573 <a name="reshape"></a>
7574 <b>reshape(mat, n_rows, n_cols, dim=0)</b>
7575 <br><b>reshape(cube, n_rows, n_cols, n_slices, dim=0)</b>
7576 <ul>
7577 <li>
7578 Generate a matrix/cube sized according to given size specifications,
7579 whose elements are taken from the given matrix/cube, either column-wise (dim=0) or row-wise (dim=1);
7580 the elements in the generated object are placed column-wise (ie. the first column is filled up before filling the second column)
7581 </li>
7582 <br>
7583 <li>
7584 The layout of the elements in the generated object will be different to the layout in the given object
7585 </li>
7586 <br>
7587 <li>
7588 This function can be used to create a vector representation of a matrix (ie. concatenate all the columns or rows)
7589 </li>
7590 <br>
7591 <li>
7592 The total number of elements in the generated matrix/cube doesn't have to be the same as the total number of elements in the given matrix/cube
7593 </li>
7594 <br>
7595 <li>
7596 If the total number of elements in the given matrix/cube is less than the specified size,
7597 the remaining elements in the generated matrix/cube are set to zero
7598 </li>
7599 <br>
7600 <li>
7601 If the total number of elements in the given matrix/cube is greater than the specified size,
7602 only a subset of elements is taken from the given matrix/cube
7603 </li>
7604 <br>
7605 <li>
7606 <b>Caveat:</b>
7607 reshape() is slower than <a href="#set_size">.set_size()</a>, which doesn't preserve data
7608 </li>
7609 <br>
7610 <li>
7611 <b>Caveat:</b>
7612 if you wish to grow/shrink a matrix while preserving the elements <b>as well as</b> the layout of the elements,
7613 use <a href="#resize">resize()</a> instead
7614 </li>
7615 <br>
7616 <li>
7617 Examples:
7618 <ul>
7619 <pre>
7620 mat A = randu&lt;mat&gt;(10, 5);
7621 mat B = reshape(A, 5, 10);
7622 </pre>
7623 </ul>
7624 </li>
7625 <br>
7626 <li>
7627 See also:
7628 <ul>
7629 <li><a href="#reshape_member">.reshape()</a> (member function of Mat and Cube)</li>
7630 <li><a href="#set_size">.set_size()</a> (member function of Mat and Cube)</li>
7631 <li><a href="#resize">resize()</a></li>
7632 <li><a href="#as_scalar">as_scalar()</a></li>
7633 <li><a href="#conv_to">conv_to()</a></li>
7634 <li><a href="#diagmat">diagmat()</a></li>
7635 </ul>
7636 </li>
7637 <br>
7638 </ul>
7639 <hr class="greyline"><br>
7640
7641 <a name="resize"></a>
7642 <b>resize(mat, n_rows, n_cols)</b>
7643 <br><b>resize(cube, n_rows, n_cols, n_slices)</b>
7644 <ul>
7645 <li>
7646 Generate a matrix/cube sized according to given size specifications,
7647 whose elements as well as the layout of the elements are taken from the given matrix/cube
7648 </li>
7649 <br>
7650 <li>
7651 <b>Caveat:</b>
7652 resize() is slower than <a href="#set_size">.set_size()</a>, which doesn't preserve data
7653 </li>
7654 <br>
7655 <li>
7656 Examples:
7657 <ul>
7658 <pre>
7659 mat A = randu&lt;mat&gt;(4, 5);
7660 mat B = resize(A, 7, 6);
7661 </pre>
7662 </ul>
7663 </li>
7664 <br>
7665 <li>
7666 This function was added in version 2.4
7667 </li>
7668 <br>
7669 <li>
7670 See also:
7671 <ul>
7672 <li><a href="#resize_member">.resize()</a> (member function of Mat and Cube)</li>
7673 <li><a href="#set_size">.set_size()</a> (member function of Mat and Cube)</li>
7674 <li><a href="#reshape">reshape()</a></li>
7675 <li><a href="#as_scalar">as_scalar()</a></li>
7676 <li><a href="#conv_to">conv_to()</a></li>
7677 </ul>
7678 </li>
7679 <br>
7680 </ul>
7681 <hr class="greyline"><br>
7682
7683 <a name="shuffle"></a>
7684 <b>shuffle(mat, dim=0)</b>
7685 <br><b>shuffle(rowvec, dim=0)</b>
7686 <br><b>shuffle(colvec, dim=0)</b>
7687 <ul>
7688 <li>
7689 Shuffle the rows (dim=0) or columns (dim=1) of a matrix or vector
7690 </li>
7691 <br>
7692 <li>
7693 Examples:
7694 <ul>
7695 <pre>
7696 mat A = randu&lt;mat&gt;(4,5);
7697 mat B = shuffle(A);
7698 </pre>
7699 </ul>
7700 </li>
7701 <br>
7702 <li>
7703 See also:
7704 <ul>
7705 <li><a href="#randu_randn_standalone">randu() / randn()</a></li>
7706 <li><a href="#sort">sort()</a></li>
7707 </ul>
7708 </li>
7709 <br>
7710 </ul>
7711 <hr class="greyline"><br>
7712
7713 <a name="sort"></a>
7714 <b>sort(mat, sort_type=0, dim=0)</b>
7715 <br><b>sort(rowvec, sort_type=0)</b>
7716 <br><b>sort(colvec, sort_type=0)</b>
7717 <ul>
7718 <li>For a matrix argument, return a matrix with the elements of the input matrix sorted in each column (<i>dim=0</i>), or each row (<i>dim=1</i>)</li>
7719 <br>
7720 <li><i>sort_type=0</i> (default) indicates an ascending sort</li>
7721 <br>
7722 <li><i>sort_type=1</i> indicates a descending sort</li>
7723 <br>
7724 <li>For a vector argument, return a vector which is a sorted version of the input vector</li>
7725 <br>
7726 <li>For matrices and vectors with complex numbers, sorting is via absolute values</li>
7727 <br>
7728 <li>
7729 Examples:
7730 <ul>
7731 <pre>
7732 mat A = randu&lt;mat&gt;(10,10);
7733 mat B = sort(A);
7734 </pre>
7735 </ul>
7736 </li>
7737 <li>
7738 See also:
7739 <ul>
7740 <li><a href="#sort_index">sort_index()</a></li>
7741 <li><a href="#shuffle">shuffle()</a></li>
7742 <li><a href="#randu_randn_standalone">randu() / randn()</a></li>
7743 </ul>
7744 </li>
7745 <br>
7746 </ul>
7747 <hr class="greyline"><br>
7748
7749 <a name="sort_index"></a>
7750 <b>sort_index(colvec, sort_type=0)</b>
7751 <br><b>sort_index(rowvec, sort_type=0)</b>
7752 <br>
7753 <br><b>stable_sort_index(colvec, sort_type=0)</b>
7754 <br><b>stable_sort_index(rowvec, sort_type=0)</b>
7755 <ul>
7756 <li>Return a vector which describes the sorted order of the given vector's elements
7757 (ie. it contains the indices of the given vector's elements)
7758 </li>
7759 <br>
7760 <li>The output vector must have the type <a href="#Col">uvec</a> or <a href="#Mat">umat</a>
7761 (ie. the indices are stored as unsigned integers of type <a href="#uword">uword</a>)
7762 </li>
7763 <br>
7764 <li><i>sort_type=0</i> (default) indicates an ascending sort</li>
7765 <br>
7766 <li><i>sort_type=1</i> indicates a descending sort</li>
7767 <br>
7768 <li>The <i>stable_sort_index()</i> variant preserves the relative order of elements with equivalent values; the variant was added in version 3.6</li>
7769 <br>
7770 <li>
7771 Examples:
7772 <ul>
7773 <pre>
7774 vec q = randu&lt;vec&gt;(10);
7775 uvec indices = sort_index(q);
7776 </pre>
7777 </ul>
7778 </li>
7779 <br>
7780 <li>
7781 See also:
7782 <ul>
7783 <li><a href="#find">find()</a></li>
7784 <li><a href="#sort">sort()</a></li>
7785 </ul>
7786 </li>
7787 <br>
7788 </ul>
7789 <hr class="greyline"><br>
7790
7791 <a name="symmat"></a>
7792 <b>symmatu(A)</b>
7793 <br><b>symmatl(A)</b>
7794 <ul>
7795 <li>
7796 <i>symmatu(A)</i>: interpret square matrix <i>A</i> as symmetric, reflecting the upper triangle to the lower triangle
7797 </li>
7798 <br>
7799 <li>
7800 <i>symmatl(A)</i>: interpret square matrix <i>A</i> as symmetric, reflecting the lower triangle to the upper triangle
7801 </li>
7802 <br>
7803 <li>
7804 If <i>A</i> is non-square, a <i>std::logic_error</i> exception is thrown
7805 </li>
7806 <br>
7807 <li>
7808 Examples:
7809 <ul>
7810 <pre>
7811 mat A = randu&lt;mat&gt;(5,5);
7812
7813 mat B = symmatu(A);
7814 mat C = symmatl(A);
7815 </pre>
7816 </ul>
7817 </li>
7818 <br>
7819 <li>See also:
7820 <ul>
7821 <li><a href="#diagmat">diagmat()</a></li>
7822 <li><a href="#trimat">trimatu() / trimatl()</a></li>
7823 <li><a href="http://en.wikipedia.org/wiki/Symmetric_matrix">Symmetric matrix in Wikipedia</a></li>
7824 </ul>
7825 </li>
7826 </ul>
7827 <br>
7828 <hr class="greyline"><br>
7829
7830 <a name="strans"></a>
7831 <b>strans(mat)</b>
7832 <br><b>strans(colvec)</b>
7833 <br><b>strans(rowvec)</b>
7834 <ul>
7835 <li>
7836 Simple matrix transpose, without taking the conjugate of the elements (complex matrices)
7837 </li>
7838 <br>
7839 <li>
7840 Use <a href="#trans">trans()</a> instead, unless you explicitly need to take the transpose of a complex matrix without taking the conjugate of the elements
7841 </li>
7842 <br>
7843 <li>See also:
7844 <ul>
7845 <li><a href="#t_st_members">.st()</a></li>
7846 <li><a href="#trans">trans()</a></li>
7847 </ul>
7848 </li>
7849 </ul>
7850 <br>
7851 <hr class="greyline"><br>
7852
7853
7854 <a name="trans"></a>
7855 <b>trans(mat)</b>
7856 <br><b>trans(colvec)</b>
7857 <br><b>trans(rowvec)</b>
7858 <ul>
7859 <li>
7860 Matrix transpose / Hermitian transpose
7861 </li>
7862 <br>
7863 <li>
7864 If a given object has real elements, a normal transpose is done
7865 </li>
7866 <br>
7867 <li>
7868 If a given object has complex elements, a Hermitian transpose is done (ie. the conjugate of the elements is taken during the transpose operation)
7869 </li>
7870 <br>
7871 <li>
7872 <b>Caveat:</b> for complex matrices, the functionality of trans() has changed in version 2.0:
7873 <ul>
7874 <li>in version 1.x, <i>trans()</i> does not take the conjugate of complex elements</li>
7875 <li>in version 1.x, the <i>htrans()</i> function is used for the Hermitian transpose</li>
7876 </ul>
7877 </li>
7878 <br>
7879 <li>
7880 Examples:
7881 <ul>
7882 <pre>mat A = randu&lt;mat&gt;(5,10);
7883 mat B = trans(A);
7884 </pre>
7885 </ul>
7886 </li>
7887 <br>
7888 <li>See also:
7889 <ul>
7890 <li><a href="#t_st_members">.t()</a></li>
7891 <li><a href="#strans">strans()</a></li>
7892 </ul>
7893 </li>
7894 </ul>
7895 <br>
7896 <hr class="greyline"><br>
7897
7898
7899 <a name="trimat"></a>
7900 <b>trimatu(A)</b>
7901 <br><b>trimatl(A)</b>
7902 <ul>
7903 <li>
7904 <i>trimatu(A)</i>: interpret square matrix <i>A</i> as upper triangular
7905 </li>
7906 <br>
7907 <li>
7908 <i>trimatl(A)</i>: interpret square matrix <i>A</i> as lower triangular
7909 </li>
7910 <br>
7911 <li>
7912 A <i>std::logic_error</i> exception is thrown if <i>A</i> is non-square
7913 </li>
7914 <br>
7915 <li>
7916 Examples:
7917 <ul>
7918 <pre>mat A = randu&lt;mat&gt;(5,5);
7919 mat U = trimatu(A);
7920 mat L = trimatl(A);
7921
7922 // tell the inv() function to look only
7923 // at the upper triangular part
7924 mat X = inv( trimatu(U) );
7925 </pre>
7926 </ul>
7927 </li>
7928 <br>
7929 <li>See also:
7930 <ul>
7931 <li><a href="#symmat">symmatu() / symmatl()</a></li>
7932 <li><a href="#diagmat">diagmat()</a></li>
7933 <li><a href="#inv">inv()</a></li>
7934 <li><a href="#solve">solve()</a></li>
7935 <li><a href="http://mathworld.wolfram.com/TriangularMatrix.html">Triangular matrix in MathWorld</a></li>
7936 <li><a href="http://en.wikipedia.org/wiki/Triangular_matrix">Triangular matrix in Wikipedia</a></li>
7937 </ul>
7938 </li>
7939 </ul>
7940 <br>
7941 <hr class="greyline">
7942 <br>
7943
7944
7945 <a name="unique"></a>
7946 <b>unique(A)</b>
7947 <br>
7948 <ul>
7949 <li>
7950 Return the unique elements of <i>A</i>, sorted in ascending order
7951 </li>
7952 <br>
7953 <li>
7954 If <i>A</i> is a vector, the output is also a vector with the same orientation (row or column) as <i>A</i>;
7955 if <i>A</i> is a matrix, the output is always a column vector
7956 </li>
7957 <br>
7958 <li>
7959 This function was added in version 3.2
7960 </li>
7961 <br>
7962 <li>
7963 Examples:
7964 <ul>
7965 <pre>
7966 mat X;
7967 X &lt;&lt; 1 &lt;&lt; 2 &lt;&lt; endr
7968 &lt;&lt; 2 &lt;&lt; 3 &lt;&lt; endr;
7969
7970 mat Y = unique(X);
7971 </pre>
7972 </ul>
7973 </li>
7974 <br>
7975 <li>See also:
7976 <ul>
7977 <li><a href="#find">find()</a></li>
7978 <li><a href="#sort">sort()</a></li>
7979 </ul>
7980 </li>
7981 </ul>
7982 <br>
7983 <hr class="greyline">
7984
7985
7986 <hr class="greyline">
7987 <br>
7988 <br>
7989 <font size=+1><b>Decompositions, Factorisations, Inverses and Equation Solvers</b></font>
7990 <br>
7991 <br>
7992 <hr class="greyline">
7993 <br>
7994
7995 <a name="chol"></a>
7996 <b>R = chol(X)</b>
7997 <br><b>chol(R, X)</b>
7998 <ul>
7999 <li>
8000 Cholesky decomposition of <i>X</i>, such that <i>R.t()*R = X</i>
8001 </li>
8002 <br>
8003 <li>
8004 X must be a symmetric, positive-definite matrix
8005 </li>
8006 <br>
8007 <li>If the decomposition fails, <i>R</i> is reset and:
8008 <ul>
8009 <li><i>chol(X)</i> throws a <i>std::runtime_error</i> exception</li>
8010 <li><i>chol(R,X)</i> returns a bool set to <i>false</i></li>
8011 </ul>
8012 </li>
8013 <br>
8014 <li>
8015 Examples:
8016 <ul>
8017 <pre>
8018 mat X = randu&lt;mat&gt;(5,5);
8019 mat Y = X.t()*X;
8020
8021 mat R = chol(Y);
8022 </pre>
8023 </ul>
8024 </li>
8025 <br>
8026 <li>
8027 See also:
8028 <ul>
8029 <li><a href="http://mathworld.wolfram.com/CholeskyDecomposition.html">Cholesky decomposition in MathWorld</a></li>
8030 <li><a href="http://en.wikipedia.org/wiki/Cholesky_decomposition">Cholesky decomposition in Wikipedia</a></li>
8031 </ul>
8032 </li>
8033 </ul>
8034 <br>
8035 <hr class="greyline"><br>
8036
8037 <a name="eig_sym"></a>
8038 <b>vec eigval = eig_sym(mat X)</b>
8039 <br><b>vec eigval = eig_sym(cx_mat X)</b>
8040 <br>
8041 <br><b>eig_sym(vec eigval, mat X)</b>
8042 <br><b>eig_sym(vec eigval, cx_mat X)</b>
8043 <br>
8044 <br><b>eig_sym(vec eigval, mat eigvec, mat X, method = "standard")</b>
8045 <br><b>eig_sym(vec eigval, cx_mat eigvec, cx_mat X, method = "standard")</b>
8046 <ul>
8047 <li>Eigen decomposition of symmetric/hermitian matrix <i>X</i></li>
8048 <br>
8049 <li>The eigenvalues and corresponding eigenvectors are stored in <i>eigval</i> and <i>eigvec</i>, respectively</li>
8050 <br>
8051 <li>The eigenvalues are in ascending order</li>
8052 <br>
8053 <li>If <i>X</i> is not square, a <i>std::logic_error</i> exception is thrown</li>
8054 <br>
8055 <li>The <i>method</i> argument is optional</li>
8056 <br>
8057 <li>
8058 By default, a standard eigen decomposition algorithm is used;
8059 a divide-and-conquer algorithm can be used instead by explicitly setting <i>method</i> to <i>"dc"</i>
8060 </li>
8061 <br>
8062 <li>
8063 The divide-and-conquer algorithm provides slightly different results, but is notably faster for large matrices
8064 </li>
8065 <br>
8066 <li>If the decomposition fails, the output objects are reset and:
8067 <ul>
8068 <li><i>eig_sym(X)</i> throws a <i>std::runtime_error</i> exception</li>
8069 <li><i>eig_sym(eigval, X)</i> and <i>eig_sym(eigval, eigvec, X)</i> return a bool set to <i>false</i></li>
8070 </ul>
8071 </li>
8072 <br>
8073 <li>There is currently no check whether <i>X</i> is symmetric</li>
8074 <br>
8075 <li>
8076 Examples:
8077 <ul>
8078 <pre>
8079 mat A = randu&lt;mat&gt;(50,50);
8080 mat B = A.t()*A; // generate a symmetric matrix
8081
8082 vec eigval;
8083 mat eigvec;
8084
8085 eig_sym(eigval, eigvec, B); // use standard algorithm by default
8086
8087 eig_sym(eigval, eigvec, B, "dc"); // use "divide &amp; conquer" algorithm
8088 </pre>
8089 </ul>
8090 </li>
8091 <br>
8092 <li>
8093 See also:
8094 <ul>
8095 <li><a href="#eig_gen">eig_gen()</a></li>
8096 <li><a href="#svd">svd()</a></li>
8097 <li><a href="#svd_econ">svd_econ()</a></li>
8098 <li><a href="http://mathworld.wolfram.com/EigenDecomposition.html">eigen decomposition in MathWorld</a></li>
8099 <li><a href="http://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors">eigenvalues &amp; eigenvectors in Wikipedia</a></li>
8100 <li><a href="http://en.wikipedia.org/wiki/Divide-and-conquer_eigenvalue_algorithm">divide &amp; conquer eigenvalue algorithm in Wikipedia</a></li>
8101 </ul>
8102 </li>
8103 <br>
8104 </ul>
8105 <hr class="greyline"><br>
8106
8107 <a name="eig_gen"></a>
8108 <b>eig_gen(cx_vec eigval, cx_mat eigvec, mat X, side='r')</b>
8109 <br>
8110 <b>eig_gen(cx_vec eigval, cx_mat eigvec, cx_mat X, side='r')</b>
8111 <br>
8112 <br>
8113 <b>eig_gen(cx_vec eigval, mat l_eigvec, mat r_eigvec, mat X)</b>
8114 <br>
8115 <b>eig_gen(cx_vec eigval, cx_mat l_eigvec, cx_mat r_eigvec, cx_mat X)</b>
8116 <ul>
8117 <li>
8118 Eigen decomposition of general (non-symmetric/non-hermitian) square matrix <i>X</i></li>
8119 <br>
8120 <li>The eigenvalues and corresponding eigenvectors are stored in <i>eigval</i> and <i>eigvec</i>, respectively</li>
8121 <br>
8122 <li>
8123 For the first two forms, <i>side='r'</i> (default) specifies that right eigenvectors are computed,
8124 while <i>side='l'</i> specifies that left eigenvectors are computed
8125 </li>
8126 <br>
8127 <li>For the last two forms, both left and right eigenvectors are computed</li>
8128 <br>
8129 <li>
8130 The eigenvalues are not guaranteed to be ordered
8131 </li>
8132 <br>
8133 <li>If <i>X</i> is not square, a <i>std::logic_error</i> exception is thrown</li>
8134 <br>
8135 <li>If the decomposition fails, the output objects are reset and <i>eig_gen()</i> returns a bool set to <i>false</i></li>
8136 <br>
8137 <li>
8138 Examples:
8139 <ul>
8140 <pre>
8141 mat A = randu&lt;mat&gt;(10,10);
8142
8143 cx_vec eigval;
8144 cx_mat eigvec;
8145
8146 eig_gen(eigval, eigvec, A);
8147 </pre>
8148 </ul>
8149 </li>
8150 <br>
8151 <li>
8152 See also:
8153 <ul>
8154 <li><a href="#eig_sym">eig_sym()</a></li>
8155 <li><a href="#svd">svd()</a></li>
8156 <li><a href="#svd_econ">svd_econ()</a></li>
8157 <li><a href="http://mathworld.wolfram.com/EigenDecomposition.html">eigen decomposition in MathWorld</a></li>
8158 <li><a href="http://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors">eigenvalues &amp; eigenvectors in Wikipedia</a></li>
8159 </ul>
8160 </li>
8161 </ul>
8162 <br>
8163 <hr class="greyline"><br>
8164
8165 <a name="fft"></a>
8166 <b>cx_mat Y = &nbsp;fft(X)</b><br>
8167 <b>cx_mat Y = &nbsp;fft(X, n)</b><br>
8168 <br>
8169 <b>cx_mat Z = ifft(cx_mat Y)</b><br>
8170 <b>cx_mat Z = ifft(cx_mat Y, n)</b><br>
8171 <ul>
8172 <li>fft(): fast Fourier transform of a vector or matrix (real or complex)</li>
8173 <br>
8174 <li>ifft(): inverse fast Fourier transform of a vector or matrix (complex only)</li>
8175 <br>
8176 <li>If given a matrix, the transform is done on each column vector of the matrix</li>
8177 <br>
8178 <li>
8179 The optional <i>n</i> argument specifies the transform length:
8180 <ul>
8181 <li>if <i>n</i> is larger than the length of the input vector, a zero-padded version of the vector is used</li>
8182 <li>if <i>n</i> is smaller than the length of the input vector, only the first <i>n</i> elements of the vector are used</li>
8183 </ul>
8184 </li>
8185 <br>
8186 <li>
8187 If <i>n</i> is not specified, the transform length is the same as the length of the input vector
8188 </li>
8189 <br>
8190 <li><b>Caveat:</b> the transform is fastest when the transform length is a power of 2, eg. 64, 128, 256, 512, 1024, ...</li>
8191 <br>
8192 <li>The implementation of the transform in this version is preliminary; it is not yet fully optimised</li>
8193 <br>
8194 <li>This function was added in version 3.810</li>
8195 <br>
8196 <li>
8197 Examples:
8198 <ul>
8199 <pre>
8200 vec X = randu&lt;vec&gt;(100);
8201 cx_vec Y = fft(X, 128);
8202 </pre>
8203 </ul>
8204 </li>
8205 <br>
8206 <li>
8207 See also:
8208 <ul>
8209 <li><a href="#conv">conv()</a></li>
8210 <li><a href="#imag_real">real()</a></li>
8211 <li><a href="http://mathworld.wolfram.com/FastFourierTransform.html">fast Fourier transform in MathWorld</a></li>
8212 <li><a href="http://en.wikipedia.org/wiki/Fast_Fourier_transform">fast Fourier transform in Wikipedia</a></li>
8213 </ul>
8214 </li>
8215 <br>
8216 </ul>
8217 <hr class="greyline"><br>
8218
8219 <a name="inv"></a>
8220 <b>B = inv(A, </b><i>slow=false</i><b>)</b>
8221 <br>
8222 <b>inv(B, A, </b><i>slow=false</i><b>)</b>
8223 <ul>
8224 <li>
8225 Inverse of square matrix <i>A</i>
8226 </li>
8227 <br>
8228 <li>the <i>slow</i> argument is optional</li>
8229 <br>
8230 <li>
8231 If <i>A</i> is known to be a triangular matrix,
8232 the inverse can be computed faster by explicitly marking the matrix as triangular
8233 through <a href="#trimat">trimatu()</a> or <a href="#trimat">trimatl()</a>
8234 </li>
8235 <br>
8236 <li>
8237 If <i>A</i> is known to be a positive-definite symmetric matrix,
8238 the inverse can be computed faster by explicitly marking the matrix using sympd()
8239 </li>
8240 <br>
8241 <li>
8242 If <i>A</i> is not square, a <i>std::logic_error</i> exception is thrown
8243 </li>
8244 <br>
8245 <li>If <i>A</i> appears to be singular, <i>B</i> is reset and:
8246 <ul>
8247 <li><i>inv(A)</i> throws a <i>std::runtime_error</i> exception</li>
8248 <li><i>inv(B,A)</i> returns a bool set to <i>false</i></li>
8249 </ul>
8250 </li>
8251 <br>
8252 <li>
8253 <b>NOTE:</b> in many cases it is more efficient/faster to use the <a href="#solve">solve()</a> function instead of performing a matrix inverse;
8254 for example, if you want to solve a system of linear equations, eg., <i>X = inv(A)*B</i>,
8255 use <a href="#solve">solve()</a> instead
8256 </li>
8257 <br>
8258 <li>
8259 For matrix sizes &le; 4x4, a fast inverse algorithm is used by default.
8260 In rare instances, the fast algorithm might be less precise than the standard algorithm.
8261 To force the use of the standard algorithm, set the <i>slow</i> argument to <i>true</i>
8262 </li>
8263 <br>
8264 <li>
8265 Examples:
8266 <ul>
8267 <pre>
8268 mat A = randu&lt;mat&gt;(5,5);
8269 mat B = inv(A);
8270
8271
8272 // Diagonal elements in C are set to the
8273 // reciprocal of the corresponding elements in A.
8274 // Off-diagonal elements in C are set to zero.
8275 mat C = inv( diagmat(A) );
8276
8277
8278 // tell inv() to look only at the upper triangular part of A
8279 mat D = inv( trimatu(A) );
8280
8281
8282 // tell inv() that AA is a symmetric positive definite matrix
8283 mat AA = A*A.t();
8284 mat E = inv( sympd(AA) );
8285
8286
8287 mat44 F = randu&lt;mat&gt;(4,4);
8288
8289 mat G = inv(F); // use fast algorithm by default
8290 mat H = inv(F, true); // use slow algorithm
8291 </pre>
8292 </ul>
8293 </li>
8294 <br>
8295 <li>
8296 See also:
8297 <ul>
8298 <li><a href="#i_member">.i()</a>
8299 <li><a href="#pinv">pinv()</a>
8300 <li><a href="#solve">solve()</a></li>
8301 <li><a href="#trimat">trimatu() / trimatl()</a></li>
8302 <li><a href="http://mathworld.wolfram.com/MatrixInverse.html">matrix inverse in MathWorld</a></li>
8303 <li><a href="http://en.wikipedia.org/wiki/Invertible_matrix">invertible matrix in Wikipedia</a></li>
8304 </ul>
8305 </li>
8306 </ul>
8307 <br>
8308 <hr class="greyline"><br>
8309
8310
8311
8312 <a name="lu"></a>
8313 <b>lu(mat L, mat U, mat P, mat X)</b>
8314 <br>
8315 <b>lu(mat L, mat U, mat X)</b>
8316 <ul>
8317 <li>
8318 Lower-upper decomposition (with partial pivoting) of matrix <i>X</i>
8319 </li>
8320 <br>
8321 <li>
8322 The first form provides
8323 a lower-triangular matrix <i>L</i>,
8324 an upper-triangular matrix <i>U</i>,
8325 and a permutation matrix <i>P</i>,
8326 such that <i>P.t()*L*U&nbsp;=&nbsp;X</i>
8327 </li>
8328 <br>
8329 <li>
8330 The second form provides permuted <i>L</i> and <i>U</i>, such that <i>L*U = X</i>.
8331 Note that in this case <i>L</i> is generally not lower-triangular
8332 </li>
8333 <br>
8334 <li>
8335 If the decomposition fails, the output objects are reset and <i>lu()</i> returns a bool set to <i>false</i>
8336 </li>
8337 <br>
8338 <li>
8339 Examples:
8340 <ul>
8341 <pre>
8342 mat A = randu&lt;mat&gt;(5,5);
8343
8344 mat L, U, P;
8345
8346 lu(L, U, P, A);
8347
8348 mat B = P.t()*L*U;
8349 </pre>
8350 </ul>
8351 </li>
8352 <br>
8353 <li>
8354 See also:
8355 <ul>
8356 <li><a href="http://en.wikipedia.org/wiki/LU_decomposition">LU decomposition in Wikipedia</a></li>
8357 <li><a href="http://mathworld.wolfram.com/LUDecomposition.html">LU decomposition in MathWorld</a></li>
8358 </ul>
8359 </li>
8360 </ul>
8361 <br>
8362 <hr class="greyline"><br>
8363
8364 <a name="pinv"></a>
8365 <b>B = pinv(A, tolerance = default)</b>
8366 <br><b>pinv(B, A, tolerance = default)</b>
8367 <ul>
8368 <li>Moore-Penrose pseudo-inverse of matrix <i>A</i></li>
8369 <br>
8370 <li>The <i>tolerance</i> argument is optional</li>
8371 <br>
8372 <li>The computation is based on singular value decomposition;
8373 if the decomposition fails, <i>B</i> is reset and:
8374 <ul>
8375 <li><i>pinv(A)</i> throws a <i>std::runtime_error</i> exception</li>
8376 <li><i>pinv(B,A)</i> returns a bool set to <i>false</i></li>
8377 </ul>
8378 <br>
8379 <li>Any singular values less than <i>tolerance</i> are treated as zero</li>
8380 <br>
8381 <li>For matrix <i>A</i> with <i>m</i> rows and <i>n</i> columns,
8382 the default tolerance is <i>max(m,n)*norm(A)*datum::eps</i>,
8383 where <i>datum::eps</i> denotes the difference between 1 and the least value greater than 1 that is representable</li>
8384 <br>
8385 <li>
8386 Examples:
8387 <ul>
8388 <pre>
8389 mat A = randu&lt;mat&gt;(4,5);
8390 mat B = pinv(A);
8391 </pre>
8392 </ul>
8393 </li>
8394 <br>
8395 <li>
8396 See also:
8397 <ul>
8398 <li><a href="#i_member">.i()</a></li>
8399 <li><a href="#inv">inv()</a></li>
8400 <li><a href="#solve">solve()</a></li>
8401 <li><a href="#constants">datum::eps</a></li>
8402 <li><a href="http://mathworld.wolfram.com/Pseudoinverse.html">Pseudoinverse in MathWorld</a></li>
8403 <li><a href="http://mathworld.wolfram.com/Moore-PenroseMatrixInverse.html">Moore-Penrose Matrix Inverse in MathWorld</a></li>
8404 <li><a href="http://en.wikipedia.org/wiki/Moore-Penrose_pseudoinverse">Moore-Penrose pseudoinverse in Wikipedia</a></li>
8405 </ul>
8406 </li>
8407 </ul>
8408 <br>
8409 <hr class="greyline"><br>
8410
8411 <a name="princomp"></a>
8412 <b>mat coeff = princomp(mat X)</b>
8413 <br><b>cx_mat coeff = princomp(cx_mat X)</b><br>
8414
8415 <br><b>princomp(mat coeff, mat X)</b>
8416 <br><b>princomp(cx_mat coeff, cx_mat X)</b><br>
8417
8418 <br><b>princomp(mat coeff, mat score, mat X)</b>
8419 <br><b>princomp(cx_mat coeff, cx_mat score, cx_mat X)</b><br>
8420
8421 <br><b>princomp(mat coeff, mat score, vec latent, mat X)</b>
8422 <br><b>princomp(cx_mat coeff, cx_mat score, vec latent, cx_mat X)</b><br>
8423
8424 <br><b>princomp(mat coeff, mat score, vec latent, vec tsquared, mat X)</b>
8425 <br><b>princomp(cx_mat coeff, cx_mat score, vec latent, cx_vec tsquared, cx_mat X)</b><br>
8426 <br>
8427 <ul>
8428 <li>Principal component analysis of matrix <i>X</i></li><br>
8429 <li>Each row of <i>X</i> is an observation and each column is a variable</li><br>
8430 <li>output objects:
8431 <ul>
8432 <li><i>coeff</i>: principal component coefficients</li>
8433 <li><i>score</i>: projected data</li>
8434 <li><i>latent</i>: eigenvalues of the covariance matrix of <i>X</i></li>
8435 <li><i>tsquared</i>: Hotteling's statistic for each sample</li>
8436 </ul>
8437 </li>
8438 <br>
8439 <li>The computation is based on singular value decomposition;
8440 if the decomposition fails, the output objects are reset and:
8441 <ul>
8442 <li><i>princomp(X)</i> throws a <i>std::runtime_error</i> exception</li>
8443 <li>remaining forms of <i>princomp()</i> return a bool set to <i>false</i></li>
8444 </ul>
8445 </li>
8446 <br>
8447 <li>
8448 Examples:
8449 <ul>
8450 <pre>
8451 mat A = randu&lt;mat&gt;(5,4);
8452
8453 mat coeff;
8454 mat score;
8455 vec latent;
8456 vec tsquared;
8457
8458 princomp(coeff, score, latent, tsquared, A);
8459 </pre>
8460 </ul>
8461 </li>
8462 <br>
8463 <li>
8464 See also:
8465 <ul>
8466 <li><a href="http://en.wikipedia.org/wiki/Principal_component_analysis">principal components analysis in Wikipedia</a></li>
8467 <li><a href="http://mathworld.wolfram.com/PrincipalComponentAnalysis.html">principal components analysis in MathWorld</a></li>
8468 </ul>
8469 </li>
8470 <br>
8471 </ul>
8472 <hr class="greyline"><br>
8473
8474 <a name="qr"></a>
8475 <b>qr(Q,R,X)</b>
8476 <ul>
8477 <li>
8478 Decomposition of <i>X</i> into an orthogonal matrix <i>Q</i> and a right triangular matrix <i>R</i>, such that <i>Q*R = X</i>
8479 </li>
8480 <br>
8481 <li>
8482 If the decomposition fails, <i>Q</i> and <i>R</i> are reset and the function returns a bool set to <i>false</i>
8483 </li>
8484 <br>
8485 <li>
8486 Examples:
8487 <ul>
8488 <pre>
8489 mat X = randu&lt;mat&gt;(5,5);
8490 mat Q, R;
8491
8492 qr(Q,R,X);
8493 </pre>
8494 </ul>
8495 </li>
8496 <br>
8497 <li>
8498 See also:
8499 <ul>
8500 <li><a href="#qr_econ">qr_econ()</a></li>
8501 <li><a href="http://en.wikipedia.org/wiki/Orthogonal_matrix">Orthogonal matrix in Wikipedia</a></li>
8502 <li><a href="http://en.wikipedia.org/wiki/QR_decomposition">QR decomposition in Wikipedia</a></li>
8503 <li><a href="http://mathworld.wolfram.com/QRDecomposition.html">QR decomposition in MathWorld</a></li>
8504 <li><a href="http://octave.sourceforge.net/octave/function/qr.html">QR decomposition in Octave</a></li>
8505 </ul>
8506 </li>
8507 </ul>
8508 <br>
8509 <hr class="greyline"><br>
8510
8511 <a name="qr_econ"></a>
8512 <b>qr_econ(Q,R,X)</b>
8513 <ul>
8514 <li>
8515 Economical decomposition of <i>X</i> (with size <i>m</i> x <i>n</i>) into an orthogonal matrix <i>Q</i> and a right triangular matrix <i>R</i>, such that <i>Q*R = X</i>
8516 </li>
8517 <br>
8518 <li>
8519 If <i>m</i> &gt; <i>n</i>, only the first <i>n</i> rows of <i>R</i> and the first <i>n</i> columns of <i>Q</i> are calculated
8520 (ie. the zero rows of <i>R</i> and the corresponding columns of <i>Q</i> are omitted)
8521 </li>
8522 <br>
8523 <li>
8524 If the decomposition fails, <i>Q</i> and <i>R</i> are reset and the function returns a bool set to <i>false</i>
8525 </li>
8526 <br>
8527 <li>
8528 This function was added in version 3.4
8529 </li>
8530 <br>
8531 <li>
8532 Examples:
8533 <ul>
8534 <pre>
8535 mat X = randu&lt;mat&gt;(6,5);
8536 mat Q, R;
8537
8538 qr_econ(Q,R,X);
8539 </pre>
8540 </ul>
8541 </li>
8542 <br>
8543 <li>
8544 See also:
8545 <ul>
8546 <li><a href="#qr">qr()</a></li>
8547 <li><a href="http://en.wikipedia.org/wiki/Orthogonal_matrix">Orthogonal matrix in Wikipedia</a></li>
8548 <li><a href="http://en.wikipedia.org/wiki/QR_decomposition">QR decomposition in Wikipedia</a></li>
8549 <li><a href="http://octave.sourceforge.net/octave/function/qr.html">QR decomposition in Octave</a></li>
8550 <li><a href="http://mathworld.wolfram.com/QRDecomposition.html">QR decomposition in MathWorld</a></li>
8551 </ul>
8552 </li>
8553 </ul>
8554 <br>
8555 <hr class="greyline"><br>
8556
8557 <a name="solve"></a>
8558 <b>X = solve(A, B, </b><i>slow=false</i><b>)</b>
8559 <br><b>solve(X, A, B, </b><i>slow=false</i><b>)</b>
8560 <ul>
8561 <li>Solve a system of linear equations, ie., <i>A*X = B</i>, where <i>X</i> is unknown</li>
8562 <br>
8563 <li>The <i>slow</i> argument is optional</li>
8564 <br>
8565 <li>For a square matrix <i>A</i>, this function is conceptually the same as <i>X = inv(A)*B</i>, but is more efficient</li>
8566 <br>
8567 <li>Similar functionality to the "\" (left division operator) operator in Matlab/Octave, ie. <i>X&nbsp;=&nbsp;A&nbsp;\&nbsp;B</i></li>
8568 <br>
8569 <li>The number of rows in <i>A</i> and <i>B</i> must be the same</li>
8570 <br>
8571 <li>
8572 If <i>A</i> is known to be a triangular matrix,
8573 the solution can be computed faster by explicitly marking the matrix as triangular
8574 through <a href="#trimat">trimatu()</a> or <a href="#trimat">trimatl()</a>
8575 </li>
8576 <br>
8577 <li>
8578 If <i>A</i> is non-square (and hence also non-triangular),
8579 solve() will also try to provide approximate solutions to under-determined as well as over-determined systems</li>
8580 <br>
8581 <li>
8582 If no solution is found, <i>X</i> is reset and:
8583 <ul>
8584 <li><i>solve(A,B)</i> throws a <i>std::runtime_error</i> exception</li>
8585 <li><i>solve(X,A,B)</i> returns a bool set to <i>false</i></li>
8586 </ul>
8587 </li>
8588 <br>
8589 <li>
8590 For matrix sizes &le; 4x4, a fast algorithm is used by default.
8591 In rare instances, the fast algorithm might be less precise than the standard algorithm.
8592 To force the use of the standard algorithm, set the <i>slow</i> argument to <i>true</i>
8593 </li>
8594 <br>
8595 <li>
8596 <b>NOTE:</b> Old versions of the ATLAS library (eg.&nbsp;3.6) can corrupt memory and crash your program;
8597 the standard LAPACK library and later versions of ATLAS (eg.&nbsp;3.8) work without problems
8598 </li>
8599 <br>
8600 <li>
8601 Examples:
8602 <ul>
8603 <pre>
8604 mat A = randu&lt;mat&gt;(5,5);
8605 vec b = randu&lt;vec&gt;(5);
8606 mat B = randu&lt;mat&gt;(5,5);
8607
8608 vec x = solve(A, b);
8609 mat X = solve(A, B);
8610
8611 vec x2;
8612 solve(x2, A, b);
8613
8614 // tell solve() to look only at the upper triangular part of A
8615 mat Y = solve( trimatu(A), B );
8616
8617
8618 mat44 C = randu&lt;mat&gt;(4,4);
8619 mat44 D = randu&lt;mat&gt;(4,4);
8620
8621 mat E = solve(C, D); // use fast algorithm by default
8622 mat F = solve(C, D, true); // use slow algorithm
8623
8624 </pre>
8625 </ul>
8626 </li>
8627 <br>
8628 <li>
8629 See also:
8630 <ul>
8631 <li><a href="#i_member">.i()</a></li>
8632 <li><a href="#inv">inv()</a></li>
8633 <li><a href="#pinv">pinv()</a></li>
8634 <li><a href="#syl">syl()</a></li>
8635 <li><a href="#trimat">trimatu() / trimatl()</a></li>
8636 <li><a href="http://mathworld.wolfram.com/LinearSystemofEquations.html">linear system of equations in MathWorld</a></li>
8637 <li><a href="http://en.wikipedia.org/wiki/Linear_system_of_equations">system of linear equations in Wikipedia</a></li>
8638 </ul>
8639 </li>
8640 <br>
8641 </ul>
8642 <hr class="greyline"><br>
8643
8644
8645 <a name="svd"></a>
8646 <b>vec s = svd(mat X)</b>
8647 <br><b>vec s = svd(cx_mat X)</b>
8648 <br>
8649 <br><b>svd(vec s, mat X)</b>,
8650 <br><b>svd(vec s, cx_mat X)</b>
8651 <br>
8652 <br><b>svd(mat U, vec s, mat V, mat X, method = "standard")</b>
8653 <br><b>svd(cx_mat U, vec s, cx_mat V, cx_mat X, method = "standard")</b>
8654 <ul>
8655 <li>
8656 The first four forms compute the singular values of <i>X</i>
8657 </li>
8658 <br>
8659 <li>
8660 The last two forms compute the full singular value decomposition of <i>X</i>
8661 </li>
8662 <br>
8663 <li>The <i>method</i> argument is optional</li>
8664 <br>
8665 <li>
8666 By default, a standard decomposition algorithm is used;
8667 a divide-and-conquer algorithm can be used instead by explicitly setting <i>method</i> to <i>"dc"</i>
8668 </li>
8669 <br>
8670 <li>
8671 The divide-and-conquer algorithm provides slightly different results, but is notably faster for large matrices
8672 </li>
8673 <br>
8674 <li>If <i>X</i> is square, it can be reconstructed using <i>X = U*diagmat(s)*V.t()</i>
8675 </li>
8676 <br>
8677 <li>
8678 The singular values are in descending order
8679 </li>
8680 <br>
8681 <li>
8682 If the decomposition fails, the output objects are reset and:
8683 <ul>
8684 <li><i>svd(X)</i> throws a <i>std::runtime_error</i> exception</li>
8685 <li><i>svd(s,X)</i> and <i>svd(U,s,V,X)</i> return a bool set to <i>false</i></li>
8686 </ul>
8687 </li>
8688 <br>
8689 <li>
8690 <b>NOTE:</b> Old versions of the ATLAS library (eg.&nbsp;3.6) can corrupt memory and crash your program;
8691 the standard LAPACK library and later versions of ATLAS (eg.&nbsp;3.8) work without problems
8692 </li>
8693 <br>
8694 <li>
8695 Examples:
8696 <ul>
8697 <pre>
8698 mat X = randu&lt;mat&gt;(5,5);
8699
8700 mat U;
8701 vec s;
8702 mat V;
8703
8704 svd(U,s,V,X); // use standard algorithm by default
8705
8706 svd(U,s,V,X, "dc"); // use "divide &amp; conquer" algorithm
8707 </pre>
8708 </ul>
8709 </li>
8710 <br>
8711 <li>
8712 See also:
8713 <ul>
8714 <li><a href="#svd_econ">svd_econ()</a></li>
8715 <li><a href="#eig_gen">eig_gen()</a></li>
8716 <li><a href="#eig_sym">eig_sym()</a></li>
8717 <li><a href="http://en.wikipedia.org/wiki/Singular_value_decomposition">singular value decomposition in Wikipedia</a></li>
8718 <li><a href="http://mathworld.wolfram.com/SingularValueDecomposition.html">singular value decomposition in MathWorld</a></li>
8719 </ul>
8720 </li>
8721 </ul>
8722 <br>
8723 <hr class="greyline">
8724 <br>
8725
8726 <a name="svd_econ"></a>
8727 <b>svd_econ(mat U, vec s, mat V, mat X, mode = 'b')</b>
8728 <br><b>svd_econ(cx_mat U, vec s, cx_mat V, cx_mat X, mode = 'b')</b>
8729 <ul>
8730 <li>
8731 Economical singular value decomposition of <i>X</i>
8732 </li>
8733 <br>
8734 <li>
8735 mode is one of:
8736 <ul>
8737 <li><i>'l'</i>: compute only left singular vectors</li>
8738 <li><i>'r'</i>: compute only right singular vectors</li>
8739 <li><i>'b'</i>: compute both left and right singular vectors (default)</li>
8740 </ul>
8741 </li>
8742 <br>
8743 <li>
8744 The singular values are in descending order
8745 </li>
8746 <br>
8747 <li>
8748 If the decomposition fails, the output objects are reset and bool set to <i>false</i> is returned
8749 </li>
8750 <br>
8751 <li>
8752 Examples:
8753 <ul>
8754 <pre>
8755 mat X = randu&lt;mat&gt;(4,5);
8756
8757 mat U;
8758 vec s;
8759 mat V;
8760 svd_econ(U, s, V, X, 'l');
8761 </pre>
8762 </ul>
8763 </li>
8764 <br>
8765 <li>
8766 See also:
8767 <ul>
8768 <li><a href="#svd">svd()</a></li>
8769 <li><a href="#eig_gen">eig_gen()</a></li>
8770 <li><a href="#eig_sym">eig_sym()</a></li>
8771 <li><a href="http://en.wikipedia.org/wiki/Singular_value_decomposition">singular value decomposition in Wikipedia</a></li>
8772 <li><a href="http://mathworld.wolfram.com/SingularValueDecomposition.html">singular value decomposition in MathWorld</a></li>
8773 </ul>
8774 </li>
8775 </ul>
8776 <br>
8777 <hr class="greyline">
8778 <br>
8779
8780 <a name="syl"></a>
8781 <b>X = syl(A, B, C)</b>
8782 <br><b>syl(X, A, B, C)</b>
8783 <ul>
8784 <li>Solve the Sylvester equation, ie., <i>AX + XB + C = 0</i>, where <i>X</i> is unknown.</li>
8785 <br>
8786 <li>Matrices <i>A</i>, <i>B</i> and <i>C</i> must be square sized.</li>
8787 <br>
8788 <li>
8789 If no solution is found, <i>X</i> is reset and:
8790 <ul>
8791 <li><i>syl(A,B,C)</i> throws a <i>std::runtime_error</i> exception</li>
8792 <li><i>svd(X,A,B,C)</i> returns a bool set to <i>false</i></li>
8793 </ul>
8794 </li>
8795 <br>
8796 <li>
8797 Examples:
8798 <ul>
8799 <pre>
8800 mat A = randu&lt;mat&gt;(5,5);
8801 mat B = randu&lt;mat&gt;(5,5);
8802 mat C = randu&lt;mat&gt;(5,5);
8803
8804 mat X1 = syl(A, B, C);
8805
8806 mat X2;
8807 syl(X2, A, B, C);
8808 </pre>
8809 </ul>
8810 </li>
8811 <br>
8812 <li>
8813 See also:
8814 <ul>
8815 <li><a href="#solve">solve()</a></li>
8816 <li><a href="http://en.wikipedia.org/wiki/Sylvester_equation">Sylvester equation in Wikipedia</a></li>
8817 </ul>
8818 </li>
8819 <br>
8820 </ul>
8821 <hr class="greyline">
8822
8823
8824 <hr class="greyline">
8825 <br>
8826 <br>
8827 <font size=+1><b>Miscellaneous</b></font>
8828 <br>
8829 <br>
8830 <hr class="greyline">
8831 <br>
8832
8833 <a name="is_finite_standalone"></a>
8834 <b>is_finite(X)</b>
8835 <ul>
8836 <li>
8837 Returns <i>true</i> if all elements in <i>X</i> are finite
8838 </li>
8839 <br>
8840 <li>
8841 Returns <i>false</i> if at least one element in <i>X</i> is non-finite (&plusmn;infinity or NaN)
8842 </li>
8843 <br>
8844 <li>
8845 <i>X</i> can be a scalar (eg. <i>double</i>), vector, matrix or cube
8846 </li>
8847 <br>
8848 <li>
8849 Examples:
8850 <ul>
8851 <pre>
8852 mat A = randu&lt;mat&gt;(5,5);
8853 mat B = randu&lt;mat&gt;(5,5);
8854
8855 B(1,1) = datum::nan;
8856
8857 cout &lt;&lt; is_finite(A) &lt;&lt; endl;
8858 cout &lt;&lt; is_finite(B) &lt;&lt; endl;
8859
8860 cout &lt;&lt; is_finite( 0.123456789 ) &lt;&lt; endl;
8861 cout &lt;&lt; is_finite( datum::nan ) &lt;&lt; endl;
8862 cout &lt;&lt; is_finite( datum::inf ) &lt;&lt; endl;
8863 </pre>
8864 </ul>
8865 </li>
8866 <br>
8867 <li>
8868 See also:
8869 <ul>
8870 <li><a href="#constants">datum::nan</a></li>
8871 <li><a href="#constants">datum::inf</a></li>
8872 <li><a href="#is_finite">.is_finite()</a> (member function of <i>Mat</i> and <i>Cube</i>)</li>
8873 </ul>
8874 </li>
8875 <br>
8876 </ul>
8877 <hr class="greyline"><br>
8878
8879 <a name="logging"></a>
8880 <b>logging of warnings and errors</b>
8881 <br>
8882 <br>
8883 <b>set_stream_err1(user_stream)</b><br>
8884 <b>set_stream_err2(user_stream)</b><br>
8885 <br>
8886 <b>std::ostream&amp; x = get_stream_err1()</b>
8887 <br>
8888 <b>std::ostream&amp; x = get_stream_err2()</b>
8889 <br>
8890 <ul>
8891 <li>
8892 By default, Armadillo prints warnings and messages associated with <i>std::logic_error</i> and <i>std::runtime_error</i> exceptions to the <i>std::cout</i> stream
8893 </li>
8894 <br>
8895 <li><b>set_stream_err1()</b>: change the stream for messages associated with <i>std::logic_error</i> exceptions (eg. out of bounds accesses)</li>
8896 <br>
8897 <li><b>set_stream_err2()</b>: change the stream for warnings and messages associated with <i>std::runtime_error</i> exceptions (eg. failed decompositions)</li>
8898 <br>
8899 <li><b>get_stream_err1()</b>: get a reference to the stream for messages associated with <i>std::logic_error</i> exceptions</li>
8900 <br>
8901 <li><b>get_stream_err2()</b>: get a reference to the stream for warnings and messages associated with <i>std::runtime_error</i> exceptions</li>
8902 <br>
8903 <li>
8904 Examples:
8905 <ul>
8906 <pre>
8907 // print "hello" to the current err1 stream
8908 get_stream_err1() &lt;&lt; "hello" &lt;&lt; endl;
8909
8910 // change the err2 stream to be a file
8911 ofstream f("my_log.txt");
8912 set_stream_err2(f);
8913
8914 // trying to invert a singular matrix
8915 // will print a message to the err2 stream
8916 // and throw an exception
8917 mat X = zeros&lt;mat&gt;(5,5);
8918 mat Y = inv(X);
8919
8920 // disable messages being printed to the err2 stream
8921 std::ostream nullstream(0);
8922 set_stream_err2(nullstream);
8923 </pre>
8924 </ul>
8925 </li>
8926 <br>
8927 <li>
8928 <b>Caveat</b>: set_stream_err1() and set_stream_err2() will not change the stream used by .print()
8929 </li>
8930 <br>
8931 <li>
8932 See also:
8933 <ul>
8934 <li><a href="#print">.print()</a></li>
8935 <li><a href="http://cplusplus.com/reference/iostream/cout/">std::cout</a></li>
8936 <li><a href="http://cplusplus.com/reference/iostream/ostream/">std::ostream</a></li>
8937 <li><a href="http://cplusplus.com/reference/std/stdexcept/logic_error/">std::logic_error</a></li>
8938 <li><a href="http://cplusplus.com/reference/std/stdexcept/runtime_error/">std::runtime_error</a></li>
8939 <li><a href="http://cplusplus.com/doc/tutorial/exceptions/">tutorial on exceptions</a></li>
8940 </ul>
8941 </li>
8942 <br>
8943 </ul>
8944 <hr class="greyline"><br>
8945
8946
8947
8948 <a name="constants"></a>
8949 <b>various constants (pi, inf, speed of light, ...)</b>
8950 <br>
8951 <ul>
8952 <li>
8953 Collection of math and fundamental physical constants
8954 </li>
8955 <br>
8956 <li>
8957 Physical constants were mainly taken from
8958 <a href="http://physics.nist.gov/cuu/Constants">NIST</a>
8959 and some from
8960 <a href="http://www.wolframalpha.com">WolframAlpha</a>
8961 on 2009-06-23;
8962 constants from NIST are in turn sourced from the <a href="http://physics.nist.gov/cuu/Constants/papers.html">2006 CODATA values</a>
8963 </li>
8964 <br>
8965 <li>
8966 The constants are stored in the <i>Datum&lt;type&gt;</i> class,
8967 where <i>type</i> is either <i>float</i> or <i>double</i>
8968 </li>
8969 <br>
8970 <li>
8971 For convenience,
8972 <i>Datum&lt;double&gt;</i> has been typedefed as <i>datum</i>
8973 while
8974 <i>Datum&lt;float&gt;</i> has been typedefed as <i>fdatum</i>
8975 </li>
8976 <br>
8977 <li>
8978 In previous versions of Armadillo (eg. 2.x), the constants are accessed via static functions in <i>math</i> and <i>phy</i> classes, eg. <i>math::pi()</i>;
8979 for compatibility, these classes are still available in version 3.x, but are not explicitly documented
8980 </li>
8981 <br>
8982 <li>
8983 Meaning of the constants:
8984 <br>
8985 <br>
8986 <ul>
8987 <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
8988 <tbody>
8989 <tr>
8990 <td style="vertical-align: top;">
8991 datum::pi
8992 </td>
8993 <td style="vertical-align: top;">
8994 &nbsp;
8995 </td>
8996 <td style="vertical-align: top;">
8997 &pi;, the ratio of any circle's circumference to its diameter
8998 </td>
8999 </tr>
9000 <tr>
9001 <td style="vertical-align: top;">
9002 datum::inf
9003 </td>
9004 <td style="vertical-align: top;">
9005 &nbsp;
9006 </td>
9007 <td style="vertical-align: top;">
9008 infinity
9009 </td>
9010 </tr>
9011 <tr>
9012 <td style="vertical-align: top;">
9013 datum::nan
9014 </td>
9015 <td style="vertical-align: top;">
9016 &nbsp;
9017 </td>
9018 <td style="vertical-align: top;">
9019 &ldquo;not a number&rdquo; (NaN); <b>caveat:</b> NaN is not equal to anything, even itself
9020 </td>
9021 </tr>
9022 <tr>
9023 <td style="vertical-align: top;">
9024 datum::e
9025 </td>
9026 <td style="vertical-align: top;">
9027 &nbsp;
9028 </td>
9029 <td style="vertical-align: top;">
9030 base of the natural logarithm
9031 </td>
9032 </tr>
9033 <tr>
9034 <td style="vertical-align: top;">
9035 datum::sqrt2
9036 </td>
9037 <td style="vertical-align: top;">
9038 &nbsp;
9039 </td>
9040 <td style="vertical-align: top;">
9041 square root of 2
9042 </td>
9043 </tr>
9044 <tr>
9045 <td style="vertical-align: top;">
9046 datum::eps
9047 </td>
9048 <td style="vertical-align: top;">
9049 &nbsp;
9050 </td>
9051 <td style="vertical-align: top;">
9052 the difference between 1 and the least value greater than 1 that is representable (type and machine dependant)
9053 </td>
9054 </tr>
9055 <tr>
9056 <td style="vertical-align: top;">
9057 datum::log_min
9058 </td>
9059 <td style="vertical-align: top;">
9060 &nbsp;
9061 </td>
9062 <td style="vertical-align: top;">
9063 log of minimum non-zero value (type and machine dependant)
9064 </td>
9065 </tr>
9066 <tr>
9067 <td style="vertical-align: top;">
9068 datum::log_max
9069 </td>
9070 <td style="vertical-align: top;">
9071 &nbsp;
9072 </td>
9073 <td style="vertical-align: top;">
9074 log of maximum value (type and machine dependant)
9075 </td>
9076 </tr>
9077 <tr>
9078 <td style="vertical-align: top;">
9079 datum::euler
9080 </td>
9081 <td style="vertical-align: top;">
9082 &nbsp;
9083 </td>
9084 <td style="vertical-align: top;">
9085 Euler's constant, aka Euler-Mascheroni constant
9086 </td>
9087 </tr>
9088 <tr>
9089 <td style="vertical-align: top;">
9090 datum::gratio
9091 </td>
9092 <td style="vertical-align: top;">
9093 &nbsp;
9094 </td>
9095 <td style="vertical-align: top;">
9096 golden ratio
9097 </td>
9098 </tr>
9099 <tr>
9100 <td style="vertical-align: top;">
9101 datum::m_u
9102 </td>
9103 <td style="vertical-align: top;">
9104 &nbsp;
9105 </td>
9106 <td style="vertical-align: top;">
9107 atomic mass constant (in kg)
9108 </td>
9109 </tr>
9110 <tr>
9111 <td style="vertical-align: top;">
9112 datum::N_A
9113 </td>
9114 <td style="vertical-align: top;">
9115 &nbsp;
9116 </td>
9117 <td style="vertical-align: top;">
9118 Avogadro constant
9119 </td>
9120 </tr>
9121 <tr>
9122 <td style="vertical-align: top;">
9123 datum::k
9124 </td>
9125 <td style="vertical-align: top;">
9126 &nbsp;
9127 </td>
9128 <td style="vertical-align: top;">
9129 Boltzmann constant (in joules per kelvin)
9130 </td>
9131 </tr>
9132 <tr>
9133 <td style="vertical-align: top;">
9134 datum::k_evk
9135 </td>
9136 <td style="vertical-align: top;">
9137 &nbsp;
9138 </td>
9139 <td style="vertical-align: top;">
9140 Boltzmann constant (in eV/K)
9141 </td>
9142 </tr>
9143 <tr>
9144 <td style="vertical-align: top;">
9145 datum::a_0
9146 </td>
9147 <td style="vertical-align: top;">
9148 &nbsp;
9149 </td>
9150 <td style="vertical-align: top;">
9151 Bohr radius (in meters)
9152 </td>
9153 </tr>
9154 <tr>
9155 <td style="vertical-align: top;">
9156 datum::mu_B
9157 </td>
9158 <td style="vertical-align: top;">
9159 &nbsp;
9160 </td>
9161 <td style="vertical-align: top;">
9162 Bohr magneton
9163 </td>
9164 </tr>
9165 <tr>
9166 <td style="vertical-align: top;">
9167 datum::Z_0
9168 </td>
9169 <td style="vertical-align: top;">
9170 &nbsp;
9171 </td>
9172 <td style="vertical-align: top;">
9173 characteristic impedance of vacuum (in ohms)
9174 </td>
9175 </tr>
9176 <tr>
9177 <td style="vertical-align: top;">
9178 datum::G_0
9179 </td>
9180 <td style="vertical-align: top;">
9181 &nbsp;
9182 </td>
9183 <td style="vertical-align: top;">
9184 conductance quantum (in siemens)
9185 </td>
9186 </tr>
9187 <tr>
9188 <td style="vertical-align: top;">
9189 datum::k_e
9190 </td>
9191 <td style="vertical-align: top;">
9192 &nbsp;
9193 </td>
9194 <td style="vertical-align: top;">
9195 Coulomb's constant (in meters per farad)
9196 </td>
9197 </tr>
9198 <tr>
9199 <td style="vertical-align: top;">
9200 datum::eps_0
9201 </td>
9202 <td style="vertical-align: top;">
9203 &nbsp;
9204 </td>
9205 <td style="vertical-align: top;">
9206 electric constant (in farads per meter)
9207 </td>
9208 </tr>
9209 <tr>
9210 <td style="vertical-align: top;">
9211 datum::m_e
9212 </td>
9213 <td style="vertical-align: top;">
9214 &nbsp;
9215 </td>
9216 <td style="vertical-align: top;">
9217 electron mass (in kg)
9218 </td>
9219 </tr>
9220 <tr>
9221 <td style="vertical-align: top;">
9222 datum::eV
9223 </td>
9224 <td style="vertical-align: top;">
9225 &nbsp;
9226 </td>
9227 <td style="vertical-align: top;">
9228 electron volt (in joules)
9229 </td>
9230 </tr>
9231 <tr>
9232 <td style="vertical-align: top;">
9233 datum::ec
9234 </td>
9235 <td style="vertical-align: top;">
9236 &nbsp;
9237 </td>
9238 <td style="vertical-align: top;">
9239 elementary charge (in coulombs)
9240 </td>
9241 </tr>
9242 <tr>
9243 <td style="vertical-align: top;">
9244 datum::F
9245 </td>
9246 <td style="vertical-align: top;">
9247 &nbsp;
9248 </td>
9249 <td style="vertical-align: top;">
9250 Faraday constant (in coulombs)
9251 </td>
9252 </tr>
9253 <tr>
9254 <td style="vertical-align: top;">
9255 datum::alpha
9256 </td>
9257 <td style="vertical-align: top;">
9258 &nbsp;
9259 </td>
9260 <td style="vertical-align: top;">
9261 fine-structure constant
9262 </td>
9263 </tr>
9264 <tr>
9265 <td style="vertical-align: top;">
9266 datum::alpha_inv
9267 </td>
9268 <td style="vertical-align: top;">
9269 &nbsp;
9270 </td>
9271 <td style="vertical-align: top;">
9272 inverse fine-structure constant
9273 </td>
9274 </tr>
9275 <tr>
9276 <td style="vertical-align: top;">
9277 datum::K_J
9278 </td>
9279 <td style="vertical-align: top;">
9280 &nbsp;
9281 </td>
9282 <td style="vertical-align: top;">
9283 Josephson constant
9284 </td>
9285 </tr>
9286 <tr>
9287 <td style="vertical-align: top;">
9288 datum::mu_0
9289 </td>
9290 <td style="vertical-align: top;">
9291 &nbsp;
9292 </td>
9293 <td style="vertical-align: top;">
9294 magnetic constant (in henries per meter)
9295 </td>
9296 </tr>
9297 <tr>
9298 <td style="vertical-align: top;">
9299 datum::phi_0
9300 </td>
9301 <td style="vertical-align: top;">
9302 &nbsp;
9303 </td>
9304 <td style="vertical-align: top;">
9305 magnetic flux quantum (in webers)
9306 </td>
9307 </tr>
9308 <tr>
9309 <td style="vertical-align: top;">
9310 datum::R
9311 </td>
9312 <td style="vertical-align: top;">
9313 &nbsp;
9314 </td>
9315 <td style="vertical-align: top;">
9316 molar gas constant (in joules per mole kelvin)
9317 </td>
9318 </tr>
9319 <tr>
9320 <td style="vertical-align: top;">
9321 datum::G
9322 </td>
9323 <td style="vertical-align: top;">
9324 &nbsp;
9325 </td>
9326 <td style="vertical-align: top;">
9327 Newtonian constant of gravitation (in newton square meters per kilogram squared)
9328 </td>
9329 </tr>
9330 <tr>
9331 <td style="vertical-align: top;">
9332 datum::h
9333 </td>
9334 <td style="vertical-align: top;">
9335 &nbsp;
9336 </td>
9337 <td style="vertical-align: top;">
9338 Planck constant (in joule seconds)
9339 </td>
9340 </tr>
9341 <tr>
9342 <td style="vertical-align: top;">
9343 datum::h_bar
9344 </td>
9345 <td style="vertical-align: top;">
9346 &nbsp;
9347 </td>
9348 <td style="vertical-align: top;">
9349 Planck constant over 2 pi, aka reduced Planck constant (in joule seconds)
9350 </td>
9351 </tr>
9352 <tr>
9353 <td style="vertical-align: top;">
9354 datum::m_p
9355 </td>
9356 <td style="vertical-align: top;">
9357 &nbsp;
9358 </td>
9359 <td style="vertical-align: top;">
9360 proton mass (in kg)
9361 </td>
9362 </tr>
9363 <tr>
9364 <td style="vertical-align: top;">
9365 datum::R_inf
9366 </td>
9367 <td style="vertical-align: top;">
9368 &nbsp;
9369 </td>
9370 <td style="vertical-align: top;">
9371 Rydberg constant (in reciprocal meters)
9372 </td>
9373 </tr>
9374 <tr>
9375 <td style="vertical-align: top;">
9376 datum::c_0
9377 </td>
9378 <td style="vertical-align: top;">
9379 &nbsp;
9380 </td>
9381 <td style="vertical-align: top;">
9382 speed of light in vacuum (in meters per second)
9383 </td>
9384 </tr>
9385 <tr>
9386 <td style="vertical-align: top;">
9387 datum::sigma
9388 </td>
9389 <td style="vertical-align: top;">
9390 &nbsp;
9391 </td>
9392 <td style="vertical-align: top;">
9393 Stefan-Boltzmann constant
9394 </td>
9395 </tr>
9396 <tr>
9397 <td style="vertical-align: top;">
9398 datum::R_k
9399 </td>
9400 <td style="vertical-align: top;">
9401 &nbsp;
9402 </td>
9403 <td style="vertical-align: top;">
9404 von Klitzing constant (in ohms)
9405 </td>
9406 </tr>
9407 <tr>
9408 <td style="vertical-align: top;">
9409 datum::b
9410 </td>
9411 <td style="vertical-align: top;">
9412 &nbsp;
9413 </td>
9414 <td style="vertical-align: top;">
9415 Wien wavelength displacement law constant
9416 </td>
9417 </tr>
9418 </tbody>
9419 </table>
9420 </ul>
9421 </li>
9422 <br>
9423 <li>
9424 <b>Caveat:</b>
9425 datum::nan is not equal to anything, even itself;
9426 if you wish to check whether a given number <i>x</i> is finite,
9427 use <a href="#is_finite_standalone">is_finite</a>(<i>x</i>).
9428 </li>
9429 <br>
9430 <li>
9431 Examples:
9432 <ul>
9433 <pre>
9434 cout &lt;&lt; "2.0 * pi = " &lt;&lt; 2.0 * datum::pi &lt;&lt; endl;
9435
9436 cout &lt;&lt; "speed of light = " &lt;&lt; datum::c_0 &lt;&lt; endl;
9437
9438 cout &lt;&lt; "log_max for floats = ";
9439 cout &lt;&lt; fdatum::log_max &lt;&lt; endl;
9440
9441 cout &lt;&lt; "log_max for doubles = ";
9442 cout &lt;&lt; datum::log_max &lt;&lt; endl;
9443 </pre>
9444 </ul>
9445 </li>
9446 <li>
9447 See also:
9448 <ul>
9449 <li><a href="#is_finite_standalone">is_finite()</a></li>
9450 <li><a href="http://en.wikipedia.org/wiki/NaN">NaN</a> in Wikipedia</li>
9451 <li><a href="http://en.wikipedia.org/wiki/Physical_constant">physical constant</a> in Wikipedia</li>
9452 <li><a href="http://cplusplus.com/reference/std/limits/numeric_limits/">std::numeric_limits</a></li>
9453 </ul>
9454 </li>
9455 </ul>
9456 <br>
9457 <hr class="greyline"><br>
9458
9459 <!--
9460 <a name="log_add"></a>
9461 <b>log_add(log_a, log_b)</b>
9462 <ul>
9463 <li>
9464 Safe replacement for log(exp(log_a) + exp(log_b))
9465 </li>
9466 <br>
9467 <li>
9468 Usage:
9469 <ul>
9470 <li>
9471 <i>scalar_type</i> log_c = log_add(log_a, log_b)
9472 </li>
9473 <li>
9474 <i>scalar_type</i> is either <i>float</i> or <i>double</i>
9475 </li>
9476 <li>
9477 log_a, log_b and log_c must have the same type
9478 </li>
9479 </ul>
9480 </li>
9481 </ul>
9482 <br>
9483 <hr class="greyline"><br>
9484 -->
9485
9486 <a name="uword"></a>
9487 <b>uword</b>, <b>sword</b>
9488 <ul>
9489 <li>
9490 <i>uword</i> is a typedef for an unsigned integer with a minimum width of 32 bits; if <i>ARMA_64BIT_WORD</i> is enabled, the minimum width is 64 bits
9491 </li>
9492 <br>
9493 <li>
9494 <i>sword</i> is a typedef for a signed integer with a minimum width of 32 bits; if <i>ARMA_64BIT_WORD</i> is enabled, the minimum width is 64 bits
9495 </li>
9496 <br>
9497 <li>
9498 <a href="#config_hpp_arma_64bit_word"><i>ARMA_64BIT_WORD</i></a> can be enabled via editing <i>include/armadillo_bits/config.hpp</i>
9499 </li>
9500 <br>
9501 <li>See also:
9502 <ul>
9503 <li><a href="http://cplusplus.com/doc/tutorial/variables/">C++ variable types</a></li>
9504 <li><a href="http://www.cplusplus.com/doc/tutorial/other_data_types/">explanation of <i>typedef</i></a></li>
9505 <li><a href="#Mat">imat &amp; umat</a> matrix types
9506 <li><a href="#Col">ivec &amp; uvec</a> vector types
9507 </ul>
9508 </li>
9509 <br>
9510 </ul>
9511 <hr class="greyline"><br>
9512
9513 <a name="cx_float_double"></a>
9514 <b>cx_float</b>, <b>cx_double</b>
9515 <ul>
9516 <li>
9517 cx_float is a typedef for <i>std::complex&lt;float&gt;</i>
9518 </li>
9519 <br>
9520 <li>
9521 cx_double is a typedef for <i>std::complex&lt;double&gt;</i>
9522 </li>
9523 <br>
9524 <li>See also:
9525 <ul>
9526 <li><a href="http://cplusplus.com/reference/std/complex/">complex numbers in the standard C++ library</a></li>
9527 <li><a href="http://www.cplusplus.com/doc/tutorial/other_data_types/">explanation of <i>typedef</i></a></li>
9528 <li><a href="#Mat">cx_mat</a> matrix type
9529 <li><a href="#Col">cx_vec</a> vector type
9530 </ul>
9531 </li>
9532 <br>
9533 </ul>
9534
9535 <a name="syntax"></a>
9536 <hr class="greyline">
9537 <br>
9538 <b>
9539 Examples of Matlab/Octave syntax and conceptually corresponding Armadillo syntax
9540 </b>
9541 <br>
9542 <br>
9543 <ul>
9544 <table style="text-align: left;" border="0" cellpadding="2" cellspacing="2">
9545 <tbody>
9546 <tr>
9547 <td style="vertical-align: top;">
9548 <b>Matlab/Octave</b>
9549 </td>
9550 <td style="vertical-align: top;">
9551 &nbsp;
9552 </td>
9553 <td style="vertical-align: top;">
9554 <b>Armadillo</b>
9555 </td>
9556 <td style="vertical-align: top;">
9557 &nbsp;
9558 </td>
9559 <td style="vertical-align: top;">
9560 <b>Notes</b>
9561 </td>
9562 </tr>
9563 <tr>
9564 <td style="vertical-align: top;">
9565 &nbsp;
9566 </td>
9567 <td style="vertical-align: top;">
9568 &nbsp;
9569 </td>
9570 <td style="vertical-align: top;">
9571 &nbsp;
9572 </td>
9573 <td style="vertical-align: top;">
9574 &nbsp;
9575 </td>
9576 <td style="vertical-align: top;">
9577 &nbsp;
9578 </td>
9579 </tr>
9580 <tr>
9581 <td style="vertical-align: top;">
9582 A(1, 1)
9583 </td>
9584 <td style="vertical-align: top;">
9585 &nbsp;
9586 </td>
9587 <td style="vertical-align: top;">
9588 A(0, 0)
9589 </td>
9590 <td style="vertical-align: top;">
9591 &nbsp;
9592 </td>
9593 <td style="vertical-align: top;">
9594 indexing in Armadillo starts at 0
9595 </td>
9596 </tr>
9597 <tr>
9598 <td style="vertical-align: top;">
9599 A(k, k)
9600 </td>
9601 <td style="vertical-align: top;">
9602 &nbsp;
9603 </td>
9604 <td style="vertical-align: top;">
9605 A(k-1, k-1)
9606 </td>
9607 <td style="vertical-align: top;">
9608 &nbsp;
9609 </td>
9610 <td style="vertical-align: top;">
9611 &nbsp;
9612 </td>
9613 </tr>
9614 <tr>
9615 <td style="vertical-align: top;">
9616 &nbsp;
9617 </td>
9618 <td style="vertical-align: top;">
9619 &nbsp;
9620 </td>
9621 <td style="vertical-align: top;">
9622 &nbsp;
9623 </td>
9624 <td style="vertical-align: top;">
9625 &nbsp;
9626 </td>
9627 <td style="vertical-align: top;">
9628 &nbsp;
9629 </td>
9630 </tr>
9631 <tr>
9632 <td style="vertical-align: top;">
9633 size(A,1)
9634 </td>
9635 <td style="vertical-align: top;">
9636 &nbsp;
9637 </td>
9638 <td style="vertical-align: top;">
9639 A<a href="#attributes">.n_rows</a>
9640 </td>
9641 <td style="vertical-align: top;">
9642 &nbsp;
9643 </td>
9644 <td style="vertical-align: top;">
9645 read only
9646 </td>
9647 </tr>
9648 <tr>
9649 <td style="vertical-align: top;">
9650 size(A,2)
9651 </td>
9652 <td style="vertical-align: top;">
9653 &nbsp;
9654 </td>
9655 <td style="vertical-align: top;">
9656 A<a href="#attributes">.n_cols</a>
9657 </td>
9658 <td style="vertical-align: top;">
9659 &nbsp;
9660 </td>
9661 <td style="vertical-align: top;">
9662 &nbsp;
9663 </td>
9664 </tr>
9665 <tr>
9666 <td style="vertical-align: top;">
9667 size(Q,3)
9668 </td>
9669 <td style="vertical-align: top;">
9670 &nbsp;
9671 </td>
9672 <td style="vertical-align: top;">
9673 Q<a href="#attributes">.n_slices</a>
9674 </td>
9675 <td style="vertical-align: top;">
9676 &nbsp;
9677 </td>
9678 <td style="vertical-align: top;">
9679 Q is a <a href="#Cube">cube</a> (3D array)
9680 </td>
9681 </tr>
9682 <tr>
9683 <td style="vertical-align: top;">
9684 numel(A)
9685 </td>
9686 <td style="vertical-align: top;">
9687 &nbsp;
9688 </td>
9689 <td style="vertical-align: top;">
9690 A<a href="#attributes">.n_elem</a>
9691 </td>
9692 <td style="vertical-align: top;">
9693 &nbsp;
9694 </td>
9695 <td style="vertical-align: top;">
9696 &nbsp;
9697 </td>
9698 </tr>
9699 <tr>
9700 <td style="vertical-align: top;">
9701 &nbsp;
9702 </td>
9703 <td style="vertical-align: top;">
9704 &nbsp;
9705 </td>
9706 <td style="vertical-align: top;">
9707 &nbsp;
9708 </td>
9709 <td style="vertical-align: top;">
9710 &nbsp;
9711 </td>
9712 <td style="vertical-align: top;">
9713 &nbsp;
9714 </td>
9715 </tr>
9716 <tr>
9717 <td style="vertical-align: top;">
9718 A(:, k)
9719 </td>
9720 <td style="vertical-align: top;">
9721 &nbsp;
9722 </td>
9723 <td style="vertical-align: top;">
9724 A<a href="#submat">.col</a>(k)
9725 </td>
9726 <td style="vertical-align: top;">
9727 &nbsp;
9728 </td>
9729 <td style="vertical-align: top;">
9730 this is a conceptual example only;
9731 exact conversion from Matlab/Octave to Armadillo syntax
9732 will require taking into account that indexing starts at 0
9733 </td>
9734 </tr>
9735 <tr>
9736 <td style="vertical-align: top;">
9737 A(k, :)
9738 </td>
9739 <td style="vertical-align: top;">
9740 &nbsp;
9741 </td>
9742 <td style="vertical-align: top;">
9743 A<a href="#submat">.row</a>(k)
9744 </td>
9745 <td style="vertical-align: top;">
9746 &nbsp;
9747 </td>
9748 <td style="vertical-align: top;">
9749 &nbsp;
9750 </td>
9751 </tr>
9752 <tr>
9753 <td style="vertical-align: top;">
9754 A(:, p:q)
9755 </td>
9756 <td style="vertical-align: top;">
9757 &nbsp;
9758 </td>
9759 <td style="vertical-align: top;">
9760 A<a href="#submat">.cols</a>(p, q)
9761 </td>
9762 <td style="vertical-align: top;">
9763 &nbsp;
9764 </td>
9765 <td style="vertical-align: top;">
9766 &nbsp;
9767 </td>
9768 </tr>
9769 <tr>
9770 <td style="vertical-align: top;">
9771 A(p:q, :)
9772 </td>
9773 <td style="vertical-align: top;">
9774 &nbsp;
9775 </td>
9776 <td style="vertical-align: top;">
9777 A<a href="#submat">.rows</a>(p, q)
9778 </td>
9779 <td style="vertical-align: top;">
9780 &nbsp;
9781 </td>
9782 <td style="vertical-align: top;">
9783 &nbsp;
9784 </td>
9785 </tr>
9786 <tr>
9787 <td style="vertical-align: top;">
9788 &nbsp;
9789 </td>
9790 <td style="vertical-align: top;">
9791 &nbsp;
9792 </td>
9793 <td style="vertical-align: top;">
9794 &nbsp;
9795 </td>
9796 <td style="vertical-align: top;">
9797 &nbsp;
9798 </td>
9799 <td style="vertical-align: top;">
9800 &nbsp;
9801 </td>
9802 </tr>
9803 <tr>
9804 <td style="vertical-align: top;">
9805 A(p:q, r:s)
9806 </td>
9807 <td style="vertical-align: top;">
9808 &nbsp;
9809 </td>
9810 <td style="vertical-align: top;">
9811 <font size=-1>
9812 A<a href="#submat">.submat</a>(p, r, q, s)
9813 </font>
9814 </td>
9815 <td style="vertical-align: top;">
9816 &nbsp;
9817 </td>
9818 <td style="vertical-align: top;">
9819 <font size=-1>
9820 A.submat(first_row, first_col, last_row, last_col)
9821 </font>
9822 </td>
9823 </tr>
9824 <tr>
9825 <td style="vertical-align: top;">
9826 &nbsp;
9827 </td>
9828 <td style="vertical-align: top;">
9829 &nbsp;
9830 </td>
9831 <td style="vertical-align: top;">
9832 <font size=-1>
9833 or
9834 </font>
9835 </td>
9836 <td style="vertical-align: top;">
9837 &nbsp;
9838 </td>
9839 <td style="vertical-align: top;">
9840 &nbsp;
9841 </td>
9842 </tr>
9843 <tr>
9844 <td style="vertical-align: top;">
9845 &nbsp;
9846 </td>
9847 <td style="vertical-align: top;">
9848 &nbsp;
9849 </td>
9850 <td style="vertical-align: top;">
9851 <font size=-1>
9852 A(&nbsp;<a href="#submat">span</a>(p,q),&nbsp;<a href="#submat">span</a>(r,s)&nbsp;)
9853 </font>
9854 </td>
9855 <td style="vertical-align: top;">
9856 &nbsp;
9857 </td>
9858 <td style="vertical-align: top;">
9859 <font size=-1>
9860 A(&nbsp;span(first_row,&nbsp;last_row), span(first_col,&nbsp;last_col)&nbsp;)
9861 </font>
9862 </td>
9863 </tr>
9864 <tr>
9865 <td style="vertical-align: top;">
9866 &nbsp;
9867 </td>
9868 <td style="vertical-align: top;">
9869 &nbsp;
9870 </td>
9871 <td style="vertical-align: top;">
9872 &nbsp;
9873 </td>
9874 <td style="vertical-align: top;">
9875 &nbsp;
9876 </td>
9877 <td style="vertical-align: top;">
9878 &nbsp;
9879 </td>
9880 </tr>
9881 <tr>
9882 <td style="vertical-align: top;">
9883 Q(:, :, k)
9884 </td>
9885 <td style="vertical-align: top;">
9886 &nbsp;
9887 </td>
9888 <td style="vertical-align: top;">
9889 Q<a href="#subcube">.slice</a>(k)
9890 </td>
9891 <td style="vertical-align: top;">
9892 &nbsp;
9893 </td>
9894 <td style="vertical-align: top;">
9895 Q is a <a href="#Cube">cube</a> (3D array)
9896 </td>
9897 </tr>
9898 <tr>
9899 <td style="vertical-align: top;">
9900 Q(:, :, t:u)
9901 </td>
9902 <td style="vertical-align: top;">
9903 &nbsp;
9904 </td>
9905 <td style="vertical-align: top;">
9906 Q<a href="#subcube">.slices</a>(t, u)
9907 </td>
9908 <td style="vertical-align: top;">
9909 &nbsp;
9910 </td>
9911 <td style="vertical-align: top;">
9912 &nbsp;
9913 </td>
9914 </tr>
9915 <tr>
9916 <td style="vertical-align: top;">
9917 &nbsp;
9918 </td>
9919 <td style="vertical-align: top;">
9920 &nbsp;
9921 </td>
9922 <td style="vertical-align: top;">
9923 &nbsp;
9924 </td>
9925 <td style="vertical-align: top;">
9926 &nbsp;
9927 </td>
9928 <td style="vertical-align: top;">
9929 &nbsp;
9930 </td>
9931 </tr>
9932 <tr>
9933 <td style="vertical-align: top;">
9934 Q(p:q, r:s, t:u)
9935 </td>
9936 <td style="vertical-align: top;">
9937 &nbsp;
9938 </td>
9939 <td style="vertical-align: top;">
9940 <font size=-1>
9941 Q<a href="#subcube">.subcube</a>(p,&nbsp;r,&nbsp;t,&nbsp;q,&nbsp;s,&nbsp;u)
9942 </font>
9943 </td>
9944 <td style="vertical-align: top;">
9945 &nbsp;
9946 </td>
9947 <td style="vertical-align: top;">
9948 <font size=-1>
9949 .subcube(first_row, first_col, first_slice, last_row, last_col, last_slice)
9950 </font>
9951 </td>
9952 </tr>
9953 <tr>
9954 <td style="vertical-align: top;">
9955 &nbsp;
9956 </td>
9957 <td style="vertical-align: top;">
9958 &nbsp;
9959 </td>
9960 <td style="vertical-align: top;">
9961 <font size=-1>
9962 or
9963 </font>
9964 </td>
9965 <td style="vertical-align: top;">
9966 &nbsp;
9967 </td>
9968 <td style="vertical-align: top;">
9969 &nbsp;
9970 </td>
9971 </tr>
9972 <tr>
9973 <td style="vertical-align: top;">
9974 &nbsp;
9975 </td>
9976 <td style="vertical-align: top;">
9977 &nbsp;
9978 </td>
9979 <td style="vertical-align: top;">
9980 <font size=-1>
9981 Q(&nbsp;<a href="#subcube">span</a>(p,q),&nbsp;<a href="#subcube">span</a>(r,s),&nbsp;<a href="#subcube">span</a>(t,u)&nbsp;)
9982 </font>
9983 </td>
9984 <td style="vertical-align: top;">
9985 &nbsp;
9986 </td>
9987 <td style="vertical-align: top;">
9988 &nbsp;
9989 </td>
9990 </tr>
9991 <tr>
9992 <td style="vertical-align: top;">
9993 &nbsp;
9994 </td>
9995 <td style="vertical-align: top;">
9996 &nbsp;
9997 </td>
9998 <td style="vertical-align: top;">
9999 &nbsp;
10000 </td>
10001 <td style="vertical-align: top;">
10002 &nbsp;
10003 </td>
10004 <td style="vertical-align: top;">
10005 &nbsp;
10006 </td>
10007 </tr>
10008 <tr>
10009 <td style="vertical-align: top;">
10010 A'
10011 </td>
10012 <td style="vertical-align: top;">
10013 &nbsp;
10014 </td>
10015 <td style="vertical-align: top;">
10016 A<a href="#t_st_members">.t()</a> or <a href="#trans">trans</a>(A)
10017 </td>
10018 <td style="vertical-align: top;">
10019 &nbsp;
10020 </td>
10021 <td style="vertical-align: top;">
10022 matrix transpose / Hermitian transpose
10023 <br>
10024 (for complex matrices, the conjugate of each element is taken)
10025 </td>
10026 </tr>
10027 <tr>
10028 <td style="vertical-align: top;">
10029 A.'
10030 </td>
10031 <td style="vertical-align: top;">
10032 &nbsp;
10033 </td>
10034 <td style="vertical-align: top;">
10035 A<a href="#t_st_members">.st()</a> or <a href="#strans">strans</a>(A)
10036 </td>
10037 <td style="vertical-align: top;">
10038 &nbsp;
10039 </td>
10040 <td style="vertical-align: top;">
10041 simple matrix transpose
10042 <br>
10043 (for complex matrices, the conjugate of each element is not taken)
10044 </td>
10045 </tr>
10046 <tr>
10047 <td style="vertical-align: top;">
10048 &nbsp;
10049 </td>
10050 <td style="vertical-align: top;">
10051 &nbsp;
10052 </td>
10053 <td style="vertical-align: top;">
10054 &nbsp;
10055 </td>
10056 <td style="vertical-align: top;">
10057 &nbsp;
10058 </td>
10059 <td style="vertical-align: top;">
10060 &nbsp;
10061 </td>
10062 </tr>
10063 <tr>
10064 <td style="vertical-align: top;">
10065 A = zeros(size(A))
10066 </td>
10067 <td style="vertical-align: top;">
10068 &nbsp;
10069 </td>
10070 <td style="vertical-align: top;">
10071 A<a href="#zeros_member">.zeros()</a>
10072 </td>
10073 <td style="vertical-align: top;">
10074 &nbsp;
10075 </td>
10076 <td style="vertical-align: top;">
10077 &nbsp;
10078 </td>
10079 </tr>
10080 <tr>
10081 <td style="vertical-align: top;">
10082 A = ones(size(A))
10083 </td>
10084 <td style="vertical-align: top;">
10085 &nbsp;
10086 </td>
10087 <td style="vertical-align: top;">
10088 A.<a href="#ones_member">ones()</a>
10089 </td>
10090 <td style="vertical-align: top;">
10091 &nbsp;
10092 </td>
10093 <td style="vertical-align: top;">
10094 &nbsp;
10095 </td>
10096 </tr>
10097 <tr>
10098 <td style="vertical-align: top;">
10099 A = zeros(k)
10100 </td>
10101 <td style="vertical-align: top;">
10102 &nbsp;
10103 </td>
10104 <td style="vertical-align: top;">
10105 A = <a href="#zeros_standalone">zeros</a>&lt;mat&gt;(k,k)
10106 </td>
10107 <td style="vertical-align: top;">
10108 &nbsp;
10109 </td>
10110 <td style="vertical-align: top;">
10111 &nbsp;
10112 </td>
10113 </tr>
10114 <tr>
10115 <td style="vertical-align: top;">
10116 A = ones(k)
10117 </td>
10118 <td style="vertical-align: top;">
10119 &nbsp;
10120 </td>
10121 <td style="vertical-align: top;">
10122 A = <a href="#ones_standalone">ones</a>&lt;mat&gt;(k,k)
10123 </td>
10124 <td style="vertical-align: top;">
10125 &nbsp;
10126 </td>
10127 <td style="vertical-align: top;">
10128 &nbsp;
10129 </td>
10130 </tr>
10131 <tr>
10132 <td style="vertical-align: top;">
10133 &nbsp;
10134 </td>
10135 <td style="vertical-align: top;">
10136 &nbsp;
10137 </td>
10138 <td style="vertical-align: top;">
10139 &nbsp;
10140 </td>
10141 <td style="vertical-align: top;">
10142 &nbsp;
10143 </td>
10144 <td style="vertical-align: top;">
10145 &nbsp;
10146 </td>
10147 </tr>
10148 <tr>
10149 <td style="vertical-align: top;">
10150 C = complex(A,B)
10151 </td>
10152 <td style="vertical-align: top;">
10153 &nbsp;
10154 </td>
10155 <td style="vertical-align: top;">
10156 cx_mat C = <a href="#Mat">cx_mat</a>(A,B)
10157 </td>
10158 <td style="vertical-align: top;">
10159 &nbsp;
10160 </td>
10161 <td style="vertical-align: top;">
10162 &nbsp;
10163 </td>
10164 </tr>
10165 <tr>
10166 <td style="vertical-align: top;">
10167 &nbsp;
10168 </td>
10169 <td style="vertical-align: top;">
10170 &nbsp;
10171 </td>
10172 <td style="vertical-align: top;">
10173 &nbsp;
10174 </td>
10175 <td style="vertical-align: top;">
10176 &nbsp;
10177 </td>
10178 <td style="vertical-align: top;">
10179 &nbsp;
10180 </td>
10181 </tr>
10182 <tr>
10183 <td style="vertical-align: top;">
10184 A .* B
10185 </td>
10186 <td style="vertical-align: top;">
10187 &nbsp;
10188 </td>
10189 <td style="vertical-align: top;">
10190 A % B
10191 </td>
10192 <td style="vertical-align: top;">
10193 &nbsp;
10194 </td>
10195 <td style="vertical-align: top;">
10196 <a href="#operators">element-wise multiplication</a>
10197 </td>
10198 </tr>
10199 <tr>
10200 <td style="vertical-align: top;">
10201 A ./ B
10202 </td>
10203 <td style="vertical-align: top;">
10204 &nbsp;
10205 </td>
10206 <td style="vertical-align: top;">
10207 A / B
10208 </td>
10209 <td style="vertical-align: top;">
10210 &nbsp;
10211 </td>
10212 <td style="vertical-align: top;">
10213 <a href="#operators">element-wise division</a>
10214 </td>
10215 </tr>
10216 <tr>
10217 <td style="vertical-align: top;">
10218 A \ B
10219 </td>
10220 <td style="vertical-align: top;">
10221 &nbsp;
10222 </td>
10223 <td style="vertical-align: top;">
10224 <a href="#solve">solve</a>(A,B)
10225 </td>
10226 <td style="vertical-align: top;">
10227 &nbsp;
10228 </td>
10229 <td style="vertical-align: top;">
10230 conceptually similar to <a href="#inv">inv</a>(A)*B, but more efficient
10231 </td>
10232 </tr>
10233 <tr>
10234 <td style="vertical-align: top;">
10235 A = A + 1;
10236 </td>
10237 <td style="vertical-align: top;">
10238 &nbsp;
10239 </td>
10240 <td style="vertical-align: top;">
10241 A++
10242 </td>
10243 <td style="vertical-align: top;">
10244 &nbsp;
10245 </td>
10246 <td style="vertical-align: top;">
10247 &nbsp;
10248 </td>
10249 </tr>
10250 <tr>
10251 <td style="vertical-align: top;">
10252 A = A - 1;
10253 </td>
10254 <td style="vertical-align: top;">
10255 &nbsp;
10256 </td>
10257 <td style="vertical-align: top;">
10258 A--
10259 </td>
10260 <td style="vertical-align: top;">
10261 &nbsp;
10262 </td>
10263 <td style="vertical-align: top;">
10264 &nbsp;
10265 </td>
10266 </tr>
10267 <tr>
10268 <td style="vertical-align: top;">
10269 &nbsp;
10270 </td>
10271 <td style="vertical-align: top;">
10272 &nbsp;
10273 </td>
10274 <td style="vertical-align: top;">
10275 &nbsp;
10276 </td>
10277 <td style="vertical-align: top;">
10278 &nbsp;
10279 </td>
10280 <td style="vertical-align: top;">
10281 &nbsp;
10282 </td>
10283 </tr>
10284 <tr>
10285 <td style="vertical-align: top;">
10286 A = [ 1 2; 3 4; ]
10287 </td>
10288 <td style="vertical-align: top;">
10289 &nbsp;
10290 </td>
10291 <td style="vertical-align: top;">
10292 A&nbsp;<font size=-1>&lt;&lt;</font> 1 <font size=-1>&lt;&lt;</font> 2 <font size=-1>&lt;&lt;</font> endr<br>
10293 &nbsp;&nbsp;&nbsp;<font size=-1>&lt;&lt;</font> 3 <font size=-1>&lt;&lt;</font> 4 <font size=-1>&lt;&lt;</font> endr;
10294 </td>
10295 <td style="vertical-align: top;">
10296 &nbsp;
10297 </td>
10298 <td style="vertical-align: top;">
10299 <a href="#element_initialisation">element initialisation</a>,
10300 with special element <i>endr</i> indicating <i>end of row</i>
10301 </td>
10302 </tr>
10303 <tr>
10304 <td style="vertical-align: top;">
10305 &nbsp;
10306 </td>
10307 <td style="vertical-align: top;">
10308 &nbsp;
10309 </td>
10310 <td style="vertical-align: top;">
10311 &nbsp;
10312 </td>
10313 <td style="vertical-align: top;">
10314 &nbsp;
10315 </td>
10316 <td style="vertical-align: top;">
10317 &nbsp;
10318 </td>
10319 </tr>
10320 <tr>
10321 <td style="vertical-align: top;">
10322 X = [&nbsp;A&nbsp;&nbsp;B&nbsp;]
10323 </td>
10324 <td style="vertical-align: top;">
10325 &nbsp;
10326 </td>
10327 <td style="vertical-align: top;">
10328 X = <a href="#join">join_rows</a>(A,B)
10329 </td>
10330 <td style="vertical-align: top;">
10331 &nbsp;
10332 </td>
10333 <td style="vertical-align: top;">
10334 &nbsp;
10335 </td>
10336 </tr>
10337 <tr>
10338 <td style="vertical-align: top;">
10339 X = [&nbsp;A;&nbsp;B&nbsp;]
10340 </td>
10341 <td style="vertical-align: top;">
10342 &nbsp;
10343 </td>
10344 <td style="vertical-align: top;">
10345 X = <a href="#join">join_cols</a>(A,B)
10346 </td>
10347 <td style="vertical-align: top;">
10348 &nbsp;
10349 </td>
10350 <td style="vertical-align: top;">
10351 &nbsp;
10352 </td>
10353 </tr>
10354 <tr>
10355 <td style="vertical-align: top;">
10356 &nbsp;
10357 </td>
10358 <td style="vertical-align: top;">
10359 &nbsp;
10360 </td>
10361 <td style="vertical-align: top;">
10362 &nbsp;
10363 </td>
10364 <td style="vertical-align: top;">
10365 &nbsp;
10366 </td>
10367 <td style="vertical-align: top;">
10368 &nbsp;
10369 </td>
10370 </tr>
10371 <tr>
10372 <td style="vertical-align: top;">
10373 A
10374 </td>
10375 <td style="vertical-align: top;">
10376 &nbsp;
10377 </td>
10378 <td style="vertical-align: top;">
10379 cout <font size=-1>&lt;&lt;</font> A <font size=-1>&lt;&lt;</font> endl;
10380 <br>or
10381 <br>A<a href="#print">.print</a>("A =");
10382 </td>
10383 <td style="vertical-align: top;">
10384 &nbsp;
10385 </td>
10386 <td style="vertical-align: top;">
10387 &nbsp;
10388 </td>
10389 </tr>
10390 <tr>
10391 <td style="vertical-align: top;">
10392 &nbsp;
10393 </td>
10394 <td style="vertical-align: top;">
10395 &nbsp;
10396 </td>
10397 <td style="vertical-align: top;">
10398 &nbsp;
10399 </td>
10400 <td style="vertical-align: top;">
10401 &nbsp;
10402 </td>
10403 <td style="vertical-align: top;">
10404 &nbsp;
10405 </td>
10406 </tr>
10407 <tr>
10408 <td style="vertical-align: top;">
10409 save&nbsp;-ascii&nbsp;'A.dat'&nbsp;A
10410 </td>
10411 <td style="vertical-align: top;">
10412 &nbsp;
10413 </td>
10414 <td style="vertical-align: top;">
10415 A<a href="#save_load_mat">.save</a>("A.dat",&nbsp;raw_ascii);
10416 </td>
10417 <td style="vertical-align: top;">
10418 &nbsp;
10419 </td>
10420 <td style="vertical-align: top;">
10421 Matlab/Octave matrices saved as ascii are readable by Armadillo (and vice-versa)
10422 </td>
10423 </tr>
10424 <tr>
10425 <td style="vertical-align: top;">
10426 load&nbsp;-ascii&nbsp;'A.dat'
10427 </td>
10428 <td style="vertical-align: top;">
10429 &nbsp;
10430 </td>
10431 <td style="vertical-align: top;">
10432 A<a href="#save_load_mat">.load</a>("A.dat",&nbsp;raw_ascii);
10433 </td>
10434 <td style="vertical-align: top;">
10435 &nbsp;
10436 </td>
10437 <td style="vertical-align: top;">
10438 &nbsp;
10439 </td>
10440 </tr>
10441 <tr>
10442 <td style="vertical-align: top;">
10443 &nbsp;
10444 </td>
10445 <td style="vertical-align: top;">
10446 &nbsp;
10447 </td>
10448 <td style="vertical-align: top;">
10449 &nbsp;
10450 </td>
10451 <td style="vertical-align: top;">
10452 &nbsp;
10453 </td>
10454 <td style="vertical-align: top;">
10455 &nbsp;
10456 </td>
10457 </tr>
10458 <tr>
10459 <td style="vertical-align: top;">
10460 S&nbsp;=&nbsp;{&nbsp;'abc';&nbsp;'def'&nbsp;}
10461 </td>
10462 <td style="vertical-align: top;">
10463 &nbsp;
10464 </td>
10465 <td style="vertical-align: top;">
10466 <a href="#field">field</a>&lt;std::string&gt; S(2);
10467 <br>S(0) = "abc";
10468 <br>S(1) = "def";
10469 </td>
10470 <td style="vertical-align: top;">
10471 &nbsp;
10472 </td>
10473 <td style="vertical-align: top;">
10474 <a href="#field">fields</a> can store arbitrary objects, in a 1D or 2D layout
10475 </td>
10476 </tr>
10477 </tbody>
10478 </table>
10479 </ul>
10480 <br>
10481
10482 <a name="example_prog"></a>
10483 <hr class="greyline">
10484 <br>
10485 <b>example program</b>
10486 <br>
10487 <br>
10488 <ul>
10489 <li>
10490 If you save the program below as <i>example.cpp</i>,
10491 under Linux you can compile it using:
10492 <br>
10493 g++ example.cpp -o example -O1 -larmadillo
10494 </li>
10495 <ul>
10496 <pre>
10497 #include &lt;iostream&gt;
10498 #include &lt;armadillo&gt;
10499
10500 using namespace std;
10501 using namespace arma;
10502
10503 int main(int argc, char** argv)
10504 {
10505 mat A = randu&lt;mat&gt;(4,5);
10506 mat B = randu&lt;mat&gt;(4,5);
10507
10508 cout &lt;&lt; A*B.t() &lt;&lt; endl;
10509
10510 return 0;
10511 }
10512 </pre>
10513 </ul>
10514 <li>
10515 You may also want to have a look at the example programs that come with the Armadillo archive.
10516 </li>
10517 <br>
10518 <li>
10519 As Armadillo is a template library, we strongly recommended to have optimisation enabled when compiling programs
10520 (eg. when compiling with GCC, use the -O1 or -O2 options).
10521 </li>
10522 </ul>
10523 <br>
10524
10525
10526
10527 <a name="config_hpp"></a>
10528 <hr class="greyline">
10529 <br>
10530 <b>config.hpp</b>
10531 <br>
10532 <br>
10533 <ul>
10534 <li>
10535 Armadillo can be configured via editing the file <i>include/armadillo_bits/config.hpp</i>.
10536 Specific functionality can be enabled or disabled by uncommenting or commenting out a particular <i>#define</i>, listed below.
10537 <br>
10538 <br>
10539 <table style="text-align: left;" border="0" cellpadding="2" cellspacing="2">
10540 <tbody>
10541 <tr>
10542 <td style="vertical-align: top;">
10543 ARMA_USE_LAPACK
10544 </td>
10545 <td style="vertical-align: top;">
10546 &nbsp;
10547 </td>
10548 <td style="vertical-align: top;">
10549 Enable the use of LAPACK, or a high-speed replacement for LAPACK (eg. Intel MKL, AMD ACML or the Accelerate framework).
10550 Armadillo requires LAPACK for functions such as <a href="#svd">svd()</a>, <a href="#inv">inv()</a>, <a href="#eig_sym">eig_sym()</a>, <a href="#solve">solve()</a>, etc.
10551 </td>
10552 </tr>
10553 <tr>
10554 <td style="vertical-align: top;">
10555 &nbsp;
10556 </td>
10557 <td style="vertical-align: top;">
10558 &nbsp;
10559 </td>
10560 <td style="vertical-align: top;">
10561 &nbsp;
10562 </td>
10563 <td style="vertical-align: top;">
10564 &nbsp;
10565 </td>
10566 <td style="vertical-align: top;">
10567 &nbsp;
10568 </td>
10569 </tr>
10570 <tr>
10571 <td style="vertical-align: top;">
10572 ARMA_USE_BLAS
10573 </td>
10574 <td style="vertical-align: top;">
10575 &nbsp;
10576 </td>
10577 <td style="vertical-align: top;">
10578 Enable the use of BLAS, or a high-speed replacement for BLAS (eg. OpenBLAS, Intel MKL, AMD ACML or the Accelerate framework).
10579 BLAS is used for <a href="#operators">matrix multiplication</a>.
10580 Without BLAS, Armadillo will use a built-in matrix multiplication routine, which might be slower for large matrices.
10581 <!--However, if you're using 64 bit operating system with 32 bit BLAS, it's better to disable the use of BLAS.-->
10582 </td>
10583 </tr>
10584 <tr>
10585 <td style="vertical-align: top;">
10586 &nbsp;
10587 </td>
10588 <td style="vertical-align: top;">
10589 &nbsp;
10590 </td>
10591 <td style="vertical-align: top;">
10592 &nbsp;
10593 </td>
10594 <td style="vertical-align: top;">
10595 &nbsp;
10596 </td>
10597 <td style="vertical-align: top;">
10598 &nbsp;
10599 </td>
10600 </tr>
10601 <tr>
10602 <td style="vertical-align: top;">
10603 ARMA_BLAS_CAPITALS
10604 </td>
10605 <td style="vertical-align: top;">
10606 &nbsp;
10607 </td>
10608 <td style="vertical-align: top;">
10609 Use capitalised (uppercase) BLAS and LAPACK function names (eg. DGEMM vs dgemm)
10610 </td>
10611 </tr>
10612 <tr>
10613 <td style="vertical-align: top;">
10614 &nbsp;
10615 </td>
10616 <td style="vertical-align: top;">
10617 &nbsp;
10618 </td>
10619 <td style="vertical-align: top;">
10620 &nbsp;
10621 </td>
10622 <td style="vertical-align: top;">
10623 &nbsp;
10624 </td>
10625 <td style="vertical-align: top;">
10626 &nbsp;
10627 </td>
10628 </tr>
10629 <tr>
10630 <td style="vertical-align: top;">
10631 ARMA_BLAS_UNDERSCORE
10632 </td>
10633 <td style="vertical-align: top;">
10634 &nbsp;
10635 </td>
10636 <td style="vertical-align: top;">
10637 Append an underscore to BLAS and LAPACK function names (eg. dgemm_ vs dgemm). Enabled by default.
10638 </td>
10639 </tr>
10640 <tr>
10641 <td style="vertical-align: top;">
10642 &nbsp;
10643 </td>
10644 <td style="vertical-align: top;">
10645 &nbsp;
10646 </td>
10647 <td style="vertical-align: top;">
10648 &nbsp;
10649 </td>
10650 <td style="vertical-align: top;">
10651 &nbsp;
10652 </td>
10653 <td style="vertical-align: top;">
10654 &nbsp;
10655 </td>
10656 </tr>
10657 <tr>
10658 <td style="vertical-align: top;">
10659 ARMA_BLAS_LONG
10660 </td>
10661 <td style="vertical-align: top;">
10662 &nbsp;
10663 </td>
10664 <td style="vertical-align: top;">
10665 Use "long" instead of "int" when calling BLAS and LAPACK functions
10666 </td>
10667 </tr>
10668 <tr>
10669 <td style="vertical-align: top;">
10670 &nbsp;
10671 </td>
10672 <td style="vertical-align: top;">
10673 &nbsp;
10674 </td>
10675 <td style="vertical-align: top;">
10676 &nbsp;
10677 </td>
10678 <td style="vertical-align: top;">
10679 &nbsp;
10680 </td>
10681 <td style="vertical-align: top;">
10682 &nbsp;
10683 </td>
10684 </tr>
10685 <tr>
10686 <td style="vertical-align: top;">
10687 ARMA_BLAS_LONG_LONG
10688 </td>
10689 <td style="vertical-align: top;">
10690 &nbsp;
10691 </td>
10692 <td style="vertical-align: top;">
10693 Use "long long" instead of "int" when calling BLAS and LAPACK functions
10694 </td>
10695 </tr>
10696 <tr>
10697 <td style="vertical-align: top;">
10698 &nbsp;
10699 </td>
10700 <td style="vertical-align: top;">
10701 &nbsp;
10702 </td>
10703 <td style="vertical-align: top;">
10704 &nbsp;
10705 </td>
10706 <td style="vertical-align: top;">
10707 &nbsp;
10708 </td>
10709 <td style="vertical-align: top;">
10710 &nbsp;
10711 </td>
10712 </tr>
10713 <tr>
10714 <td style="vertical-align: top;">
10715 ARMA_USE_TBB_ALLOC
10716 </td>
10717 <td style="vertical-align: top;">
10718 &nbsp;
10719 </td>
10720 <td style="vertical-align: top;">
10721 Use Intel TBB <i>scalable_malloc()</i> and <i>scalable_free()</i> instead of standard <i>new[]</i> and <i>delete[]</i> for managing matrix memory
10722 </td>
10723 </tr>
10724 <tr>
10725 <td style="vertical-align: top;">
10726 &nbsp;
10727 </td>
10728 <td style="vertical-align: top;">
10729 &nbsp;
10730 </td>
10731 <td style="vertical-align: top;">
10732 &nbsp;
10733 </td>
10734 <td style="vertical-align: top;">
10735 &nbsp;
10736 </td>
10737 <td style="vertical-align: top;">
10738 &nbsp;
10739 </td>
10740 </tr>
10741 <tr>
10742 <td style="vertical-align: top;">
10743 ARMA_USE_MKL_ALLOC
10744 </td>
10745 <td style="vertical-align: top;">
10746 &nbsp;
10747 </td>
10748 <td style="vertical-align: top;">
10749 Use Intel MKL <i>mkl_malloc()</i> and <i>mkl_free()</i> instead of standard <i>new[]</i> and <i>delete[]</i> for managing matrix memory
10750 </td>
10751 </tr>
10752 <tr>
10753 <td style="vertical-align: top;">
10754 &nbsp;
10755 </td>
10756 <td style="vertical-align: top;">
10757 &nbsp;
10758 </td>
10759 <td style="vertical-align: top;">
10760 &nbsp;
10761 </td>
10762 <td style="vertical-align: top;">
10763 &nbsp;
10764 </td>
10765 <td style="vertical-align: top;">
10766 &nbsp;
10767 </td>
10768 </tr>
10769 <tr>
10770 <td style="vertical-align: top;">
10771 <a name="config_hpp_arma_64bit_word"></a>
10772 ARMA_64BIT_WORD
10773 </td>
10774 <td style="vertical-align: top;">
10775 &nbsp;
10776 </td>
10777 <td style="vertical-align: top;">
10778 Use 64 bit integers. Useful if you require matrices/vectors capable of holding more than 4 billion elements.
10779 Your machine and compiler must have support for 64 bit integers (eg. via "long" or "long long").
10780 This can also be enabled by adding <i>#define&nbsp;ARMA_64BIT_WORD</i> before each instance of <i>#include&nbsp;&lt;armadillo&gt;</i>.
10781 </td>
10782 </tr>
10783 <tr>
10784 <td style="vertical-align: top;">
10785 &nbsp;
10786 </td>
10787 <td style="vertical-align: top;">
10788 &nbsp;
10789 </td>
10790 <td style="vertical-align: top;">
10791 &nbsp;
10792 </td>
10793 <td style="vertical-align: top;">
10794 &nbsp;
10795 </td>
10796 <td style="vertical-align: top;">
10797 &nbsp;
10798 </td>
10799 </tr>
10800 <tr>
10801 <td style="vertical-align: top;">
10802 <a name="config_hpp_arma_use_cxx11"></a>
10803 ARMA_USE_CXX11
10804 </td>
10805 <td style="vertical-align: top;">
10806 &nbsp;
10807 </td>
10808 <td style="vertical-align: top;">
10809 Use C++11 features, such as <a href="#element_initialisation">initialiser lists</a>
10810 </td>
10811 </tr>
10812 <tr>
10813 <td style="vertical-align: top;">
10814 &nbsp;
10815 </td>
10816 <td style="vertical-align: top;">
10817 &nbsp;
10818 </td>
10819 <td style="vertical-align: top;">
10820 &nbsp;
10821 </td>
10822 <td style="vertical-align: top;">
10823 &nbsp;
10824 </td>
10825 <td style="vertical-align: top;">
10826 &nbsp;
10827 </td>
10828 </tr>
10829 <tr>
10830 <td style="vertical-align: top;">
10831 ARMA_USE_HDF5
10832 </td>
10833 <td style="vertical-align: top;">
10834 &nbsp;
10835 </td>
10836 <td style="vertical-align: top;">
10837 Enable the the ability to <a href="#save_load_mat">save and load</a> matrices stored in the HDF5 format;
10838 the <i>hdf5.h</i> header file must be available on your system and you will need to link with the hdf5 library (eg. -lhdf5)
10839 </td>
10840 </tr>
10841 <tr>
10842 <td style="vertical-align: top;">
10843 &nbsp;
10844 </td>
10845 <td style="vertical-align: top;">
10846 &nbsp;
10847 </td>
10848 <td style="vertical-align: top;">
10849 &nbsp;
10850 </td>
10851 <td style="vertical-align: top;">
10852 &nbsp;
10853 </td>
10854 <td style="vertical-align: top;">
10855 &nbsp;
10856 </td>
10857 </tr>
10858 <tr>
10859 <td style="vertical-align: top;">
10860 <a name="config_hpp_arma_no_debug"></a>
10861 ARMA_NO_DEBUG
10862 </td>
10863 <td style="vertical-align: top;">
10864 &nbsp;
10865 </td>
10866 <td style="vertical-align: top;">
10867 Disable all run-time checks, such as <a href="#element_access">bounds checking</a>.
10868 This will result in faster code, but you first need to make sure that your code runs correctly!
10869 We strongly recommend to have the run-time checks enabled during development,
10870 as this greatly aids in finding mistakes in your code, and hence speeds up development.
10871 We recommend that run-time checks be disabled <b>only</b> for the shipped version of your program.
10872 </td>
10873 </tr>
10874 <tr>
10875 <td style="vertical-align: top;">
10876 &nbsp;
10877 </td>
10878 <td style="vertical-align: top;">
10879 &nbsp;
10880 </td>
10881 <td style="vertical-align: top;">
10882 &nbsp;
10883 </td>
10884 <td style="vertical-align: top;">
10885 &nbsp;
10886 </td>
10887 <td style="vertical-align: top;">
10888 &nbsp;
10889 </td>
10890 </tr>
10891 <tr>
10892 <td style="vertical-align: top;">
10893 ARMA_EXTRA_DEBUG
10894 </td>
10895 <td style="vertical-align: top;">
10896 &nbsp;
10897 </td>
10898 <td style="vertical-align: top;">
10899 Print out the trace of internal functions used for evaluating expressions.
10900 Not recommended for normal use.
10901 This is mainly useful for debugging the library.
10902 </td>
10903 </tr>
10904 <tr>
10905 <td style="vertical-align: top;">
10906 &nbsp;
10907 </td>
10908 <td style="vertical-align: top;">
10909 &nbsp;
10910 </td>
10911 <td style="vertical-align: top;">
10912 &nbsp;
10913 </td>
10914 <td style="vertical-align: top;">
10915 &nbsp;
10916 </td>
10917 <td style="vertical-align: top;">
10918 &nbsp;
10919 </td>
10920 </tr>
10921 <tr>
10922 <td style="vertical-align: top;">
10923 ARMA_MAT_PREALLOC
10924 </td>
10925 <td style="vertical-align: top;">
10926 &nbsp;
10927 </td>
10928 <td style="vertical-align: top;">
10929 The number of preallocated elements used by matrices and vectors.
10930 Must be always enabled and set to an integer that is at least&nbsp;1.
10931 By default set to 16.
10932 If you mainly use lots of very small vectors (eg. &le; 4 elements), change the number to the size of your vectors.
10933 </td>
10934 </tr>
10935 <tr>
10936 <td style="vertical-align: top;">
10937 &nbsp;
10938 </td>
10939 <td style="vertical-align: top;">
10940 &nbsp;
10941 </td>
10942 <td style="vertical-align: top;">
10943 &nbsp;
10944 </td>
10945 <td style="vertical-align: top;">
10946 &nbsp;
10947 </td>
10948 <td style="vertical-align: top;">
10949 &nbsp;
10950 </td>
10951 </tr>
10952 <tr>
10953 <td style="vertical-align: top;">
10954 ARMA_DEFAULT_OSTREAM
10955 </td>
10956 <td style="vertical-align: top;">
10957 &nbsp;
10958 </td>
10959 <td style="vertical-align: top;">
10960 The default stream used for printing <a href="#logging">error messages</a> and by <a href="#print">.print()</a>.
10961 Must be always enabled.
10962 By default this is set to <i>std::cout</i>
10963 </td>
10964 </tr>
10965 <tr>
10966 <td style="vertical-align: top;">
10967 &nbsp;
10968 </td>
10969 <td style="vertical-align: top;">
10970 &nbsp;
10971 </td>
10972 <td style="vertical-align: top;">
10973 &nbsp;
10974 </td>
10975 <td style="vertical-align: top;">
10976 &nbsp;
10977 </td>
10978 <td style="vertical-align: top;">
10979 &nbsp;
10980 </td>
10981 </tr>
10982 <tr>
10983 <td style="vertical-align: top;">
10984 ARMA_DONT_USE_LAPACK
10985 </td>
10986 <td style="vertical-align: top;">
10987 &nbsp;
10988 </td>
10989 <td style="vertical-align: top;">
10990 Disable use of LAPACK. Overrides <i>ARMA_USE_LAPACK</i>
10991 </td>
10992 </tr>
10993 <tr>
10994 <td style="vertical-align: top;">
10995 &nbsp;
10996 </td>
10997 <td style="vertical-align: top;">
10998 &nbsp;
10999 </td>
11000 <td style="vertical-align: top;">
11001 &nbsp;
11002 </td>
11003 <td style="vertical-align: top;">
11004 &nbsp;
11005 </td>
11006 <td style="vertical-align: top;">
11007 &nbsp;
11008 </td>
11009 </tr>
11010 <tr>
11011 <td style="vertical-align: top;">
11012 ARMA_DONT_USE_BLAS
11013 </td>
11014 <td style="vertical-align: top;">
11015 &nbsp;
11016 </td>
11017 <td style="vertical-align: top;">
11018 Disable use of BLAS. Overrides <i>ARMA_USE_BLAS</i>
11019 </td>
11020 </tr>
11021 <tr>
11022 <td style="vertical-align: top;">
11023 &nbsp;
11024 </td>
11025 <td style="vertical-align: top;">
11026 &nbsp;
11027 </td>
11028 <td style="vertical-align: top;">
11029 &nbsp;
11030 </td>
11031 <td style="vertical-align: top;">
11032 &nbsp;
11033 </td>
11034 <td style="vertical-align: top;">
11035 &nbsp;
11036 </td>
11037 </tr>
11038 </tbody>
11039 </table>
11040 </li>
11041
11042 <br>
11043 <li>
11044 See also:
11045 <ul>
11046 <li><a href="#logging">logging of warnings and errors</a></li>
11047 <li><a href="#element_access">element access</a></li>
11048 <li><a href="#element_initialisation">element initialisation</a></li>
11049 <li><a href="#uword">uword/sword</a></li>
11050 </ul>
11051 </li>
11052 <br>
11053 </ul>
11054 <br>
11055
11056
11057
11058 <!--
11059 <a name="catching_exceptions"></a>
11060 <hr class="greyline">
11061 <br>
11062 <b>how to catch std::runtime_error exceptions</b>
11063 <br>
11064 <br>
11065 <ul>
11066 <li>
11067 If a function such as <a href="#inv">inv()</a> fails to find a solution,
11068 an error message is printed and a <i>std::runtime_error</i> exception is thrown.
11069 If the exception is not caught, the program typically terminates.
11070 Below is an example of how to catch exceptions:
11071 <ul>
11072 <pre>
11073 #include &lt;iostream&gt;
11074 #include &lt;armadillo&gt;
11075
11076 using namespace std;
11077 using namespace arma;
11078
11079 int main(int argc, char** argv)
11080 {
11081 // create a non-invertible matrix
11082 mat A = zeros&lt;mat&gt;(5,5);
11083
11084 mat B;
11085
11086 try
11087 {
11088 B = inv(A);
11089 }
11090 catch (std::runtime_error&amp; x)
11091 {
11092 cout &lt;&lt; "caught an exception" &lt;&lt; endl;
11093 }
11094
11095 return 0;
11096 }
11097 </pre>
11098 </ul>
11099 <li>
11100 See also:
11101 <ul>
11102 <li><a href="#logging">logging of warnings and errors</a></li>
11103 <li><a href="http://cplusplus.com/doc/tutorial/exceptions/">tutorial on exceptions</a></li>
11104 <li><a href="http://cplusplus.com/reference/std/stdexcept/runtime_error/">std::runtime_error</a></li>
11105 </ul>
11106 </li>
11107 <br>
11108 </ul>
11109 <br>
11110 -->
11111
11112 <a name="api_additions"></a>
11113 <a name="api_changes"></a>
11114 <hr class="greyline">
11115 <br>
11116 <b>API Additions, Changes and Deprecations</b>
11117 <br>
11118 <br>
11119 <li>API and Version Policy
11120 <ul>
11121 <li>
11122 Armadillo's version number is X.Y.Z, where X is a major version, Y is a minor version, and Z is the patch level (indicating bug fixes).
11123 </li>
11124 <br>
11125 <li>
11126 Within each major version (eg. 3.x), minor versions with an even number (eg. 3.2) are backwards compatible with earlier even minor versions (eg. 3.0).
11127 For example, code written for version 3.0 will work with version 3.2.
11128 However, as each minor version may have more features (ie. API extensions) than earlier versions,
11129 code specifically written for version 3.2 doesn't necessarily work with 3.0.
11130 </li>
11131 <br>
11132 <li>
11133 An odd minor version number (eg. 3.3) indicates an experimental version.
11134 Experimental versions are generally faster and have more functionality,
11135 but their APIs have not been finalised yet.
11136 </li>
11137 <br>
11138 <li>
11139 In general, we don't like changes to existing APIs and prefer not to break any user software.
11140 However, to allow evolution and help code maintenance, we reserve the right to change the APIs in future major versions of Armadillo,
11141 while remaining backwards compatible wherever possible
11142 (eg. 4.0 may have slightly different APIs than 3.x).
11143 Also, in a rare instance the user API may need to be altered if a bug fix absolutely requires it.
11144 </li>
11145 </ul>
11146 </li>
11147
11148 <!--
11149 <br>
11150 <li>
11151 <a name="deprecated"></a>
11152 List of deprecated functionality; this functionality will be <b>removed</b> in version 4.0:
11153 <ul>
11154 <li>
11155 ...
11156 </li>
11157 </ul>
11158 </li>
11159 -->
11160
11161 <br>
11162 <br>
11163 <li>
11164 List of additions and changes for each version:
11165 <br>
11166 <br>
11167 <ul>
11168 <a name="added_in_3900"></a>
11169 <li>Added in 3.900:
11170 <ul>
11171 <li>automatic SSE2 vectorisation of elementary expressions (eg. matrix addition) when using GCC 4.7+ with -O3 optimisation</li>
11172 <li>faster <a href="#stats_fns">median()</a></li>
11173 <li>faster handling of compound expressions with transposes of <a href="#submat">submatrix</a> rows</li>
11174 <li>faster handling of compound expressions with transposes of complex vectors</li>
11175 <li>added support for <a href="#save_load_mat">saving &amp; loading</a> of <a href="#Cube">cubes</a> in HDF5 format</li>
11176 </ul>
11177 </li>
11178 <br>
11179 <a name="added_in_3820"></a>
11180 <li>Added in 3.820:
11181 <ul>
11182 <li>faster <a href="#as_scalar">as_scalar()</a> for compound expressions</li>
11183 <li>faster transpose of small vectors</li>
11184 <li>faster matrix-vector product for small vectors</li>
11185 <li>faster multiplication of small <a href="#adv_constructors_mat_fixed">fixed size matrices</a></li>
11186 </ul>
11187 </li>
11188 <br>
11189 <a name="added_in_3810"></a>
11190 <li>Added in 3.810:
11191 <ul>
11192 <li>fast Fourier transform: <a href="#fft">fft()</a></li>
11193 <li>handling of <a href="#imbue">.imbue()</a> and <a href="#transform">.transform()</a> by submatrices and subcubes</li>
11194 <li><a href="#batch_constructors_sp_mat">batch insertion constructors</a> for sparse matrices
11195 </ul>
11196 </li>
11197 <br>
11198 <a name="added_in_3800"></a>
11199 <li>Added in 3.800:
11200 <ul>
11201 <li><a href="#imbue">.imbue()</a> for filling a matrix/cube with values provided by a functor or lambda expression</li>
11202 <li><a href="#swap">.swap()</a> for swapping contents with another matrix</li>
11203 <li><a href="#transform">.transform()</a> for transforming a matrix/cube using a functor or lambda expression</li>
11204 <li><a href="#misc_fns">round()</a> for rounding matrix elements towards nearest integer</li>
11205 <li>faster <a href="#find">find()</a></li>
11206 </ul>
11207 </li>
11208 <br>
11209 <li>Changed in 3.800:
11210 <ul>
11211 <li>Armadillo is now licensed using the <a href="http://www.mozilla.org/MPL/2.0/">Mozilla Public License 2.0</a>;
11212 <br>
11213 see also the associated <a href="http://www.mozilla.org/MPL/2.0/FAQ.html">frequently asked questions</a> about the license</li>
11214 </ul>
11215 <br>
11216 </li>
11217 <a name="added_in_36"></a>
11218 <li>Added in 3.6:
11219 <ul>
11220 <li>faster handling of compound expressions with submatrices and subcubes</li>
11221 <li>faster <a href="#trace">trace()</a></li>
11222 <li>support for loading matrices as text files with <i>NaN</i> and <i>Inf</i> elements</li>
11223 <li><a href="#sort_index">stable_sort_index()</a>, which preserves the relative order of elements with equivalent values</li>
11224 <li>handling of <a href="#SpMat">sparse matrices</a> by <a href="#stats_fns">mean()</a>, <a href="#stats_fns">var()</a>, <a href="#norm">norm()</a>, <a href="#abs">abs()</a>, <a href="#misc_fns">square()</a>, <a href="#misc_fns">sqrt()</a></li>
11225 <li>saving and loading of sparse matrices in <i>arma_binary</i> format</li>
11226 </ul>
11227 <br>
11228 </li>
11229 <a name="added_in_34"></a>
11230 <li>Added in 3.4:
11231 <ul>
11232 <li>economical QR decomposition: <a href="#qr_econ">qr_econ()</a></li>
11233 <li><a href="#each_colrow">.each_col() &amp; .each_row()</a> for vector operations repeated on each column or row of a matrix</li>
11234 <li>preliminary support for <a href="#SpMat">sparse matrices</a></li>
11235 <li>ability to <a href="#save_load_mat">save and load</a> matrices in HDF5 format</li>
11236 <li>faster <a href="#svd">singular value decomposition</a> via optional use of divide-and-conquer algorithm</li>
11237 <li>faster <a href="#randu_randn_member">.randn()</a></li>
11238 <li>faster <a href="#dot">dot() and cdot()</a> for complex numbers</li>
11239 </ul>
11240 <br>
11241 </li>
11242 <a name="added_in_32"></a>
11243 <li>Added in 3.2:
11244 <ul>
11245 <li><a href="#unique">unique()</a>, for finding unique elements of a matrix</li>
11246 <li><a href="#eval_member">.eval()</a>, for forcing the evaluation of delayed expressions</li>
11247 <li>faster <a href="#eig_sym">eigen decomposition</a> via optional use of divide-and-conquer algorithm</li>
11248 <li>faster <a href="#t_st_members">transpose</a> of vectors and compound expressions</li>
11249 <li>faster handling of <a href="#diag">diagonal views</a></li>
11250 <li>faster handling of tiny <a href="#adv_constructors_col_fixed">fixed size</a> vectors (&le; 4 elements)</li>
11251 </ul>
11252 <br>
11253 </li>
11254 <a name="added_in_30"></a>
11255 <li>Added in 3.0:
11256 <ul>
11257 <li>shorthand for inverse: <a href="#i_member">.i()</a></li>
11258 <li><a href="#constants">datum</a> class</li>
11259 <li><a href="#hist">hist()</a> and <a href="#histc">histc()</a></li>
11260 <li>non-contiguous <a href="#submat">submatrix views</a></li>
11261 <li>faster handling of <a href="#submat">submatrix views</a> with a single row or column</li>
11262 <li>faster element access in <a href="#adv_constructors_mat_fixed">fixed size matrices</a></li>
11263 <li>faster <a href="#repmat">repmat()</a></li>
11264 </ul>
11265 <br>
11266 </li>
11267 <li>Changed in 3.0:
11268 <ul>
11269 <li>expressions <i>X=<a href="#inv">inv</a>(A)*B</i> and <i>X=A<a href="#i_member">.i()</a>*B</i> are automatically converted to <i>X=<a href="#solve">solve</a>(A,B)</i>
11270 <li>better detection of vector expressions by <a href="#sum">sum()</a>, <a href="#cumsum">cumsum()</a>, <a href="#prod">prod()</a>, <a href="#min_and_max">min()</a>, <a href="#min_and_max">max()</a>, <a href="#stats_fns">mean()</a>, <a href="#stats_fns">median()</a>, <a href="#stats_fns">stddev()</a>, <a href="#stats_fns">var()</a>
11271 <li>faster generation of random numbers
11272 (eg. <a href="#randu_randn_standalone">randu()</a> and <a href="#randu_randn_standalone">randn()</a>),
11273 via an algorithm that produces slightly different numbers than in 2.x
11274 </li>
11275 <li>
11276 support for tying writeable auxiliary (external) memory to fixed size matrices has been removed;
11277 instead, you can use standard matrices with <a href="#adv_constructors_mat">writeable auxiliary memory</a>,
11278 or initialise fixed size matrices by <a href="#adv_constructors_mat">copying the memory</a>.
11279 Using auxiliary memory with standard matrices is unaffected.
11280 </li>
11281 <li>
11282 <i>.print_trans()</i> and <i>.raw_print_trans()</i> have been removed;
11283 instead, you can chain <i><a href="#t_st_members">.t()</a></i> and <i><a href="#print">.print()</a></i> to achieve a similar result: <i>X.t().print()</i>
11284 </li>
11285 </ul>
11286 <br>
11287 </li>
11288 <a name="added_in_24"></a>
11289 <li>Added in 2.4:
11290 <ul>
11291 <li>shorter forms of transposes: <a href="#t_st_members">.t()</a> and <a href="#t_st_members">.st()</a></li>
11292 <li><a href="#resize_member">.resize()</a> and <a href="#resize">resize()</a></li>
11293 <li>optional use of 64 bit indices (allowing matrices to have more than 4 billion elements),
11294 <br>enabled via ARMA_64BIT_WORD in <i>include/armadillo_bits/config.hpp</i></li>
11295 <li>experimental support for C++11 initialiser lists,
11296 <br>enabled via ARMA_USE_CXX11 in <i>include/armadillo_bits/config.hpp</i></li>
11297 </ul>
11298 <br>
11299 <li>Changed in 2.4:
11300 <ul>
11301 <li>refactored code to eliminate warnings when using the Clang C++ compiler</li>
11302 <li><a href="#Mat">umat</a>, <a href="#Col">uvec</a>, <a href="#min_and_max_member">.min()</a> and <a href="#min_and_max_member">.max()</a>
11303 have been changed to use the <a href="#uword"><i>uword</i></a> type instead of the <i>u32</i> type;
11304 by default the <i>uword</i> and <i>u32</i> types are equivalent (ie. unsigned integer type with a minimum width 32 bits);
11305 however, when the use of 64 bit indices is enabled via ARMA_64BIT_WORD in <i>include/armadillo_bits/config.hpp</i>,
11306 the <i>uword</i> type then has a minimum width of 64 bits
11307 </ul>
11308 </li>
11309 <br>
11310 <li>Added in 2.2:
11311 <ul>
11312 <li><a href="#svd_econ">svd_econ()</a></li>
11313 <li><a href="#toeplitz">circ_toeplitz()</a></li>
11314 <li><a href="#is_vec">.is_colvec()</a> and <a href="#is_vec">.is_rowvec()</a></li>
11315 </ul>
11316 <br>
11317 <li>Added in 2.0:
11318 <ul>
11319 <li><a href="#det">det()</a>, <a href="#inv">inv()</a> and <a href="#solve">solve()</a> can be forced to use more precise algorithms for tiny matrices (&le;&nbsp;4x4)</li>
11320 <li><a href="#syl">syl()</a>, for solving Sylvester's equation</li>
11321 <li><a href="#strans">strans()</a>, for transposing a complex matrix without taking the complex conjugate</li>
11322 <li><a href="#symmat">symmatu()</a> and <a href="#symmat">symmatl()</a></li>
11323 <li>submatrices of <a href="#submat">submatrices</a></li>
11324 <li>faster <a href="#inv">inverse</a> of symmetric positive definite matrices</li>
11325 <li>faster element access for <a href="#adv_constructors_mat_fixed">fixed size</a> matrices</li>
11326 <li>faster multiplication of tiny matrices (eg. 4x4)</li>
11327 <li>faster compound expressions containing <a href="#submat">submatrices</a></li>
11328 <li>handling of arbitrarily sized empty matrices (eg. 5x0)</li>
11329 <li>.count() member function in <a href="#running_stat">running_stat</a> and <a href="#running_stat_vec">running_stat_vec</a></li>
11330 <li><a href="#save_load_mat">loading &amp; saving</a> of matrices as CSV text files</li>
11331 </ul>
11332 <br>
11333 <li>Changed in 2.0:
11334 <ul>
11335 <li><a href="#trans">trans()</a> now takes the complex conjugate when transposing a complex matrix</li>
11336 <li>Forms of
11337 <a href="#chol">chol()</a>, <a href="#eig_sym">eig_sym()</a>, <a href="#eig_gen">eig_gen()</a>,
11338 <a href="#inv">inv()</a>, <a href="#lu">lu()</a>, <a href="#pinv">pinv()</a>, <a href="#princomp">princomp()</a>,
11339 <a href="#qr">qr()</a>, <a href="#solve">solve()</a>, <a href="#svd">svd()</a>, <a href="#syl">syl()</a>
11340 that do not return a bool indicating success now throw <i>std::runtime_error</i> exceptions when failures are detected</li>
11341 <li>princomp_cov() has been removed; <a href="#eig_sym">eig_sym()</a> in conjunction with <a href="#cov">cov()</a> can be used instead</li>
11342 <li><a href="#is_vec">.is_vec()</a> now outputs <i>true</i> for empty vectors (eg. 0x1)</li>
11343 <li>set_log_stream() &amp; get_log_stream() have been replaced by <a href="#logging">set_stream_err1()</a> &amp; <a href="#logging">get_stream_err1()</a></li>
11344 </ul>
11345 <br>
11346 <li>Added in 1.2:
11347 <ul>
11348 <li><a href="#min_and_max_member">.min() &amp; .max()</a> member functions of Mat and Cube</li>
11349 <li><a href="#misc_fns">floor()</a> and <a href="#misc_fns">ceil()</a></li>
11350 <li>representation of &ldquo;not a number&rdquo;: math::nan()</li>
11351 <li>representation of infinity: math::inf()</li>
11352 <li>standalone <a href="#is_finite_standalone">is_finite()</a></li>
11353 <li><a href="#in_range">.in_range()</a> can use <b>span()</b> arguments</li>
11354 <li><a href="#adv_constructors_mat">fixed size</a> matrices and vectors can use auxiliary (external) memory</li>
11355 <li><a href="#submat">submatrices</a> and <a href="#subfield">subfields</a> can be accessed via <i><b>X(</b>&nbsp;<b>span(</b>a,b<b>)</b>,&nbsp;<b>span(</b>c,d<b>)</b>&nbsp;<b>)</b></i></li>
11356 <li><a href="#subcube">subcubes</a> can be accessed via <i><b>X(</b>&nbsp;<b>span(</b>a,b<b>)</b>,&nbsp;<b>span(</b>c,d<b>)</b>,&nbsp;<b>span(</b>e,f<b>)</b>&nbsp;<b>)</b></i></li>
11357 <li>the two argument version of <i><b>span</b></i> can be replaced by
11358 <i><b>span::all</b></i> or <i><b>span()</b></i>, to indicate an entire range
11359 </li>
11360 <li>for cubes, the two argument version of <i><b>span</b></i> can be replaced by
11361 a single argument version, <i><b>span(</b>a<b>)</b></i>, to indicate a single column, row or slice
11362 </li>
11363 <li>arbitrary "flat" subcubes can be interpreted as matrices; for example:
11364 <ul>
11365 <pre>
11366 cube Q = randu&lt;cube&gt;(5,3,4);
11367 mat A = Q(&nbsp;span(1),&nbsp;span(1,2),&nbsp;span::all&nbsp;);
11368 // A has a size of 2x4
11369
11370 vec v = ones&lt;vec&gt;(4);
11371 Q(&nbsp;span(1),&nbsp;span(1),&nbsp;span::all&nbsp;)&nbsp;=&nbsp;v;
11372 </pre>
11373 </ul>
11374 </li>
11375 <li>interpretation of matrices as triangular through <a href="#trimat">trimatu() / trimatl()</a></li>
11376 <li>explicit handling of triangular matrices by <a href="#solve">solve()</a> and <a href="#inv">inv()</a></li>
11377 <li>extended syntax for <a href="#submat">submatrices</a>, including access to elements whose indices are specified in a vector</li>
11378 <li>ability to change the stream used for <a href="#logging">logging</a> of errors and warnings</li>
11379 <li>ability to <a href="#save_load_mat">save/load matrices</a> in raw binary format</li>
11380 <li>cumulative sum function: <a href="#cumsum">cumsum()</a></li>
11381 </ul>
11382 </li>
11383 <br>
11384 <li>
11385 Changed in 1.0 (compared to earlier 0.x development versions):
11386 <ul>
11387 <li>
11388 the 3 argument version of <a href="#lu">lu()</a>,
11389 eg. lu(L,U,X),
11390 provides L and U which should be the same as produced by Octave 3.2
11391 (this was not the case in versions prior to 0.9.90)
11392 </li>
11393 <br>
11394 <li>
11395 rand() has been replaced by <a href="#randu_randn_standalone">randu()</a>;
11396 this has been done to avoid confusion with <a href="http://cplusplus.com/reference/clibrary/cstdlib/rand/">std::rand()</a>,
11397 which generates random numbers in a different interval
11398 </li>
11399 <br>
11400 <li>
11401 In versions earlier than 0.9.0,
11402 some multiplication operations directly converted result matrices with a size of 1x1 into scalars.
11403 This is no longer the case.
11404 If you know the result of an expression will be a 1x1 matrix and wish to treat it as a pure scalar,
11405 use the <a href="#as_scalar">as_scalar()</a> wrapping function
11406 </li>
11407 <br>
11408 <li>
11409 Almost all functions have been placed in the delayed operations framework (for speed purposes).
11410 This may affect code which assumed that the output of some functions was a pure matrix.
11411 The solution is easy, as explained below.
11412 <br>
11413 <br>
11414 In general, Armadillo queues operations before executing them.
11415 As such, the direct output of an operation or function cannot be assumed to be a directly accessible matrix.
11416 The queued operations are executed when the output needs to be stored in a matrix,
11417 eg. <i>mat&nbsp;B&nbsp;=&nbsp;trans(A)</i> or <i>mat&nbsp;B(trans(A))</i>.
11418 If you need to force the execution of the delayed operations,
11419 place the operation or function inside the corresponding Mat constructor.
11420 For example, if your code assumed that the output of some functions was a pure matrix,
11421 eg. <i>chol(m).diag()</i>, change the code to <i>mat(chol(m)).diag()</i>.
11422 Similarly, if you need to pass the result of an operation such as <i>A+B</i> to one of your own functions,
11423 use <i>my_function(&nbsp;mat(A+B)&nbsp;)</i>.
11424 </li>
11425 </ul>
11426 </li>
11427 </ul>
11428 </li>
11429 <br>
11430 <br>
11431 <br>
11432
11433
11434 <!-- END CONTENT -->
11435
11436
11437 <hr>
11438 <br>
11439 <br>
11440
11441 </td>
11442 </tr>
11443 </tbody>
11444 </table>
11445 </center>
11446 </body>
11447 </html>