I am trying to integrate a 1D vector function in cuba. I get correct results when I set NDIM=2 but I get incorrect results with NDIM=1. I have reproduced a minimal working example below.
#include <iostream>
#include <cmath>
#include "cuba.h"
#define NDIM 2 //changing this to 1 gives incorrect result!
#define NCOMP 12
#define NVEC 1
#define EPSREL 1e-6
#define EPSABS 0
#define VERBOSE 0
#define LAST 4
#define MINEVAL 0
#define MAXEVAL 50000
#define STATEFILE NULL
#define SPIN NULL
#define KEY 0
static int f12(const int *ndim, const double xx[],
const int *ncomp, double ff[], void *p) {
for(int i=0;i<12;i++)
ff[i] = 1.0/(1.0+i*xx[0]*xx[0]);
return 0;
}
int main(int argc, char **argv)
{
int comp, nregions, neval, fail;
double integral[12], error[12], prob[12];
Cuhre(NDIM, NCOMP, f12, NULL, NVEC,
EPSREL, EPSABS, VERBOSE | LAST,
MINEVAL, MAXEVAL, KEY,
STATEFILE, SPIN,
&nregions, &neval, &fail, integral, error, prob);
for(int i=0;i<12;i++) printf("%lf ",integral[i]); printf("\n");
return 0;
}
Changing value of NDIM to 1 gives wrong result. I haven't looked for the bug in the source code yet.
Thank you for your attention.