Chris@49: #include Chris@49: Chris@49: #include "armadillo" Chris@49: Chris@49: using namespace arma; Chris@49: using namespace std; Chris@49: Chris@49: Chris@49: int main(int argc, char** argv) Chris@49: { Chris@49: cout << "Armadillo version: " << arma_version::as_string() << endl; Chris@49: Chris@49: mat A; Chris@49: Chris@49: A << 0.165300 << 0.454037 << 0.995795 << 0.124098 << 0.047084 << endr Chris@49: << 0.688782 << 0.036549 << 0.552848 << 0.937664 << 0.866401 << endr Chris@49: << 0.348740 << 0.479388 << 0.506228 << 0.145673 << 0.491547 << endr Chris@49: << 0.148678 << 0.682258 << 0.571154 << 0.874724 << 0.444632 << endr Chris@49: << 0.245726 << 0.595218 << 0.409327 << 0.367827 << 0.385736 << endr; Chris@49: Chris@49: A.print("A ="); Chris@49: Chris@49: // determinant Chris@49: cout << "det(A) = " << det(A) << endl; Chris@49: Chris@49: // inverse Chris@49: cout << "inv(A) = " << endl << inv(A) << endl; Chris@49: Chris@49: Chris@49: // Chris@49: Chris@49: double k = 1.23; Chris@49: Chris@49: mat B = randu(5,5); Chris@49: mat C = randu(5,5); Chris@49: Chris@49: rowvec r = randu(5); Chris@49: colvec q = randu(5); Chris@49: Chris@49: Chris@49: // examples of some expressions Chris@49: // for which optimised implementations exist Chris@49: Chris@49: // optimised implementation of a trinary expression Chris@49: // that results in a scalar Chris@49: cout << "as_scalar( r*inv(diagmat(B))*q ) = "; Chris@49: cout << as_scalar( r*inv(diagmat(B))*q ) << endl; Chris@49: Chris@49: // example of an expression which is optimised Chris@49: // as a call to the dgemm() function in BLAS: Chris@49: cout << "k*trans(B)*C = " << endl << k*trans(B)*C; Chris@49: Chris@49: Chris@49: // If you want to see a trace of how Armadillo Chris@49: // evaluates expressions, compile with the Chris@49: // ARMA_EXTRA_DEBUG macro defined. Chris@49: // This was designed to work with the GCC compiler, Chris@49: // but it may also work with other compilers Chris@49: // if you have the Boost libraries installed Chris@49: // and told Armadillo to use them. Chris@49: // Chris@49: // Example for GCC: Chris@49: // g++ example2.cpp -o example2 -larmadillo -DARMA_EXTRA_DEBUG Chris@49: // Chris@49: // Running example2 will now produce a truckload of messages, Chris@49: // so you may want to redirect the output to a log file. Chris@49: Chris@49: return 0; Chris@49: } Chris@49: