Skip to content

Commit

Permalink
rand_curveball: no need to sort the shorter swap list
Browse files Browse the repository at this point in the history
These labels will all be swapped anyway so
there is no need to subset the list.

A late update to #822 after the main PR.
  • Loading branch information
shawnlaffan committed Feb 12, 2024
1 parent a7683f4 commit 2388630
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/Biodiverse/Randomise/CurveBall.pm
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,19 @@ END_PROGRESS_TEXT
# skip if nothing can be swapped
next MAIN_ITER if !$n_labels_to_swap;

# is sort in-place optimised?
@swappable_from1 = sort @swappable_from1;
@swappable_from2 = sort @swappable_from2;

# in-place shuffle is apparently fastest (MRMA docs)
$rand->shuffle (\@swappable_from1);
$rand->shuffle (\@swappable_from2);

# curtail longer array
# Get a random subset of the longer array.
# Sort is needed to guarantee repeatability, and in-place sort is optimised by Perl.
# In-place shuffle is apparently fastest (MRMA docs)
if (@swappable_from1 > $n_labels_to_swap) {
@swappable_from1 = sort @swappable_from1;
$rand->shuffle (\@swappable_from1);
@swappable_from1 = @swappable_from1[0..$n_labels_to_swap-1];
}
elsif (@swappable_from2 > $n_labels_to_swap) {
@swappable_from2 = sort @swappable_from2;
$rand->shuffle (\@swappable_from2);
@swappable_from2 = @swappable_from2[0..$n_labels_to_swap-1];
}

Expand Down

0 comments on commit 2388630

Please sign in to comment.