xflouris / libpll

Phylogenetic Likelihood Library
GNU Affero General Public License v3.0
26 stars 6 forks source link

Restricting partitions to a subset of sites #65

Closed pierrebarbera closed 6 years ago

pierrebarbera commented 8 years ago

The structure of the partitions gives us the possibility to use pointer arithmetic to "focus" a partition on a subset of sites. There are already two possible use cases for this: the ranged clv computation in EPA, as well as possible use in the parallelization scheme of ng-raxml, where threads will (presumably) be assigned chunks of sites (@amkozlov).

A possible implementation could looks something like this:

void shift_partition_focus(pll_partition_t * partition, const int offset, const unsigned int span)
{
  const unsigned int clv_size = partition->rate_cats * partition->states_padded;
  const unsigned int num_tips = partition->tips;
  const unsigned int max_index = num_tips + partition->clv_buffers;

  // shift the tip chars
  for (unsigned int i = 0; i < num_tips; i++)
    partition->tipchars[i] += offset;

  // shift the clvs
  for (unsigned int i = 0; i < max_index; i++)
    partition->clv[i] += offset * (int)clv_size;

  // shift the scalers
  for (unsigned int i = 0; i < partition->scale_buffers; i++)
    partition->scale_buffer[i] += offset;

  // shift the pattern weights
  partition->pattern_weights += offset;

  // adjust the number of sites
  partition->sites = span;
}

Keeping this inside pll makes sense I think, since it is quite general and requires in-depth knowledge of pll internals.