On 7/11/23 03:07, Zakariyya Mughal wrote:
On 2023-07-11 at 00:01:32 -0400, Peter Ratzlaff via pdl-devel wrote:
Hello,

I've pasted the code below, since I'm not sure attachments will make it to
the list. I have a program that does something similar to this. Obviously
not as simple, but using the same concept: an inner loop using the index()
function with an argument calculated from the outer loop.

In PDL 2.082 it loops at a consistent speed. But in PDL 2.083, each
successive loop takes longer than the previous, and the real code becomes
unusable, practically speaking.

On my particular machine, with PDL 2.082 the included code runs in 13
seconds, real time. With PDL 2.083, it's 5 minutes.

Any thoughts would be appreciated.

Thanks,
Pete

#! /usr/bin/perl

use strict;
use warnings;

use PDL;

my $n = 700;

my $a = sequence($n)->dummy(0, $n)->flat;
my $b = sequence($n)->dummy(1, $n)->flat;

for my $a_val (0..$n-1) {
   printf "%d / %d\n", $a_val, $n-1;
   my $ind1 = which($a == $a_val);
   for my $b_val (0..$n-1) {
     my $ind2 = which($b->index($ind1) == $b_val);
   }
}

Hello Peter,

Thank you for identifying this.

Ed, I have run a git bisect and found that the first commit that has
this slow down is:

   # first bad commit: [03c3793f36b5739138751dd06f4b2334e0d3c7fe] use ArgOrder 
to simplify Ops overloads

Script:

   git bisect start 2.083 2.082
   git bisect run bash -c 'make -j$(nproc); timeout 20s perl -Mblib ../test.pl 
|| exist 125'

where `test.pl` contains the attached example.

I don't have the tuits to investigate just now, but hopefully that is a
start.

Regards,
- Zaki Mughal


I completely missed the obvious solution (it was late!), which is to take the index() out of the inner loop. Then it runs nice and speedy again.

for my $a_val (0..$n-1) {
  printf "%d / %d\n", $a_val, $n-1;
  my $ind1 = which($a == $a_val);
  my $bslice = $b->index($ind1);
  for my $b_val (0..$n-1) {
    my $ind2 = which($bslice == $b_val);
  }
}


_______________________________________________
pdl-devel mailing list
pdl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-devel

Reply via email to