2012-04-18 73 views
4
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") 

如何将umat转换为Armadillo上的mat?从'arma :: umat'转换为'arma :: mat'

file53a97e398eed.cpp:33: error: conversion from ‘arma::umat’ to non-scalar type ‘arma::mat’ requested 
make: *** [file53a97e398eed.o] Error 1 

谢谢

回答

11

另外两个答案已经暗示,直接转换不存在。花一分钟的Arma web site建议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> 
+1

当前文档现在推荐'as_scalar',来自** fn_conv_to.hpp **“'//!(仅用于与旧代码兼容;使用as_scalar()代替Mat等基本对象)'” – 2017-06-12 19:24:41

+0

感谢您的更新,欣赏它! – 2017-06-12 19:35:24

0

犰狳不会Mat<uword>umat)既不使用也不构造operator=

也许你已经写你自己的转换功能支持转换到Mat<double>mat)。

+0

使用'conv_to ::从()'函数犰狳_does_支持转换。 – 2012-04-19 00:15:20

0

根据这一页

http://arma.sourceforge.net/docs.html#Mat

一个matdoubleumatunsigned int矩阵的矩阵。看起来他们不能相互转换。

+1

它们可以使用'conv_to :: from()'转换。 – 2012-04-19 00:15:41