armadillo | A personal fork of the armadillo C linear algebra library

 by   lsolanka C++ Version: Current License: MPL-2.0

kandi X-RAY | armadillo Summary

kandi X-RAY | armadillo Summary

armadillo is a C++ library. armadillo has no bugs, it has no vulnerabilities, it has a Weak Copyleft License and it has low support. You can download it from GitHub.

Armadillo is a C++ linear algebra library (matrix maths) aiming towards a good balance between speed and ease of use. The syntax is deliberately similar to Matlab. Integer, floating point and complex numbers are supported, as well as a subset of trigonometric and statistics functions. Various matrix decompositions are provided through optional integration with LAPACK or high-performance LAPACK-compatible libraries (such as Intel MKL or AMD ACML). A delayed evaluation approach is employed (during compile time) to combine several operations into one and reduce (or eliminate) the need for temporaries. This is accomplished through recursive templates and template meta-programming. This library is useful for conversion of research code into production environments, or if C++ has been decided as the language of choice, due to speed and/or integration capabilities. The library is open-source software, and is distributed under a license that is useful in both open-source and commercial/proprietary contexts. Armadillo is primarily developed at NICTA (Australia), with contributions from around the world. More information about NICTA can be obtained from

            kandi-support Support

              armadillo has a low active ecosystem.
              It has 43 star(s) with 20 fork(s). There are 3 watchers for this library.
              It had no major release in the last 6 months.
              armadillo has no issues reported. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of armadillo is current.

            kandi-Quality Quality

              armadillo has no bugs reported.

            kandi-Security Security

              armadillo has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              armadillo is licensed under the MPL-2.0 License. This license is Weak Copyleft.
              Weak Copyleft licenses have some restrictions, but you can use them in commercial projects.

            kandi-Reuse Reuse

              armadillo releases are not available. You will need to build from source code and install.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of armadillo
            Get all kandi verified functions for this library.

            armadillo Key Features

            No Key Features are available at this moment for armadillo.

            armadillo Examples and Code Snippets

            No Code Snippets are available at this moment for armadillo.

            Community Discussions


            Using Armadillo C++ library in Swift 5
            Asked 2021-Jun-03 at 22:39

            I'm trying to use Armadillo C++ library in my swift code to create sinusoidal curved arrow. Earlier it worked well with Objective C. But when I'm trying to do the same implementation in Swift, it's showing 'armadillo' file not found error.

            I've downloaded the file from path and copied both armadillo_bits folder and armadillo file into the project.

            I've created a Objective C++ Wrapper around the C++ class too.

            Objective C++ Wrapper DrawSinusoidal.h file



            Answered 2021-Jun-03 at 22:39

            Finally I found the solution to it. Sharing the steps which I followed.

            • We need to install the pre-built Armadillo packages to macOS which can be installed via MacPorts or HomeBrew
            • I installed using HomeBrew.

            $ brew install armadillo

            Once it is completed, please keep a note on the installed path from the last line.

            In my machine, it is installed on path /usr/local/Cellar/armadillo/10.5.1

            • Next, we need to provide the Header Search Paths. Headers are available in below location, so just copy the path and paste in Xcode.


            • Next, we need to link the libarmadillo.dylib library that is available in the installed path to the sdk path in the Xcode. Open terminal and type following command.



            C++ armadillo linear algebra library linker error with GCC
            Asked 2021-May-28 at 21:59

            I'm getting the following error with GCC >=9 and std>=11 merely by adding the header (MacOSX on MacBook Pro 2020 and armadillo installed with Homebrew and the code is compiled with standard CMake configuration) #include to my project.

            Undefined symbols for architecture x86_64: "___emutls_v._ZN4arma19mt19937_64_instanceE", referenced from: __GLOBAL__sub_I_Test_HPP.cpp in Test_HPP.cpp.o ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status make[2]: *** [Test_HPP] Error 1 make[1]: *** [CMakeFiles/Test_HPP.dir/all] Error 2

            I've tried various hacks including optimization flags e.g. O2, O3 etc. but finally adding the preprocessor header #define ARMA_DONT_USE_WRAPPER apparently resolved the issue for now but I need an explanation to feel settled. If the above pre-processor is absolutely necessary to compile the code, should the armadillo library maintainers absorb the macro within the library itself? This kind of issues may take a lot of time to resolve as it is not originated in any programming logic.



            Answered 2021-May-28 at 21:59

            The preprocessor directive ARMA_DONT_USE_WRAPPER disables code that uses thread_local which depends on emutls in gcc on macOS. This appears unsupported on macOS 11 (Big Sur) according to the maintainers of Armadillo. As shown here CMakeLists.txt.

            A related workaround is provided by the maintainers Commit 83e48f8c in file include/armadillo_bits/arma_rng.hpp

            I'm unable to confirm why it is unsupported in macOS or Homebrew but from other doc, it looks like trying a different build system configuration with correct TLS support might fix the issue e.g ugrading gcc or maybe rebuilding gcc with the --enable-tls switch. I'm using Catalina and my gcc version installed with Homebrew is 11.1.0. If you need gcc version 9 you can switch between them using the brew link @ command.



            When two libraries have variable types with the same name, how to define the variable type correctly?
            Asked 2021-May-20 at 04:06

            I need to use the armadillo library and opencv library, but I find that both have mat type variables. How can I use them correctly when I use them?



            Answered 2021-May-20 at 04:06

            opencv places type definitions in a namespace named cv, and armadillo places type definitions in namespace arma. The reason that libraries use namespaces is to provide a means of avoiding name clashes that results from two libraries using the same name.

            The simple approach is then to avoid ANY using directives (e.g. using namespace cv, using namespace arma, or using namespace std) in your code, and use fully qualified names (e.g. cv::mat or arma::mat, in this case).

            The reason to avoid using directives is that the end result can be ambiguity. For example, when the unqualified name mat is used in code following a using namespace arma and using namespace cv, both cv::mat and arma::mat can be equally viable matches. Such ambiguity is a diagnosable error.

            If you have a name mat in the global (unnamed) namespace it is also often preferable to refer to it explicitly as ::mat. Even if using the unqualified name (i.e. mat) is acceptable, using the fully qualified name reduces effort for developers (including yourself in future) from having to work out what mat actually resolves to.



            "Illegal value" of blas functions called by Armadillo
            Asked 2021-May-19 at 08:07

            I'm using Armadillo (10.4.1) in Visual Studio 2019 to do some matrix stuff. I used OpenBlas from NuGet manager, but everything was slow. I now want to switch to an up-to-date version of OpenBlas. I took the last one (0.3.15) and compiled it with minGW following this tuto :

            The compilation works fine, but when I try matrix multiplication, an error is thrown in the console : On entry to DSPR2 parameter number 1 had an illegal value

            I do have defined ARMA_USE_BLAS, ARMA_DONT_USE_WRAPPER. I tried to played with ARMA_BLAS_LONG, ARMA_BLAS_UNDERSCORE, ARMA_USE_FORTRAN_HIDDEN_ARGS but nothing change.

            Everything was working great using NuGet manager (OpenBlas Here is a sample that doesn't works:



            Answered 2021-May-19 at 08:07

            I finally manage to fix the issue: First, I downloaded the pre compiled binary (x86) here:

            I put the dll in my project folder, renamed the "libopenblas.dll.a" into "libopenblas.lib". It worked well, but was still slower than Matlab ... So I benchmarked matrix multiplication and custom functions on a fresh new x64 project (using the precompiled binaries given by Armadillo). And ... Everything is much faster !

            So I'm leaving x86 to switch to x64 ! Subject is closed!



            C++11 conditional data type
            Asked 2021-May-14 at 15:34

            I wrote a C++11 function that conditionally initializes an object. Consider the following example:



            Answered 2021-May-14 at 14:37

            You'll probably need to put the common code in a template function which can be instantiated for all 4 different types. Then, in all 4 branches, call this template. The compiler will generate 4 different instantiations.



            How to use write access using iterators and armadillo sparse matrices?
            Asked 2021-Apr-29 at 13:26

            I have to replace some columns in a sparse matrix with columns from another sparse matrix that has the same nonzero elements, just different values, based on a condition.

            I am struggling with write access using iterators in Armadillo. The docs say that using sp_mat::col_iterator provides read/write access, however, when I try to write a value *it = B.col(...) I get an error message error: no match for ‘operator=’ (operand types are ‘arma::SpValProxy >’ and ‘arma::SpSubview_col’). Do I have a syntax mistake or am I understanding the concept of "write access" wrong?



            Answered 2021-Apr-29 at 13:26

            Looking at the (generally excellent) Armadillo documentation, I think you are up a against a design issue. Quoting


            • to modify the non-zero elements in a safer manner, use .transform() or .for_each() instead of iterators;
            • writing a zero value into a sparse matrix through an iterator will invalidate all current iterators associated with the sparse matrix row iterators for sparse matrices are only useful with Armadillo 8.500 and later versions; in earlier versions they are inefficient



            Complex matrix exponential with Armadillo library
            Asked 2021-Apr-27 at 13:58

            I'm doing some physics simulation in C++ using Armadillo. I need to calculate a product looking like:



            Answered 2021-Apr-27 at 13:58

            You need to use the expmat() function for a matrix exponential, exp() calculates an element-wise exponential.

            For example, some code I'm currently using for a physics simulation:



            How to serialize sparse matrix in Armadillo and use with mpi implementation of boost?
            Asked 2021-Apr-27 at 12:30

            I've been trying to serialize the sparse matrix from armadillo cpp library. I am doing some large-scale numerical computations, in which the data get stored in a sparse matrix, which I'd like to gather using mpi(Boost implementation) and sum over the matrices coming from different nodes. I'm stuck right now is how to send the sparse matrix from one node to other nodes. Boost suggests that to send user-defined objects (SpMat in this case) it needs to be serialized.

            Boost's documentation gives a good tutorial on how to serialize a user-defined type and I can serialize some basic classes. Now, armadillo's SpMat class is very complicated for me to understand, and serialize.

            I've come across few questions and their very elegant answers

            1. This answer by Ryan Curtin the co-author of Armadillo and author of mlpack has shown a very elegant way to serialize the Mat class.
            2. This answer by sehe shows a very simple way to serialize sparse matrix.

            Using the first I can mpi::send a Mat class to another node in the communicator, but using the latter I couldn't do mpi::send.

            This is adapted from the second linked answer



            Answered 2021-Apr-27 at 12:30

            I hate to say so, but that answer by that sehe guy was just flawed. Thanks for finding it.

            The problem was that it didn't store the number of non-zero cells during serialization. Oops. I don't know how I overlooked this when testing.

            (Looks like I had several versions and must have patched together a Frankenversion of it that wasn't actually properly tested).

            I also threw in a test the matrix is cleared (so that if you deserialize into an instance that had the right shape but wasn't empty you don't end up with a mix of old and new data.)




            Directly accessing entries of armadillo-matrix by memory-pointer (memptr) does not work after matrix is modified
            Asked 2021-Apr-22 at 00:13

            I have a problem where I want to access certain entries of an armadillo-matrix "M" by a pointer in a struct (or class). After initializing M I set the pointer in the struct. By dereferencing the pointer I can see it has the right value (the first entry of M - or M(0,0)).

            Then I change M to M * M. But now dereferencing the pointer does not give me the right value anymore. What's weird: If I have a small matrix i.e. 3x3 or 4x4 (see "matrixSize" in my code) the error does not happen. With small matrices dereferencing the pointer gives the RIGHT value. Bigger matrices though result in the wrong values (with 5x5 something like "2.76282e-320", which is probably some random place in memory).

            What am I doing wrong here? How can I solve this problem?

            If it helps, I'd like to explain what I want to achieve: I have a network of delay-coupled nodes that each have some sort of dynamic behaviour. (think delay-coupled differential equations DDEs - delay-coupled Oscillators). As they are delay-coupled I need to store their past states (an array of their histories). Each oscillator also has some LOCAL dynamic with dynamical variables that are not influencing other nodes which means that I don't have to store their histories. The matrix shall be used to keep the past states of some variable of the nodes. I want to have them in a matrix, because I want to use vector-operations on them (one index of the matrix represents time, while the other is the node-index). But I also want to access them individually to calculate some local dynamic at each of the nodes (oscillators). So I want to update the individual nodes, but also the global state. That's why having both representations helps: For the local dynamics I access the delayed states through a pointer into the matrix. For the global dynamics I access the coupled variables through a row in the matrix that functions as a history-array.



            Answered 2021-Apr-22 at 00:13

            The operation M = M * M in Armadillo is a matrix multiply (not an element by element multiply). So storing the intermediate calculations of M * M directly into M would be problematic. It would overwrite existing data in M that is still needed to complete the M * M operation.

            It's probably safe to assume that Armadillo detects this problem and stores the result of M * M into a separate chunk of memory and then assigns that chunk to M.

            There are ways around that. Use fixed size matrices like darcamo mentioned in the comments. Use Mat::fixed<4, 4> M; to declare the matrix.

            Another way is to manually manage the memory for the matrix elements and tell the M matrix to always use that memory. There are the advanced constructors to do that:



            Fail to call ones or eye function when using RcppArmadillo
            Asked 2021-Apr-08 at 15:33

            I want to use one or eye function in Armadillo to construct matrices or vectors. However, it does not allow me to do so. Here is a sample code:



            Answered 2021-Apr-08 at 15:33

            There are a few problems in your code:

            • Why return SEXP? Use types to your advantage
            • Why pass Mat in if you do not use it?
            • No return statement
            • Somewhat loose use of namespaces.

            A cleaned up version follows:


            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install armadillo

            You can use the manual installation process as described in section 3.2, or the following CMake based automatic installation.
            Step 1: If CMake is not already be present on your system, download it from On major Linux systems (such as Fedora, Ubuntu, Debian, etc), cmake is available as a pre-built package, though it may need to be explicitly installed (using a tool such as PackageKit, yum, rpm, apt, aptitude).
            Step 2: If you have LAPACK or BLAS, install them before installing Armadillo. Under Mac OS X this is not necessary. If you have ARPACK, install it before installing Armadillo. On Linux systems it is recommended that the following libraries are present: LAPACK, BLAS, ARPACK and ATLAS. LAPACK and BLAS are the most important. It is also necessary to install the corresponding development files for each library. For example, when installing the "lapack" package, also install the "lapack-devel" or "lapack-dev" package. For best performance, we recommend using the multi-threaded OpenBLAS library instead of standard BLAS. See
            Step 3: Open a shell (command line), change into the directory that was created by unpacking the armadillo archive, and type the following commands: cmake . make The full stop separated from "cmake" by a space is important. CMake will figure out what other libraries are currently installed and will modify Armadillo's configuration correspondingly. CMake will also generate a run-time armadillo library, which is a combined alias for all the relevant libraries present on your system (eg. LAPACK, BLAS, ARPACK, ATLAS). If you need to re-run cmake, it's a good idea to first delete the "CMakeCache.txt" file (not "CMakeLists.txt"). Caveat: out-of-tree builds are currently not supported; for example, creating a sub-directory called "build" and running cmake .. from within "build" is currently not supported.
            Step 4: If you have access to root/administrator/superuser privileges, first enable the privileges (eg. through "su" or "sudo") and then type the following command: make install If you don't have root/administrator/superuser privileges, type the following command: make install DESTDIR=my_usr_dir where "my_usr_dir" is for storing C++ headers and library files. Make sure your C++ compiler is configured to use the sub-directories present within this directory.
            The manual installation is comprised of 3 steps:.
            Step 1: Copy the entire "include" folder to a convenient location and tell your compiler to use that location for header files (in addition to the locations it uses already). Alternatively, you can use the "include" folder directly.
            Step 2: Modify "include/armadillo_bits/config.hpp" to indicate which libraries are currently available on your system. For example, if you have LAPACK, BLAS (or OpenBLAS) and ARPACK present, uncomment the following lines: #define ARMA_USE_LAPACK #define ARMA_USE_BLAS #define ARMA_USE_ARPACK If you're not going to use sparse matrices, don't worry about ARPACK.
            Step 3: If you have LAPACK and BLAS present, configure your compiler to link with these libraries. If using Linux, link using -llapack -lblas If using Mac OS X, link using -framework Accelerate If using Windows, see section 4.2. You can also link with high-speed replacements for LAPACK and BLAS, such as OpenBLAS, or Intel MKL, or AMD ACML. See section 5 for more info. If you have ARPACK present, also link with it. For example, under Linux link using -llapack -lblas -larpack


            Armadillo can use OpenBLAS, or Intel Math Kernel Library (MKL), or the AMD Core Math Library (ACML) as high-speed replacements for BLAS and LAPACK. Generally this just involves linking with the replacement libraries instead of BLAS and LAPACK. You may need to make minor modifications to "include/armadillo_bits/config.hpp" in order to make sure Armadillo uses the same style of function names as used by MKL or ACML. For example, the function names might be in capitals. On Linux systems, MKL and ACML might be installed in a non-standard location, such as /opt, which can cause problems during linking. Before installing Armadillo, the system should know where the MKL or ACML libraries are located. For example, "/opt/intel/mkl/lib/intel64/". This can be achieved by setting the LD_LIBRARY_PATH environment variable, or for a more permanent solution, adding the directory locations to "/etc/". It may also be possible to store a text file with the locations in the "/etc/" directory. For example, "/etc/". If you modify "/etc/" or create "/etc/", you will need to run "/sbin/ldconfig" afterwards.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • HTTPS


          • CLI

            gh repo clone lsolanka/armadillo

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link