armadillo | A personal fork of the armadillo C linear algebra library
kandi X-RAY | armadillo Summary
kandi X-RAY | armadillo Summary
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
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of armadillo
armadillo Key Features
armadillo Examples and Code Snippets
Community Discussions
Trending Discussions on armadillo
QUESTION
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 https://github.com/gadomski/armadillo/tree/master/branch-5.600/include 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
...ANSWER
Answered 2021-Jun-03 at 22:39Finally 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.
/usr/local/Cellar/armadillo/10.5.1/include/armadillo_bits
- 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.
QUESTION
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.
ANSWER
Answered 2021-May-28 at 21:59The 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.
QUESTION
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?
...ANSWER
Answered 2021-May-20 at 04:06opencv 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.
QUESTION
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 : https://github.com/xianyi/OpenBLAS/wiki/How-to-use-OpenBLAS-in-Microsoft-Visual-Studio.
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 0.2.14.1). Here is a sample that doesn't works:
...ANSWER
Answered 2021-May-19 at 08:07I finally manage to fix the issue: First, I downloaded the pre compiled binary (x86) here: https://github.com/xianyi/OpenBLAS/releases/download/v0.3.10/OpenBLAS-0.3.10-x86.zip
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!
QUESTION
I wrote a C++11 function that conditionally initializes an object. Consider the following example:
...ANSWER
Answered 2021-May-14 at 14:37You'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.
QUESTION
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?
ANSWER
Answered 2021-Apr-29 at 13:26Looking at the (generally excellent) Armadillo documentation, I think you are up a against a design issue. Quoting
Caveats:
- 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
QUESTION
I'm doing some physics simulation in C++ using Armadillo. I need to calculate a product looking like:
...ANSWER
Answered 2021-Apr-27 at 13:58QUESTION
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
- 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. - 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
...ANSWER
Answered 2021-Apr-27 at 12:30I 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.)
FIXEDQUESTION
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.
...ANSWER
Answered 2021-Apr-22 at 00:13The 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:
QUESTION
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:
ANSWER
Answered 2021-Apr-08 at 15:33There 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
Vulnerabilities
No vulnerabilities reported
Install armadillo
Step 1: If CMake is not already be present on your system, download it from http://www.cmake.org 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 http://xianyi.github.com/OpenBLAS/
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
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page