Skip to content

Commit

Permalink
Indices: _calc_pe_lists: call _calc_pe if needed to populate cache
Browse files Browse the repository at this point in the history
Most of the time _calc_pe will have been called previously
so the cache will exist.  However there are occasions where
this is not done, for example the range weighted phylo
turnover calcs.

That calc has also now been simplified.
  • Loading branch information
shawnlaffan committed Mar 10, 2024
1 parent f04a819 commit 113cd2f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
13 changes: 12 additions & 1 deletion lib/Biodiverse/Indices/Phylogenetic/RefAlias.pm
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,13 @@ sub _calc_pe_lists {
my (%wts, %local_ranges, %results);

foreach my $group (@$element_list_all) {
# this is populated by _calc_pe
# this is populated by _calc_pe under the calc dependency system
my $results_this_gp = $results_cache->{$group};
# but can be called directly so need to handle that and populate the cache
if (!exists $results_this_gp->{PE_WTLIST}) {
$self->_calc_pe(%args);
$results_this_gp = $results_cache->{$group};
}

# Avoid some redundant slicing and dicing when we have only one group
# Pays off when processing large data sets
Expand Down Expand Up @@ -274,7 +279,13 @@ sub _calc_pe_lists_hierarchical {
my (%wts, %local_ranges, %results);

foreach my $group (@$child_names) {
# this is populated by _calc_pe under the calc dependency system
my $results_this_gp = $results_cache->{$group};
# but can be called directly so need to handle that and populate the cache
if (!exists $results_this_gp->{PE_WTLIST}) {
$self->_calc_pe(%args);
$results_this_gp = $results_cache->{$group};
}

# Avoid some redundant slicing and dicing when we have only one group
# Pays off when processing large data sets
Expand Down
14 changes: 4 additions & 10 deletions lib/Biodiverse/Indices/RWTurnover.pm
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,10 @@ sub _calc_pe_lists_per_element_set {
$results[$i]
= $have_cache
? $cache->{$elements[0]}
: { # messy but we need results from both
$self->_calc_pe(
%args,
element_list_all => $args{$list_name},
),
$self->_calc_pe_lists(
%args,
element_list_all => $args{$list_name},
),
};
: $self->_calc_pe_lists(
%args,
element_list_all => $args{$list_name},
);
$cache->{$elements[0]} = $results[$i]
if @elements == 1;
}
Expand Down

0 comments on commit 113cd2f

Please sign in to comment.