From c1af2f514831b0f30678617fd6542b83fc34c5a7 Mon Sep 17 00:00:00 2001 From: "Kevin R. Thornton" Date: Fri, 2 Aug 2024 14:03:55 -0700 Subject: [PATCH] use new API internally --- fwdpy11/headers/fwdpy11/gsl/gsl_discrete.hpp | 2 +- .../simulation/multideme_fitness_lookups.hpp | 14 +++++-------- lib/genetic_maps/regions.cc | 21 ++----------------- 3 files changed, 8 insertions(+), 29 deletions(-) diff --git a/fwdpy11/headers/fwdpy11/gsl/gsl_discrete.hpp b/fwdpy11/headers/fwdpy11/gsl/gsl_discrete.hpp index db0022722..d8d4c6606 100644 --- a/fwdpy11/headers/fwdpy11/gsl/gsl_discrete.hpp +++ b/fwdpy11/headers/fwdpy11/gsl/gsl_discrete.hpp @@ -7,7 +7,7 @@ namespace fwdpy11 { - void + inline void update_lookup_table(const double *data, std::size_t size, fwdpp::gsl_ran_discrete_t_ptr &lookup) { diff --git a/lib/evolve_discrete_demes/discrete_demography/simulation/multideme_fitness_lookups.hpp b/lib/evolve_discrete_demes/discrete_demography/simulation/multideme_fitness_lookups.hpp index 5baf8ab1b..1489179f3 100644 --- a/lib/evolve_discrete_demes/discrete_demography/simulation/multideme_fitness_lookups.hpp +++ b/lib/evolve_discrete_demes/discrete_demography/simulation/multideme_fitness_lookups.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include "multideme_fitness_bookmark.hpp" @@ -113,17 +114,12 @@ namespace fwdpy11_core << " are zero."; throw std::runtime_error(o.str()); } - auto table = gsl_ran_discrete_preproc( + fwdpy11::update_lookup_table( + fitness_bookmark.individual_fitness.data() + + fitness_bookmark.starts[i], fitness_bookmark.stops[i] - fitness_bookmark.starts[i], - fitness_bookmark.individual_fitness.data() - + fitness_bookmark.starts[i]); - if (table == nullptr) - { - throw std::runtime_error( - "gsl_ran_discrete_preproc returned nullptr"); - } - lookups[i].reset(table); + lookups[i]); } else { diff --git a/lib/genetic_maps/regions.cc b/lib/genetic_maps/regions.cc index 30a67bdf9..e05e2aeb8 100644 --- a/lib/genetic_maps/regions.cc +++ b/lib/genetic_maps/regions.cc @@ -1,4 +1,5 @@ #include "fwdpy11/regions/RecombinationRegions.hpp" +#include #include #include #include @@ -141,7 +142,6 @@ namespace fwdpy11_core std::vector weights; weights.reserve(regions.size()); segments.reserve(regions.size()); - bool all_weights_are_zero = true; for (const auto& r : this->regions) { validate_interval(r.beg, r.end, discrete); @@ -150,27 +150,10 @@ namespace fwdpy11_core { w += (r.end - r.beg); } - if (w != 0.0) - { - all_weights_are_zero = false; - } - if (w < 0.0) - { - throw std::invalid_argument("weights must be non-negative"); - } weights.push_back(w); segments.push_back(Segment{r.beg, r.end}); } - if (all_weights_are_zero == true) - { - throw std::invalid_argument("all weights are zero"); - } - auto table = gsl_ran_discrete_preproc(segments.size(), weights.data()); - if (table == nullptr) - { - throw std::runtime_error("gsl_ran_discrete_preproc returned nullptr"); - } - lookup.reset(table); + fwdpy11::update_lookup_table(weights.data(), weights.size(), lookup); } double