Discussion:
[Pdl-porters] BAD values and minmax()
Zakariyya Mughal
2014-11-29 07:38:38 UTC
Permalink
Hi,

I was looking at the `minmax` function and I noticed that it does not
treat BAD values the same way as the `min` and `max` functions.

Code to reproduce below:

use Test::More tests => 3; use strict; use warnings; use PDL;

my $bad_0dim = pdl(q|BAD|);

is( $bad_0dim->min, 'BAD' );
is( ($bad_0dim->minmax)[0], $bad_0dim->min );
is( ($bad_0dim->minmaximum)[0], $bad_0dim->min );

which gives the following output:

1..3
ok 1
not ok 2
# Failed test at - line 6.
# got: '-1.79769313486232e+308'
# expected: 'BAD'
ok 3
# Looks like you failed 1 test of 3.

Is this intentional? The docs do not mention BAD values at all and say
(pdldoc minmax):

The two values are returned as Perl scalars similar to min/max.

Is there a way to make this follow POLA more?

Regards,
- Zaki Mughal
David Mertens
2014-11-29 14:17:35 UTC
Permalink
Hey Zaki,

I believe this is a bug. Looking at ufunc.pd, it appears that min and max
simply invoke minimum and maximum and access $data->at(), whereas minmax
uses $data->sclr. So, this appears to be a bug in sclr. To see that this is
an issue, here is a simple perldl shell example:

pdl> $a = pdl q[bad]

pdl> p $a
BAD

pdl> p $a->at
BAD

pdl> p $a->sclr
-1.79769313486232e+308


We can band-aid this problem by changing minmax to use ->at instead of
->sclr, but I think we really ought to fix the behavior of ->sclr.

David
Post by Zakariyya Mughal
Hi,
I was looking at the `minmax` function and I noticed that it does not
treat BAD values the same way as the `min` and `max` functions.
use Test::More tests => 3; use strict; use warnings; use PDL;
my $bad_0dim = pdl(q|BAD|);
is( $bad_0dim->min, 'BAD' );
is( ($bad_0dim->minmax)[0], $bad_0dim->min );
is( ($bad_0dim->minmaximum)[0], $bad_0dim->min );
1..3
ok 1
not ok 2
# Failed test at - line 6.
# got: '-1.79769313486232e+308'
# expected: 'BAD'
ok 3
# Looks like you failed 1 test of 3.
Is this intentional? The docs do not mention BAD values at all and say
The two values are returned as Perl scalars similar to min/max.
Is there a way to make this follow POLA more?
Regards,
- Zaki Mughal
_______________________________________________
PDL-porters mailing list
http://mailman.jach.hawaii.edu/mailman/listinfo/pdl-porters
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." -- Brian Kernighan
Ed .
2014-11-29 15:25:29 UTC
Permalink
Zaki,

(David – sorry for double send to you)

Nice find! You should PR a test with David’s code so that if a dev or other release ever happens, the CPAN tester reports will ensure –>sclr is fixed.

Ed

From: David Mertens
Sent: Saturday, November 29, 2014 2:17 PM
To: Zakariyya Mughal ; pdl-porters
Subject: Re: [Pdl-porters] BAD values and minmax()

Hey Zaki,

I believe this is a bug. Looking at ufunc.pd, it appears that min and max simply invoke minimum and maximum and access $data->at(), whereas minmax uses $data->sclr. So, this appears to be a bug in sclr. To see that this is an issue, here is a simple perldl shell example:


pdl> $a = pdl q[bad]

pdl> p $a
BAD

pdl> p $a->at
BAD

pdl> p $a->sclr
-1.79769313486232e+308



We can band-aid this problem by changing minmax to use ->at instead of ->sclr, but I think we really ought to fix the behavior of ->sclr.


David


On Sat, Nov 29, 2014 at 2:38 AM, Zakariyya Mughal <***@gmail.com> wrote:

Hi,

I was looking at the `minmax` function and I noticed that it does not
treat BAD values the same way as the `min` and `max` functions.

Code to reproduce below:

use Test::More tests => 3; use strict; use warnings; use PDL;

my $bad_0dim = pdl(q|BAD|);

is( $bad_0dim->min, 'BAD' );
is( ($bad_0dim->minmax)[0], $bad_0dim->min );
is( ($bad_0dim->minmaximum)[0], $bad_0dim->min );

which gives the following output:

1..3
ok 1
not ok 2
# Failed test at - line 6.
# got: '-1.79769313486232e+308'
# expected: 'BAD'
ok 3
# Looks like you failed 1 test of 3.

Is this intentional? The docs do not mention BAD values at all and say
(pdldoc minmax):

The two values are returned as Perl scalars similar to min/max.

Is there a way to make this follow POLA more?

Regards,
- Zaki Mughal

_______________________________________________
PDL-porters mailing list
PDL-***@jach.hawaii.edu
http://mailman.jach.hawaii.edu/mailman/listinfo/pdl-porters
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." -- Brian Kernighan



--------------------------------------------------------------------------------
Zakariyya Mughal
2014-11-29 19:03:25 UTC
Permalink
Zaki,
(David – sorry for double send to you)
Nice find! You should PR a test with David’s code so that if a dev or other release ever happens, the CPAN tester reports will ensure –>sclr is fixed.
All right, done!

<https://sourceforge.net/p/pdl/code/merge-requests/9/>
<https://sourceforge.net/p/pdl/code/merge-requests/10/>

Cheers,
- Zaki Mughal

P.S., my project to embed R in Perl is coming along nicely. All the
major R data types are converted (with the big exceptions being complex
numbers, closures, expressions, and formulas). But I'm really happy that
automatically calling a function and handling the shuffling of data to
and fro works: <https://github.com/zmughal/embedding-r-in-perl-experiment/blob/master/t/function_call_autoload.t>!
Ed
From: David Mertens
Sent: Saturday, November 29, 2014 2:17 PM
To: Zakariyya Mughal ; pdl-porters
Subject: Re: [Pdl-porters] BAD values and minmax()
Hey Zaki,
pdl> $a = pdl q[bad]
pdl> p $a
BAD
pdl> p $a->at
BAD
pdl> p $a->sclr
-1.79769313486232e+308
We can band-aid this problem by changing minmax to use ->at instead of ->sclr, but I think we really ought to fix the behavior of ->sclr.
David
Hi,
I was looking at the `minmax` function and I noticed that it does not
treat BAD values the same way as the `min` and `max` functions.
use Test::More tests => 3; use strict; use warnings; use PDL;
my $bad_0dim = pdl(q|BAD|);
is( $bad_0dim->min, 'BAD' );
is( ($bad_0dim->minmax)[0], $bad_0dim->min );
is( ($bad_0dim->minmaximum)[0], $bad_0dim->min );
1..3
ok 1
not ok 2
# Failed test at - line 6.
# got: '-1.79769313486232e+308'
# expected: 'BAD'
ok 3
# Looks like you failed 1 test of 3.
Is this intentional? The docs do not mention BAD values at all and say
The two values are returned as Perl scalars similar to min/max.
Is there a way to make this follow POLA more?
Regards,
- Zaki Mughal
_______________________________________________
PDL-porters mailing list
http://mailman.jach.hawaii.edu/mailman/listinfo/pdl-porters
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." -- Brian Kernighan
--------------------------------------------------------------------------------
_______________________________________________
PDL-porters mailing list
http://mailman.jach.hawaii.edu/mailman/listinfo/pdl-porters
Loading...