Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print output #631

Closed
wants to merge 1 commit into from
Closed

print output #631

wants to merge 1 commit into from

Conversation

willow-ahrens
Copy link
Collaborator

@willow-ahrens willow-ahrens commented Nov 1, 2024

[ Info: Testing Continuous Finch Examples
ex 1:
begin
    C_lvl = ((ex.bodies[1]).bodies[1]).tns.bind.lvl
    C_lvl_ptr = C_lvl.ptr
    C_lvl_left = C_lvl.left
    C_lvl_right = C_lvl.right
    C_lvl_2 = C_lvl.lvl
    C_lvl_val = C_lvl.lvl.val
    C_lvl_3 = C_lvl.buf
    C_lvl_val_2 = C_lvl.buf.val
    A_lvl = (((ex.bodies[1]).bodies[2]).body.rhs.args[1]).tns.bind.lvl
    A_lvl_ptr = A_lvl.ptr
    A_lvl_left = A_lvl.left
    A_lvl_right = A_lvl.right
    A_lvl_val = A_lvl.lvl.val
    B_lvl = (((ex.bodies[1]).bodies[2]).body.rhs.args[2]).tns.bind.lvl
    B_lvl_ptr = B_lvl.ptr
    B_lvl_left = B_lvl.left
    B_lvl_right = B_lvl.right
    B_lvl_val = B_lvl.lvl.val
    B_lvl.shape == A_lvl.shape || throw(DimensionMismatch("mismatched dimension limits ($(B_lvl.shape) != $(A_lvl.shape))"))
    C_lvl_qos_stop = 0
    Finch.resize_if_smaller!(C_lvl_ptr, 1 + 1)
    Finch.fill_range!(C_lvl_ptr, 0, 1 + 1, 1 + 1)
    C_lvl_qos = 0 + 1
    0 < 1 || throw(FinchProtocolError("SparseRunListLevels cannot be updated multiple times"))
    B_lvl_q = B_lvl_ptr[1]
    B_lvl_q_stop = B_lvl_ptr[1 + 1]
    if B_lvl_q < B_lvl_q_stop
        B_lvl_i_end = B_lvl_right[B_lvl_q_stop - 1]
    else
        B_lvl_i_end = 0.0
    end
    A_lvl_q = A_lvl_ptr[1]
    A_lvl_q_stop = A_lvl_ptr[1 + 1]
    if A_lvl_q < A_lvl_q_stop
        A_lvl_i_end = A_lvl_right[A_lvl_q_stop - 1]
    else
        A_lvl_i_end = 0.0
    end
    phase_stop = min(B_lvl.shape, B_lvl_i_end, A_lvl_i_end)
    if phase_stop >= limit(1.0)
        i = limit(1.0)
        if B_lvl_right[B_lvl_q] < limit(1.0)
            B_lvl_q = Finch.scansearch(B_lvl_right, limit(1.0), B_lvl_q, B_lvl_q_stop - 1)
        end
        if A_lvl_right[A_lvl_q] < limit(1.0)
            A_lvl_q = Finch.scansearch(A_lvl_right, limit(1.0), A_lvl_q, A_lvl_q_stop - 1)
        end
        while i <= phase_stop
            B_lvl_i_start = B_lvl_left[B_lvl_q]
            B_lvl_i_stop = B_lvl_right[B_lvl_q]
            A_lvl_i_start = A_lvl_left[A_lvl_q]
            A_lvl_i_stop = A_lvl_right[A_lvl_q]
            phase_start_2 = i
            phase_stop_2 = min(A_lvl_i_stop, phase_stop, B_lvl_i_stop)
            phase_start_4 = max(phase_start_2, B_lvl_i_start)
            phase_stop_4 = min(phase_stop_2, limit(0-ϵ) + A_lvl_i_start)
            if phase_stop_4 >= phase_start_4
                B_lvl_2_val = B_lvl_val[B_lvl_q]
                if C_lvl_qos > C_lvl_qos_stop
                    C_lvl_qos_stop = max(C_lvl_qos_stop << 1, 1)
                    Finch.resize_if_smaller!(C_lvl_left, C_lvl_qos_stop)
                    Finch.resize_if_smaller!(C_lvl_right, C_lvl_qos_stop)
                    Finch.resize_if_smaller!(C_lvl_val_2, C_lvl_qos_stop)
                    Finch.fill_range!(C_lvl_val_2, 0, C_lvl_qos, C_lvl_qos_stop)
                end
                C_lvl_val_2[C_lvl_qos] = B_lvl_2_val + C_lvl_val_2[C_lvl_qos]
                C_lvl_left[C_lvl_qos] = phase_start_4
                C_lvl_right[C_lvl_qos] = phase_stop_4
                C_lvl_qos += 1
            end
            phase_start_5 = max(phase_start_2, A_lvl_i_start)
            phase_stop_5 = min(phase_stop_2, limit(0-ϵ) + B_lvl_i_start)
            if phase_stop_5 >= phase_start_5
                A_lvl_2_val = A_lvl_val[A_lvl_q]
                if C_lvl_qos > C_lvl_qos_stop
                    C_lvl_qos_stop = max(C_lvl_qos_stop << 1, 1)
                    Finch.resize_if_smaller!(C_lvl_left, C_lvl_qos_stop)
                    Finch.resize_if_smaller!(C_lvl_right, C_lvl_qos_stop)
                    Finch.resize_if_smaller!(C_lvl_val_2, C_lvl_qos_stop)
                    Finch.fill_range!(C_lvl_val_2, 0, C_lvl_qos, C_lvl_qos_stop)
                end
                C_lvl_val_2[C_lvl_qos] = A_lvl_2_val + C_lvl_val_2[C_lvl_qos]
                C_lvl_left[C_lvl_qos] = phase_start_5
                C_lvl_right[C_lvl_qos] = phase_stop_5
                C_lvl_qos += 1
            end
            phase_start_6 = max(phase_start_2, B_lvl_i_start, A_lvl_i_start)
            if phase_stop_2 >= phase_start_6
                A_lvl_2_val_2 = A_lvl_val[A_lvl_q]
                B_lvl_2_val_2 = B_lvl_val[B_lvl_q]
                if C_lvl_qos > C_lvl_qos_stop
                    C_lvl_qos_stop = max(C_lvl_qos_stop << 1, 1)
                    Finch.resize_if_smaller!(C_lvl_left, C_lvl_qos_stop)
                    Finch.resize_if_smaller!(C_lvl_right, C_lvl_qos_stop)
                    Finch.resize_if_smaller!(C_lvl_val_2, C_lvl_qos_stop)
                    Finch.fill_range!(C_lvl_val_2, 0, C_lvl_qos, C_lvl_qos_stop)
                end
                C_lvl_val_2[C_lvl_qos] = A_lvl_2_val_2 + C_lvl_val_2[C_lvl_qos] + B_lvl_2_val_2
                C_lvl_left[C_lvl_qos] = phase_start_6
                C_lvl_right[C_lvl_qos] = phase_stop_2
                C_lvl_qos += 1
            end
            B_lvl_q += phase_stop_2 == B_lvl_i_stop
            A_lvl_q += phase_stop_2 == A_lvl_i_stop
            i = phase_stop_2 + limit(0+ϵ)
        end
    end
    phase_start_7 = max(limit(0+ϵ) + B_lvl_i_end, limit(1.0))
    phase_stop_7 = min(B_lvl.shape, A_lvl_i_end)
    if phase_stop_7 >= phase_start_7
        i = phase_start_7
        if A_lvl_right[A_lvl_q] < phase_start_7
            A_lvl_q = Finch.scansearch(A_lvl_right, phase_start_7, A_lvl_q, A_lvl_q_stop - 1)
        end
        while true
            i_start_4 = i
            A_lvl_i_start = A_lvl_left[A_lvl_q]
            A_lvl_i_stop = A_lvl_right[A_lvl_q]
            if A_lvl_i_stop < phase_stop_7
                phase_start_9 = max(A_lvl_i_start, i_start_4)
                if A_lvl_i_stop >= phase_start_9
                    A_lvl_2_val_3 = A_lvl_val[A_lvl_q]
                    if C_lvl_qos > C_lvl_qos_stop
                        C_lvl_qos_stop = max(C_lvl_qos_stop << 1, 1)
                        Finch.resize_if_smaller!(C_lvl_left, C_lvl_qos_stop)
                        Finch.resize_if_smaller!(C_lvl_right, C_lvl_qos_stop)
                        Finch.resize_if_smaller!(C_lvl_val_2, C_lvl_qos_stop)
                        Finch.fill_range!(C_lvl_val_2, 0, C_lvl_qos, C_lvl_qos_stop)
                    end
                    C_lvl_val_2[C_lvl_qos] = A_lvl_2_val_3 + C_lvl_val_2[C_lvl_qos]
                    C_lvl_left[C_lvl_qos] = phase_start_9
                    C_lvl_right[C_lvl_qos] = A_lvl_i_stop
                    C_lvl_qos += 1
                end
                A_lvl_q += A_lvl_i_stop == A_lvl_i_stop
                i = A_lvl_i_stop + limit(0+ϵ)
            else
                phase_start_10 = i
                phase_stop_11 = min(A_lvl_i_stop, phase_stop_7)
                phase_start_12 = max(A_lvl_i_start, phase_start_10)
                if phase_stop_11 >= phase_start_12
                    A_lvl_2_val_4 = A_lvl_val[A_lvl_q]
                    if C_lvl_qos > C_lvl_qos_stop
                        C_lvl_qos_stop = max(C_lvl_qos_stop << 1, 1)
                        Finch.resize_if_smaller!(C_lvl_left, C_lvl_qos_stop)
                        Finch.resize_if_smaller!(C_lvl_right, C_lvl_qos_stop)
                        Finch.resize_if_smaller!(C_lvl_val_2, C_lvl_qos_stop)
                        Finch.fill_range!(C_lvl_val_2, 0, C_lvl_qos, C_lvl_qos_stop)
                    end
                    C_lvl_val_2[C_lvl_qos] = A_lvl_2_val_4 + C_lvl_val_2[C_lvl_qos]
                    C_lvl_left[C_lvl_qos] = phase_start_12
                    C_lvl_right[C_lvl_qos] = phase_stop_11
                    C_lvl_qos += 1
                end
                A_lvl_q += phase_stop_11 == A_lvl_i_stop
                i = phase_stop_11 + limit(0+ϵ)
                break
            end
        end
    end
    phase_start_13 = max(limit(1.0), limit(0+ϵ) + A_lvl_i_end)
    phase_stop_14 = min(B_lvl.shape, B_lvl_i_end)
    if phase_stop_14 >= phase_start_13
        i = phase_start_13
        if B_lvl_right[B_lvl_q] < phase_start_13
            B_lvl_q = Finch.scansearch(B_lvl_right, phase_start_13, B_lvl_q, B_lvl_q_stop - 1)
        end
        while true
            i_start_7 = i
            B_lvl_i_start = B_lvl_left[B_lvl_q]
            B_lvl_i_stop = B_lvl_right[B_lvl_q]
            if B_lvl_i_stop < phase_stop_14
                phase_start_15 = max(B_lvl_i_start, i_start_7)
                if B_lvl_i_stop >= phase_start_15
                    B_lvl_2_val_3 = B_lvl_val[B_lvl_q]
                    if C_lvl_qos > C_lvl_qos_stop
                        C_lvl_qos_stop = max(C_lvl_qos_stop << 1, 1)
                        Finch.resize_if_smaller!(C_lvl_left, C_lvl_qos_stop)
                        Finch.resize_if_smaller!(C_lvl_right, C_lvl_qos_stop)
                        Finch.resize_if_smaller!(C_lvl_val_2, C_lvl_qos_stop)
                        Finch.fill_range!(C_lvl_val_2, 0, C_lvl_qos, C_lvl_qos_stop)
                    end
                    C_lvl_val_2[C_lvl_qos] = B_lvl_2_val_3 + C_lvl_val_2[C_lvl_qos]
                    C_lvl_left[C_lvl_qos] = phase_start_15
                    C_lvl_right[C_lvl_qos] = B_lvl_i_stop
                    C_lvl_qos += 1
                end
                B_lvl_q += B_lvl_i_stop == B_lvl_i_stop
                i = B_lvl_i_stop + limit(0+ϵ)
            else
                phase_start_16 = i
                phase_stop_18 = min(B_lvl_i_stop, phase_stop_14)
                phase_start_18 = max(B_lvl_i_start, phase_start_16)
                if phase_stop_18 >= phase_start_18
                    B_lvl_2_val_4 = B_lvl_val[B_lvl_q]
                    if C_lvl_qos > C_lvl_qos_stop
                        C_lvl_qos_stop = max(C_lvl_qos_stop << 1, 1)
                        Finch.resize_if_smaller!(C_lvl_left, C_lvl_qos_stop)
                        Finch.resize_if_smaller!(C_lvl_right, C_lvl_qos_stop)
                        Finch.resize_if_smaller!(C_lvl_val_2, C_lvl_qos_stop)
                        Finch.fill_range!(C_lvl_val_2, 0, C_lvl_qos, C_lvl_qos_stop)
                    end
                    C_lvl_val_2[C_lvl_qos] = B_lvl_2_val_4 + C_lvl_val_2[C_lvl_qos]
                    C_lvl_left[C_lvl_qos] = phase_start_18
                    C_lvl_right[C_lvl_qos] = phase_stop_18
                    C_lvl_qos += 1
                end
                B_lvl_q += phase_stop_18 == B_lvl_i_stop
                i = phase_stop_18 + limit(0+ϵ)
                break
            end
        end
    end
    C_lvl_ptr[1 + 1] += (C_lvl_qos - 0) - 1
    resize!(C_lvl_ptr, 1 + 1)
    for p = 1:1
        C_lvl_ptr[p + 1] += C_lvl_ptr[p]
    end
    qos_stop = C_lvl_ptr[1 + 1] - 1
    resize!(C_lvl_val_2, qos_stop)
    Finch.resize_if_smaller!(C_lvl_val, qos_stop)
    Finch.fill_range!(C_lvl_val, 0, 1, qos_stop)
    q = 1
    q_2 = 1
    for p_2 = 1:1
        q_stop = C_lvl_ptr[p_2 + 1]
        while q < q_stop
            q_head = q
            while q + 1 < q_stop && C_lvl_right[q] == C_lvl_left[q + 1] - 0
                C_lvl_3_val = C_lvl_val_2[q_head]
                C_lvl_3_val_2 = C_lvl_val_2[1 + q]
                check = isequal(C_lvl_3_val, C_lvl_3_val_2) && true
                if !check
                    break
                else
                    q += 1
                end
            end
            C_lvl_left[q_2] = C_lvl_left[q_head]
            C_lvl_right[q_2] = C_lvl_right[q]
            C_lvl_3_val_3 = C_lvl_val_2[q_head]
            C_lvl_val[q_2] = C_lvl_3_val_3
            q_2 += 1
            q += 1
        end
        C_lvl_ptr[p_2 + 1] = q_2
    end
    resize!(C_lvl_left, q_2 - 1)
    resize!(C_lvl_right, q_2 - 1)
    qos_stop = q_2 - 1
    resize!(C_lvl_val, qos_stop)
    resize!(C_lvl_val_2, 0)
    (C = Tensor((SparseRunListLevel){Float64}(C_lvl_2, B_lvl.shape, C_lvl_ptr, C_lvl_left, C_lvl_right, C_lvl_3; merge = true)),)
end
def 1:
function rangequery(output::Tensor{SparseByteMapLevel{Int64, Vector{Int64}, Vector{Bool}, Vector{Tuple{Int64, Int64}}, PatternLevel{Int64}}}, box::Tensor{SparseIntervalLevel{Float64, Vector{Int64}, Vector{Float64}, Vector{Float64}, SparseIntervalLevel{Float64, Vector{Int64}, Vector{Float64}, Vector{Float64}, PatternLevel{Int64}}}}, points::Tensor{SparseListLevel{Float64, Vector{Int64}, Vector{Float64}, SparseListLevel{Float64, Vector{Int64}, Vector{Float64}, SparsePointLevel{Int64, Vector{Int64}, Vector{Int64}, PatternLevel{Int64}}}}})
    @inbounds @fastmath(begin
                output_lvl = output.lvl
                output_lvl_ptr = output.lvl.ptr
                output_lvl_tbl = output.lvl.tbl
                output_lvl_srt = output.lvl.srt
                output_lvl_qos_stop = (output_lvl_qos_fill = length(output_lvl.srt))
                box_lvl = box.lvl
                box_lvl_ptr = box_lvl.ptr
                box_lvl_left = box_lvl.left
                box_lvl_right = box_lvl.right
                box_lvl_2 = box_lvl.lvl
                box_lvl_ptr_2 = box_lvl_2.ptr
                box_lvl_left_2 = box_lvl_2.left
                box_lvl_right_2 = box_lvl_2.right
                points_lvl = points.lvl
                points_lvl_ptr = points_lvl.ptr
                points_lvl_idx = points_lvl.idx
                points_lvl_2 = points_lvl.lvl
                points_lvl_ptr_2 = points_lvl_2.ptr
                points_lvl_idx_2 = points_lvl_2.idx
                points_lvl_3 = points_lvl_2.lvl
                points_lvl_2_ptr = points_lvl_3.ptr
                points_lvl_2_idx = points_lvl_3.idx
                points_lvl_2.shape == box_lvl_2.shape || throw(DimensionMismatch("mismatched dimension limits ($(points_lvl_2.shape) != $(box_lvl_2.shape))"))
                points_lvl.shape == box_lvl.shape || throw(DimensionMismatch("mismatched dimension limits ($(points_lvl.shape) != $(box_lvl.shape))"))
                for output_lvl_r = 1:output_lvl_qos_fill
                    output_lvl_p = first(output_lvl_srt[output_lvl_r])
                    output_lvl_ptr[output_lvl_p] = 0
                    output_lvl_ptr[output_lvl_p + 1] = 0
                    output_lvl_i = last(output_lvl_srt[output_lvl_r])
                    output_lvl_q = (output_lvl_p - 1) * points_lvl_3.shape + output_lvl_i
                    output_lvl_tbl[output_lvl_q] = false
                end
                output_lvl_qos_fill = 0
                output_lvl_qos_stop = 0
                output_lvl_ptr[1] = 1
                output_lvlq_stop = 1 * points_lvl_3.shape
                Finch.resize_if_smaller!(output_lvl_ptr, 1 + 1)
                Finch.fill_range!(output_lvl_ptr, 0, 1 + 1, 1 + 1)
                output_lvlold = length(output_lvl_tbl) + 1
                Finch.resize_if_smaller!(output_lvl_tbl, output_lvlq_stop)
                Finch.fill_range!(output_lvl_tbl, false, output_lvlold, output_lvlq_stop)
                points_lvl_q = points_lvl_ptr[1]
                points_lvl_q_stop = points_lvl_ptr[1 + 1]
                if points_lvl_q < points_lvl_q_stop
                    points_lvl_i1 = points_lvl_idx[points_lvl_q_stop - 1]
                else
                    points_lvl_i1 = 0.0
                end
                box_lvl_q = box_lvl_ptr[1]
                box_lvl_q_stop = box_lvl_ptr[1 + 1]
                if box_lvl_q < box_lvl_q_stop
                    box_lvl_i_start = box_lvl_left[box_lvl_q]
                    box_lvl_i_stop = box_lvl_right[box_lvl_q]
                else
                    box_lvl_i_start = 1.0
                    box_lvl_i_stop = 0.0
                end
                phase_start_3 = max(box_lvl_i_start, limit(1.0))
                phase_stop_3 = min(points_lvl.shape, points_lvl_i1, box_lvl_i_stop)
                if phase_stop_3 >= phase_start_3
                    if points_lvl_idx[points_lvl_q] < phase_start_3
                        points_lvl_q = Finch.scansearch(points_lvl_idx, phase_start_3, points_lvl_q, points_lvl_q_stop - 1)
                    end
                    while true
                        points_lvl_i = points_lvl_idx[points_lvl_q]
                        if points_lvl_i < phase_stop_3
                            box_lvl_2_q = box_lvl_ptr_2[box_lvl_q]
                            box_lvl_2_q_stop = box_lvl_ptr_2[box_lvl_q + 1]
                            if box_lvl_2_q < box_lvl_2_q_stop
                                box_lvl_2_i_start = box_lvl_left_2[box_lvl_2_q]
                                box_lvl_2_i_stop = box_lvl_right_2[box_lvl_2_q]
                            else
                                box_lvl_2_i_start = 1.0
                                box_lvl_2_i_stop = 0.0
                            end
                            points_lvl_2_q_2 = points_lvl_ptr_2[points_lvl_q]
                            points_lvl_2_q_stop_2 = points_lvl_ptr_2[points_lvl_q + 1]
                            if points_lvl_2_q_2 < points_lvl_2_q_stop_2
                                points_lvl_2_i1_2 = points_lvl_idx_2[points_lvl_2_q_stop_2 - 1]
                            else
                                points_lvl_2_i1_2 = 0.0
                            end
                            phase_start_5 = max(limit(1.0), box_lvl_2_i_start)
                            phase_stop_6 = min(points_lvl_2.shape, points_lvl_2_i1_2, box_lvl_2_i_stop)
                            if phase_stop_6 >= phase_start_5
                                if points_lvl_idx_2[points_lvl_2_q_2] < phase_start_5
                                    points_lvl_2_q_2 = Finch.scansearch(points_lvl_idx_2, phase_start_5, points_lvl_2_q_2, points_lvl_2_q_stop_2 - 1)
                                end
                                while true
                                    points_lvl_2_i_2 = points_lvl_idx_2[points_lvl_2_q_2]
                                    if points_lvl_2_i_2 < phase_stop_6
                                        points_lvl_3_q_2 = points_lvl_2_ptr[points_lvl_2_q_2]
                                        points_lvl_3_q_stop_2 = points_lvl_2_ptr[points_lvl_2_q_2 + 1]
                                        if points_lvl_3_q_2 < points_lvl_3_q_stop_2
                                            points_lvl_3_i_2 = points_lvl_2_idx[points_lvl_3_q_2]
                                        else
                                            points_lvl_3_i_2 = 0
                                        end
                                        phase_stop_8 = min(points_lvl_3_i_2, points_lvl_3.shape)
                                        if phase_stop_8 >= 1
                                            if phase_stop_8 < points_lvl_3_i_2
                                            else
                                                output_lvl_q_2 = (1 - 1) * points_lvl_3.shape + phase_stop_8
                                                if !(output_lvl_tbl[output_lvl_q_2])
                                                    output_lvl_tbl[output_lvl_q_2] = true
                                                    output_lvl_qos_fill += 1
                                                    if output_lvl_qos_fill > output_lvl_qos_stop
                                                        output_lvl_qos_stop = max(output_lvl_qos_stop << 1, 1)
                                                        Finch.resize_if_smaller!(output_lvl_srt, output_lvl_qos_stop)
                                                    end
                                                    output_lvl_srt[output_lvl_qos_fill] = (1, phase_stop_8)
                                                end
                                            end
                                        end
                                        points_lvl_2_q_2 += 1
                                    else
                                        phase_stop_10 = min(phase_stop_6, points_lvl_2_i_2)
                                        if points_lvl_2_i_2 == phase_stop_10
                                            points_lvl_3_q_2 = points_lvl_2_ptr[points_lvl_2_q_2]
                                            points_lvl_3_q_stop_2 = points_lvl_2_ptr[points_lvl_2_q_2 + 1]
                                            if points_lvl_3_q_2 < points_lvl_3_q_stop_2
                                                points_lvl_3_i_2 = points_lvl_2_idx[points_lvl_3_q_2]
                                            else
                                                points_lvl_3_i_2 = 0
                                            end
                                            phase_stop_11 = min(points_lvl_3_i_2, points_lvl_3.shape)
                                            if phase_stop_11 >= 1
                                                if phase_stop_11 < points_lvl_3_i_2
                                                else
                                                    output_lvl_q_2 = (1 - 1) * points_lvl_3.shape + phase_stop_11
                                                    if !(output_lvl_tbl[output_lvl_q_2])
                                                        output_lvl_tbl[output_lvl_q_2] = true
                                                        output_lvl_qos_fill += 1
                                                        if output_lvl_qos_fill > output_lvl_qos_stop
                                                            output_lvl_qos_stop = max(output_lvl_qos_stop << 1, 1)
                                                            Finch.resize_if_smaller!(output_lvl_srt, output_lvl_qos_stop)
                                                        end
                                                        output_lvl_srt[output_lvl_qos_fill] = (1, phase_stop_11)
                                                    end
                                                end
                                            end
                                            points_lvl_2_q_2 += 1
                                        end
                                        break
                                    end
                                end
                            end
                            points_lvl_q += 1
                        else
                            phase_stop_17 = min(phase_stop_3, points_lvl_i)
                            if points_lvl_i == phase_stop_17
                                box_lvl_2_q = box_lvl_ptr_2[box_lvl_q]
                                box_lvl_2_q_stop = box_lvl_ptr_2[box_lvl_q + 1]
                                if box_lvl_2_q < box_lvl_2_q_stop
                                    box_lvl_2_i_start = box_lvl_left_2[box_lvl_2_q]
                                    box_lvl_2_i_stop = box_lvl_right_2[box_lvl_2_q]
                                else
                                    box_lvl_2_i_start = 1.0
                                    box_lvl_2_i_stop = 0.0
                                end
                                points_lvl_2_q_2 = points_lvl_ptr_2[points_lvl_q]
                                points_lvl_2_q_stop_2 = points_lvl_ptr_2[points_lvl_q + 1]
                                if points_lvl_2_q_2 < points_lvl_2_q_stop_2
                                    points_lvl_2_i1_2 = points_lvl_idx_2[points_lvl_2_q_stop_2 - 1]
                                else
                                    points_lvl_2_i1_2 = 0.0
                                end
                                phase_start_17 = max(limit(1.0), box_lvl_2_i_start)
                                phase_stop_19 = min(points_lvl_2.shape, points_lvl_2_i1_2, box_lvl_2_i_stop)
                                if phase_stop_19 >= phase_start_17
                                    if points_lvl_idx_2[points_lvl_2_q_2] < phase_start_17
                                        points_lvl_2_q_2 = Finch.scansearch(points_lvl_idx_2, phase_start_17, points_lvl_2_q_2, points_lvl_2_q_stop_2 - 1)
                                    end
                                    while true
                                        points_lvl_2_i_2 = points_lvl_idx_2[points_lvl_2_q_2]
                                        if points_lvl_2_i_2 < phase_stop_19
                                            points_lvl_3_q_5 = points_lvl_2_ptr[points_lvl_2_q_2]
                                            points_lvl_3_q_stop_5 = points_lvl_2_ptr[points_lvl_2_q_2 + 1]
                                            if points_lvl_3_q_5 < points_lvl_3_q_stop_5
                                                points_lvl_3_i_5 = points_lvl_2_idx[points_lvl_3_q_5]
                                            else
                                                points_lvl_3_i_5 = 0
                                            end
                                            phase_stop_21 = min(points_lvl_3.shape, points_lvl_3_i_5)
                                            if phase_stop_21 >= 1
                                                if phase_stop_21 < points_lvl_3_i_5
                                                else
                                                    output_lvl_q_2 = (1 - 1) * points_lvl_3.shape + phase_stop_21
                                                    if !(output_lvl_tbl[output_lvl_q_2])
                                                        output_lvl_tbl[output_lvl_q_2] = true
                                                        output_lvl_qos_fill += 1
                                                        if output_lvl_qos_fill > output_lvl_qos_stop
                                                            output_lvl_qos_stop = max(output_lvl_qos_stop << 1, 1)
                                                            Finch.resize_if_smaller!(output_lvl_srt, output_lvl_qos_stop)
                                                        end
                                                        output_lvl_srt[output_lvl_qos_fill] = (1, phase_stop_21)
                                                    end
                                                end
                                            end
                                            points_lvl_2_q_2 += 1
                                        else
                                            phase_stop_23 = min(points_lvl_2_i_2, phase_stop_19)
                                            if points_lvl_2_i_2 == phase_stop_23
                                                points_lvl_3_q_5 = points_lvl_2_ptr[points_lvl_2_q_2]
                                                points_lvl_3_q_stop_5 = points_lvl_2_ptr[points_lvl_2_q_2 + 1]
                                                if points_lvl_3_q_5 < points_lvl_3_q_stop_5
                                                    points_lvl_3_i_5 = points_lvl_2_idx[points_lvl_3_q_5]
                                                else
                                                    points_lvl_3_i_5 = 0
                                                end
                                                phase_stop_24 = min(points_lvl_3.shape, points_lvl_3_i_5)
                                                if phase_stop_24 >= 1
                                                    if phase_stop_24 < points_lvl_3_i_5
                                                    else
                                                        output_lvl_q_2 = (1 - 1) * points_lvl_3.shape + phase_stop_24
                                                        if !(output_lvl_tbl[output_lvl_q_2])
                                                            output_lvl_tbl[output_lvl_q_2] = true
                                                            output_lvl_qos_fill += 1
                                                            if output_lvl_qos_fill > output_lvl_qos_stop
                                                                output_lvl_qos_stop = max(output_lvl_qos_stop << 1, 1)
                                                                Finch.resize_if_smaller!(output_lvl_srt, output_lvl_qos_stop)
                                                            end
                                                            output_lvl_srt[output_lvl_qos_fill] = (1, phase_stop_24)
                                                        end
                                                    end
                                                end
                                                points_lvl_2_q_2 += 1
                                            end
                                            break
                                        end
                                    end
                                end
                                points_lvl_q += 1
                            end
                            break
                        end
                    end
                end
                result = ()
                resize!(output_lvl_ptr, 1 + 1)
                resize!(output_lvl_tbl, 1 * points_lvl_3.shape)
                resize!(output_lvl_srt, output_lvl_qos_fill)
                sort!(output_lvl_srt)
                output_lvl_p_prev = 0
                for output_lvl_r_2 = 1:output_lvl_qos_fill
                    output_lvl_p_2 = first(output_lvl_srt[output_lvl_r_2])
                    if output_lvl_p_2 != output_lvl_p_prev
                        output_lvl_ptr[output_lvl_p_prev + 1] = output_lvl_r_2
                        output_lvl_ptr[output_lvl_p_2] = output_lvl_r_2
                    end
                    output_lvl_p_prev = output_lvl_p_2
                end
                output_lvl_ptr[output_lvl_p_prev + 1] = output_lvl_qos_fill + 1
                result
            end)
end
def 2:
function radiusquery(output::Tensor{SparseByteMapLevel{Int64, Vector{Int64}, Vector{Bool}, Vector{Tuple{Int64, Int64}}, PatternLevel{Int64}}}, points::Tensor{SparseListLevel{Float64, Vector{Int64}, Vector{Float64}, SparseListLevel{Float64, Vector{Int64}, Vector{Float64}, SparsePointLevel{Int64, Vector{Int64}, Vector{Int64}, PatternLevel{Int64}}}}}, radius::Float64, ox::Float64, oy::Float64)
    @inbounds @fastmath(begin
                output_lvl = output.lvl
                output_lvl_ptr = output.lvl.ptr
                output_lvl_tbl = output.lvl.tbl
                output_lvl_srt = output.lvl.srt
                output_lvl_qos_stop = (output_lvl_qos_fill = length(output_lvl.srt))
                points_lvl = points.lvl
                points_lvl_ptr = points_lvl.ptr
                points_lvl_idx = points_lvl.idx
                points_lvl_2 = points_lvl.lvl
                points_lvl_ptr_2 = points_lvl_2.ptr
                points_lvl_idx_2 = points_lvl_2.idx
                points_lvl_3 = points_lvl_2.lvl
                points_lvl_2_ptr = points_lvl_3.ptr
                points_lvl_2_idx = points_lvl_3.idx
                y_start = -radius + oy
                y_stop = oy + radius
                x_start = -radius + ox
                x_stop = radius + ox
                for output_lvl_r = 1:output_lvl_qos_fill
                    output_lvl_p = first(output_lvl_srt[output_lvl_r])
                    output_lvl_ptr[output_lvl_p] = 0
                    output_lvl_ptr[output_lvl_p + 1] = 0
                    output_lvl_i = last(output_lvl_srt[output_lvl_r])
                    output_lvl_q = (output_lvl_p - 1) * points_lvl_3.shape + output_lvl_i
                    output_lvl_tbl[output_lvl_q] = false
                end
                output_lvl_qos_fill = 0
                output_lvl_qos_stop = 0
                output_lvl_ptr[1] = 1
                output_lvlq_stop = 1 * points_lvl_3.shape
                Finch.resize_if_smaller!(output_lvl_ptr, 1 + 1)
                Finch.fill_range!(output_lvl_ptr, 0, 1 + 1, 1 + 1)
                output_lvlold = length(output_lvl_tbl) + 1
                Finch.resize_if_smaller!(output_lvl_tbl, output_lvlq_stop)
                Finch.fill_range!(output_lvl_tbl, false, output_lvlold, output_lvlq_stop)
                phase_start_2 = max(x_start, limit(0.0+ϵ))
                phase_stop_2 = min(x_stop, points_lvl.shape)
                if phase_stop_2 >= phase_start_2
                    points_lvl_q = points_lvl_ptr[1]
                    points_lvl_q_stop = points_lvl_ptr[1 + 1]
                    if points_lvl_q < points_lvl_q_stop
                        points_lvl_i1 = points_lvl_idx[points_lvl_q_stop - 1]
                    else
                        points_lvl_i1 = 0.0
                    end
                    phase_stop_3 = min(points_lvl_i1, phase_stop_2)
                    if phase_stop_3 >= phase_start_2
                        if points_lvl_idx[points_lvl_q] < phase_start_2
                            points_lvl_q = Finch.scansearch(points_lvl_idx, phase_start_2, points_lvl_q, points_lvl_q_stop - 1)
                        end
                        while true
                            points_lvl_i = points_lvl_idx[points_lvl_q]
                            if points_lvl_i < phase_stop_3
                                points_lvl_2_q = points_lvl_ptr_2[points_lvl_q]
                                points_lvl_2_q_stop = points_lvl_ptr_2[points_lvl_q + 1]
                                if points_lvl_2_q < points_lvl_2_q_stop
                                    points_lvl_2_i1 = points_lvl_idx_2[points_lvl_2_q_stop - 1]
                                else
                                    points_lvl_2_i1 = 0.0
                                end
                                phase_stop_5 = min(points_lvl_2_i1, y_stop)
                                if phase_stop_5 >= y_start
                                    if points_lvl_idx_2[points_lvl_2_q] < y_start
                                        points_lvl_2_q = Finch.scansearch(points_lvl_idx_2, y_start, points_lvl_2_q, points_lvl_2_q_stop - 1)
                                    end
                                    while true
                                        points_lvl_2_i = points_lvl_idx_2[points_lvl_2_q]
                                        if points_lvl_2_i < phase_stop_5
                                            cond = (-ox + points_lvl_i) ^ 2 + (-oy + points_lvl_2_i) ^ 2 <= radius ^ 2
                                            if cond
                                                points_lvl_3_q = points_lvl_2_ptr[points_lvl_2_q]
                                                points_lvl_3_q_stop = points_lvl_2_ptr[points_lvl_2_q + 1]
                                                if points_lvl_3_q < points_lvl_3_q_stop
                                                    points_lvl_3_i = points_lvl_2_idx[points_lvl_3_q]
                                                else
                                                    points_lvl_3_i = 0
                                                end
                                                phase_stop_7 = min(points_lvl_3_i, points_lvl_3.shape)
                                                if phase_stop_7 >= 1
                                                    if phase_stop_7 < points_lvl_3_i
                                                    else
                                                        output_lvl_q_2 = (1 - 1) * points_lvl_3.shape + phase_stop_7
                                                        if !(output_lvl_tbl[output_lvl_q_2])
                                                            output_lvl_tbl[output_lvl_q_2] = true
                                                            output_lvl_qos_fill += 1
                                                            if output_lvl_qos_fill > output_lvl_qos_stop
                                                                output_lvl_qos_stop = max(output_lvl_qos_stop << 1, 1)
                                                                Finch.resize_if_smaller!(output_lvl_srt, output_lvl_qos_stop)
                                                            end
                                                            output_lvl_srt[output_lvl_qos_fill] = (1, phase_stop_7)
                                                        end
                                                    end
                                                end
                                            end
                                            points_lvl_2_q += 1
                                        else
                                            phase_stop_9 = min(phase_stop_5, points_lvl_2_i)
                                            if points_lvl_2_i == phase_stop_9
                                                cond_2 = (-ox + points_lvl_i) ^ 2 + (-oy + phase_stop_9) ^ 2 <= radius ^ 2
                                                if cond_2
                                                    points_lvl_3_q = points_lvl_2_ptr[points_lvl_2_q]
                                                    points_lvl_3_q_stop = points_lvl_2_ptr[points_lvl_2_q + 1]
                                                    if points_lvl_3_q < points_lvl_3_q_stop
                                                        points_lvl_3_i = points_lvl_2_idx[points_lvl_3_q]
                                                    else
                                                        points_lvl_3_i = 0
                                                    end
                                                    phase_stop_10 = min(points_lvl_3_i, points_lvl_3.shape)
                                                    if phase_stop_10 >= 1
                                                        if phase_stop_10 < points_lvl_3_i
                                                        else
                                                            output_lvl_q_2 = (1 - 1) * points_lvl_3.shape + phase_stop_10
                                                            if !(output_lvl_tbl[output_lvl_q_2])
                                                                output_lvl_tbl[output_lvl_q_2] = true
                                                                output_lvl_qos_fill += 1
                                                                if output_lvl_qos_fill > output_lvl_qos_stop
                                                                    output_lvl_qos_stop = max(output_lvl_qos_stop << 1, 1)
                                                                    Finch.resize_if_smaller!(output_lvl_srt, output_lvl_qos_stop)
                                                                end
                                                                output_lvl_srt[output_lvl_qos_fill] = (1, phase_stop_10)
                                                            end
                                                        end
                                                    end
                                                end
                                                points_lvl_2_q += 1
                                            end
                                            break
                                        end
                                    end
                                end
                                points_lvl_q += 1
                            else
                                phase_stop_13 = min(phase_stop_3, points_lvl_i)
                                if points_lvl_i == phase_stop_13
                                    points_lvl_2_q = points_lvl_ptr_2[points_lvl_q]
                                    points_lvl_2_q_stop = points_lvl_ptr_2[points_lvl_q + 1]
                                    if points_lvl_2_q < points_lvl_2_q_stop
                                        points_lvl_2_i1 = points_lvl_idx_2[points_lvl_2_q_stop - 1]
                                    else
                                        points_lvl_2_i1 = 0.0
                                    end
                                    phase_stop_14 = min(points_lvl_2_i1, y_stop)
                                    if phase_stop_14 >= y_start
                                        if points_lvl_idx_2[points_lvl_2_q] < y_start
                                            points_lvl_2_q = Finch.scansearch(points_lvl_idx_2, y_start, points_lvl_2_q, points_lvl_2_q_stop - 1)
                                        end
                                        while true
                                            points_lvl_2_i = points_lvl_idx_2[points_lvl_2_q]
                                            if points_lvl_2_i < phase_stop_14
                                                cond_3 = (-ox + phase_stop_13) ^ 2 + (-oy + points_lvl_2_i) ^ 2 <= radius ^ 2
                                                if cond_3
                                                    points_lvl_3_q_2 = points_lvl_2_ptr[points_lvl_2_q]
                                                    points_lvl_3_q_stop_2 = points_lvl_2_ptr[points_lvl_2_q + 1]
                                                    if points_lvl_3_q_2 < points_lvl_3_q_stop_2
                                                        points_lvl_3_i_2 = points_lvl_2_idx[points_lvl_3_q_2]
                                                    else
                                                        points_lvl_3_i_2 = 0
                                                    end
                                                    phase_stop_16 = min(points_lvl_3.shape, points_lvl_3_i_2)
                                                    if phase_stop_16 >= 1
                                                        if phase_stop_16 < points_lvl_3_i_2
                                                        else
                                                            output_lvl_q_2 = (1 - 1) * points_lvl_3.shape + phase_stop_16
                                                            if !(output_lvl_tbl[output_lvl_q_2])
                                                                output_lvl_tbl[output_lvl_q_2] = true
                                                                output_lvl_qos_fill += 1
                                                                if output_lvl_qos_fill > output_lvl_qos_stop
                                                                    output_lvl_qos_stop = max(output_lvl_qos_stop << 1, 1)
                                                                    Finch.resize_if_smaller!(output_lvl_srt, output_lvl_qos_stop)
                                                                end
                                                                output_lvl_srt[output_lvl_qos_fill] = (1, phase_stop_16)
                                                            end
                                                        end
                                                    end
                                                end
                                                points_lvl_2_q += 1
                                            else
                                                phase_stop_18 = min(points_lvl_2_i, phase_stop_14)
                                                if points_lvl_2_i == phase_stop_18
                                                    cond_4 = (-ox + phase_stop_13) ^ 2 + (-oy + phase_stop_18) ^ 2 <= radius ^ 2
                                                    if cond_4
                                                        points_lvl_3_q_2 = points_lvl_2_ptr[points_lvl_2_q]
                                                        points_lvl_3_q_stop_2 = points_lvl_2_ptr[points_lvl_2_q + 1]
                                                        if points_lvl_3_q_2 < points_lvl_3_q_stop_2
                                                            points_lvl_3_i_2 = points_lvl_2_idx[points_lvl_3_q_2]
                                                        else
                                                            points_lvl_3_i_2 = 0
                                                        end
                                                        phase_stop_19 = min(points_lvl_3.shape, points_lvl_3_i_2)
                                                        if phase_stop_19 >= 1
                                                            if phase_stop_19 < points_lvl_3_i_2
                                                            else
                                                                output_lvl_q_2 = (1 - 1) * points_lvl_3.shape + phase_stop_19
                                                                if !(output_lvl_tbl[output_lvl_q_2])
                                                                    output_lvl_tbl[output_lvl_q_2] = true
                                                                    output_lvl_qos_fill += 1
                                                                    if output_lvl_qos_fill > output_lvl_qos_stop
                                                                        output_lvl_qos_stop = max(output_lvl_qos_stop << 1, 1)
                                                                        Finch.resize_if_smaller!(output_lvl_srt, output_lvl_qos_stop)
                                                                    end
                                                                    output_lvl_srt[output_lvl_qos_fill] = (1, phase_stop_19)
                                                                end
                                                            end
                                                        end
                                                    end
                                                    points_lvl_2_q += 1
                                                end
                                                break
                                            end
                                        end
                                    end
                                    points_lvl_q += 1
                                end
                                break
                            end
                        end
                    end
                end
                result = ()
                resize!(output_lvl_ptr, 1 + 1)
                resize!(output_lvl_tbl, 1 * points_lvl_3.shape)
                resize!(output_lvl_srt, output_lvl_qos_fill)
                sort!(output_lvl_srt)
                output_lvl_p_prev = 0
                for output_lvl_r_2 = 1:output_lvl_qos_fill
                    output_lvl_p_2 = first(output_lvl_srt[output_lvl_r_2])
                    if output_lvl_p_2 != output_lvl_p_prev
                        output_lvl_ptr[output_lvl_p_prev + 1] = output_lvl_r_2
                        output_lvl_ptr[output_lvl_p_2] = output_lvl_r_2
                    end
                    output_lvl_p_prev = output_lvl_p_2
                end
                output_lvl_ptr[output_lvl_p_prev + 1] = output_lvl_qos_fill + 1
                result
            end)
end
ex 2:
begin
    output_lvl = (ex.bodies[1]).body.cond.tns.bind.lvl
    output_lvl_ptr = (ex.bodies[1]).body.cond.tns.bind.lvl.ptr
    output_lvl_srt = (ex.bodies[1]).body.cond.tns.bind.lvl.srt
    count = (ex.bodies[1]).body.body.lhs.tns.bind
    count_val = count.val
    output_lvl_r = output_lvl_ptr[1]
    output_lvl_r_stop = output_lvl_ptr[1 + 1]
    if output_lvl_r != 0 && output_lvl_r < output_lvl_r_stop
        output_lvl_i_stop = last(output_lvl_srt[output_lvl_r_stop - 1])
    else
        output_lvl_i_stop = 0
    end
    phase_stop = min(output_lvl_i_stop, output_lvl.shape)
    if phase_stop >= 1
        while output_lvl_r + 1 < output_lvl_r_stop && last(output_lvl_srt[output_lvl_r]) < 1
            output_lvl_r += 1
        end
        while true
            output_lvl_i = last(output_lvl_srt[output_lvl_r])
            if output_lvl_i < phase_stop
                count_val = 1 + count_val
                output_lvl_r += 1
            else
                phase_stop_3 = min(phase_stop, output_lvl_i)
                if output_lvl_i == phase_stop_3
                    count_val = 1 + count_val
                    output_lvl_r += 1
                end
                break
            end
        end
    end
    result = ()
    count.val = count_val
    result
end
ex 3:
begin
    output_lvl = (ex.bodies[1]).body.cond.tns.bind.lvl
    output_lvl_ptr = (ex.bodies[1]).body.cond.tns.bind.lvl.ptr
    output_lvl_srt = (ex.bodies[1]).body.cond.tns.bind.lvl.srt
    count = (ex.bodies[1]).body.body.lhs.tns.bind
    count_val = count.val
    output_lvl_r = output_lvl_ptr[1]
    output_lvl_r_stop = output_lvl_ptr[1 + 1]
    if output_lvl_r != 0 && output_lvl_r < output_lvl_r_stop
        output_lvl_i_stop = last(output_lvl_srt[output_lvl_r_stop - 1])
    else
        output_lvl_i_stop = 0
    end
    phase_stop = min(output_lvl_i_stop, output_lvl.shape)
    if phase_stop >= 1
        while output_lvl_r + 1 < output_lvl_r_stop && last(output_lvl_srt[output_lvl_r]) < 1
            output_lvl_r += 1
        end
        while true
            output_lvl_i = last(output_lvl_srt[output_lvl_r])
            if output_lvl_i < phase_stop
                count_val = 1 + count_val
                output_lvl_r += 1
            else
                phase_stop_3 = min(phase_stop, output_lvl_i)
                if output_lvl_i == phase_stop_3
                    count_val = 1 + count_val
                    output_lvl_r += 1
                end
                break
            end
        end
    end
    result = ()
    count.val = count_val
    result
end
Test Summary: | Pass  Total   Time
Finch.jl      |    4      4  29.8s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant