comparison armadillo-2.4.4/examples/example2.cpp @ 0:8b6102e2a9b0

Armadillo Library
author maxzanoni76 <max.zanoni@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 09:27:06 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8b6102e2a9b0
1 #include <iostream>
2
3 #include "armadillo"
4
5 using namespace arma;
6 using namespace std;
7
8
9 int main(int argc, char** argv)
10 {
11 cout << "Armadillo version: " << arma_version::as_string() << endl;
12
13 mat A;
14
15 A << 0.165300 << 0.454037 << 0.995795 << 0.124098 << 0.047084 << endr
16 << 0.688782 << 0.036549 << 0.552848 << 0.937664 << 0.866401 << endr
17 << 0.348740 << 0.479388 << 0.506228 << 0.145673 << 0.491547 << endr
18 << 0.148678 << 0.682258 << 0.571154 << 0.874724 << 0.444632 << endr
19 << 0.245726 << 0.595218 << 0.409327 << 0.367827 << 0.385736 << endr;
20
21 A.print("A =");
22
23 // determinant
24 cout << "det(A) = " << det(A) << endl;
25
26 // inverse
27 cout << "inv(A) = " << endl << inv(A) << endl;
28
29
30 //
31
32 double k = 1.23;
33
34 mat B = randu<mat>(5,5);
35 mat C = randu<mat>(5,5);
36
37 rowvec r = randu<rowvec>(5);
38 colvec q = randu<colvec>(5);
39
40
41 // examples of some expressions
42 // for which optimised implementations exist
43
44 // optimised implementation of a trinary expression
45 // that results in a scalar
46 cout << "as_scalar( r*inv(diagmat(B))*q ) = ";
47 cout << as_scalar( r*inv(diagmat(B))*q ) << endl;
48
49 // example of an expression which is optimised
50 // as a call to the dgemm() function in BLAS:
51 cout << "k*trans(B)*C = " << endl << k*trans(B)*C;
52
53
54 // If you want to see a trace of how Armadillo
55 // evaluates expressions, compile with the
56 // ARMA_EXTRA_DEBUG macro defined.
57 // This was designed to work with the GCC compiler,
58 // but it may also work with other compilers
59 // if you have the Boost libraries installed
60 // and told Armadillo to use them.
61 //
62 // Example for GCC:
63 // g++ example2.cpp -o example2 -larmadillo -DARMA_EXTRA_DEBUG
64 //
65 // Running example2 will now produce a truckload of messages,
66 // so you may want to redirect the output to a log file.
67
68 return 0;
69 }
70