use strict; use warnings; use feature 'say'; use PDL; use PDL::Image2D; use PDL::IO::Image; # sample: http://image.ibb.co/i6Qj76/test171217.png my $fn = 'test171217.png'; my $pdl = PDL::IO::Image-> new_from_file( $fn )-> pixels_to_pdl-> shor +t; say $pdl-> info; my $segmented = cc8compt( $pdl ); say $segmented-> info; say $segmented-> max;

Function cc8compt in PDL 2.015, that shipped with Strawberry 5.24.0, returns piddle of same data format as its argument, i.e. e.g. short for short. Later versions appear to always return long, and therefore the described bug can not be observed.

Running the script several times, I'm getting something like this:

D:\>perl 171217.pl PDL: Short D [1200,3950] PDL: Short D [1200,3950] 32756 D:\>perl 171217.pl PDL: Short D [1200,3950] PDL: Short D [1200,3950] 32764 D:\>perl 171217.pl PDL: Short D [1200,3950] PDL: Short D [1200,3950] 32736 D:\>perl 171217.pl PDL: Short D [1200,3950] PDL: Short D [1200,3950] 32756 D:\>perl 171217.pl PDL: Short D [1200,3950] PDL: Short D [1200,3950] 32760

The result is unpredictable, and I'm puzzled why -- even if Google says that signed integer overflow is "undefined behaviour", but shouldn't result be deterministic, at least? If I'm wrong, what exactly is happenning, during program execution? And BTW, changing short to long, in code, leads to correct (?) maximum count of 28299, value below maximum positive short, so it's unclear why any problems happen at all (I'm not brave enough to look into PDL source).

I also was trying to use simple sample pdl, e.g. a kind of checker-board, but with that, no problem like described above.


In reply to [maybe OT] What kind of bug was that? Non-deterministic result with C integer overflow? by vr

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.