Skip to content

Commit

Permalink
fixes due to tests--occasional seg fault
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen committed Jun 11, 2021
1 parent 8edd505 commit dbdf6da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 7 additions & 3 deletions fwdpy11/src/functions/add_mutation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ add_mutation(const fwdpy11::GSLrng_t& rng, const double left, const double right
= std::make_pair(i, 1);
}

for (auto n : candidates[candidate].descendants)
for (auto n : candidate_data.descendants)
{
if (nodes_to_haploid_genome[static_cast<std::size_t>(n)]
== std::numeric_limits<std::size_t>::max())
Expand Down Expand Up @@ -299,18 +299,22 @@ add_mutation(const fwdpy11::GSLrng_t& rng, const double left, const double right
// decrement the original genome count
pop.haploid_genomes[nodes_to_haploid_genome[n]].n--;

auto ind = nodes_to_individuals[nodes_to_haploid_genome[n]];
auto ind = nodes_to_individuals[n];
if (ind.first == std::numeric_limits<std::size_t>::max())
{
throw std::runtime_error("bad node to individual mapping");
}
// Add the new genome to the pop
if (new_genome.smutations.empty())
{
throw std::runtime_error("new genome is empty");
}
pop.haploid_genomes.emplace_back(std::move(new_genome));
if (ind.second == 0)
{
pop.diploids[ind.first].first = pop.haploid_genomes.size() - 1;
}
if (ind.second == 1)
else if (ind.second == 1)
{
pop.diploids[ind.first].second = pop.haploid_genomes.size() - 1;
}
Expand Down
19 changes: 17 additions & 2 deletions tests/test_add_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,24 @@ def test_new_mutation_data_bad_construction():
)


def test_add_singleton_in_single_deme():
@pytest.mark.parametrize("ndescendants", [1, 2, 3, 4, 5, 10])
def test_add_singleton_in_single_deme(ndescendants):
ts = msprime.simulate(sample_size=50, Ne=100)
pop = fwdpy11.DiploidPopulation.create_from_tskit(ts)
data = fwdpy11.NewMutationData(effect_size=-1e-3, dominance=1.0)
rng = fwdpy11.GSLrng(42)
pop.add_mutation(rng, ndescendants=1, data=data)
key = pop.add_mutation(rng, ndescendants=ndescendants, data=data)
# Skip over cases where ndescendants could not be satisfied
if key != np.iinfo(np.uint64).max:
assert key == 0
assert pop.mcounts[key] == ndescendants

count = 0
for d in pop.diploids:
for i in [d.first, d.second]:
assert i >= 0
assert i < len(pop.haploid_genomes)
for k in pop.haploid_genomes[i].smutations:
if k == key:
count += 1
assert count == pop.mcounts[key]

0 comments on commit dbdf6da

Please sign in to comment.