Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Broadcasting NamedDimsArray wrapping BlockSparseArrays.BlockSparseArray is broken #17

Open
mtfishman opened this issue Jan 13, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@mtfishman
Copy link
Member

using BlockSparseArrays: BlockSparseArray
using NamedDimsArrays: NamedDimsArray
b = BlockSparseArray{Float64}([2, 3], [2, 3])
b[2, 4] = 24
bᵢⱼ = NamedDimsArray(b, ("i", "j"))
bⱼᵢ = NamedDimsArray(b, ("j", "i"))
bᵢⱼ .+ 2 .* bⱼᵢ

which outputs:

MethodError: no method matching similar(::Base.Broadcast.Broadcasted{BlockSparseArrays.BlockSparseArrayStyle{2}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}, MapBroadcast.MapFunction{typeof(+), Tuple{MapBroadcast.Arg, MapBroadcast.MapFunction{typeof(*), Tuple{Int64, MapBroadcast.Arg}}}}, Tuple{PermutedDimsArray{Float64, 2, (1, 2), (1, 2), BlockSparseArray{Float64, 2, Matrix{Float64}, SparseArraysBase.SparseMatrixDOK{Matrix{Float64}, BlockSparseArrays.GetUnstoredBlock{Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, PermutedDimsArray{Float64, 2, (2, 1), (2, 1), BlockSparseArray{Float64, 2, Matrix{Float64}, SparseArraysBase.SparseMatrixDOK{Matrix{Float64}, BlockSparseArrays.GetUnstoredBlock{Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}}}, ::Type{Float64}, ::Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}})
The function `similar` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  similar(::Type{<:Union{var"#s40", var"#s39"} where {T, N, var"#s40"<:BlockSparseArrays.AbstractBlockSparseArray{T, N}, var"#s39"<:Union{Base.LogicalIndex{T, <:BlockSparseArrays.AbstractBlockSparseArray}, Base.ReinterpretArray{T, N, <:Any, <:Union{SubArray{<:Any, <:Any, var"#s14"}, var"#s14"}} where var"#s14"<:BlockSparseArrays.AbstractBlockSparseArray, Base.ReshapedArray{T, N, <:Union{Base.ReinterpretArray{<:Any, <:Any, <:Any, <:Union{SubArray{<:Any, <:Any, var"#s15"}, var"#s15"}}, SubArray{<:Any, <:Any, var"#s15"}, var"#s15"}} where var"#s15"<:BlockSparseArrays.AbstractBlockSparseArray, SubArray{T, N, <:Union{Base.ReinterpretArray{<:Any, <:Any, <:Any, <:Union{SubArray{<:Any, <:Any, var"#s16"}, var"#s16"}}, Base.ReshapedArray{<:Any, <:Any, <:Union{Base.ReinterpretArray{<:Any, <:Any, <:Any, <:Union{SubArray{<:Any, <:Any, var"#s16"}, var"#s16"}}, SubArray{<:Any, <:Any, var"#s16"}, var"#s16"}}, var"#s16"}} where var"#s16"<:BlockSparseArrays.AbstractBlockSparseArray, LinearAlgebra.Adjoint{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.Diagonal{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.LowerTriangular{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.Symmetric{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.Transpose{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.Tridiagonal{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.UnitLowerTriangular{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.UnitUpperTriangular{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.UpperTriangular{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, PermutedDimsArray{T, N, <:Any, <:Any, <:BlockSparseArrays.AbstractBlockSparseArray}}}}, ::Type, ::Tuple{Vararg{AbstractUnitRange{<:Integer}}})
   @ BlockSparseArrays ~/.julia/packages/BlockSparseArrays/aOmcd/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl:242
  similar(::BlockArrays.BlockedArray, ::Type{T}, ::Tuple{BlockArrays.AbstractBlockedUnitRange, BlockArrays.AbstractBlockedUnitRange, Vararg{Union{Integer, AbstractUnitRange{<:Integer}}}}) where T
   @ BlockArrays ~/.julia/packages/BlockArrays/tOOU0/src/blockedarray.jl:225
  similar(::Union{BlockSparseArrays.AbstractBlockSparseArray{T, N}, Base.LogicalIndex{T, <:BlockSparseArrays.AbstractBlockSparseArray}, Base.ReinterpretArray{T, N, <:Any, <:Union{SubArray{<:Any, <:Any, var"#s14"}, var"#s14"}} where var"#s14"<:BlockSparseArrays.AbstractBlockSparseArray, Base.ReshapedArray{T, N, <:Union{Base.ReinterpretArray{<:Any, <:Any, <:Any, <:Union{SubArray{<:Any, <:Any, var"#s15"}, var"#s15"}}, SubArray{<:Any, <:Any, var"#s15"}, var"#s15"}} where var"#s15"<:BlockSparseArrays.AbstractBlockSparseArray, SubArray{T, N, <:Union{Base.ReinterpretArray{<:Any, <:Any, <:Any, <:Union{SubArray{<:Any, <:Any, var"#s16"}, var"#s16"}}, Base.ReshapedArray{<:Any, <:Any, <:Union{Base.ReinterpretArray{<:Any, <:Any, <:Any, <:Union{SubArray{<:Any, <:Any, var"#s16"}, var"#s16"}}, SubArray{<:Any, <:Any, var"#s16"}, var"#s16"}}, var"#s16"}} where var"#s16"<:BlockSparseArrays.AbstractBlockSparseArray, LinearAlgebra.Adjoint{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.Diagonal{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.LowerTriangular{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.Symmetric{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.Transpose{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.Tridiagonal{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.UnitLowerTriangular{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.UnitUpperTriangular{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, LinearAlgebra.UpperTriangular{T, <:BlockSparseArrays.AbstractBlockSparseArray{T, N}}, PermutedDimsArray{T, N, <:Any, <:Any, <:BlockSparseArrays.AbstractBlockSparseArray}} where {T, N}, ::Type, ::Tuple{Vararg{AbstractUnitRange{<:Integer}}})
   @ BlockSparseArrays ~/.julia/packages/BlockSparseArrays/aOmcd/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl:251
  ...

Stacktrace:
 [1] similar(m::MapBroadcast.Mapped{BlockSparseArrays.BlockSparseArrayStyle{2}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}, MapBroadcast.MapFunction{typeof(+), Tuple{MapBroadcast.Arg, MapBroadcast.MapFunction{typeof(*), Tuple{Int64, MapBroadcast.Arg}}}}, Tuple{PermutedDimsArray{Float64, 2, (1, 2), (1, 2), BlockSparseArray{Float64, 2, Matrix{Float64}, SparseArraysBase.SparseMatrixDOK{Matrix{Float64}, BlockSparseArrays.GetUnstoredBlock{Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, PermutedDimsArray{Float64, 2, (2, 1), (2, 1), BlockSparseArray{Float64, 2, Matrix{Float64}, SparseArraysBase.SparseMatrixDOK{Matrix{Float64}, BlockSparseArrays.GetUnstoredBlock{Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}}}, elt::Type, ax::Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}})
   @ MapBroadcast ~/.julia/packages/MapBroadcast/3Dh8L/src/MapBroadcast.jl:168
 [2] similar(bc::Base.Broadcast.Broadcasted{NamedDimsArrays.NamedDimsArrayStyle{2}, NamedDimsArrays.NaiveOrderedSet{Tuple{NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}}}}, typeof(+), Tuple{NamedDimsArray{Float64, 2, BlockSparseArray{Float64, 2, Matrix{Float64}, SparseArraysBase.SparseMatrixDOK{Matrix{Float64}, BlockSparseArrays.GetUnstoredBlock{Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}, Tuple{NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}}}, Base.Broadcast.Broadcasted{NamedDimsArrays.NamedDimsArrayStyle{2}, Nothing, typeof(*), Tuple{Int64, NamedDimsArray{Float64, 2, BlockSparseArray{Float64, 2, Matrix{Float64}, SparseArraysBase.SparseMatrixDOK{Matrix{Float64}, BlockSparseArrays.GetUnstoredBlock{Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}, Tuple{NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}}}}}}}, elt::Type, ax::NamedDimsArrays.NaiveOrderedSet{Tuple{NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}}}})
   @ NamedDimsArrays ~/.julia/packages/NamedDimsArrays/8aJCc/src/abstractnameddimsarray.jl:793
 [3] similar(bc::Base.Broadcast.Broadcasted{NamedDimsArrays.NamedDimsArrayStyle{2}, NamedDimsArrays.NaiveOrderedSet{Tuple{NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}}}}, typeof(+), Tuple{NamedDimsArray{Float64, 2, BlockSparseArray{Float64, 2, Matrix{Float64}, SparseArraysBase.SparseMatrixDOK{Matrix{Float64}, BlockSparseArrays.GetUnstoredBlock{Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}, Tuple{NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}}}, Base.Broadcast.Broadcasted{NamedDimsArrays.NamedDimsArrayStyle{2}, Nothing, typeof(*), Tuple{Int64, NamedDimsArray{Float64, 2, BlockSparseArray{Float64, 2, Matrix{Float64}, SparseArraysBase.SparseMatrixDOK{Matrix{Float64}, BlockSparseArrays.GetUnstoredBlock{Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}, Tuple{NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}}}}}}}, ::Type{Float64})
   @ Base.Broadcast ./broadcast.jl:223
 [4] copy
   @ ./broadcast.jl:892 [inlined]
 [5] materialize(bc::Base.Broadcast.Broadcasted{NamedDimsArrays.NamedDimsArrayStyle{2}, Nothing, typeof(+), Tuple{NamedDimsArray{Float64, 2, BlockSparseArray{Float64, 2, Matrix{Float64}, SparseArraysBase.SparseMatrixDOK{Matrix{Float64}, BlockSparseArrays.GetUnstoredBlock{Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}, Tuple{NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}}}, Base.Broadcast.Broadcasted{NamedDimsArrays.NamedDimsArrayStyle{2}, Nothing, typeof(*), Tuple{Int64, NamedDimsArray{Float64, 2, BlockSparseArray{Float64, 2, Matrix{Float64}, SparseArraysBase.SparseMatrixDOK{Matrix{Float64}, BlockSparseArrays.GetUnstoredBlock{Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}}}, Tuple{NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}, NamedDimsArrays.NamedUnitRange{Int64, BlockArrays.BlockedOneTo{Int64, Vector{Int64}}, String}}}}}}})
   @ Base.Broadcast ./broadcast.jl:867
 [6] top-level scope
   @ REPL[23]:1

with versions:

julia> import Pkg; Pkg.status()
Status `/private/var/folders/qz/q22pzwm144z9fq57mpf1hfp40000gq/T/jl_EIrZHM/Project.toml`
  [2c9a651f] BlockSparseArrays v0.2.5
  [60cbd0c0] NamedDimsArrays v0.3.4

Other expressions like 2bᵢⱼ, bᵢⱼ + bᵢⱼ, etc. fail with similar errors.

@mtfishman mtfishman added the bug Something isn't working label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant