JuliaSparse / SuiteSparseGraphBLAS.jl

Sparse, General Linear Algebra for Graphs!
MIT License
102 stars 17 forks source link

Broken tests for some sparse operations #51

Closed rayegun closed 3 years ago

rayegun commented 3 years ago

These tests on master: https://github.com/JuliaSparse/SuiteSparseGraphBLAS.jl/blob/b18d1acada52c0885ff198be5c1492e701b55075/test/chainrules/selectrules.jl#L32-L35

are broken. I can't tell if the rules are wrong or not, though. The error is deep within ChainRulesTestUtils/FiniteDifferences. @mzgubic any ideas? These are the rules: https://github.com/JuliaSparse/SuiteSparseGraphBLAS.jl/blob/master/src/chainrules/selectrules.jl

and they past all the other tests, until I add the thunk argument to the select ops (not the same as thunk from ChainRules, it's just a scalar). Manually verifying I don't see any problems.

select is effectively just a filter. select(offdiag, A) results in a matrix, with the same dimensions as A, but with only offdiagonal entries. select(triu, A) results in a matrix, once again with the same dimensions as A, but with only upper triangular entries. Select operators can compare off of position and value.

rayegun commented 3 years ago

On master to reproduce the select issue:

julia> using SuiteSparseGraphBLAS
[ Info: Precompiling SuiteSparseGraphBLAS [c2e53296-7b14-11e9-1210-bddfa8111e1d]

julia> using ChainRulesTestUtils

julia> X = GBMatrix(sprand(50, 50, 0.15))
50x50 GraphBLAS double matrix, sparse by col
  355 entries, memory: 6.2 KB

    (10,1)    0.782534
    (16,1)    0.654211
    (27,1)    0.860879
    (30,1)    0.651362
    (33,1)    0.163511
    (50,1)    0.0795375
    (2,2)    0.885013
    (9,2)    0.627248
    (15,2)    0.212118
    (25,2)    0.426957
    (26,2)    0.0830815
    (35,2)    0.181953
    (14,3)    0.904474
    (19,3)    0.183669
    (22,3)    0.198684
    (29,3)    0.368111
    (31,3)    0.322366
    (32,3)    0.615471
    (33,3)    0.4521
    (35,3)    0.523002
    (39,3)    0.0448496
    (42,3)    0.960813
    (45,3)    0.396205
    (4,4)    0.246083
    (22,4)    0.711053
    (23,4)    0.722867
    (25,4)    0.886616
    (28,4)    0.716874
    (29,4)    0.564928
    ...

julia> test_frule(select, >, X, 0.)
test_frule: select on typeof(>),GBMatrix{Float64},Float64: Error During Test at /home/will/.julia/packages/ChainRulesTestUtils/AX7fv/src/testers.jl:122
  Got exception outside of a @test
  DimensionMismatch("dimensions must match: a has dims (Base.OneTo(354),), b has dims (Base.OneTo(355),), mismatch at 1")
  Stacktrace:
    [1] promote_shape
      @ ./indices.jl:178 [inlined]
    [2] promote_shape
      @ ./indices.jl:169 [inlined]
    [3] +(A::Vector{Float64}, Bs::Vector{Float64})
      @ Base ./arraymath.jl:45
    [4] macro expansion
      @ ~/.julia/packages/StaticArrays/vxjOO/src/mapreduce.jl:140 [inlined]
    [5] _mapfoldl
      @ ~/.julia/packages/StaticArrays/vxjOO/src/mapreduce.jl:115 [inlined]
    [6] _mapreduce
      @ ~/.julia/packages/StaticArrays/vxjOO/src/mapreduce.jl:113 [inlined]
    [7] _reduce (repeats 2 times)
      @ ~/.julia/packages/StaticArrays/vxjOO/src/mapreduce.jl:209 [inlined]
    [8] #sum#303
      @ ~/.julia/packages/StaticArrays/vxjOO/src/mapreduce.jl:250 [inlined]
    [9] sum
      @ ~/.julia/packages/StaticArrays/vxjOO/src/mapreduce.jl:250 [inlined]
   [10] _compute_estimate(m::FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}, fs::StaticArrays.SVector{7, Vector{Float64}}, x::Float64, step::Float64, coefs::StaticArrays.SVector{7, Float64})
      @ FiniteDifferences ~/.julia/packages/FiniteDifferences/Jh2Y2/src/methods.jl:263
   [11] _estimate_magnitudes(m::FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}, f::FiniteDifferences.var"#68#69"{FiniteDifferences.var"#70#71"{FiniteDifferences.var"#72#73"{ChainRulesTestUtils.var"#fnew#38"{ChainRulesTestUtils.var"#call_on_copy#42"{NamedTuple{(), Tuple{}}}, Tuple{typeof(select), typeof(>), GBMatrix{Float64}, Float64}, NTuple{4, Bool}}}, FiniteDifferences.var"#Tuple_from_vec#43"{Tuple{Int64, Int64}, Tuple{Int64, Int64}, Tuple{SuiteSparseGraphBLAS.var"#backtomat#190"{GBMatrix{Float64}, Vector{UInt64}, Vector{UInt64}}, FiniteDifferences.var"#Real_from_vec#20"}}}, Vector{Float64}, Vector{Float64}}, x::Float64)
      @ FiniteDifferences ~/.julia/packages/FiniteDifferences/Jh2Y2/src/methods.jl:380
   [12] estimate_step(m::FiniteDifferences.AdaptedFiniteDifferenceMethod{5, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}}, f::FiniteDifferences.var"#68#69"{FiniteDifferences.var"#70#71"{FiniteDifferences.var"#72#73"{ChainRulesTestUtils.var"#fnew#38"{ChainRulesTestUtils.var"#call_on_copy#42"{NamedTuple{(), Tuple{}}}, Tuple{typeof(select), typeof(>), GBMatrix{Float64}, Float64}, NTuple{4, Bool}}}, FiniteDifferences.var"#Tuple_from_vec#43"{Tuple{Int64, Int64}, Tuple{Int64, Int64}, Tuple{SuiteSparseGraphBLAS.var"#backtomat#190"{GBMatrix{Float64}, Vector{UInt64}, Vector{UInt64}}, FiniteDifferences.var"#Real_from_vec#20"}}}, Vector{Float64}, Vector{Float64}}, x::Float64)
      @ FiniteDifferences ~/.julia/packages/FiniteDifferences/Jh2Y2/src/methods.jl:365
   [13] (::FiniteDifferences.AdaptedFiniteDifferenceMethod{5, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}})(f::FiniteDifferences.var"#68#69"{FiniteDifferences.var"#70#71"{FiniteDifferences.var"#72#73"{ChainRulesTestUtils.var"#fnew#38"{ChainRulesTestUtils.var"#call_on_copy#42"{NamedTuple{(), Tuple{}}}, Tuple{typeof(select), typeof(>), GBMatrix{Float64}, Float64}, NTuple{4, Bool}}}, FiniteDifferences.var"#Tuple_from_vec#43"{Tuple{Int64, Int64}, Tuple{Int64, Int64}, Tuple{SuiteSparseGraphBLAS.var"#backtomat#190"{GBMatrix{Float64}, Vector{UInt64}, Vector{UInt64}}, FiniteDifferences.var"#Real_from_vec#20"}}}, Vector{Float64}, Vector{Float64}}, x::Float64)
      @ FiniteDifferences ~/.julia/packages/FiniteDifferences/Jh2Y2/src/methods.jl:193
   [14] _jvp
      @ ~/.julia/packages/FiniteDifferences/Jh2Y2/src/grad.jl:46 [inlined]
   [15] jvp(fdm::FiniteDifferences.AdaptedFiniteDifferenceMethod{5, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}}, f::FiniteDifferences.var"#72#73"{ChainRulesTestUtils.var"#fnew#38"{ChainRulesTestUtils.var"#call_on_copy#42"{NamedTuple{(), Tuple{}}}, Tuple{typeof(select), typeof(>), GBMatrix{Float64}, Float64}, NTuple{4, Bool}}}, ::Tuple{Tuple{GBMatrix{Float64}, Float64}, Tuple{GBMatrix{Float64}, Float64}})
      @ FiniteDifferences ~/.julia/packages/FiniteDifferences/Jh2Y2/src/grad.jl:58
   [16] jvp(::FiniteDifferences.AdaptedFiniteDifferenceMethod{5, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}}, ::Function, ::Tuple{GBMatrix{Float64}, GBMatrix{Float64}}, ::Tuple{Float64, Float64})
      @ FiniteDifferences ~/.julia/packages/FiniteDifferences/Jh2Y2/src/grad.jl:62
   [17] _make_jvp_call(fdm::FiniteDifferences.AdaptedFiniteDifferenceMethod{5, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}}, f::Function, y::GBMatrix{Float64}, xs::Tuple{typeof(select), typeof(>), GBMatrix{Float64}, Float64}, ẋs::Tuple{ChainRulesCore.NoTangent, ChainRulesCore.NoTangent, GBMatrix{Float64}, Float64}, ignores::NTuple{4, Bool})
      @ ChainRulesTestUtils ~/.julia/packages/ChainRulesTestUtils/AX7fv/src/finite_difference_calls.jl:24
   [18] macro expansion
      @ ~/.julia/packages/ChainRulesTestUtils/AX7fv/src/testers.jl:150 [inlined]
   [19] macro expansion
      @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1151 [inlined]
   [20] test_frule(::ChainRulesTestUtils.ADviaRuleConfig, ::typeof(select), ::typeof(>), ::Vararg{Any, N} where N; output_tangent::ChainRulesTestUtils.Auto, tangent_transforms::Vector{Function}, fdm::FiniteDifferences.AdaptedFiniteDifferenceMethod{5, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}}, frule_f::Function, check_inferred::Bool, fkwargs::NamedTuple{(), Tuple{}}, rtol::Float64, atol::Float64, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
      @ ChainRulesTestUtils ~/.julia/packages/ChainRulesTestUtils/AX7fv/src/testers.jl:124
   [21] test_frule(::ChainRulesTestUtils.ADviaRuleConfig, ::Function, ::Function, ::Vararg{Any, N} where N)
      @ ChainRulesTestUtils ~/.julia/packages/ChainRulesTestUtils/AX7fv/src/testers.jl:117
   [22] test_frule(::Function, ::Vararg{Any, N} where N; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
      @ ChainRulesTestUtils ~/.julia/packages/ChainRulesTestUtils/AX7fv/src/testers.jl:99
   [23] test_frule(::Function, ::Function, ::GBMatrix{Float64}, ::Vararg{Any, N} where N)
      @ ChainRulesTestUtils ~/.julia/packages/ChainRulesTestUtils/AX7fv/src/testers.jl:98
   [24] top-level scope
      @ REPL[4]:1
   [25] eval
      @ ./boot.jl:360 [inlined]
   [26] eval
      @ ./Base.jl:39 [inlined]
   [27] repleval(m::Module, code::Expr, #unused#::String)
      @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.3.32/scripts/packages/VSCodeServer/src/repl.jl:157
   [28] (::VSCodeServer.var"#69#71"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
      @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.3.32/scripts/packages/VSCodeServer/src/repl.jl:123
   [29] with_logstate(f::Function, logstate::Any)
      @ Base.CoreLogging ./logging.jl:491
   [30] with_logger
      @ ./logging.jl:603 [inlined]
   [31] (::VSCodeServer.var"#68#70"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
      @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.3.32/scripts/packages/VSCodeServer/src/repl.jl:124
   [32] #invokelatest#2
      @ ./essentials.jl:708 [inlined]
   [33] invokelatest(::Any)
      @ Base ./essentials.jl:706
   [34] macro expansion
      @ ~/.vscode/extensions/julialang.language-julia-1.3.32/scripts/packages/VSCodeServer/src/eval.jl:34 [inlined]
   [35] (::VSCodeServer.var"#53#54")()
      @ VSCodeServer ./task.jl:411
Test Summary:                                             | Pass  Error  Total
test_frule: select on typeof(>),GBMatrix{Float64},Float64 |    2      1      3
ERROR: Some tests did not pass: 2 passed, 0 failed, 1 errored, 0 broken.
rayegun commented 3 years ago

To reproduce the constructor issue:

julia> test_frule(GBVector, [1,2,3,4,5], rand(-10.0:0.05:10.0, 5))
test_frule: GBVector on Vector{Int64},Vector{Float64}: Error During Test at /home/will/.julia/packages/ChainRulesTestUtils/AX7fv/src/testers.jl:122
  Got exception outside of a @test
  DimensionMismatch("arrays could not be broadcast to a common size; got a dimension with lengths 10 and 5")
  Stacktrace:
    [1] _bcs1
      @ ./broadcast.jl:501 [inlined]
    [2] _bcs
      @ ./broadcast.jl:495 [inlined]
    [3] broadcast_shape
      @ ./broadcast.jl:489 [inlined]
    [4] combine_axes
      @ ./broadcast.jl:484 [inlined]
    [5] instantiate
      @ ./broadcast.jl:266 [inlined]
    [6] materialize
      @ ./broadcast.jl:883 [inlined]
    [7] (::FiniteDifferences.var"#68#69"{FiniteDifferences.var"#70#71"{FiniteDifferences.var"#72#73"{ChainRulesTestUtils.var"#fnew#38"{ChainRulesTestUtils.var"#call_on_copy#42"{NamedTuple{(), Tuple{}}}, Tuple{UnionAll, Vector{Int64}, Vector{Float64}}, Tuple{Bool, Bool, Bool}}}, FiniteDifferences.var"#Tuple_from_vec#43"{Tuple{Int64, Int64}, Tuple{Int64, Int64}, Tuple{typeof(identity), typeof(identity)}}}, Vector{Float64}, Vector{Float64}})(ε::Float64)
      @ FiniteDifferences ~/.julia/packages/FiniteDifferences/Jh2Y2/src/grad.jl:46
    [8] #2
      @ ./broadcast.jl:314 [inlined]
    [9] macro expansion
      @ ~/.julia/packages/StaticArrays/vxjOO/src/broadcast.jl:126 [inlined]
   [10] _broadcast
      @ ~/.julia/packages/StaticArrays/vxjOO/src/broadcast.jl:100 [inlined]
   [11] copy
      @ ~/.julia/packages/StaticArrays/vxjOO/src/broadcast.jl:27 [inlined]
   [12] materialize
      @ ./broadcast.jl:883 [inlined]
   [13] _eval_function(m::FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}, f::FiniteDifferences.var"#68#69"{FiniteDifferences.var"#70#71"{FiniteDifferences.var"#72#73"{ChainRulesTestUtils.var"#fnew#38"{ChainRulesTestUtils.var"#call_on_copy#42"{NamedTuple{(), Tuple{}}}, Tuple{UnionAll, Vector{Int64}, Vector{Float64}}, Tuple{Bool, Bool, Bool}}}, FiniteDifferences.var"#Tuple_from_vec#43"{Tuple{Int64, Int64}, Tuple{Int64, Int64}, Tuple{typeof(identity), typeof(identity)}}}, Vector{Float64}, Vector{Float64}}, x::Float64, step::Float64)
      @ FiniteDifferences ~/.julia/packages/FiniteDifferences/Jh2Y2/src/methods.jl:249
   [14] _estimate_magnitudes(m::FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}, f::FiniteDifferences.var"#68#69"{FiniteDifferences.var"#70#71"{FiniteDifferences.var"#72#73"{ChainRulesTestUtils.var"#fnew#38"{ChainRulesTestUtils.var"#call_on_copy#42"{NamedTuple{(), Tuple{}}}, Tuple{UnionAll, Vector{Int64}, Vector{Float64}}, Tuple{Bool, Bool, Bool}}}, FiniteDifferences.var"#Tuple_from_vec#43"{Tuple{Int64, Int64}, Tuple{Int64, Int64}, Tuple{typeof(identity), typeof(identity)}}}, Vector{Float64}, Vector{Float64}}, x::Float64)
      @ FiniteDifferences ~/.julia/packages/FiniteDifferences/Jh2Y2/src/methods.jl:378
   [15] estimate_step(m::FiniteDifferences.AdaptedFiniteDifferenceMethod{5, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}}, f::FiniteDifferences.var"#68#69"{FiniteDifferences.var"#70#71"{FiniteDifferences.var"#72#73"{ChainRulesTestUtils.var"#fnew#38"{ChainRulesTestUtils.var"#call_on_copy#42"{NamedTuple{(), Tuple{}}}, Tuple{UnionAll, Vector{Int64}, Vector{Float64}}, Tuple{Bool, Bool, Bool}}}, FiniteDifferences.var"#Tuple_from_vec#43"{Tuple{Int64, Int64}, Tuple{Int64, Int64}, Tuple{typeof(identity), typeof(identity)}}}, Vector{Float64}, Vector{Float64}}, x::Float64)
      @ FiniteDifferences ~/.julia/packages/FiniteDifferences/Jh2Y2/src/methods.jl:365
   [16] (::FiniteDifferences.AdaptedFiniteDifferenceMethod{5, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}})(f::FiniteDifferences.var"#68#69"{FiniteDifferences.var"#70#71"{FiniteDifferences.var"#72#73"{ChainRulesTestUtils.var"#fnew#38"{ChainRulesTestUtils.var"#call_on_copy#42"{NamedTuple{(), Tuple{}}}, Tuple{UnionAll, Vector{Int64}, Vector{Float64}}, Tuple{Bool, Bool, Bool}}}, FiniteDifferences.var"#Tuple_from_vec#43"{Tuple{Int64, Int64}, Tuple{Int64, Int64}, Tuple{typeof(identity), typeof(identity)}}}, Vector{Float64}, Vector{Float64}}, x::Float64)
      @ FiniteDifferences ~/.julia/packages/FiniteDifferences/Jh2Y2/src/methods.jl:193
   [17] _jvp
      @ ~/.julia/packages/FiniteDifferences/Jh2Y2/src/grad.jl:46 [inlined]
   [18] jvp(fdm::FiniteDifferences.AdaptedFiniteDifferenceMethod{5, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}}, f::FiniteDifferences.var"#72#73"{ChainRulesTestUtils.var"#fnew#38"{ChainRulesTestUtils.var"#call_on_copy#42"{NamedTuple{(), Tuple{}}}, Tuple{UnionAll, Vector{Int64}, Vector{Float64}}, Tuple{Bool, Bool, Bool}}}, ::Tuple{Tuple{Vector{Int64}, Vector{Float64}}, Tuple{Vector{ChainRulesCore.NoTangent}, Vector{Float64}}})
      @ FiniteDifferences ~/.julia/packages/FiniteDifferences/Jh2Y2/src/grad.jl:58
   [19] jvp(::FiniteDifferences.AdaptedFiniteDifferenceMethod{5, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}}, ::Function, ::Tuple{Vector{Int64}, Vector{ChainRulesCore.NoTangent}}, ::Tuple{Vector{Float64}, Vector{Float64}})
      @ FiniteDifferences ~/.julia/packages/FiniteDifferences/Jh2Y2/src/grad.jl:62
   [20] _make_jvp_call(fdm::FiniteDifferences.AdaptedFiniteDifferenceMethod{5, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}}, f::Function, y::GBVector{Float64}, xs::Tuple{UnionAll, Vector{Int64}, Vector{Float64}}, ẋs::Tuple{ChainRulesCore.NoTangent, Vector{ChainRulesCore.NoTangent}, Vector{Float64}}, ignores::Tuple{Bool, Bool, Bool})
      @ ChainRulesTestUtils ~/.julia/packages/ChainRulesTestUtils/AX7fv/src/finite_difference_calls.jl:24
   [21] macro expansion
      @ ~/.julia/packages/ChainRulesTestUtils/AX7fv/src/testers.jl:150 [inlined]
   [22] macro expansion
      @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1151 [inlined]
   [23] test_frule(::ChainRulesTestUtils.ADviaRuleConfig, ::Type, ::Vector{Int64}, ::Vararg{Any, N} where N; output_tangent::ChainRulesTestUtils.Auto, tangent_transforms::Vector{Function}, fdm::FiniteDifferences.AdaptedFiniteDifferenceMethod{5, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}}, frule_f::Function, check_inferred::Bool, fkwargs::NamedTuple{(), Tuple{}}, rtol::Float64, atol::Float64, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
      @ ChainRulesTestUtils ~/.julia/packages/ChainRulesTestUtils/AX7fv/src/testers.jl:124
   [24] test_frule
      @ ~/.julia/packages/ChainRulesTestUtils/AX7fv/src/testers.jl:117 [inlined]
   [25] #test_frule#40
      @ ~/.julia/packages/ChainRulesTestUtils/AX7fv/src/testers.jl:99 [inlined]
   [26] test_frule(::Type, ::Vector{Int64}, ::Vector{Float64})
      @ ChainRulesTestUtils ~/.julia/packages/ChainRulesTestUtils/AX7fv/src/testers.jl:98
   [27] top-level scope
      @ REPL[5]:1
   [28] eval
      @ ./boot.jl:360 [inlined]
   [29] eval
      @ ./Base.jl:39 [inlined]
   [30] repleval(m::Module, code::Expr, #unused#::String)
      @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.3.32/scripts/packages/VSCodeServer/src/repl.jl:157
   [31] (::VSCodeServer.var"#69#71"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
      @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.3.32/scripts/packages/VSCodeServer/src/repl.jl:123
   [32] with_logstate(f::Function, logstate::Any)
      @ Base.CoreLogging ./logging.jl:491
   [33] with_logger
      @ ./logging.jl:603 [inlined]
   [34] (::VSCodeServer.var"#68#70"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
      @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.3.32/scripts/packages/VSCodeServer/src/repl.jl:124
   [35] #invokelatest#2
      @ ./essentials.jl:708 [inlined]
   [36] invokelatest(::Any)
      @ Base ./essentials.jl:706
   [37] macro expansion
      @ ~/.vscode/extensions/julialang.language-julia-1.3.32/scripts/packages/VSCodeServer/src/eval.jl:34 [inlined]
   [38] (::VSCodeServer.var"#53#54")()
      @ VSCodeServer ./task.jl:411
Test Summary:                                         | Pass  Error  Total
test_frule: GBVector on Vector{Int64},Vector{Float64} |    2      1      3
ERROR: Some tests did not pass: 2 passed, 0 failed, 1 errored, 0 broken.

Note that doing this:

test_frule(GBVector, [1,2,3,4,5], rand(-10.0:0.05:10.0, 5); output_tangent=GBVector([1,2,3,4,5], rand(-10.0:0.05:10.0, 5)))

Gives the exact same error as above.

I believe these issues are related, but they do occur in slightly different places.

mzgubic commented 3 years ago

Ok, I know what's happening for the select rules.

Essentially finite differencing takes a step and changes the vector/matrix a bit, meaning that select selects different elements of the vector/matrix, resulting in a longer/shorter vector.

Potentially we could fix this by pretending, for the purposes of finite differencing and testing rules, that the sparse matrices and vectors are actually dense. This would be done in to_vec. I tried doing it quickly but realised I don't know how to quickly densify a GBMatrix{Float64} - may I suggest we also implementing Matrix(::GBMatrix)?

(This might fix the constructor issue also, but it might not. I'll take a look once we get select done)

rayegun commented 3 years ago

I can quickly create a Matrix(::GBMatrix) that densifies. Right now it only works if the matrix is already dense, but I can just do a union with a GBMatrix full of zero(T).

Should to_vec always densify? I'm worried that we won't be testing that things work with sparse matrices if we're really just testing things as dense matrices, but I haven't thought much about how it would work.

mzgubic commented 3 years ago

Should to_vec always densify?

Yes, I think so - though I may have told you not densifying is the right thing to do, I have changed my mind on this at least once. I wrote down some reasons here https://github.com/JuliaDiff/FiniteDifferences.jl/issues/186 in case you are interested.

We are still testing them as sparse matrices inside the rules, which is what really matters. It's just that we are computing the finite differences tangents using the densified versions.

rayegun commented 3 years ago

Resolved thanks to lots of help by Miha :).