Jon*_*ona 5 c++ matrix armadillo rcpp
code <- '
arma::mat M=Rcpp::as<arma::mat>(m);
arma::umat a=trans(M)>M;
arma::mat N=a;
return Rcpp::wrap(N);
'
coxFunc <- cxxfunction(signature(m="matrix"),
code,
plugin="RcppArmadillo")
Run Code Online (Sandbox Code Playgroud)
如何在Armadillo上从umat转换为mat?
file53a97e398eed.cpp:33: error: conversion from ‘arma::umat’ to non-scalar type ‘arma::mat’ requested
make: *** [file53a97e398eed.o] Error 1
Run Code Online (Sandbox Code Playgroud)
谢谢,
Dir*_*tel 11
另外两个答案已经暗示不存在直接转换.花一分钟在Arma网站上建议conv_to<T>::from(var)
你想要的功能:
R> code <- '
+ arma::mat M = Rcpp::as<arma::mat>(m);
+ arma::umat a = trans(M) > M;
+ arma::mat N = arma::conv_to<arma::mat>::from(a);
+ return Rcpp::wrap(N);
+ '
R> coxFunc <- cxxfunction(signature(m="matrix"),
+ code,
+ plugin="RcppArmadillo")
R> coxFunc( matrix(1:9, 3, 3) )
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 1 0 0
[3,] 1 1 0
R>
Run Code Online (Sandbox Code Playgroud)