vr has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [maybe OT] What kind of bug was that? Non-deterministic result with C integer overflow?
by Anonymous Monk on Dec 17, 2017 at 15:19 UTC | |
|
Re: [maybe OT] What kind of bug was that? Non-deterministic result with C integer overflow?
by Laurent_R (Canon) on Dec 18, 2017 at 00:04 UTC | |
|
Re: [maybe OT] What kind of bug was that? Non-deterministic result with C integer overflow?
by Anonymous Monk on Dec 18, 2017 at 13:51 UTC | |
by vr (Curate) on Dec 18, 2017 at 16:46 UTC | |
by Anonymous Monk on Dec 18, 2017 at 16:23 UTC |