#332 "isn't numeric in null operation" warning could be more helpful

Ed Avis

Sometimes programs using PDL give warnings like

Argument "x" isn't numeric in null operation at x line 7

This is a bit of a perplexing warning, because when you look at the program code on that line it might be a simple 'eq' comparison against what looks like an array element. For example,

use 5.016;
use warnings;
use strict;
use PDL;
my @s = pdl();
say scalar @s;
if ($s[0] eq 'x') {}

Here it is obvious that @s is a piddle but it might not be so obvious as part of a larger program where it looks like an ordinary array variable. The 'eq' test is string equality, so there is no clear reason why perl is trying to convert its RHS 'x' into a number. Also the 'null operation' sounds odd.

It would be better for this to give a more understandable warning, e.g. "PDL element cannot be compared to non-numeric value 'x'".


  • Derek Lamb
    Derek Lamb

    There are a few issues here.

    1) In Perl, objects (of which a piddle is one type) are indicated by the sigil $, not @. So the line should be "my $s = pdl();" Thus the line with scalar() and $s[0] don't really make sense when you are trying to make a piddle. Your line of @s=pdl() constructed a piddle with one element (0), and put the piddle in the first element of the list @s. So if you would do in the shell "help $s[0]" you would see that that is the piddle, not @s.

    2) PDL has an operation 'eq', which computes the binary equal to of two piddles, and is overloaded by the == call. So you can say $c = eq($a,$b,0); or $c = $a==$b; Do "?eq" from the pdl shell or "pdldoc eq" from the command line to see the documentation. I don't think that PDL's eq got called in your script, I'm just drawing your attention to that.

    3) The error "Argument %s isn't numeric" comes from Perl itself, not PDL, so there's not much we could do about it. That being said, I'm not exactly sure why you did got the error you did.

  • Chris Marshall
    Chris Marshall

    I think the problem is exactly that PDL's PDL::eq() is being called
    instead of the intrinsic eq. Maybe the bug is that PDL::eq() is
    being exported. Also, the name is confusing since what is the PDL
    operator for 'eq' ?


    Last edit: Chris Marshall 2013-06-14
  • Ed Avis
    Ed Avis

    OK, so the test case can be reduced to

    my $r = (pdl() eq 'x');

    I still think that the error message about a 'null operation' is confusing.
    If PDL's eq is being called it should give a better warning about not being able to compare a piddle against a string.

  • I have created a patch at https://github.com/PDLPorters/pdl/pull/63 on the pdl-eq-with-string-warning branch.

    The current Travis-CI tests aren't passing because the master branch build is broken.

  • Chris Marshall
    Chris Marshall

    • status: open --> closed-fixed
    • assigned_to: Zakariyya Mughal