Skip to content

Commit

Permalink
try to force some init
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen committed Jul 4, 2024
1 parent 334c027 commit 0a2d0f5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool(double)> 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)
{
Expand Down
37 changes: 35 additions & 2 deletions fwdpy11/headers/fwdpy11/genetic_values/site_dependent_fitness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ namespace fwdpy11
{
struct site_dependent_genetic_value
{
private:
std::function<bool(double)> clamp;

public:
//! The return value type
using result_type = double;

Expand Down Expand Up @@ -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)
Expand All @@ -85,24 +102,40 @@ 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
|| mutations[*first1].pos == mutations[*first2].pos))
// 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);
}
Expand Down

0 comments on commit 0a2d0f5

Please sign in to comment.