开发者

C code from Cubature package

Can you please help me understand a C code from Cubature package?

My specific questions:

1) What is the purpose of the fwrapper function rcubature.c file?

开发者_JS百科void fWrapper(unsigned ndim, const double *x, void *fdata, unsigned fdim, double *fval) {
    SEXP xx, fx;
    double *rx, *rfx;
    int i;


    PROTECT(xx = allocVector(REALSXP, ndim));
    rx = REAL(xx);
    for (i = 0; i < ndim; ++i) {
        rx[i] = x[i];
    }
    defineVar(install("x"), xx, CUB_common_env);
    PROTECT(fx = eval(f, CUB_common_env));

    rfx = REAL(fx);
    for (i = 0; i < fdim; ++i) {
        fval[i] = rfx[i];
    }
    UNPROTECT(2);
    count++;
}

2) What does the defineVar call in fWrapper do?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜