Skip to content

Commit

Permalink
use global extinction. support skipping zero check
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen committed Aug 3, 2024
1 parent 22c8c93 commit 8277bb4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/core/gsl/gsl_discrete.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ namespace fwdpy11_core
{
void update_lookup_table(const double *data, std::size_t size,
fwdpp::gsl_ran_discrete_t_ptr &lookup);
void update_lookup_table_skip_zero_check(const double *data, std::size_t size,
fwdpp::gsl_ran_discrete_t_ptr &lookup);
}
7 changes: 5 additions & 2 deletions lib/evolve_discrete_demes/diploid_pop_fitness.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "diploid_pop_fitness.hpp"
#include <stdexcept>

#include "diploid_pop_fitness.hpp"
#include <fwdpy11/discrete_demography/exceptions.hpp>

void
calculate_diploid_fitness(const fwdpy11::GSLrng_t &rng, fwdpy11::DiploidPopulation &pop,
std::vector<fwdpy11::DiploidGeneticValue *> &gvalue_pointers,
Expand Down Expand Up @@ -40,7 +42,8 @@ calculate_diploid_fitness(const fwdpy11::GSLrng_t &rng, fwdpy11::DiploidPopulati
}
if (all_fitneses_are_zero == true)
{
throw std::runtime_error("all individual fitness values are zero");
throw fwdpy11::discrete_demography::GlobalExtinction(
"all individual fitness values are zero");
}
// If the sum of parental fitnesses is not finite,
// then the genetic value calculator returned a non-finite value/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ namespace fwdpy11_core
- fitness_bookmark.starts[i]

);

// generate a more useful error message here...
if (std::all_of(first, last,
[](const double d) { return d == 0.0; }))
{
Expand All @@ -114,7 +116,8 @@ namespace fwdpy11_core
<< " are zero.";
throw std::runtime_error(o.str());
}
fwdpy11_core::update_lookup_table(
// ...then use the call that skips the same check
fwdpy11_core::update_lookup_table_skip_zero_check(
fitness_bookmark.individual_fitness.data()
+ fitness_bookmark.starts[i],
fitness_bookmark.stops[i]
Expand Down
7 changes: 7 additions & 0 deletions lib/gsl/gsl_discrete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ namespace fwdpy11_core
{
throw fwdpy11::GSLError("all weights are 0.0");
}
update_lookup_table_skip_zero_check(data, size, lookup);
}

void
update_lookup_table_skip_zero_check(const double *data, std::size_t size,
fwdpp::gsl_ran_discrete_t_ptr &lookup)
{
// Note, without a handler from
// #include <fwdpy11/gsl/gsl_error_handler_wrapper.hpp>
// the following call with abort when presented invalid data
Expand Down

0 comments on commit 8277bb4

Please sign in to comment.