From 0a2d0f5991d6e44070c0e16815fcf50026376598 Mon Sep 17 00:00:00 2001 From: "Kevin R. Thornton" Date: Thu, 4 Jul 2024 12:17:15 -0700 Subject: [PATCH] try to force some init --- .../fwdpp_wrappers/fwdpp_genetic_value.hpp | 5 ++- .../genetic_values/site_dependent_fitness.hpp | 37 ++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/fwdpy11/headers/fwdpy11/genetic_values/fwdpp_wrappers/fwdpp_genetic_value.hpp b/fwdpy11/headers/fwdpy11/genetic_values/fwdpp_wrappers/fwdpp_genetic_value.hpp index 80ae93008..520ed1c78 100644 --- a/fwdpy11/headers/fwdpy11/genetic_values/fwdpp_wrappers/fwdpp_genetic_value.hpp +++ b/fwdpy11/headers/fwdpy11/genetic_values/fwdpp_wrappers/fwdpp_genetic_value.hpp @@ -99,8 +99,9 @@ namespace fwdpy11 public: stateless_site_dependent_genetic_value_wrapper( std::size_t ndim, double scaling, make_return_value_t mrv, - const GeneticValueToFitnessMap* gv2w_, const GeneticValueNoise* noise_) - : DiploidGeneticValue{ndim, gv2w_, noise_}, gv{}, aa_scaling(scaling), + std::function clamp, const GeneticValueToFitnessMap* gv2w_, + const GeneticValueNoise* noise_) + : DiploidGeneticValue{ndim, gv2w_, noise_}, gv(std::move(clamp)), aa_scaling(scaling), make_return_value(std::move(mrv)), callback(init_callback(ndim, aa_scaling)), isfitness(gv2w->isfitness) { diff --git a/fwdpy11/headers/fwdpy11/genetic_values/site_dependent_fitness.hpp b/fwdpy11/headers/fwdpy11/genetic_values/site_dependent_fitness.hpp index 8c609a741..632be6bc2 100644 --- a/fwdpy11/headers/fwdpy11/genetic_values/site_dependent_fitness.hpp +++ b/fwdpy11/headers/fwdpy11/genetic_values/site_dependent_fitness.hpp @@ -6,6 +6,10 @@ namespace fwdpy11 { struct site_dependent_genetic_value { + private: + std::function clamp; + + public: //! The return value type using result_type = double; @@ -68,13 +72,26 @@ namespace fwdpy11 else if (first1 == last1) { for (; first2 != last2; ++first2) - fpol_het(w, mutations[*first2]); + { + fpol_het(w, mutations[*first2]); + if (clamp(w)) + { + return rv_function(0.0); + } + } return rv_function(w); } else if (first2 == last2) { for (; first1 != last1; ++first1) - fpol_het(w, mutations[*first1]); + { + fpol_het(w, mutations[*first1]); + if (clamp(w)) + { + return rv_function(0.0); + } + } + return rv_function(w); } for (; first1 != last1; ++first1) @@ -85,6 +102,10 @@ namespace fwdpy11 // All mutations in this range are Aa { fpol_het(w, mutations[*first2]); + if (clamp(w)) + { + return rv_function(0.0); + } } if (first2 < last2 && (*first1 == *first2 @@ -92,17 +113,29 @@ namespace fwdpy11 // mutation with index first1 is homozygous { fpol_hom(w, mutations[*first1]); + if (clamp(w)) + { + return rv_function(0.0); + } ++first2; // increment so that we don't re-process // this site as a het next time 'round } else // mutation first1 is heterozygous { fpol_het(w, mutations[*first1]); + if (clamp(w)) + { + return rv_function(0.0); + } } } for (; first2 != last2; ++first2) { fpol_het(w, mutations[*first2]); + if (clamp(w)) + { + return rv_function(0.0); + } } return rv_function(w); }