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")
How can I convert from umat to mat on Armadillo?
file53a97e398eed.cpp:33: error: conversion from ‘arma::umat’ to non-scalar type ‘arma::mat’ requested
make: *** [file53a97e398eed.o] Error 1
Thank you,
The two other answers already hinted that a straight conversion does not exist. Spending a minute on the Arma web site suggest the conv_to<T>::from(var) function you want here:
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> 
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With