BlockArrays.jl icon indicating copy to clipboard operation
BlockArrays.jl copied to clipboard

missing `similar` method for `PseudoBlockArray` (`mapslices` unusable)

Open yha opened this issue 2 years ago • 4 comments

julia> using BlockArrays

julia> b = mortar([rand(5,5) for i=1:2, j=1:2]);

julia> mapslices(identity, b[1:5,:]; dims=1)
ERROR: MethodError: no method matching similar(::Vector{Float64}, ::Type{Float64}, ::Tuple{UnitRange{Int64}, UnitRange{Int64}})
Closest candidates are:
  similar(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{N}}, ::Type{ElType}, ::Any) where {N, ElType} at C:\Users\sternlab\AppData\Local\Programs\Julia-1.7.2\share\julia\base\broadcast.jl:212
  similar(::Base.Broadcast.Broadcasted{Base.Broadcast.ArrayConflict}, ::Type{ElType}, ::Any) where ElType at C:\Users\sternlab\AppData\Local\Programs\Julia-1.7.2\share\julia\base\broadcast.jl:217
  similar(::ArrayLayouts.MulAdd{<:Any, <:ArrayLayouts.DualLayout, ArrayLayouts.ZerosLayout}, ::Type{T}, ::Any) where T at C:\Users\sternlab\.julia\packages\ArrayLayouts\nCtQC\src\muladd.jl:414
  ...
Stacktrace:
 [1] similar(a::Vector{Float64}, dims::Tuple{UnitRange{Int64}, UnitRange{Int64}})
   @ Base .\abstractarray.jl:783
 [2] mapslices(f::typeof(identity), A::PseudoBlockMatrix{Float64, Matrix{Float64}, Tuple{Base.OneTo{Int64}, BlockedUnitRange{Vector{Int64}}}}; dims::Int64)
   @ Base .\abstractarray.jl:2795
 [3] top-level scope
   @ REPL[5]:1

This is a regression introduced between 0.16.17 and 0.16.18

yha avatar Oct 11 '22 22:10 yha

This appears to work now:

julia> mapslices(identity, b[1:5,:]; dims=1)
1×2-blocked 5×10 PseudoBlockMatrix{Float64, Matrix{Float64}, Tuple{Base.OneTo{Int64}, BlockedUnitRange{Vector{Int64}}}}:
 0.89626   0.274113    0.703425   0.579062  0.989165   │  0.372363  0.659855   0.689075  0.0578565   0.688581 
 0.278924  0.147276    0.791482   0.133684  0.0279632  │  0.693008  0.0273849  0.594499  0.713912    0.2946   
 0.865734  0.00203172  0.184889   0.758688  0.9495     │  0.271894  0.44169    0.467267  0.501292    0.692319 
 0.866907  0.894063    0.0381348  0.272919  0.926828   │  0.248664  0.798704   0.807312  0.520421    0.859454 
 0.615061  0.603609    0.564914   0.263001  0.423267   │  0.402052  0.452154   0.571618  0.00275745  0.0255126

jishnub avatar Jul 20 '23 07:07 jishnub

It works in julia 1.6 and 1.9, but not in 1.7 or 1.8. Are these versions still meant to be supported?

yha avatar Jul 20 '23 13:07 yha

Ah ok, worth looking into it then, as these versions are supported. Wonder what changed in v1.9 that makes this work?

jishnub avatar Jul 20 '23 13:07 jishnub

Seems to be this: https://github.com/JuliaLang/julia/pull/40996 Stack trace on julia 1.8.5 points to this line: https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/abstractarray.jl#L2875C38-L2875C38 which was eliminated in that PR

yha avatar Jul 20 '23 14:07 yha