AlgebraicJulia / GraphicalLinearAlgebra.jl

Theories of linear algebra and graphical linear algebra
MIT License
7 stars 1 forks source link

fix tests #5

Open kris-brown opened 2 years ago

kris-brown commented 2 years ago

For no discernible reason, when the GLA module from Catlab.jl was moved to this repo, an error was introduced into the test suite. The cause should be tracked down and fixed.

GLA: Test Failed at /Users/ksb/code/GraphicalLinearAlgebra/test/linear_algebra/GLA.jl:141
  Expression: (f ⊕ g) * [x; y] == [f * x; g * y]
   Evaluated: [0, 0, 28, 73, 118] == [1, 2, 28, 73, 118]
kris-brown commented 1 year ago

I've looked more into this by adding a print statement: something odd is happening in oplus

  oplus(f::LinearOperator, g::LinearOperator) = begin
    dom_total   = size(f,2) + size(g,2)
    codom_total = size(f,1) + size(g,1)
    dom_f   = 1:size(f,2)
    codom_f = 1:size(f,1)
    dom_g   = (size(f,2)+1):dom_total
    codom_g = (size(f,1)+1):codom_total
    fOp = opExtension(codom_f, codom_total)*f*opRestriction(dom_f,dom_total)
    gOp = opExtension(codom_g, codom_total)*g*opRestriction(dom_g,dom_total)
    println("fOp $(Matrix(fOp)) \ngOp $(Matrix(gOp)) ")
    println("\nfOp+gOp $(Matrix(fOp + gOp)) \ngOp+fOp $(Matrix(gOp + fOp))")
    fOp + gOp
  end

Extending f and g to be the right shape seems to be working correctly, but when the two LinearOperators are added something bizarre seems to happen:

fOp [0 1 0 0 0; 1 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0] 
gOp [0 0 0 0 0; 0 0 0 0 0; 0 0 1 2 3; 0 0 4 5 6; 0 0 7 8 9] 
fOp+gOp [0 0 0 0 0; 0 0 0 0 0; 0 0 1 2 3; 0 0 4 5 6; 0 0 7 8 9] 
gOp+fOp [0 1 0 0 0; 1 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0]

So + on LinearOperators doesn't seem to have the expected behavior when opExtension is involved. (it seems to have normal behavior otherwise)