armadillo

Dynamic parameterization of Armadillo matrix dimensions in C++

拥有回忆 提交于 2021-02-13 05:45:06
问题 The title summarizes the goal that is more exactly to dynamically retrieve the number of dimensions of MATLAB arrays passed to armadillo matrices. I would like to change the second and third arguments of mY() and mD() to parametric ones below. // mat(ptr_aux_mem, n_rows, n_cols, copy_aux_mem = true, strict = false) arma::mat mY(&dY[0], 2, 168, false); arma::mat mD(&dD[0], 2, 168, false); This must be definitely a common use case, but I still could not find a nice way of achieving it for the

Dynamic parameterization of Armadillo matrix dimensions in C++

半城伤御伤魂 提交于 2021-02-13 05:43:47
问题 The title summarizes the goal that is more exactly to dynamically retrieve the number of dimensions of MATLAB arrays passed to armadillo matrices. I would like to change the second and third arguments of mY() and mD() to parametric ones below. // mat(ptr_aux_mem, n_rows, n_cols, copy_aux_mem = true, strict = false) arma::mat mY(&dY[0], 2, 168, false); arma::mat mD(&dD[0], 2, 168, false); This must be definitely a common use case, but I still could not find a nice way of achieving it for the

Dynamic parameterization of Armadillo matrix dimensions in C++

放肆的年华 提交于 2021-02-13 05:42:10
问题 The title summarizes the goal that is more exactly to dynamically retrieve the number of dimensions of MATLAB arrays passed to armadillo matrices. I would like to change the second and third arguments of mY() and mD() to parametric ones below. // mat(ptr_aux_mem, n_rows, n_cols, copy_aux_mem = true, strict = false) arma::mat mY(&dY[0], 2, 168, false); arma::mat mD(&dD[0], 2, 168, false); This must be definitely a common use case, but I still could not find a nice way of achieving it for the

efficient distance calculations in armadillo

偶尔善良 提交于 2021-02-08 06:36:37
问题 I'm new to armadillo. I have the below code, which I assume is inefficient. Any suggestions to make it more memory efficient and/or speedy? Following the armadillo docs and Rcpp gallery, I was unable to get .colptr 's, uvec 's, or batch insertion to work. But I assume any of them would be improvements. With an input of X (~100 x 30000), even my stupidly large work VM crashes. Linux release 7.3.1611 (Core) 117GB RAM / 0GB SWAP (24 x 2.494 GHz) processor(s) R version 3.3.2 (2016-10-31) Platform

Get error when use Rcpp remove rows of matrix

。_饼干妹妹 提交于 2021-02-05 09:37:40
问题 #include <RcppArmadillo.h> // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; // [[Rcpp::export]] arma::mat fed(arma::mat x){ arma::mat zz=x.shed_rows(0,2); return(zz); } Just want remove some rows from matrix, get error as follows. conversion from 'void' to non-scalar type 'arma::Mat} requested' 回答1: Two points: Please don't post error messages as image. Use Text instead. As the error indicates, the shed_rows() method does not return anything. Instead it alters the matrix it acts on,

Using SuperLU sparse solver with RcppArmadillo

混江龙づ霸主 提交于 2021-02-05 04:49:56
问题 I am trying to use the SparseLU solver from armadillo (http://arma.sourceforge.net/docs.html#spsolve) through RcppArmadillo: #define ARMA_USE_SUPERLU // [Rcpp::depends(RcppArmadillo)] #include <RcppArmadillo.h> // [[Rcpp::export]] arma::vec sp_solver(arma::sp_mat K, arma::vec x) { arma::superlu_opts opts; opts.symmetric = true; arma::vec res; arma::spsolve(res, K, x, "superlu", opts); return res; } /*** R library(Matrix) K <- sparseMatrix(i = c(1, 2, 1), j = c(1, 2, 2), x = c(1, 1, 0.5),

Using SuperLU sparse solver with RcppArmadillo

戏子无情 提交于 2021-02-05 04:49:45
问题 I am trying to use the SparseLU solver from armadillo (http://arma.sourceforge.net/docs.html#spsolve) through RcppArmadillo: #define ARMA_USE_SUPERLU // [Rcpp::depends(RcppArmadillo)] #include <RcppArmadillo.h> // [[Rcpp::export]] arma::vec sp_solver(arma::sp_mat K, arma::vec x) { arma::superlu_opts opts; opts.symmetric = true; arma::vec res; arma::spsolve(res, K, x, "superlu", opts); return res; } /*** R library(Matrix) K <- sparseMatrix(i = c(1, 2, 1), j = c(1, 2, 2), x = c(1, 1, 0.5),

Armadillo之行向量(row vector)

删除回忆录丶 提交于 2021-02-01 10:53:31
1 行向量类:定义 Row< type > 2 常用的typedef rowvec = Row<double> frowvec = Row<float> cx_rowvec = Row<cx_double> cx_frowvec = Row<cx_float> urowvec = Row<uword> irowvec = Row<sword> 3 创建 rowvec r1 = "1,2,3,4"; rowvec r2 = initializer_list<double>{ 1, 2, 3, 4 }; rowvec r3; //行向量未初始化 r3 << 1 << 2 << 3 << 4; rowvec r4(r1); double *elem = new double[4]{1, 2, 3, 4}; rowvec r5(elem, 4); //这个是从elem指针指向的内存中复制元素,所以是安全的 rowvec r6(elem, 4, false); //这个是直接使用elem指针所指向的内存,所以要保证elem所指向的内存在v6的生命期内有效且不被它人使用 //而且向量的大小不能被直接或间接改变 rowvec r7(elem, 4, false, false); //这个是直接使用elem指针所指向的内存,所以要保证elem所指向的内存在v6的生命期内有效且不被它人使用 /

A simple RcppArmadillo index issue

岁酱吖の 提交于 2021-01-29 16:56:25
问题 I'm coding with RcppArmadillo and got stuck with a very basic question. Suppose I have a vector "v", and I want to take its first 10 elements, like in R: v[1:10] . Since 1:10 doesn't work in RcppArmadillo , I tried v.elem(seq_len(10)) , but it didn't work. Any hint? 回答1: Assuming you're taking about an arma::vec , this should work: #include <RcppArmadillo.h> // [[Rcpp::depends(RcppArmadillo)]] // [[Rcpp::export]] arma::vec f(const arma::vec & v, int first, int last) { arma::vec out = v.subvec

Armadillo + BLAS + LAPACK

徘徊边缘 提交于 2021-01-29 12:31:23
问题 I am using the armadillo library inside a package (LAMMPS package). I also used Armadillo to compile different codes, and it works fines, and I use the following compiling command: g++ example2.cpp -o example2 -O3 -larmadillo -DARMA_DONT_USE_WRAPPER -lblas -llapack Armadillo works fine for matrix storage and loading inside the package, however, when it comes to matrix-vector multiplication, it gives me the following error: /usr/include/armadillo_bits/wrapper_blas.hpp:42: undefined reference