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