Ed & David,

I stumbled across the problem because of this behaviour:

pdl> p max pdl[]

BAD

which does not expand to 0 as would an undef perl scalar.  Here's the
function. The isbad() line was necessary to catch the case where which
returns an empty list.

sub openBox {

        my $filename=shift;

        my $filename2=shift;

        my $time=shift;

        $c_ti = 0;

        $c_loc = 0;

        if ( -f $filename && -f $filename2)  {

                $c_loc = 4;

                $pos=rcols( $filename, [], {LINES=>"1:"})->transpose; #
{ HEADER => "$border{0} $border{1} $border{2} $border{3}"};

                $posSF=rcols( $filename2, [], {LINES=>"1:"})->transpose;
# { HEADER => "$border{0} $border{1} $border{2} $border{3}"};

                do {

                        $c_loc--;

                        $c_ti=sclr max (which ($pos($c_loc)>-1));

                        $c_ti=0 if isbad($c_ti);

                        #say "border $c_loc time $c_ti";

                }

                while ($c_ti <= 0 && $c_loc>0) ;

                #say "Reading from file $filename; Size of box file
",$pos->info;

        } else {

                $pos = zeroes(4,$time)-1;

                $posSF = zeroes(4,$time)-1;

        }

        #say "border (open) $c_loc";

}




On 2/24/2022 5:51 PM, Ed . wrote:
>
> Hi David,
>
>  
>
> Can you show a complete (small) example of using the return value of
> `max` in Boolean context that fails with the current code? I am unable
> to reproduce this, and it ought to work correctly.
>
>  
>
> The change was made in Aug 2021, with version 2.056. Those functions
> were never documented as returning Perl scalars, and I was extremely
> surprised when I discovered it then did so.
>
>  
>
> Best regards,
>
> Ed
>
>  
>
> *From: *David Mertens <mailto:dcmertens.p...@gmail.com>
> *Sent: *24 February 2022 15:53
> *To: *Ingo Schmid <mailto:ingo...@gmx.at>
> *Cc: *pdl-devel <mailto:pdl-devel@lists.sourceforge.net>
> *Subject: *Re: [Pdl-devel] PDL 2.075 released
>
>  
>
> To follow-up on max/min being piddles, this broke some of my tests in
> PDL::Parallel::threads. Specifically croak-in-boolean-context is now
> easily triggered where it used to be safe:
>
>  
>
> if ($data->max < 40) {  # croaks: piddle in boolean context
>
>     ....
>
> }
>
>  
>
> Was this use case considered and discussed? I missed it, though I
> haven't always paid terribly close attention.
>
>  
>
> David
>
>  
>
> On Thu, Feb 24, 2022 at 10:18 AM Ingo Schmid <ingo...@gmx.at> wrote:
>
>     HI Ed,
>
>     here's some feedback to the new release. Thank you for your
>     tireless efforts!
>
>     I experience errors in previously working code, at least in 2.074
>     and 2.075.
>
>     $r and $i are piddles, as are $empty_lines and $vlines. These
>     lines (67
>
>     #!perl
>
>     use PDL;
>     use PDL::NiceSlice;
>
>     use 5.10.0;
>     use strict;
>
>     sub foo {
>             my $r=shift; #piddle
>             my $i=shift; #piddle
>
>             my $empty_lines=(whichND ($r(0,,0,0,0,0,0,0;-)==0));
>             unless ($empty_lines->isempty) {
>                     $empty_lines=$empty_lines(0,;-) if
>     $empty_lines->nelem;
>                     my $vlines=$$p{y}-1-$empty_lines;
>                     $r(,$empty_lines,).=$r(,$vlines,); # syntax error
>                     $i(,$empty_lines,).=-$i(,$vlines,); # syntax error
>             
>             }
>     }       
>
>     syntax error at /home/ingo/perl/test_errors.pl
>     <http://test_errors.pl> line 17, near "$r("
>     syntax error at /home/ingo/perl/test_errors.pl
>     <http://test_errors.pl> line 18, near "$i("
>
>     Could that be a PDL::NiceSlice issue?
>
>      
>
>     Also, max (and probably min) are piddles now, (tested in 2.074),
>     which breaks some code. They used to returen perl scalars.
>
>      
>
>     On 2/19/22 10:22, Ed . wrote:
>
>         Dear PDL folks,
>
>          
>
>         PDL 2.075 has just been released. Notable changes since 2.064:
>
>          
>
>           * threading now called broadcasting (compat aliases created)
>           * fix when readdata functions return error (#356)
>           * RedoDimsCode can now use $SIZE(other_index) (#386)
>           * can now unify Code and BadCode into Code, and use
>             PDL_IF_BAD() or #ifdef PDL_BAD_CODE
>           * add macros
>             PDL_IF_GENTYPE_{REAL,INTEGER,UNSIGNED}(iftrue,iffalse) in Code
>           * fixes to PDL::NiceSlice including performance bug by
>             monkey-patching Text::Balanced::extract_multiple
>           * Minuit and Slatec 64-bit safe
>
>           * bifuncs like Ops::plus no longer need explicit swap parameter
>
>          
>
>         Future plans, in something like intended order:
>
>           * fix more open GitHub issues
>           * make PDL::LinearAlgebra work right with “native complex”
>             (several of the above issues were related to enabling this)
>           * “loop fusion” techniques to maximise locality of
>             computation, minimising data’s trips through the “straw”
>             between CPU and main RAM
>           * finish the independent C interface for making PDL usable
>             from e.g. Python
>           * use OpenCL or other means to also utilise GPUs if available
>
>          
>
>         The IRC channel (#pdl on irc.perl.org <http://irc.perl.org>)
>         is a great virtual place to come and ask questions, or just
>         watch the GitHub messages flow by.
>
>          
>
>         As usual, please give the new PDL a try and report problems.
>
>          
>
>         Best regards,
>
>         Ed
>
>
>
>
>         _______________________________________________
>
>         pdl-devel mailing list
>
>         pdl-devel@lists.sourceforge.net
>
>         https://lists.sourceforge.net/lists/listinfo/pdl-devel
>
>     _______________________________________________
>     pdl-devel mailing list
>     pdl-devel@lists.sourceforge.net
>     https://lists.sourceforge.net/lists/listinfo/pdl-devel
>
>
>
> --
>
>  "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-devel mailing list
pdl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-devel

Reply via email to