From c1a3f9d5be5a4168be4a4c39a5ed31002c7b3e82 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Sun, 25 Feb 2024 20:02:05 +1100 Subject: [PATCH] Indices: micro-optimise the aed calcs --- lib/Biodiverse/Indices/Phylogenetic.pm | 36 ++++++++++++-------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/Biodiverse/Indices/Phylogenetic.pm b/lib/Biodiverse/Indices/Phylogenetic.pm index 2a5551e35..94b0d4050 100644 --- a/lib/Biodiverse/Indices/Phylogenetic.pm +++ b/lib/Biodiverse/Indices/Phylogenetic.pm @@ -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 = ( @@ -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 = ( @@ -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; }