Armadillo C++ Library
Armadillo C++ Library
- Armadillo is a high quality linear algebra library (matrix maths) for the C++ language, aiming towards a good balance between speed and ease of use
- Provides high-level syntax and functionality deliberately similar to Matlab
- Useful for algorithm development directly in C++, or quick conversion of research code into production environments (eg. software & hardware products)
- Provides efficient classes for vectors, matrices and cubes (1st, 2nd and 3rd order tensors); dense and sparse matrices are supported
- Integer, floating point and complex numbers are supported
- Various matrix decompositions are provided through integration with LAPACK, or one of its high performance drop-in replacements (eg. multi-threaded Intel MKL, or OpenBLAS)
- A sophisticated expression evaluator (based on template meta-programming) automatically combines several operations to increase speed and efficiency
- Can automatically use OpenMP multi-threading (parallelisation) to speed up computationally expensive operations
- Available under a permissive license, useful for both open-source and proprietary (closed-source) software
- Can be used for machine learning, pattern recognition, computer vision, signal processing, bioinformatics, statistics, finance, etc.
Using Armadillo on RCC Resources
In order to use Armadillo, you'll need to link your code against the armadillo library. The best way to do this is to use the following syntax. You will need the gnu module for this.
module load gnu
g++ MYCODE.cpp -o MYCODE -std=c++11 -O2 -larmadillo
Here, MYCODE.cpp
can be renamed to whatever the name of your code is. As an example, we can compile the example code given on the Armadillo Documentation. Type the following code into a text editor and save it as example.cpp
#include
#include
using namespace std;
using namespace arma;
int main() {
mat A(4, 5, fill::randu);
mat B(4, 5, fill::randu);
cout << A*B.t() << endl;
return 0;
}
Then compile it by using the command listed above. For this example, that command will be:
module load gnu
g++ example.cpp -o example -std=c++11 -O2 -larmadillo
This should produce an executable file called example which can be run by typing ./example
into the terminal.