willow-ahrens / Finch.jl

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

Fix SingleList #445

Closed nullplay closed 6 months ago

nullplay commented 6 months ago

This fixes #444 .

Now the generated code looks like this. I want to remove all the empty switch cases but it is hard to filter out in Finch AST level because we can know whether the body of case is empty or not after the dead code elimination:

quote
    s = ((ex.bodies[1]).bodies[1]).tns.bind
    x_lvl = (((ex.bodies[1]).bodies[2]).body.rhs.args[1]).tns.bind.lvl
    x_lvl_ptr = x_lvl.ptr
    x_lvl_idx = x_lvl.idx
    x_lvl_val = x_lvl.lvl.val
    y_lvl = (((ex.bodies[1]).bodies[2]).body.rhs.args[2]).tns.bind.lvl
    y_lvl_ptr = y_lvl.ptr
    y_lvl_idx = y_lvl.idx
    y_lvl_val = y_lvl.lvl.val
    y_lvl.shape == x_lvl.shape || throw(DimensionMismatch("mismatched dimension limits ($(y_lvl.shape) != $(x_lvl.shape))"))
    result = nothing
    s_val = 0
    y_lvl_q = y_lvl_ptr[1]
    y_lvl_q_stop = y_lvl_ptr[1 + 1]
    if y_lvl_q < y_lvl_q_stop
        y_lvl_i = y_lvl_idx[y_lvl_q]
    else
        y_lvl_i = 0
    end
    x_lvl_q = x_lvl_ptr[1]
    x_lvl_q_stop = x_lvl_ptr[1 + 1]
    if x_lvl_q < x_lvl_q_stop
        x_lvl_i = x_lvl_idx[x_lvl_q]
    else
        x_lvl_i = 0
    end
    phase_stop = min(y_lvl.shape, y_lvl_i, x_lvl_i)
    if phase_stop >= 1
        if phase_stop < y_lvl_i && phase_stop < x_lvl_i
        elseif phase_stop < x_lvl_i
        elseif phase_stop < y_lvl_i
        else
            y_lvl_2_val = y_lvl_val[y_lvl_q]
            x_lvl_2_val = x_lvl_val[x_lvl_q]
            s_val = 0 + x_lvl_2_val * y_lvl_2_val
        end
    end
    s.val = s_val
    result = (s = s,)
    result
end
codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 75.98%. Comparing base (8ad7d0f) to head (b005791).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #445 +/- ## ========================================== - Coverage 76.02% 75.98% -0.04% ========================================== Files 89 89 Lines 8300 8300 ========================================== - Hits 6310 6307 -3 - Misses 1990 1993 +3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.