Dear monks and nuns,
when playing with PDL's range function I stumbled across a problem. While for dimensions up to 3 everything looks good, at d=4 something seems to be seriously broken. There is some memory corruption causing a segfault.
Looking at d=3 everything looks as expected:
my $p = zeroes(4,4,4); say 'p: ', $p->info; say 'ndcoords: ', ndcoords($p)->info; say 'range: ', $p->range(ndcoords($p), 2, 't')->info;
produces:
p: PDL: Double D [4,4,4] ndcoords: PDL: Double D [3,4,4,4] range: PDL: Double D [4,4,4,2,2,2]
The first dimensions of range correspond to the second to last dimensions of the index piddle, i.e. [4,4,4]. The following dimensions correspond to the shape of the selected slices, i.e. [2,2,2].
With d=4 things become weird.
my $q = zeroes(5,5,5,5); say 'q: ', $q->info; say 'ndcoords: ', ndcoords($q)->info; say 'range: ', $q->range(ndcoords($q), 2, 't')->info;
produces:
q: PDL: Double D [5,5,5,5] ndcoords: PDL: Double D [4,5,5,5,5] range: PDL: Double D [5,5,5,5,2,2,1,5]
Here we have - as expected - the second to last dimensions of the index piddle coming first. But then, instead of the expected [2,2,2,2] remainder, there comes [2,2,1,5]. Memory is corrupted afterwards, as it appears here on my Debian 11. So here is the full example script:
#!/usr/bin/perl use v5.24; use warnings; use PDL; my $p = zeroes(4,4,4); say 'p: ', $p->info; say 'ndcoords: ', ndcoords($p)->info; say 'range: ', $p->range(ndcoords($p), 2, 't')->info; say ones(4); my $q = zeroes(5,5,5,5); say 'q: ', $q->info; say 'ndcoords: ', ndcoords($q)->info; say 'range: ', $q->range(ndcoords($q), 2, 't')->info; say ones(5); __DATA__ p: PDL: Double D [4,4,4] ndcoords: PDL: Double D [3,4,4,4] range: PDL: Double D [4,4,4,2,2,2] [1 1 1 1] q: PDL: Double D [5,5,5,5] ndcoords: PDL: Double D [4,5,5,5,5] range: PDL: Double D [5,5,5,5,2,2,1,5] Segmentation fault
Can anybody reproduce this behaviour? If so, I'd report a bug.
Greetings,
-jo
In reply to PDL range on 4-d piddles by jo37
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |