aboutsummaryrefslogtreecommitdiffstats
path: root/src/low_discrepancy.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/low_discrepancy.hpp')
-rw-r--r--src/low_discrepancy.hpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/low_discrepancy.hpp b/src/low_discrepancy.hpp
index bc8e820..8157329 100644
--- a/src/low_discrepancy.hpp
+++ b/src/low_discrepancy.hpp
@@ -10,20 +10,21 @@
#include <gsl/gsl_qrng.h>
#ifdef NLOPT
#include "nlopt-util.h"
+#include <memory>
#endif
class p_adic {
- public:
+ public:
typedef std::list<int> coeff;
p_adic(coeff ak, coeff pk) : ak(ak), pk(pk), p(*(++pk.begin())) {};
p_adic(int n, int p = 2);
p_adic(double x, int p = 2);
operator double() {
- return std::inner_product(ak.begin(), ak.end(), ++pk.begin(),
+ return std::inner_product(ak.begin(), ak.end(), ++pk.begin(),
0.0, std::plus<double>(), std::divides<double>());
}
operator int() {
- return std::inner_product(ak.begin(), ak.end(), pk.begin(), 0);
+ return std::inner_product(ak.begin(), ak.end(), pk.begin(), 0);
}
friend p_adic operator+(const p_adic &m, const p_adic &o);
p_adic operator++(int) {
@@ -53,7 +54,7 @@ static int primes[255] = {
173, 179, 181, 191, 193, 197, 199, 211, 223, 227,
229, 233, 239, 241, 251, 257, 263, 269, 271, 277,
281, 283, 293, 307, 311, 313, 317, 331, 337, 347,
- 349, 353, 359, 367, 373, 379, 383, 389, 397, 401,
+ 349, 353, 359, 367, 373, 379, 383, 389, 397, 401,
409, 419, 421, 431, 433, 439, 443, 449, 457, 461,
463, 467, 479, 487, 491, 499, 503, 509, 521, 523,
541, 547, 557, 563, 569, 571, 577, 587, 593, 599,
@@ -112,17 +113,17 @@ struct kakutani {
list_p_adic yk;
result_type result;
struct t_op {
- double operator()(p_adic &x, const p_adic &y) {
+ double operator()(p_adic &x, const p_adic &y) {
x = x + y;
return (double) x;
- };
+ };
} op;
};
struct faure {
typedef std::vector<double> result_type;
typedef std::vector< std::vector<int> > coeff_binom;
- faure(int dimension, const p_adic &x)
+ faure(int dimension, const p_adic &x)
: x(x), result(dimension), Comb(32, std::vector<int>(32,0)) {
for (int n = 0; n < 32; n++) {
Comb[0][n] = 1;
@@ -157,7 +158,7 @@ struct faure {
protected:
p_adic x;
result_type result;
- coeff_binom Comb;
+ coeff_binom Comb;
};
@@ -165,7 +166,7 @@ struct sobol {
typedef std::vector<double> result_type;
sobol(int dimension) : dimension(dimension), result(dimension) {
#ifdef NLOPT
- s = nlopt_sobol_create(dimension);
+ s = std::shared_ptr<nlopt_soboldata_s>(nlopt_sobol_create(dimension), nlopt_sobol_destroy);
#else
q = gsl_qrng_alloc(gsl_qrng_sobol, dimension);
#endif
@@ -202,14 +203,13 @@ struct sobol {
#endif
~sobol() {
#ifdef NLOPT
- nlopt_sobol_destroy(s);
#else
gsl_qrng_free(q);
#endif
}
result_type operator()() {
#ifdef NLOPT
- nlopt_sobol_next01(s, result.data());
+ nlopt_sobol_next01(s.get(), result.data());
#else
gsl_qrng_get(q, result.data());
#endif
@@ -218,7 +218,7 @@ struct sobol {
protected:
int dimension;
#ifdef NLOPT
- nlopt_sobol s;
+ std::shared_ptr<nlopt_soboldata_s> s;
#else
gsl_qrng * q;
#endif