Skip to content

Commit

Permalink
Indices: micro-optimise the aed calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnlaffan committed Feb 25, 2024
1 parent 71ef863 commit c1a3f9d
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions lib/Biodiverse/Indices/Phylogenetic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2918,22 +2918,18 @@ sub _calc_phylo_aed_t {
my $self = shift;
my %args = @_;

my $aed_hash = $args{PHYLO_AED_LIST};
my $label_hash = $args{label_hash_all};
\my %aed_hash = $args{PHYLO_AED_LIST};
\my %label_hash = $args{label_hash_all};
my $aed_t;
my %scores;

LABEL:
foreach my $label (keys %$label_hash) {
my $abundance = $label_hash->{$label};

next LABEL if !exists $aed_hash->{$label};

my $aed_score = $aed_hash->{$label};
my $weight = $abundance * $aed_score;
foreach my $label (keys %label_hash) {
next LABEL if !exists $aed_hash{$label};

my $weight = $label_hash{$label} * $aed_hash{$label};
$scores{$label} = $weight;
$aed_t += $weight;
$aed_t += $weight;
}

my %results = (
Expand Down Expand Up @@ -2986,20 +2982,20 @@ sub calc_phylo_aed {
my $self = shift;
my %args = @_;

my $label_hash = $args{label_hash_all};
my $es_wts = $args{ES_SCORES};
my $ed_wts = $args{ED_SCORES};
my $aed_wts = $args{AED_SCORES};
\my %label_hash = $args{label_hash_all};
\my %es_wts = $args{ES_SCORES};
\my %ed_wts = $args{ED_SCORES};
\my %aed_wts = $args{AED_SCORES};

my (%es, %ed, %aed);
# now loop over the terminals and extract the weights (would slices be faster?)
# Do we want the proportional values? Divide by PD to get them.
LABEL:
foreach my $label (keys %$label_hash) {
next LABEL if !exists $aed_wts->{$label};
$aed{$label} = $aed_wts->{$label};
$ed{$label} = $ed_wts->{$label};
$es{$label} = $es_wts->{$label};
foreach my $label (keys %label_hash) {
next LABEL if !exists $aed_wts{$label};
$aed{$label} = $aed_wts{$label};
$ed{$label} = $ed_wts{$label};
$es{$label} = $es_wts{$label};
}

my %results = (
Expand Down Expand Up @@ -3055,7 +3051,7 @@ sub get_aed_scores {
my $node_ref = eval {
$tree->get_node_ref (node => $label);
};
if (my $e = $EVAL_ERROR) { # still needed?
if (my $e = $EVAL_ERROR) { # still needed?
next LABEL if Biodiverse::Tree::NotExistsNode->caught;
croak $e;
}
Expand Down

0 comments on commit c1a3f9d

Please sign in to comment.