at(0) is almost certainly returning a proxy object, which can be converted to double, or be assigned a double, but is not actually a reference. This may be to avoid dangling references, or to allow for efficient storage of sparse matrices. The documentation for Armadillo is unfortunately pretty quiet on...

The associated sparse matrix iterator has .row() and .col() functions: sp_mat::const_iterator start = X.begin(); sp_mat::const_iterator end = X.end(); for(sp_mat::const_iterator it = start; it != end; ++it) { cout << "location: " << it.row() << "," << it.col() << " "; cout << "value: " << (*it) << endl; } ...

The main error here is that you pass pointers to mat type objects to the circshift() function (the out and in argument, but then use these arguments as arrays to mat. The following line is not interpreted as you think out[iOutputInd] = in[iInputInd]; because out and in are not mat...

Many programs write their output to a temporary file, then rename it to the destination file. This is often done to avoid leaving a half-written output file if the process is killed while writing. By using a temporary, the file can be atomically renamed to the output file name ensuring...

According to the documentation of sgtsv(), the upper (DU) and lower (DL) diagonals of the tridiagonal matrix A will be overwritten as the linear equation is solved. On exit, DL is overwritten by the (n-2) elements of the second super-diagonal of the upper triangular matrix U from the LU factorization...

First convert the integer matrix to a double matrix using the conv_to function. For example, imat A = ...; mat B = conv_to<mat>::from(A);. Then you can do eigen decomposition on the converted matrix.

c++,visual-studio-2010,armadillo,glpk,openblas

libopenblas.dll was the cause of the problem - for some reason linking in VS2010 caused errors. I am not sure why, but linking against the lapack libraries in the Armadillo distribution (pre v4) fixed the issue.

c++,visual-studio-2010,matrix,64bit,armadillo

I found the answer. TL;DR: ARMA_64BIT_WORD was not defined for the source file I was using, but it was defined for other object files, thus creating an unstable mix of 32-bit and 64-bit word sizes in the Armadillo library. The simple fix was to add ARMA_64BIT_WORD as a preprocessor macro...

I also received this error when attempting to use an arma::cube as an Rcpp function parameter. Based on the compiler error, I believe this is because there is no Rcpp::wrap<arma::cube> currently defined (which is needed to handle the R object you would pass to the function). † After reading a...

RcppArmadillo ships its own copy of Armadillo to avoid exactly this problem. As RcppArmadillpo is used from R, it can rely on R (and R's configuration) to get LAPACK, BLAS, etc pp. We don't need to run configure to use Armadillo from R, and so we don't do. RcppArmadillo installs...

The error handling mechanism of Armadillo is not clear from its documentation. By email communication with the author Sanderson, it's figured out that the error handling mechanism of Armadillo is actually a mixture of C++ std exception and C-style return value. However, the information of what exception will be thrown...

Although, I haven''t found a way of conversion between armadillo and caffe blobs. But I noticed that caffe uses MKL library for CPU computations, which has both of the required functions i.e. pseudo inverse and transpose. In case, caffe is not configured to use MKL, I can easily implement a...

I was having same problem while running make after cmake . when I check the cmake output it was pointing to wrong atlas directory i.e. it was pointing to ATLAS_INCLUDE_DIR = /usr/include/ where as it should have been pointing to ATLAS_INCLUDE_DIR = /usr/include/atlas. -- Found ATLAS: /usr/lib/libatlas.so -- Found BLAS:...

void FillMyMatrix(MyMatrixType& thisIsTheNameOfTheLocalVariableInTheFoo) { // fill your matrix called thisIsTheNameOfTheLocalVariableInTheFoo // let's say the MyMatrixType has an Insert(int, int, int) method. thisIsTheNameOfTheLocalVariableInTheFoo.Insert(1, 2, 3); } ...

linker,gfortran,rcpp,armadillo

Can you run the following command, please: [email protected]:~$ dpkg -l | grep libgfortran | cut -c-75 ii libgfortran-4.7-dev:amd64 4.7.3-7ubuntu3 ii libgfortran-4.8-dev:amd64 4.8.1-10ubuntu9 ii libgfortran3:amd64 4.8.1-10ubuntu9 [email protected]:~$ You need the libgfortrain-$VERSION-dev package for your machine. At some point having gfortran implied this via r-base-dev and its dependence on build-essentials. Edit: Version...

If you are just dealing with positive values, then the conv_to function of the armadillo package will do exactly the same as the method you are trying to use. vec t = linspace(0, 100); double freq = 0.25; ivec indices = conv_to<ivec>::from(t / freq); If you want the results to...

Key observation is that Armadillo exp() function is way slower than MATLAB. Similar overhead is observed in log(), pow() and sqrt().

python,c++,r,armadillo,eigenvector

That is answered by help(eigen) in R: Value: The spectral decomposition of ‘x’ is returned as components of a list with components values: a vector containing the p eigenvalues of ‘x’, sorted in _decreasing_ order, according to ‘Mod(values)’ in the asymmetric case when they might be complex (even for real...

Step 1: Identify where it happens. Compile with $ g++ -std=c++0x -Wall -O0 -g3 psinkt.cpp -o ./psinkt.out and debug with $ gdb ./psinkt.out gdb> run Or use valgrind $ yum install valgrind # or $ apt-get install valgrind $ valgrind --tool=memcheck ./psinkt.out Step 2: Improve your C++ I'd strongly encourage...

Armadillo makes heavy use of lazy evaluation and has a large number of intermediate results that hold other intermediates with limited lifetime by reference1. The one that came to bite you here is the return value of min, and that you attempt to return it as you got it. If...

sqrt(-1) is not representable as double (which models real numbers). The result of sqrt(-1) is NaN (not a number), not the complex number i you expect. To make Armadillo work with complex numbers, use cx_mat instead of mat everywhere, and instead of sqrt(-1), use std::complex<double>(0, 1) or, if you can...

The general functions find_finite() and find_nonfinite() will always be slower than specialised summation loops. find_finite() was not designed specifically for summation, but for the general case of, well, finding the indices of finite values. What you do with those indices is up to you, and you've chosen to use them...

It's up to each library as to how they want to handle this. Armadillo doesn't seem to document their choice, but it's a perfectly reasonable and valid one. I see no reason to assume it's a library bug.

c++,eigen,armadillo,expression-templates

Just for future reference, this is how I decided to implement my solution: I overloaded the operator+ in the following way: template< typename T1, typename T2 > auto operator+( const my_vec< T1 > & X, const my_vec< T2 > & Y ) ->decltype( X.data() + Y.data() ) { return X.data()...

matlab,shared-libraries,mex,armadillo

So I found out how to run it. Now it's segfaulting :/ And I'm fairly confident it's not the code itself, because I can compile and run the exact same code outside Matlab. I'll try to find out what's wrong, and if it's relevant, I'll post my adventures here later...

sparse-matrix,armadillo,eigenvalue

I believe that the issue here is that you are running eigs_gen() (which calls DNAUPD) on a symmetric matrix. ARPACK notes that DNAUPD is not meant for symmetric matrices, but does not specify what will happen if you use symmetric matrices anyway: NOTE: If the linear operator "OP" is real...

According to the Submatrix view section of Armadillo's API documentation, the X.rows(vector_of_row_indices) would extract the selected set of non-contiguous rows in the provided vector_of_row_indices from the matrix X. Thus in your case, to obtain a result equivalent to Pts = Pts(ifAny,:) of Matlab, you can use : Pts = Pts.rows(ifAny);...

Using Perfmon.exe, i was able to check the memory size of the program just before and just after the function i suspected of allocating on the heap. And the difference was of a little bit more than 100k for a variable of 100k...

c++,matlab,linear-algebra,armadillo

If you have two matrices A and B of the same dimension you could set all of the elements of A where the corresponding element of B is > 0 to a value with using namespace arma; // A and B are matrices of the same shape. mat A =...

When compiling with the -c switch, no linking is done. g++ simply produces myclass.o, without linking to the armadillo run-time library. The solution is to do the linking when the final executable is being produced: g++ -c myclass.cpp -O2 g++ myclass.o boost_utf.cpp -O2 -larmadillo -L/home/me/bin/boost_libs/lib -lboost_unit_test_framework -static -std=c++11 You may...

You cannot just R CMD SHLIB this file. Because you use Rcpp attributes, you need some code to be generated from Rcpp::depends and Rcpp::export. You can either call sourceCpp( 'my.cpp' ) from R if you just want standalone use of the file or use various tools such as compileAttributes or...

c++,c,makefile,armadillo,linuxmint

Your Makefile is not telling the linker to link it with the Armadillo library. A way to solve it, although I'm not sure if it's the "good practices" way is to add -l armadillo to the end of the "all:" line. It probably will be unable to find "EXCUTE_ALL", as...

I took a quick glance at the armadillo library documentation and I see the following problems. The argument you are passing to arma_matrix is syntactically right but incorrect. You need to use: double *matrix = new double [block_size*block_size]; arma::mat arma_matrix( matrix, block_size, block_size, true, true ); The syntax for accessing...

The easiest way is to define ARMA_DONT_PRINT_ERRORS before including the Armadillo header. For example: #define ARMA_DONT_PRINT_ERRORS #include <armadillo> // or #include <RcppArmadillo.h> if you're using Rcpp The defines are described in http://arma.sourceforge.net/docs.html#config_hpp...

Change the input type to a const reference (const arma::mat&), which allows the compiler to automatically generate a temporary matrix in such cases. Example: using namespace arma; mat foo(const mat& my_matrix) { mat y = my_matrix * 2.0; return y; } void bar() { mat x(10,10, fill::randu); mat y =...

If you implement this: inline urowvec operator|(const urowvec& lhs, urowvec& rhs){ // ToDo - operate on an element by element basis, and return // a urowvec. Decide on something reasonable if the vectors // differ in size. } and make sure this is included in every compilation unit requiring the...

Repeatedly appending elements to a vector is a really bad idea from a performance point of view, as it can cause repeated memory reallocations and copies. There are two main solutions to that. Set the size of the vector to the theoretical maximum length of your operation (nn in this...

The sparse SVD can be computed indirectly. For example, first calculate X'*X or X*X', and then pass the resultant matrix to eigs_sym(). Another way is to first construct a sparse matrix like [zeros(m,m) X; X' zeros(n,n)], where m and n indicate the number of rows and columns in X. You...

Operator '%' is for element-wise matrix multiplication. You have to create your own function: /** * Extend division reminder to vectors * * @param a Dividend * @param n Divisor */ template<typename T> T mod(T a, int n) { return a - floor(a/n)*n; } ...

This problem is solved with the Intel MKL library, when we compile with the -DMKL_ILP64 -m64. Typically we focus only on link flags. But it is important to note that these flags must be enabled during compile phase on the gcc command as well. I am not sure how to...

If you Google and go to armadillo docs you can clearly see that eigs_sym gives you eigenvalues of a sparse matrix (hence the S in eigS_sym), and that eig_sym will give them for a dense matrix.

I would use arma::mat dataset(data_points, dim); // populate dataset arma::rowvec mean_vec = mean (dataset); If there is no specific reason for which you are storing vec3 objects in CPP STL vector. If you want to grow the matrix at runtime, then you can use the resize function. But I would...

find_finite returns a vector of type arma::uvec, which is a typedef for arma::Col<uword>. Every object Col has an attribute .n_elem which indicates the vector's length. Because find_finite() returns a vector that contains the indices of elements of X(argument) that are finite, one can simply assign that vector to a variable...

c++,heap,parameter-passing,rcpp,armadillo

Looks like the solution was quite simple. Left over from testing the train() function, I had left the //[[Rcpp::export]] tag above the train function which allows train() to be accessible by R. Removing this dealt with the error!...

How about A.col(1) = vec({1,2}); If you're working with C++11 ?...