Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conversion from ‘arma::umat’ to ‘arma::mat’

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,

like image 331
Jona Avatar asked Apr 18 '12 15:04

Jona


1 Answers

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> 
like image 90
Dirk Eddelbuettel Avatar answered Oct 19 '22 11:10

Dirk Eddelbuettel