armadillo

NLopt with Armadillo data

限于喜欢 提交于 2019-12-21 20:37:07
问题 The NLopt objective function looks like this: double myfunc(const std::vector<double> &x, std::vector<double> &grad, void *my_func_data) x is the data being optimized, grad is a vector of gradients, and my_func_data holds additional data. I am interested in supplying Armadillo matrices A and B to void *my_func_data . I fiddled with Armadillo's member functions mat A(5,5); mat B(5,5); double* A_mem = A.memptr(); double* B_mem = B.memptr(); which gives me a pointers to the matrices A and B. I

Armadillo: efficient matrix allocation on the heap

梦想的初衷 提交于 2019-12-21 20:33:17
问题 I'm using Armadillo to manipulate large matrices in C++ read from a CSV-file. mat X; X.load("myfile.csv",csv_ascii); colvec x1 = X(span::all,0); colvec x2 = X(span::all,1); //etc. So x1,...,xk (for k=20 say) are the columns of X. X will typically have rows ranging from 2000 to 16000. My question is: How can I allocate (and subsequently deallocate) X onto the heap (free store)? This section of Armadillo docs explains auxiliary memory allocation of a mat. Is this the same as heap allocation? It

Is armadillo solve() thread safe?

非 Y 不嫁゛ 提交于 2019-12-20 15:37:38
问题 In my code I have loop in which I construct and over determined linear system and try to solve it: #pragma omp parallel for for (int i = 0; i < n[0]+1; i++) { for (int j = 0; j < n[1]+1; j++) { for (int k = 0; k < n[2]+1; k++) { arma::mat A(max_points, 2); arma::mat y(max_points, 1); // initialize A and y arma::vec solution = solve(A,y); } } } Sometimes, quite randomly the program hangs or the results in the solution vector are NaN. And if I put do this: arma::vec solution; #pragma omp

Rcpp causes segfault RcppArmadillo does not

假装没事ソ 提交于 2019-12-20 07:40:01
问题 I'm currently trying to parallelize an existing hierarchical MCMC sampling scheme. The majority of my (by now sequential) source code is written in RcppArmadillo, so I'd like to stick with this framework for parallelization, too. Before starting with parallelizing my code I have read a couple of blog posts on Rcpp/Openmp. In the majority of these blog posts (e.g. Drew Schmidt, wrathematics) the authors warn about the issue of thread safety, R/Rcpp data structures and Openmp. The bottom line

Rcpp causes segfault RcppArmadillo does not

两盒软妹~` 提交于 2019-12-20 07:39:21
问题 I'm currently trying to parallelize an existing hierarchical MCMC sampling scheme. The majority of my (by now sequential) source code is written in RcppArmadillo, so I'd like to stick with this framework for parallelization, too. Before starting with parallelizing my code I have read a couple of blog posts on Rcpp/Openmp. In the majority of these blog posts (e.g. Drew Schmidt, wrathematics) the authors warn about the issue of thread safety, R/Rcpp data structures and Openmp. The bottom line

C++ building error for a simple code using armadillo and hdf5 libraries

被刻印的时光 ゝ 提交于 2019-12-19 10:38:08
问题 I'm quite new to C++ and armadillo, and I get stuck with a building error describe below. I'm trying to test the following simple code to save an armadillo matrix as hdf5 file: #include <iostream> #include <armadillo> using namespace std; using namespace arma; int main() { mat A = randu<mat>(240,320); A.save("A.hdf5",hdf5_binary); return 0; } When compiling, I get the following errors: /usr/include/armadillo_bits/hdf5_misc.hpp:131: undefined reference in « arma_H5T_NATIVE_DOUBLE » /usr

Is there a way to print an Armadillo matrix in gdb?

允我心安 提交于 2019-12-19 06:39:11
问题 I'm using gdb to debug my c++ program. I'm using the armadillo numerical library to define my matrices. I have an armadillo matrix defined like so: mat A = randu<mat>(5,5); Is it possible to print the whole matrix while using the gdb debugger? 回答1: The question may be old, but stumbling over it made me find a solution for my own work. Due to the template-based nature of the Armadillo library you need to provide some helpers of your own: #include <iostream> #include <armadillo> template<class

RcppArmadillo sample on armadillo vector classes

蓝咒 提交于 2019-12-18 09:47:16
问题 We have been using the sample function from RcppArmadillo to randomly sample a NumericVector object. However, we have noticed that it isn't possible to use the same function on Armadillo types ( vec or uvec ). We have looked at the function definitions from the sample.h file and it looks like a templated function that should be able to work with these types, but we haven't been able to figure out how to make it work with Armadillo classes without doing a lot of conversions to and from the

Calling 'mypackage' function within public worker

夙愿已清 提交于 2019-12-18 09:26:51
问题 I know the problem I have is a thread-safety issue. As the code I have now will execute with 'seThreadOptions(1)'. My question is what would be a good practice to overcome this. I know this: Threadsafe function pointer with Rcpp and RcppParallel via std::shared_ptr Will come into play somehow. And I have also been thinking/playing around with making the internal function part of the structure for the parallel worker. Realistically, I am calling two internal functions and I would like one to

Armadillo reading MAT file error

我只是一个虾纸丫 提交于 2019-12-13 18:11:49
问题 I'm currently cross-compiling on the BeagleBone Black in a Visual Studio environment using Armadillo to translate MATLAB code into C++. This is a signal processing project, so I need a way to read and write binary data files, specifically .mat files. Thankfully, the armadillo documentation says that you can load .mat files directly into a matrix using .load() I attempted that at first, but it seems like it's not reading the file correctly, nor is it reading all the entries. My reference file