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