PDLPorters / pdl-linearalgebra

https://p3rl.org/PDL::LinearAlgebra
1 stars 7 forks source link

mpinv isn't broadcasting #20

Open KJ7LNW opened 2 years ago

KJ7LNW commented 2 years ago

I could be wrong here, but I sort of think that mpinv() should function about the same as minv() --- but broadcasting fails for mpinv():

minv() broadcasts the inverse:

pdl> $p = sequence(2,2,5)
pdl> p $p->minv
[
 [
  [-1.5  0.5]
  [   1    0]
 ]
 [
  [      -3.5        2.5]
  [         3         -2]
 ]
 [
  [      -5.5        4.5]
  [         5         -4]
 ]
...
]

whereas mpinv() blows up when trying the pseudo-inverse:

pdl> p $p->mpinv
PDL: PDL::Ops::gt(a,b,c): Parameter 'b':
  Mismatched implicit broadcast dimension 0: size 2 vs. 5
There are 3 PDLs in the expression; 2 broadcast dims.
   PDL IN EXPR.    BROADCAST DIMS
   #  0 (normal):        2       5
   #  1 (normal):        5
   #  2 (null)

.. at ops.pd line 136.
    PDL::Ops::__ANON__(PDL=SCALAR(0x564b231f17a0), PDL=SCALAR(0x564b23290390), "") called at /usr/local/lib64/perl5/PDL/LinearAlgebra.pm line 926
    PDL::mpinv(PDL=SCALAR(0x564b232406c8)) called at (eval 65) line 4
    main::__ANON__() called at /usr/local/bin/perldl line 682
    eval {...} called at /usr/local/bin/perldl line 682
    main::eval_and_report("p \$p->mpinv\x{a}") called at /usr/local/bin/perldl line 618
    main::process_input() called at /usr/local/bin/perldl line 638
    eval {...} called at /usr/local/bin/perldl line 638
mohawk2 commented 2 years ago

As noted on IRC:

the starting-point would be to enhance runtest so that the 1st ndarray param routinely also got tested in both real and complex mode, having had a dummy-dim added at the top with value 2. that would shake out all the non-broadcast-capable functions at once [...] fixing things to work for broadcasting is quite a fun exercise to force oneself to think n-dimensionally