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

$gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

In reply to PDL range on 4-d piddles by jo37

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.