willow-ahrens / Finch.jl

Sparse tensors in Julia and more! Datastructure-driven array programing language.
http://willowahrens.io/Finch.jl/
MIT License
157 stars 15 forks source link

Format Inference doesn't respect literals #467

Open willow-ahrens opened 5 months ago

willow-ahrens commented 5 months ago

Literals aren't treated as literals in format inference, so we can't evaluate certain cases where the default would be clear. For example, A + 1 will densify. This was discovered in https://github.com/willow-ahrens/Finch.jl/pull/465#issuecomment-1996161923. Though that case could be resolved by adding the some rules to Finch about /, we might also want to consider how to get the format inference trait system to understand literals better. It's also unclear whether we should interpret A + 1 as a program that adds the literal 1 to A, or a program that adds an unspecified integer value to A.

        (@rule call(/, ~a, ~b::isliteral) => if iszero(b.val) Inf end),
        (@rule call(\, ~a::isliteral, ~b) => if iszero(a.val) Inf end),