سؤال

لدي البرنامج التالي.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <ctime>
#include <cmath>
#include <RInside.h>
using std::cout;
using std::endl;
using std::vector;
using namespace Rcpp;
int main(int argc, char** argv){
    RInside R;
    R.parseEvalQ("set.seed(1)"); Rcpp::RNGScope();
    const Function sample("sample");
    vector<int> vv = as<vector<int> >(sample(NumericVector::create(0,1,2,3), 1e6, true,NumericVector::create(.3,.3,.2,.2)));
    cout<<"1"<<endl<<std::flush;
    const vector<int> vv2 = as<vector<int> >(sample(NumericVector::create(0,1,2,3), 2e6, true,NumericVector::create(.3,.3,.2,.2)));
    cout<<"2"<<endl;
}

الإخراج هو

1
Segmentation fault

وهذا يعني أن ناقلات ج vector vv2 لا يمكن تهيئة.لماذا لا يمكن تعيين في في 2?

مع مضمنة ، وهنا هو ما حصلت عليه:

> body <- '
+ using namespace Rcpp;
+ using std::vector;
+ using std::cout;
+ using std::endl;
+      Rcpp::RNGScope();
+     const Function sample("sample");
+     vector<int> vv = as<vector<int> >(sample(NumericVector::create(0,1,2,3), 1e6, true,NumericVector::create(.3,.3,.2,.2)));
+     cout<<"1"<<endl<<std::flush;
+     const vector<int> vv2 = as<vector<int> >(sample(NumericVector::create(0,1,2,3), 2e6, true,NumericVector::create(.3,.3,.2,.2)));
+     cout<<"2"<<endl;
+     List vecs(2);
+     vecs[1]=vv;
+     vecs[1]=vv2;
+     return(vecs);
+     '
> require( inline )
Loading required package: inline
> require( Rcpp )
Loading required package: Rcpp
Loading required package: int64
> 
> signatures <- NULL
> fx <- cxxfunction( signatures, body, plugin = "Rcpp" )
> a <- fx()

 *** caught segfault ***
address 0x7f2b850eb013, cause 'memory not mapped'

Traceback:
 1: .Primitive(".Call")(<pointer: 0x7f2b8627d2c0>)
 2: fx()

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
هل كانت مفيدة؟

المحلول

يمكنك أن تفعل الشيء نفسه في ص على جهازك?2 مليون عنصر هو الكثير جدا.

أيضا ، أنا تقريبا لا ندعو مرة أخرى إلى وظائف ص بهذه الطريقة لأنها غير فعالة.إذا كنت تريد تسريع ، إعادة تنفيذ sample() في ج which والتي لا يمكن أن تكون صعبة للغاية.

بعد ذلك ، أوصي أيضا بتعبير أبسط تم تجربته أولا عبر مضمنة.

وأخيرا ، وأنا سوف يبدو وكأنه سجل كسر ، حاول قائمة ركب-ديفيل.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top