finch-tensor / Finch.jl

Sparse and Structured Tensor Compiler
http://willowahrens.io/Finch.jl/
MIT License
161 stars 16 forks source link

Matmul and reduce in lazy mode fails with `ArgumentError` #615

Open mtsokol opened 3 weeks ago

mtsokol commented 3 weeks ago

Hi @willow-ahrens,

I implemented triangle counting (SpA @ SpA * SpA), it runs for eager mode but decorating with @sparse.compiled to run lazy mode fails with:

ERROR: ArgumentError: Please supply initial value for reduction of Any with +.
Stacktrace:
 [1] initial_value(op::Function, T::Type)
   @ Finch ~/JuliaProjects/Finch.jl/src/interface/lazy.jl:114
 [2] reduce(op::Function, arg::Finch.LazyTensor{Any, 2})
   @ Finch ~/JuliaProjects/Finch.jl/src/interface/lazy.jl:127
 [3] sum(arr::Finch.LazyTensor{Any, 2})
   @ Finch ~/JuliaProjects/Finch.jl/src/interface/lazy.jl:74
 [4] top-level scope
   @ REPL[5]:1

Here's a code snippet to reproduce it:

using Finch

A = Tensor(Dense(Dense(Element(0.0))), 10, 10)
res = sum(tensordot(A, A, ((1,), (2,))))

A_lazy = Finch.LazyTensor(A)
res = sum(tensordot(A_lazy, A_lazy, ((1,), (2,))))  # fails
willow-ahrens commented 2 hours ago

this looks like a type inference failure. somehow tensordot lost the types of things.