armadillo

Applying the optim function in R in C++ with Rcpp

梦想的初衷 提交于 2019-12-05 04:03:18
问题 I am trying to call R function optim() in Rcpp . I saw an example in Calling R's optim function from within C++ using Rcpp, but I am unable to modify it correctly for my use case. Basically, the objective function depends on the x and y but I want to optimize it with respect to b . Here is the R code that does what I want: example_r = function(b, x, y) { phi = rnorm(length(x)) tar_val = (x ^ 2 + y ^ 2) * b * phi objftn_r = function(beta, x, y) { obj_val = (x ^ 2 + y ^ 2) * beta return(obj_val

Linking to Armadillo libraries with CMake

断了今生、忘了曾经 提交于 2019-12-04 23:54:58
问题 I am trying to install MLPack on windows 8. I configure the CMakeLists.txt file with: set(ARMADILLO_LIBRARY "C:\\Program Files (x86)\\armadillo\\lib") set(ARMADILLO_INCLUDE_DIR "C:\\Program Files (x86)\\armadillo\\include") Then when I ran CMake I had a whole series of warning like these ones: WARNING: Target "mlpack" requests linking to directory "C:\Program Files (x86)\armadillo\lib". Targets may link only to libraries. CMake is dropping the item. In \mlpack-1.0.4\src\mlpack directory I

Rcpp equivalent for rowsum [closed]

一曲冷凌霜 提交于 2019-12-04 19:09:43
I am looking for a fast alternative for the R function rowsum in C++ / Rcpp / Eigen or Armadillo. The purpose is to get the sum of elements in a vector a according to a grouping vector b . For example: > a [1] 2 2 2 2 2 2 2 2 2 2 > b [1] 1 1 1 1 1 2 2 2 2 2 > rowsum(a,b) [,1] 1 10 2 10 Writing a simple for loop in Rcpp is very slow, but maybe my code was just inefficient. I tried also to call the function rowsum in Rcpp , however, rowsum is not very fast. Here's my attempt at doing this using Rcpp (first time using the package, so do point out my inefficiencies): library(inline) library(Rcpp)

Efficient parallelisation of a linear algebraic function in C++ OpenMP

与世无争的帅哥 提交于 2019-12-04 18:53:19
I have little experience with parallel programming and was wondering if anyone could have a quick glance at a bit of code I've written and see, if there are any obvious ways I can improve the efficiency of the computation. The difficulty arises due to the fact that I have multiple matrix operations of unequal dimensionality that I need to compute, so I'm not sure the most condensed way of coding the computation. Below is my code. Note this code DOES work. The matrices I am working with are of dimension approx 700x700 [see int s below] or 700x30 [int n]. Also, I am using the armadillo library

Multiplying a column vector by a numeric scalar in RcppArmadillo

僤鯓⒐⒋嵵緔 提交于 2019-12-04 15:59:03
I am having some trouble compiling this simple c++ code using Rcpp and the RcppArmadillo package. Take the following simple example to multiply each column of a matrix by a numeric scalar: code <- 'arma::mat out = Rcpp::as<arma::mat>(m); for(int i = 0; i < out.n_cols; ++i){ out.col(i) *= v; } return Rcpp::wrap( out );' Trying to compile this using... require( RcppArmadillo ) armMult <- cxxfunction( signature( m = "numeric" , v = "numeric" ), code , plugin = "RcppArmadillo" ) Results in the compile error.... #error: no match for 'operator*=' in 'arma::Mat<eT>::col(arma::uword) [with eT = double

Conversion of R matrices to armadillo is really slow

若如初见. 提交于 2019-12-04 13:29:48
问题 An Observation For medium-size matrices, the overheads on passing matrices from R to C++ are massively slower for arma::mat types than for NumericMatrix types. Like taking around 250x as long. Here's a minimal example #include <RcppArmadillo.h> // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; // [[Rcpp::export]] double test_nm( NumericMatrix X ) { return 0.0 ; } // [[Rcpp::export]] double test_arma( mat X ) { return 0.0 ; } // [[Rcpp::export]] double test_nm

Cross-Compiling Armadillo Linear Algebra Library

不羁的心 提交于 2019-12-04 13:12:11
问题 I enjoy using the Armadillo Linear Algebra Library. It becomes extremely nice when porting octave .m files over to C++, especially when you have to use the eigen methods. However I ran into issues when I had to take my program from my native vanilla G++ and dump it onto my ARM processor. Since I spent a few hours muddling my way though it I wanted to share so others might avoid some frustration. If anyone else could add anything else I would love it. This was the process I used to tackle this

NLopt with Armadillo data

随声附和 提交于 2019-12-04 12:00:26
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 was thinking of defining another pointer to these pointers: double** CombineMat; int* Arow = A.n_rows;

low RAM consuming c++ eigen solver

两盒软妹~` 提交于 2019-12-04 11:41:36
I'm newbie in C++ programming , but I have a task to compute eigenvalues and eigenvectors (standard eigenproblem Ax=lx ) for symmetric matrices (and hermitian)) for very large matrix of size: binomial(L,L/2) where L is about 18-22. Now I'm testing it on machine which has about 7.7 GB ram available, but at final I'll have access to PC with 64GB RAM. I've started with Lapack++ . At the beginning my project assume to solve this problem only for symmetrical real matrices. This library was great. Very quick and small RAM consuming. It has an option to compute eigenvectors and place into input

Importing Armadillo C++ library into Xcode

拈花ヽ惹草 提交于 2019-12-04 10:26:04
I'm a mac user and am trying to install and import C++ Armadillo library. Here are the steps I've had so far: 1) I downloaded the Armadillo library from its website. 2) I went over the Readme.txt file in the download file explaining how to install it. 3) I used CMake to make the armadillo download files into binary files. 4) Then by using terminal and the code sudo make install, I installed the binary codes and they generated some "library-like" files: libarmadillo.4.0.2.dylib, libarmadillo.4.dylib, lib armadillo.dylib 5) I then copied all these files into /url/lib directory. 6) Now I have my