Reputation: 669
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,
Upvotes: 6
Views: 5161
Reputation: 368639
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>
Upvotes: 12
Reputation: 92391
According to this page
http://arma.sourceforge.net/docs.html#Mat
a mat
is a matrix of double
while umat
is a matrix of unsigned int
. Seems like they are not convertible to each other.
Upvotes: 0
Reputation: 827
Armadillo does not support conversion from Mat<uword>
(umat
) to Mat<double>
(mat
) using neither constructor nor operator=
Perhaps you have to write your own conversion function.
Upvotes: 0