Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Rcpp Type List in R language

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you the "sample analysis of Rcpp type List in R language", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and study the "sample analysis of Rcpp type List in R language".

When we want to return multiple types of objects in Rcpp through a return function, we need to organize all our objects into a Rcpp::List type and then return them.

However, compared to list in R (mat1 = mat1, mat2 = mat2), list creation in Rcpp is relatively complex and requires the use of the create () function, as shown in the following example:

Rcpp::List ListFun (MatrixXd X) {Eigen::MatrixXd mat1, mat2; return List::create (Named ("matrix1") = mat1, Named ("matrix2") = mat2);}

After return, what should we do when we want to call the List in our .cpp file (or read the list type in R directly)?

In fact, it is also very simple, which can be divided into two steps: the first step is to create the List, and the second step is to create the content in the List, with the object type corresponding to it, as shown below:

Void TestFun (MatrixXd X, MatrixXd Y) {Rcpp::List result_x, result_y; result_x= ListFun (X); result_y= ListFun (Y); MatrixXd mat1_x = result_x ["matrix1"]; MatrixXd mat1_y = result_y ["matrix1"]; MatrixXd mat2_x = result_x ["matrix2"]; MatrixXd mat2_y = result_y ["matrix2"] } the above is all the content of the article "sample Analysis of Rcpp Type List in R language". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report