Skip to content

Commit

Permalink
Removing extra mem allocation+copy in geese::likelihood
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Oct 2, 2023
1 parent 0645d92 commit 20f3297
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/barry/model-meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ inline double likelihood_(
double numerator = 0.0;

// Computing the numerator
for (size_t j = 0u; j < params.size(); ++j)
for (size_t j = 0u; j < n_params; ++j)
numerator += *(stats_target + j) * params[j];

if (!log_)
Expand Down
17 changes: 8 additions & 9 deletions include/barry/models/geese/geese-meat-likelihood.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inline void pset_loop(
const std::vector<std::vector<bool>> & states,
const std::vector< PhyloArray > & psets,
const std::vector<double> & psets_stats,
std::vector< std::vector< size_t > > & locations,
const std::vector< std::vector< size_t > > & locations,
const std::vector<geese::Node *> & node_offspring
)
{
Expand Down Expand Up @@ -73,17 +73,11 @@ inline void pset_loop(
if (off_mult < 0.0)
return;

// Multiplying by P(x|x_n), the transition probability
std::vector< double > temp_stats;
temp_stats.reserve(par0.size());
for (auto p = 0u; p < par0.size(); ++p)
temp_stats.push_back(psets_stats[par0.size() * n + p]);

// Use try catch in the following line
try {

off_mult *= barry::likelihood_(
&temp_stats[0u],
&psets_stats[par0.size() * n],
par0,
norm_const_i,
par0.size(),
Expand Down Expand Up @@ -223,8 +217,13 @@ inline double Geese::likelihood(

// Setting the probability at the node
node.subtree_prob[s] = 0.0;
auto & nsp = node.subtree_prob[s];
#if defined(_OPENMP) || defined(__OPENMP)
#pragma omp simd reduction(+:nsp)
#endif
for (size_t n = 0u; n < psets.size(); ++n)
node.subtree_prob[s] += totprob_n[n];
nsp += totprob_n[n];


}

Expand Down

0 comments on commit 20f3297

Please sign in to comment.