in reply to perl PDL question

What is happening is that your 2 arrays are being threaded over, however the dimensions don't match. The case that works has a 1 element pdl, which can be threaded over because pdl replicates length 1 dimensions as many times as necessary. Try this:
my $a = sequence(10)->dummy; my $b = pdl(2,5,7); my $z = which(sumover($a == $b));
This inserts a dummy dimension into $a so that $a is dimensionality (10,1) and $b is dimensionality (1,3). Dimensions of length 1 get threaded over nicely. The sumover is there to take away 1 of the dimensions (otherwise you get location in $a times location in $b) for matches

Replies are listed 'Best First'.
Re^2: perl PDL question
by Anonymous Monk on Nov 27, 2007 at 11:34 UTC
    Replace sumover with any. It is more appropriate for the context.
      The sumover part works, and produces the output array that is the appropriate indexes... brilliant!
      When I replace sumover($a==$b) with any($a==$b) I get an error though....
      perldl> $z = which(any($a == $b)); Can't call method "flat" without a package or object reference at /usr +/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/PDL/Primitive. +pm line 1962, <STDIN> line 20.
Re^2: perl PDL question
by nickschurch (Acolyte) on Nov 28, 2007 at 02:39 UTC
    Interestingly, this works fine from the perldl console, but in a scrip I get an error....
    my $time = rcols "testdata.txt"; my $tsearch = $time -> dummy; print $tsearch,"\n";
    produces:
    [njs@localhost]$ ./testcode Use of uninitialized value in numeric lt (<) at /usr/lib64/perl5/site_ +perl/5.8.8/x86_64-linux-thread-multi/PDL/Core.pm line 936. Use of uninitialized value in numeric lt (<) at /usr/lib64/perl5/site_ +perl/5.8.8/x86_64-linux-thread-multi/PDL/Core.pm line 939. Use of uninitialized value in numeric gt (>) at /usr/lib64/perl5/site_ +perl/5.8.8/x86_64-linux-thread-multi/PDL/Core.pm line 942. Use of uninitialized value in repeat (x) at /usr/lib64/perl5/site_perl +/5.8.8/x86_64-linux-thread-multi/PDL/Core.pm line 942. Use of uninitialized value in subtraction (-) at /usr/lib64/perl5/site +_perl/5.8.8/x86_64-linux-thread-multi/PDL/Core.pm line 943. [ [ 50093.199] [ 50094.308] [ 50954.953] [ 51767.383] [ 51958.219] [ 52005.696] [ 52005.763] [ 52142.188] [ 52422.043] [ 52459.414] [ 52482.509] [ 52693.953] [ 52752.918] [ 52836.803] [ 52837.198] [ 53107.974] [ 53125.429] [ 53141.53] [ 53198.495] [ 53243.578] [ 53489.381] [ 53603.709] [ 53661.37] [ 53724.982] [ 53724.983] [ 53864.724] [ 53882.002] [ 53969.248] [ 54224.674] [ 54225.636] [ 54304.474] [ 54304.539] [ 54366.513] ]
    Clearly the dummy is being inserted, so I'm a bit confused as to the uninitiated value errors??
      dummy takes 2 mandatory arguments:
      1. the pdl
      2. the dimension number that will be the dummy dimension
      Somehow, the dimension is defaulting to 0.
      This error should go away if you use
      $tsearch = $time->dummy(0);
      which has the same effect and is more explicit
        Brilliant! Anonymous++