Menu

#327 topdl ignores list elements after the first

critical
closed-fixed
nobody
core (120)
5
2013-03-22
2013-03-15
Diab Jerius
No

PDL 2.4.11, Perl 15.12.2

The docs for PDL::Core::topdl indicate it can take an array:

$a = topdl(SCALAR|ARRAY REFERENCE|ARRAY);

Passing it an array is broken.

pdl> p topdl (1, 2, 3, 4 )
1

Looks like topdl is ignoring any argument but the first.

Using the Source,

sub PDL::topdl {
return $_[1] if blessed($_[1]); # Fall through
return $_[0]->new($_[1]) if ref(\$_[1]) eq 'SCALAR' or
ref($_[1]) eq 'ARRAY';
barf("Can not convert a ".ref($_[1])." to a ".$_[0]);
0;}

Sure enough. The topdl tests don't test this case, either.

I scanned the PDL code to see if this affected the code, and found this one instance:

Lib/Transform/Cartography/Cartography.pm:1769: $p->{c} = topdl(-75,75);

Unfortunately my git fu is much weaker than my mercurial fu (especially at this time of night), so I regret I can go no further with this.

Discussion

  • Diab Jerius

    Diab Jerius - 2013-03-15

    I should note that this bug is more evil than it looks, as when passed a list it will silently create a 1D piddle which will just as silently get upgraded as appropriate (via PDL's wonderful threadedness) to higher dimensions and will generate incorrect results. Silently. TGFTPD (or, thank goodness for the Perl debugger).

     
  • Craig DeForest

    Craig DeForest - 2013-03-22

    Thanks, Diab. I fixed PDL::topdl and also the line in Cartography.pm (belt and suspenders). I guess a more complete test suite for Cartography is in order...

     
  • Craig DeForest

    Craig DeForest - 2013-03-22
    • status: open --> closed-fixed
     

Log in to post a comment.