【问题标题】:conversion from ‘arma::umat’ to ‘arma::mat’从“arma::umat”到“arma::mat”的转换
【发布时间】:2012-04-18 15:03:46
【问题描述】:
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 转换为 mat?

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

谢谢,

【问题讨论】:

    标签: c++ matrix rcpp armadillo


    【解决方案1】:

    另外两个答案已经暗示不存在直接转换。在Arma web site 上花一分钟建议您在此处使用您想要的conv_to&lt;T&gt;::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> 
    

    【讨论】:

      【解决方案2】:

      犰狳不支持从Mat&lt;uword&gt; (umat) 到Mat&lt;double&gt; (mat) 的转换,既不使用构造函数也不使用operator=

      也许你必须编写自己的转换函数。

      【讨论】:

      • 犰狳确实支持使用conv_to&lt;T&gt;::from()函数进行转换。
      【解决方案3】:

      根据这个页面

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

      matdouble 的矩阵,而umatunsigned int 的矩阵。好像它们不能相互转换。

      【讨论】:

      • 它们可以使用conv_to&lt;T&gt;::from()进行转换。
      猜你喜欢
      • 2020-02-09
      • 1970-01-01
      • 1970-01-01
      • 2015-01-14
      • 1970-01-01
      • 2022-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多