JuliaSparse / SuiteSparseGraphBLAS.jl

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

error in broadcasted multiplication #98

Closed CarloLucibello closed 1 year ago

CarloLucibello commented 1 year ago
julia> x = GBMatrix([1,2], [2, 3], [1,2], fill=0)
2x3 GraphBLAS int64_t matrix, bitmap by row
  2 entries, memory: 264 bytes

    (1,2)   1
    (2,3)   2

julia> Array(x) .* [1,2] 
2×3 Matrix{Int64}:
 0  1  0
 0  0  4

julia> x .* [1,2]
ERROR: DimensionMismatch: 
Stacktrace:
 [1] emul!(C::GBMatrix{Int64, Int64}, A::GBMatrix{Int64, Int64}, B::SuiteSparseGraphBLAS.GBShallowVector{Int64, Vector{Int64}, Vector{Bool}, Vector{Int64}, Int64}, op::Function; mask::Nothing, accum::Nothing, desc::Nothing)
   @ SuiteSparseGraphBLAS ~/.julia/packages/SuiteSparseGraphBLAS/ijDcs/src/operations/ewise.jl:36
 [2] emul(A::GBMatrix{Int64, Int64}, B::SuiteSparseGraphBLAS.GBShallowVector{Int64, Vector{Int64}, Vector{Bool}, Vector{Int64}, Int64}, op::Function; mask::Nothing, accum::Nothing, desc::Nothing)
   @ SuiteSparseGraphBLAS ~/.julia/packages/SuiteSparseGraphBLAS/ijDcs/src/operations/ewise.jl:82
 [3] emul
   @ ~/.julia/packages/SuiteSparseGraphBLAS/ijDcs/src/operations/ewise.jl:72 [inlined]
 [4] copy
   @ ~/.julia/packages/SuiteSparseGraphBLAS/ijDcs/src/operations/broadcasts.jl:97 [inlined]
 [5] materialize(bc::Base.Broadcast.Broadcasted{SuiteSparseGraphBLAS.GBMatrixStyle, Nothing, typeof(*), Tuple{GBMatrix{Int64, Int64}, Vector{Int64}}})
   @ Base.Broadcast ./broadcast.jl:860
 [6] top-level scope
   @ REPL[50]:1
rayegun commented 1 year ago

This is tricky. I have to know that the operator is commutative, since I turn this into Diagonal([1,2]) * x. Currently if you do: [1,2] .* x this should work, and x .* [1,2,3]' should work.

I need to do a bit of work to do it irrespective of ordering (at least for the builtin operators).

rayegun commented 1 year ago

Fixed on master as far as I can tell.