Armadillo (C++ library)

Armadillo is a linear algebra software library for the C++ programming language. It aims to provide efficient and streamlined base calculations, while at the same time having a straightforward and easy-to-use interface. Its intended target users are scientists and engineers.

Armadillo C++ Library
Stable release
9.850 / February 9, 2020 (2020-02-09)[1]
Written inC++
Operating systemCross-platform
Available inEnglish
TypeSoftware library
LicenseApache 2.0 (open source)
Websitearma.sourceforge.net

It supports integer, floating point (single and double precision), complex numbers, and a subset of trigonometric and statistics functions. Dense and sparse matrices are supported.[2] Various matrix decompositions are provided through optional integration with Linear Algebra PACKage (LAPACK), Automatically Tuned Linear Algebra Software (ATLAS), and ARPACK.[3][4] High-performance BLAS/LAPACK replacement libraries such as OpenBLAS and Intel MKL can also be used.

The library employs a delayed-evaluation approach (during compile time) to combine several operations into one and reduce (or eliminate) the need for temporaries. Where applicable, the order of operations is optimised. Delayed evaluation and optimisation are achieved through template metaprogramming.

Armadillo is related to the Boost Basic Linear Algebra Subprograms (uBLAS) library, which also uses template metaprogramming. However, Armadillo builds upon ATLAS and LAPACK libraries, thereby providing machine-dependent optimisations and functions not present in uBLAS.

It is open-source software distributed under the permissive Apache License, making it applicable for the development of both open source and proprietary software. The project is supported by the NICTA research centre in Australia.

Example in C++ 11

Here is a trivial example demonstrating Armadillo functionality:

// Compile with:
// $ g++ -std=c++11 main.cpp -o file_name -O2 -larmadillo

#include <iostream>
#include <armadillo>
#include <cmath>

int main()
{
                                                //    ^
  // Position of a particle                     //    |
  arma::vec Pos = {{0},                         //    | (0,1)
                   {1}};                        //    +---x-->

  // Rotation matrix 
  double phi = -3.1416/2; 
  arma::mat RotM = {{+cos(phi), -sin(phi)},
                    {+sin(phi), +cos(phi)}};

  Pos.print("Current position of the particle:");
  std::cout << "Rotating the point " << phi*180/3.1416 << " deg" << std::endl;

  Pos = RotM*Pos;

  Pos.print("New position of the particle:");   //    ^
                                                //    x (1,0)
                                                //    | 
                                                //    +------>

  return 0;
}

Example in C++ 98

Here is another trivial example in C++ 98:

#include <iostream>
#include <armadillo>

int main()
{
  arma::vec b;
  b << 2.0 << 5.0 << 2.0;

  // arma::endr represents the end of a row in a matrix
  arma::mat A;
  A << 1.0 << 2.0 << arma::endr
    << 2.0 << 3.0 << arma::endr
    << 1.0 << 3.0 << arma::endr;

  std::cout << "Least squares solution:\n";
  std::cout << arma::solve(A,b) << '\n';

  return 0;
}
gollark: You know, in a very real sense, snapchat bad.
gollark: rüst
gollark: <@332271551481118732> EMU WAR ONLINE RUST REWRITE!!!!!!!!!
gollark: I'm not convinced that EWO actually exists.
gollark: New types of emu with magic powers, perhaps? How goes EWO?

See also

References

  1. "Armadillo C++ matrix library / News: Recent posts". Retrieved 9 February 2020 via SourceForge.
  2. Conrad Sanderson and Ryan Curtin (2018). A User-Friendly Hybrid Sparse Matrix Class in C++. Lecture Notes in Computer Science (LNCS), Vol. 10931, pp. 422-430. arXiv:1805.03380. doi:10.1007/978-3-319-96418-8_50.
  3. Conrad Sanderson and Ryan Curtin (2016). "Armadillo: a template-based C++ library for linear algebra". Journal of Open Source Software. 1 (2): 26. Bibcode:2016JOSS....1...26S. doi:10.21105/joss.00026.
  4. Ryan Curtin; et al. (2013). "MLPACK: A Scalable C++ Machine Learning Library". Journal of Machine Learning Research. 14 (Mar): 801–805. arXiv:1210.6293. Bibcode:2012arXiv1210.6293C.
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.