Hi, Maggie,
To get your 5x2 matrix you want the threading engine to work across
both input parameters' thread dimensions (the extras after the active
dimension of the operator is lopped off the left side of the dimension
list). To do that you have to put the (5) and the (2) in different
positions in the dim list.
The "inner" operator has one active dim, so in this case you are
taking the inner product of 5-vectors. Inner is failing because it is
trying to thread across the other dimensions in your vectors, and they
don't match one another. One of the inputs to "inner" has a thread
dimensionality of (5) and the other has a thread dimensionality of
(2), which doesn't match (5). Instead you should be operating on one
variable of dimension (5,5,1) and another of (5,1,2).
You can use dummy() to control the threading by padding the dimension
list of one or more arguments. Then PDL will thread across both of
the thread dimensions rather than trying to match the size of a single
thread dimension across both arguments to inner().
perldl> $a = random 10,5;
perldl> $b = sequence 10,2;
perldl> $b0 = $b->dummy(1,1);
perldl> $c = $a->inner($b0);
perldl> help $c
This variable is Double D[5,2] P 0.08Kb
This time, inner's arguments have dimensionalities of (5,5) and
(5,1,2) respectively. The active dims match (they have size 5), and
the thread dims can be promoted to match: $a's (5) gets automatically
promoted to (5,1), so that it has the same dimensionality as $b0's
(1,2). The threading engine sees thread sizes of (5,1) and (1,2) and
can match them, so you get a (5,2) output.
Er, that is more long-winded than perhaps you wanted, but perhaps it
helps...
On Apr 20, 2009, at 9:00 AM, Maggie J. Xiong wrote:
> Hi,
>
> I'm learning to work with PP (yeah!). I have a correlation function
> that has a signature like "inner" Signature: (a(n); b(n); [o]c()).
> Both my function and "inner" threads correctly if one of the pdl is
> 1D (or with empty extra dim), but fails (as per my intention) when
> both pdls are 2D. For instance here, my intent is to get back a 5 x
> 2 matix, but
>
> perldl> $a = random 10, 5
>
> perldl> $b = sequence 10, 2
>
> perldl> p $a->inner($b)
> PDL: PDL::Primitive::inner(a,b,c): Parameter 'b'
> PDL: Mismatched implicit thread dimension 0: should be 5, is 2
>
> Caught at file (eval 97), line 4, pkg main
>
> perldl> p $a->inner($b( ,0))
> [ 27.700621 22.191472 19.461998 27.395397 27.038342]
>
>
> Is there an easy way to make it thread thru the 1st pdl, then thread
> thru the 2nd pdl?
>
>
> Thanks,
> Maggie
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl