JuliaSparse / SuiteSparseGraphBLAS.jl

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

No type promotion in reduce with Monoids #129

Open AntoineBut opened 6 months ago

AntoineBut commented 6 months ago

Hello,

Im currently getting started with your package (very nice work btw!) and I am wondering if there is a way to make something like this :

using SuiteSparseGraphsBLAS, Graphs
A_T = GBMatrix{Bool}((adjacency_matrix(graph, Bool; dir=:in)))   # Some sparse GB_Matrix of Bool
out_degree = reduce(+, A_T; dims=2)   # count the number of true elements on each line

without having this error :

ArgumentError: The SuiteSparse:GraphBLAS reduce function only supports monoids where T x T -> T.
            Please pass a function whose output type matches both input types.

The way I understand it, there is no type promotion happening in the reduce function. Since using the boolean matrix is quite faster for some operations, I'd be nice to have a way of doing this. Do you know any way around this ? Is this something that could be made possible at some point ?

Thank you for this nice package!