From 79153ab1884f309bc28027e0c6ea191dba40c46a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Fri, 26 Jan 2024 18:04:02 +0100 Subject: [PATCH] C++20 modernization: use some concepts --- mex/sources/sobol/gaussian.hh | 11 ++++++----- mex/sources/sobol/sobol.hh | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/mex/sources/sobol/gaussian.hh b/mex/sources/sobol/gaussian.hh index a10a807774..39dfc759a9 100644 --- a/mex/sources/sobol/gaussian.hh +++ b/mex/sources/sobol/gaussian.hh @@ -28,6 +28,7 @@ #include <algorithm> #include <array> #include <cmath> +#include <concepts> #include <limits> #include <numbers> #include <vector> @@ -41,7 +42,7 @@ using namespace std; constexpr double lb = .02425; constexpr double ub = .97575; -template<typename T> +template<floating_point T> T icdf(const T uniform) /* @@ -105,7 +106,7 @@ icdf(const T uniform) } void -icdfm(int n, auto* U) +icdfm(int n, floating_point auto* U) { #pragma omp parallel for for (int i = 0; i < n; i++) @@ -114,7 +115,7 @@ icdfm(int n, auto* U) } void -icdfmSigma(int d, int n, auto* U, const double* LowerCholSigma) +icdfmSigma(int d, int n, floating_point auto* U, const double* LowerCholSigma) { double one = 1.0; double zero = 0.0; @@ -127,7 +128,7 @@ icdfmSigma(int d, int n, auto* U, const double* LowerCholSigma) } void -usphere(int d, int n, auto* U) +usphere(int d, int n, floating_point auto* U) { icdfm(n * d, U); #pragma omp parallel for @@ -145,7 +146,7 @@ usphere(int d, int n, auto* U) } void -usphereRadius(int d, int n, double radius, auto* U) +usphereRadius(int d, int n, double radius, floating_point auto* U) { icdfm(n * d, U); #pragma omp parallel for diff --git a/mex/sources/sobol/sobol.hh b/mex/sources/sobol/sobol.hh index 026ccfa261..1cbaee6c5b 100644 --- a/mex/sources/sobol/sobol.hh +++ b/mex/sources/sobol/sobol.hh @@ -1,6 +1,6 @@ /* Interface to quasi Monte Carlo sequences (à la Sobol) routines. * - * Copyright © 2010-2023 Dynare Team + * Copyright © 2010-2024 Dynare Team * * This file is part of Dynare. * @@ -21,6 +21,7 @@ #ifndef SOBOL_HH #define SOBOL_HH +#include <concepts> #include <cstdint> #include <dynblas.h> // For the FORTRAN_WRAPPER macro @@ -48,7 +49,7 @@ sobol_block(int dimension, int block_size, int64_t seed, double* block) return seed; } -template<typename T> +template<floating_point T> void expand_unit_hypercube(int dimension, int block_size, T* block, const T* lower_bound, const T* upper_bound) -- GitLab