JuliaArrays / BlockDiagonals.jl

Functionality for working efficiently with block diagonal matrices.
MIT License
51 stars 11 forks source link

fix the getindex bug for abstract arrays #100

Closed mzgubic closed 2 years ago

mzgubic commented 2 years ago

Fixes the bug in the test (introduced in https://github.com/invenia/BlockDiagonals.jl/pull/88) which gives

julia> b = BlockDiagonal(AbstractMatrix{Float64}[rand(2, 2)]);

julia> b[1]
ERROR: MethodError: no method matching zero(::Type{Any})
Closest candidates are:
  zero(::Type{Union{Missing, T}}) where T at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/missing.jl:105
  zero(::Union{Type{P}, P}) where P<:Dates.Period at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Dates/src/periods.jl:53
  zero(::FillArrays.Ones{T, N}) where {T, N} at ~/.julia/packages/FillArrays/7oBjc/src/FillArrays.jl:539
  ...
Stacktrace:
  [1] zero(#unused#::Type{Any})
    @ Base ./missing.jl:106
  [2] reduce_empty(#unused#::typeof(+), #unused#::Type{Any})
    @ Base ./reduce.jl:313
  [3] reduce_empty(#unused#::typeof(Base.add_sum), #unused#::Type{Any})
    @ Base ./reduce.jl:322
  [4] mapreduce_empty(#unused#::typeof(identity), op::Function, T::Type)
    @ Base ./reduce.jl:345
  [5] reduce_empty(op::Base.MappingRF{typeof(identity), typeof(Base.add_sum)}, #unused#::Type{Any})
    @ Base ./reduce.jl:331
  [6] reduce_empty_iter
    @ ./reduce.jl:357 [inlined]
  [7] mapreduce_empty_iter(f::Function, op::Function, itr::Vector{Any}, ItrEltype::Base.HasEltype)
    @ Base ./reduce.jl:353
  [8] _mapreduce(f::typeof(identity), op::typeof(Base.add_sum), #unused#::IndexLinear, A::Vector{Any})
    @ Base ./reduce.jl:402
  [9] _mapreduce_dim
    @ ./reducedim.jl:330 [inlined]
 [10] #mapreduce#725
    @ ./reducedim.jl:322 [inlined]
 [11] mapreduce
    @ ./reducedim.jl:322 [inlined]
 [12] #_sum#735
    @ ./reducedim.jl:894 [inlined]
 [13] _sum
    @ ./reducedim.jl:894 [inlined]
 [14] #_sum#734
    @ ./reducedim.jl:893 [inlined]
 [15] _sum
    @ ./reducedim.jl:893 [inlined]
 [16] #sum#732
    @ ./reducedim.jl:889 [inlined]
 [17] sum(a::Vector{Any})
    @ Base ./reducedim.jl:889
 [18] _block_indices(B::BlockDiagonal{Float64, AbstractMatrix{Float64}}, i::Int64, j::Int64)
    @ BlockDiagonals ~/JuliaEnvs/GPForecasting.jl/dev/BlockDiagonals/src/blockdiagonal.jl:158
 [19] getindex(B::BlockDiagonal{Float64, AbstractMatrix{Float64}}, i::Int64, j::Int64)
    @ BlockDiagonals ~/JuliaEnvs/GPForecasting.jl/dev/BlockDiagonals/src/blockdiagonal.jl:140
 [20] _getindex
    @ ./abstractarray.jl:1257 [inlined]
 [21] getindex(A::BlockDiagonal{Float64, AbstractMatrix{Float64}}, I::Int64)
    @ Base ./abstractarray.jl:1218
 [22] top-level scope
    @ REPL[84]:1
codecov[bot] commented 2 years ago

Codecov Report

Merging #100 (d77c395) into master (fc727ab) will not change coverage. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #100   +/-   ##
=======================================
  Coverage   95.92%   95.92%           
=======================================
  Files           5        5           
  Lines         319      319           
=======================================
  Hits          306      306           
  Misses         13       13           
Impacted Files Coverage Δ
src/blockdiagonal.jl 85.71% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update fc727ab...d77c395. Read the comment docs.