2012-04-18 42 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