Skip to content

Commit

Permalink
use new API internally
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen committed Aug 2, 2024
1 parent d207a57 commit c1af2f5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 29 deletions.
2 changes: 1 addition & 1 deletion fwdpy11/headers/fwdpy11/gsl/gsl_discrete.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <limits>
#include <fwdpy11/discrete_demography/exceptions.hpp>
#include <fwdpy11/rng.hpp>
#include <fwdpy11/gsl/gsl_discrete.hpp>
#include <fwdpp/gsl_discrete.hpp>
#include <stdexcept>
#include "multideme_fitness_bookmark.hpp"
Expand Down Expand Up @@ -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
{
Expand Down
21 changes: 2 additions & 19 deletions lib/genetic_maps/regions.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "fwdpy11/regions/RecombinationRegions.hpp"
#include <fwdpy11/gsl/gsl_discrete.hpp>
#include <cmath>
#include <gsl/gsl_randist.h>
#include <limits>
Expand Down Expand Up @@ -141,7 +142,6 @@ namespace fwdpy11_core
std::vector<double> 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);
Expand All @@ -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
Expand Down

0 comments on commit c1af2f5

Please sign in to comment.