Thanks for the simple example.  That helps a lot.

The actual problem is that piddles with the badflags set always evaluate to BAD 
when element-wise logical operations are performed on them.

"print $s<0" prints BAD instead of 0 or 1.  "print $x>0" also prints [BAD BAD 
BAD BAD].

$m and $s have their badflags set (as they should, since they were made from 
partially-bad data).  You can check if they can be safely cleared, and clear 
them if so, with $s->check_badflag, etc.  Since $m and $s are 1-element 
piddles, you can also just set them directly to their scalar values, for 
example 

map{$_=$_->sclr} ($m,$s)=stats($x); #if you know they are only going to be 1 
element piddles
OR
map{$_=$_->((0))} ($m,$s)=stats($x); #if you just want the first value

The fact that $m and $s are 1-element piddles is likely what is causing your 
problem.  My guess is that this behavior has changed (perhaps intentionally, 
perhaps not) between your old version and more recent versions, and if you were 
getting $m and $s as simple perl scalars before you would not have seen this 
problem.  I can verify that stats() has returned 1-piddles and not perl scalars 
at least as far back as PDL-2.4.11.

cheers,
Derek

> On Jun 16, 2015, at 6:29 AM, Marek Gierliński <[email protected]> 
> wrote:
> 
> Oops, sorry, I missed a line when copying the text. Here is the code again.
> 
> use PDL;
> use PDL::NiceSlice;
> 
> 
> my $x = pdl(1, 2, 3, 0);
> $x->badflag(1);
> $x->badvalue(0);
> 
> print "x = $x\n";
> 
> my ($m, $s) = stats($x);
> 
> print "m = $m, s = $s\n";
> print "s greater than zero\n" if $s > 0;
> print "s less than zero\n" if $s < 0;
> print "s equals zero\n" if $s == 0;
> 
> 
> On Tue, 16 Jun 2015 at 12:20 Chris Marshall <[email protected] 
> <mailto:[email protected]>> wrote:
> Hi Marek-
> 
> Do you have a complete example showing the problem?
> You don't show where $m and $s are being set below.
> 
> Thanks,
> Chris
> 
> 
> On 6/16/2015 07:04, Marek Gierliński wrote:
>> I have recently encountered a weird problem with stats (or statsover) using 
>> bad values. The resulting numbers have a strange property, they always 
>> return true in comparisons. This code:
>> 
>> use PDL;
>> use PDL::NiceSlice;
>> 
>> my $x = pdl(1, 2, 3, 0);
>> $x->badflag(1); $x->badvalue(0);
>> 
>> print "m = $m, s = $s\n";
>> print "s greater than zero\n" if $s > 0;
>> print "s less than zero\n" if $s < 0;
>> print "s equals zero\n" if $s == 0;
>> 
>> returns the following output:
>> 
>> x = [1 2 3 BAD]
>> m = 2, s = 1
>> s greater than zero
>> s less than zero
>> s equals zero
>> 
>> which doesn't make any sense. Can anyone explain this? I always assumed that 
>> 'stats' returned ordinary Perl scalars, but this must be something different.
>> 
>> I'm using PDL version 2.007. We had an older version installed for a long 
>> time and I think this problem appeared when we upgraded to 2.007.
>> 
>> Marek
>> 
>> 
> 
>> ------------------------------------------------------------------------------
>> 
>> 
>> _______________________________________________
>> pdl-general mailing list
>> [email protected] <mailto:[email protected]>
>> https://lists.sourceforge.net/lists/listinfo/pdl-general 
>> <https://lists.sourceforge.net/lists/listinfo/pdl-general>
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> pdl-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pdl-general

------------------------------------------------------------------------------
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to