gpt4 book ai didi

c++ - 从 ‘arma::umat’ 到 ‘arma::mat’ 的转换

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:05:26 24 4
gpt4 key购买 nike

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")

如何在 Armadillo 上将 umat 转换为 mat?

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

谢谢,

最佳答案

另外两个答案已经暗示不存在直接转换。在 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>

关于c++ - 从 ‘arma::umat’ 到 ‘arma::mat’ 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10212247/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com