Skip to content

Commit

Permalink
add a little more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Willow Ahrens committed Oct 8, 2023
1 parent c11b475 commit c95091f
Show file tree
Hide file tree
Showing 10 changed files with 696 additions and 9 deletions.
6 changes: 0 additions & 6 deletions src/tensors/levels/sparsebytemaplevels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,6 @@ function thaw_level!(lvl::VirtualSparseByteMapLevel, ctx::AbstractCompiler, pos)
Ti = lvl.Ti
Tp = postype(lvl)
p = freshen(ctx.code, lvl.ex, :_p)
push!(ctx.code.preamble, quote
for $p = 1:$(ctx(pos))
$(lvl.ptr)[$p] -= $(lvl.ptr)[$p + 1]
end
$(lvl.ptr)[1] = 1
end)
lvl.lvl = thaw_level!(lvl.lvl, ctx, call(*, pos, lvl.shape))
return lvl
end
Expand Down
4 changes: 2 additions & 2 deletions src/tensors/levels/sparsehashlevels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ function thaw_level!(lvl::VirtualSparseHashLevel, ctx::AbstractCompiler, pos)
Tp = postype(lvl)
p = freshen(ctx.code, lvl.ex, :_p)
push!(ctx.code.preamble, quote
for $p = 1:$(ctx(pos))
$(lvl.ptr)[$p] -= $(lvl.ptr)[$p + 1]
for $p = $(ctx(pos)) + 1:-1:2
$(lvl.ptr)[$p] -= $(lvl.ptr)[$p - 1]
end
$(lvl.ptr)[1] = 1
$(lvl.qos_fill) = length($(lvl.tbl))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
begin
fmt_lvl = ex.body.body.lhs.tns.bind.lvl
fmt_lvl_qos_fill = length(fmt_lvl.tbl)
fmt_lvl_qos_stop = fmt_lvl_qos_fill
fmt_lvl_ptr = ex.body.body.lhs.tns.bind.lvl.ptr
fmt_lvl_tbl = ex.body.body.lhs.tns.bind.lvl.tbl
fmt_lvl_srt = ex.body.body.lhs.tns.bind.lvl.srt
fmt_lvl_2 = fmt_lvl.lvl
fmt_lvl_val = fmt_lvl.lvl.val
arr_2_lvl = ex.body.body.rhs.tns.bind.lvl
arr_2_lvl_ptr = ex.body.body.rhs.tns.bind.lvl.ptr
arr_2_lvl_tbl1 = ex.body.body.rhs.tns.bind.lvl.tbl[1]
arr_2_lvl_tbl2 = ex.body.body.rhs.tns.bind.lvl.tbl[2]
arr_2_lvl_val = arr_2_lvl.lvl.val
arr_2_lvl.shape[1] == fmt_lvl.shape[1] || throw(DimensionMismatch("mismatched dimension limits ($(arr_2_lvl.shape[1]) != $(fmt_lvl.shape[1]))"))
arr_2_lvl.shape[2] == fmt_lvl.shape[2] || throw(DimensionMismatch("mismatched dimension limits ($(arr_2_lvl.shape[2]) != $(fmt_lvl.shape[2]))"))
for fmt_lvl_p = 1:1
fmt_lvl_ptr[fmt_lvl_p] = fmt_lvl_ptr[fmt_lvl_p] - fmt_lvl_ptr[fmt_lvl_p + 1]
end
fmt_lvl_ptr[1] = 1
fmt_lvl_qos_fill = length(fmt_lvl_tbl)
arr_2_lvl_q = arr_2_lvl_ptr[1]
arr_2_lvl_q_stop = arr_2_lvl_ptr[1 + 1]
if arr_2_lvl_q < arr_2_lvl_q_stop
arr_2_lvl_i_stop = arr_2_lvl_tbl2[arr_2_lvl_q_stop - 1]
else
arr_2_lvl_i_stop = 0
end
phase_stop = min(arr_2_lvl.shape[2], arr_2_lvl_i_stop)
if phase_stop >= 1
j = 1
if arr_2_lvl_tbl2[arr_2_lvl_q] < 1
arr_2_lvl_q = Finch.scansearch(arr_2_lvl_tbl2, 1, arr_2_lvl_q, arr_2_lvl_q_stop - 1)
end
while j <= phase_stop
arr_2_lvl_i = arr_2_lvl_tbl2[arr_2_lvl_q]
arr_2_lvl_q_step = arr_2_lvl_q
if arr_2_lvl_tbl2[arr_2_lvl_q] == arr_2_lvl_i
arr_2_lvl_q_step = Finch.scansearch(arr_2_lvl_tbl2, arr_2_lvl_i + 1, arr_2_lvl_q, arr_2_lvl_q_stop - 1)
end
phase_stop_2 = min(phase_stop, arr_2_lvl_i)
if arr_2_lvl_i == phase_stop_2
arr_2_lvl_q_2 = arr_2_lvl_q
if arr_2_lvl_q < arr_2_lvl_q_step
arr_2_lvl_i_stop_2 = arr_2_lvl_tbl1[arr_2_lvl_q_step - 1]
else
arr_2_lvl_i_stop_2 = 0
end
phase_stop_3 = min(arr_2_lvl.shape[1], arr_2_lvl_i_stop_2)
if phase_stop_3 >= 1
i = 1
if arr_2_lvl_tbl1[arr_2_lvl_q] < 1
arr_2_lvl_q_2 = Finch.scansearch(arr_2_lvl_tbl1, 1, arr_2_lvl_q, arr_2_lvl_q_step - 1)
end
while i <= phase_stop_3
arr_2_lvl_i_2 = arr_2_lvl_tbl1[arr_2_lvl_q_2]
phase_stop_4 = min(phase_stop_3, arr_2_lvl_i_2)
if arr_2_lvl_i_2 == phase_stop_4
arr_2_lvl_2_val = arr_2_lvl_val[arr_2_lvl_q_2]
fmt_lvl_key_2 = (1, (phase_stop_4, phase_stop_2))
fmt_lvl_q_2 = get(fmt_lvl_tbl, fmt_lvl_key_2, fmt_lvl_qos_fill + 1)
if fmt_lvl_q_2 > fmt_lvl_qos_stop
fmt_lvl_qos_stop = max(fmt_lvl_qos_stop << 1, 1)
Finch.resize_if_smaller!(fmt_lvl_val, fmt_lvl_qos_stop)
Finch.fill_range!(fmt_lvl_val, 0.0, fmt_lvl_q_2, fmt_lvl_qos_stop)
end
fmt_lvl_val[fmt_lvl_q_2] = arr_2_lvl_2_val + fmt_lvl_val[fmt_lvl_q_2]
if fmt_lvl_q_2 > fmt_lvl_qos_fill
fmt_lvl_qos_fill = fmt_lvl_q_2
fmt_lvl_tbl[fmt_lvl_key_2] = fmt_lvl_q_2
fmt_lvl_ptr[1 + 1] += 1
end
arr_2_lvl_q_2 += 1
end
i = phase_stop_4 + 1
end
end
arr_2_lvl_q = arr_2_lvl_q_step
end
j = phase_stop_2 + 1
end
end
resize!(fmt_lvl_srt, length(fmt_lvl_tbl))
copyto!(fmt_lvl_srt, pairs(fmt_lvl_tbl))
sort!(fmt_lvl_srt, by = hashkeycmp)
for p = 2:1 + 1
fmt_lvl_ptr[p] += fmt_lvl_ptr[p - 1]
end
resize!(fmt_lvl_ptr, 1 + 1)
qos = fmt_lvl_ptr[end] - 1
resize!(fmt_lvl_srt, qos)
resize!(fmt_lvl_val, qos)
(fmt = Fiber((SparseHashLevel){2, Tuple{Int64, Int64}}(fmt_lvl_2, (fmt_lvl.shape[1], fmt_lvl.shape[2]), fmt_lvl_ptr, fmt_lvl_tbl, fmt_lvl_srt)),)
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
begin
fmt_lvl = ex.body.body.lhs.tns.bind.lvl
fmt_lvl_2 = fmt_lvl.lvl
fmt_lvl_ptr = fmt_lvl.lvl.ptr
fmt_lvl_tbl = fmt_lvl.lvl.tbl
fmt_lvl_srt = fmt_lvl.lvl.srt
fmt_lvl_2_qos_stop = (fmt_lvl_2_qos_fill = length(fmt_lvl_2.srt))
fmt_lvl_3 = fmt_lvl_2.lvl
fmt_lvl_2_val = fmt_lvl_2.lvl.val
arr_2_lvl = ex.body.body.rhs.tns.bind.lvl
arr_2_lvl_ptr = ex.body.body.rhs.tns.bind.lvl.ptr
arr_2_lvl_tbl1 = ex.body.body.rhs.tns.bind.lvl.tbl[1]
arr_2_lvl_tbl2 = ex.body.body.rhs.tns.bind.lvl.tbl[2]
arr_2_lvl_val = arr_2_lvl.lvl.val
arr_2_lvl.shape[1] == fmt_lvl_2.shape || throw(DimensionMismatch("mismatched dimension limits ($(arr_2_lvl.shape[1]) != $(fmt_lvl_2.shape))"))
arr_2_lvl.shape[2] == fmt_lvl.shape || throw(DimensionMismatch("mismatched dimension limits ($(arr_2_lvl.shape[2]) != $(fmt_lvl.shape))"))
arr_2_lvl_q = arr_2_lvl_ptr[1]
arr_2_lvl_q_stop = arr_2_lvl_ptr[1 + 1]
if arr_2_lvl_q < arr_2_lvl_q_stop
arr_2_lvl_i_stop = arr_2_lvl_tbl2[arr_2_lvl_q_stop - 1]
else
arr_2_lvl_i_stop = 0
end
phase_stop = min(arr_2_lvl.shape[2], arr_2_lvl_i_stop)
if phase_stop >= 1
j = 1
if arr_2_lvl_tbl2[arr_2_lvl_q] < 1
arr_2_lvl_q = Finch.scansearch(arr_2_lvl_tbl2, 1, arr_2_lvl_q, arr_2_lvl_q_stop - 1)
end
while j <= phase_stop
arr_2_lvl_i = arr_2_lvl_tbl2[arr_2_lvl_q]
arr_2_lvl_q_step = arr_2_lvl_q
if arr_2_lvl_tbl2[arr_2_lvl_q] == arr_2_lvl_i
arr_2_lvl_q_step = Finch.scansearch(arr_2_lvl_tbl2, arr_2_lvl_i + 1, arr_2_lvl_q, arr_2_lvl_q_stop - 1)
end
phase_stop_2 = min(phase_stop, arr_2_lvl_i)
if arr_2_lvl_i == phase_stop_2
fmt_lvl_q = (1 - 1) * fmt_lvl.shape + phase_stop_2
arr_2_lvl_q_2 = arr_2_lvl_q
if arr_2_lvl_q < arr_2_lvl_q_step
arr_2_lvl_i_stop_2 = arr_2_lvl_tbl1[arr_2_lvl_q_step - 1]
else
arr_2_lvl_i_stop_2 = 0
end
phase_stop_3 = min(arr_2_lvl.shape[1], arr_2_lvl_i_stop_2)
if phase_stop_3 >= 1
i = 1
if arr_2_lvl_tbl1[arr_2_lvl_q] < 1
arr_2_lvl_q_2 = Finch.scansearch(arr_2_lvl_tbl1, 1, arr_2_lvl_q, arr_2_lvl_q_step - 1)
end
while i <= phase_stop_3
arr_2_lvl_i_2 = arr_2_lvl_tbl1[arr_2_lvl_q_2]
phase_stop_4 = min(phase_stop_3, arr_2_lvl_i_2)
if arr_2_lvl_i_2 == phase_stop_4
arr_2_lvl_2_val = arr_2_lvl_val[arr_2_lvl_q_2]
fmt_lvl_2_q = (fmt_lvl_q - 1) * fmt_lvl_2.shape + phase_stop_4
fmt_lvl_2_val[fmt_lvl_2_q] = arr_2_lvl_2_val + fmt_lvl_2_val[fmt_lvl_2_q]
if !(fmt_lvl_tbl[fmt_lvl_2_q])
fmt_lvl_tbl[fmt_lvl_2_q] = true
fmt_lvl_2_qos_fill += 1
if fmt_lvl_2_qos_fill > fmt_lvl_2_qos_stop
fmt_lvl_2_qos_stop = max(fmt_lvl_2_qos_stop << 1, 1)
Finch.resize_if_smaller!(fmt_lvl_srt, fmt_lvl_2_qos_stop)
end
fmt_lvl_srt[fmt_lvl_2_qos_fill] = (fmt_lvl_q, phase_stop_4)
end
arr_2_lvl_q_2 += 1
end
i = phase_stop_4 + 1
end
end
arr_2_lvl_q = arr_2_lvl_q_step
end
j = phase_stop_2 + 1
end
end
sort!(view(fmt_lvl_srt, 1:fmt_lvl_2_qos_fill))
fmt_lvl_2_p_prev = 0
for fmt_lvl_2_r = 1:fmt_lvl_2_qos_fill
fmt_lvl_2_p_2 = first(fmt_lvl_srt[fmt_lvl_2_r])
if fmt_lvl_2_p_2 != fmt_lvl_2_p_prev
fmt_lvl_ptr[fmt_lvl_2_p_prev + 1] = fmt_lvl_2_r
fmt_lvl_ptr[fmt_lvl_2_p_2] = fmt_lvl_2_r
end
fmt_lvl_2_p_prev = fmt_lvl_2_p_2
end
fmt_lvl_ptr[fmt_lvl_2_p_2 + 1] = fmt_lvl_2_qos_fill + 1
qos = 1 * fmt_lvl.shape
resize!(fmt_lvl_ptr, qos + 1)
resize!(fmt_lvl_tbl, qos * fmt_lvl_2.shape)
resize!(fmt_lvl_srt, fmt_lvl_2_qos_fill)
resize!(fmt_lvl_2_val, qos * fmt_lvl_2.shape)
(fmt = Fiber((DenseLevel){Int64}((SparseByteMapLevel){Int64}(fmt_lvl_3, fmt_lvl_2.shape, fmt_lvl_ptr, fmt_lvl_tbl, fmt_lvl_srt), fmt_lvl.shape)),)
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
begin
fmt_lvl = ex.body.body.lhs.tns.bind.lvl
fmt_lvl_2 = fmt_lvl.lvl
fmt_lvl_2_qos_fill = length(fmt_lvl_2.tbl)
fmt_lvl_2_qos_stop = fmt_lvl_2_qos_fill
fmt_lvl_ptr = fmt_lvl.lvl.ptr
fmt_lvl_tbl = fmt_lvl.lvl.tbl
fmt_lvl_srt = fmt_lvl.lvl.srt
fmt_lvl_3 = fmt_lvl_2.lvl
fmt_lvl_2_val = fmt_lvl_2.lvl.val
arr_2_lvl = ex.body.body.rhs.tns.bind.lvl
arr_2_lvl_ptr = ex.body.body.rhs.tns.bind.lvl.ptr
arr_2_lvl_tbl1 = ex.body.body.rhs.tns.bind.lvl.tbl[1]
arr_2_lvl_tbl2 = ex.body.body.rhs.tns.bind.lvl.tbl[2]
arr_2_lvl_val = arr_2_lvl.lvl.val
arr_2_lvl.shape[1] == fmt_lvl_2.shape[1] || throw(DimensionMismatch("mismatched dimension limits ($(arr_2_lvl.shape[1]) != $(fmt_lvl_2.shape[1]))"))
arr_2_lvl.shape[2] == fmt_lvl.shape || throw(DimensionMismatch("mismatched dimension limits ($(arr_2_lvl.shape[2]) != $(fmt_lvl.shape))"))
for fmt_lvl_2_p = 1 * fmt_lvl.shape:-1:1
fmt_lvl_ptr[fmt_lvl_2_p + 1] = fmt_lvl_ptr[fmt_lvl_2_p + 1] - fmt_lvl_ptr[fmt_lvl_2_p]
end
fmt_lvl_ptr[1] = 1
fmt_lvl_2_qos_fill = length(fmt_lvl_tbl)
arr_2_lvl_q = arr_2_lvl_ptr[1]
arr_2_lvl_q_stop = arr_2_lvl_ptr[1 + 1]
if arr_2_lvl_q < arr_2_lvl_q_stop
arr_2_lvl_i_stop = arr_2_lvl_tbl2[arr_2_lvl_q_stop - 1]
else
arr_2_lvl_i_stop = 0
end
phase_stop = min(arr_2_lvl.shape[2], arr_2_lvl_i_stop)
if phase_stop >= 1
j = 1
if arr_2_lvl_tbl2[arr_2_lvl_q] < 1
arr_2_lvl_q = Finch.scansearch(arr_2_lvl_tbl2, 1, arr_2_lvl_q, arr_2_lvl_q_stop - 1)
end
while j <= phase_stop
arr_2_lvl_i = arr_2_lvl_tbl2[arr_2_lvl_q]
arr_2_lvl_q_step = arr_2_lvl_q
if arr_2_lvl_tbl2[arr_2_lvl_q] == arr_2_lvl_i
arr_2_lvl_q_step = Finch.scansearch(arr_2_lvl_tbl2, arr_2_lvl_i + 1, arr_2_lvl_q, arr_2_lvl_q_stop - 1)
end
phase_stop_2 = min(phase_stop, arr_2_lvl_i)
if arr_2_lvl_i == phase_stop_2
fmt_lvl_q = (1 - 1) * fmt_lvl.shape + phase_stop_2
arr_2_lvl_q_2 = arr_2_lvl_q
if arr_2_lvl_q < arr_2_lvl_q_step
arr_2_lvl_i_stop_2 = arr_2_lvl_tbl1[arr_2_lvl_q_step - 1]
else
arr_2_lvl_i_stop_2 = 0
end
phase_stop_3 = min(arr_2_lvl.shape[1], arr_2_lvl_i_stop_2)
if phase_stop_3 >= 1
i = 1
if arr_2_lvl_tbl1[arr_2_lvl_q] < 1
arr_2_lvl_q_2 = Finch.scansearch(arr_2_lvl_tbl1, 1, arr_2_lvl_q, arr_2_lvl_q_step - 1)
end
while i <= phase_stop_3
arr_2_lvl_i_2 = arr_2_lvl_tbl1[arr_2_lvl_q_2]
phase_stop_4 = min(phase_stop_3, arr_2_lvl_i_2)
if arr_2_lvl_i_2 == phase_stop_4
arr_2_lvl_2_val = arr_2_lvl_val[arr_2_lvl_q_2]
fmt_lvl_2_key = (fmt_lvl_q, (phase_stop_4,))
fmt_lvl_2_q = get(fmt_lvl_tbl, fmt_lvl_2_key, fmt_lvl_2_qos_fill + 1)
if fmt_lvl_2_q > fmt_lvl_2_qos_stop
fmt_lvl_2_qos_stop = max(fmt_lvl_2_qos_stop << 1, 1)
Finch.resize_if_smaller!(fmt_lvl_2_val, fmt_lvl_2_qos_stop)
Finch.fill_range!(fmt_lvl_2_val, 0.0, fmt_lvl_2_q, fmt_lvl_2_qos_stop)
end
fmt_lvl_2_val[fmt_lvl_2_q] = arr_2_lvl_2_val + fmt_lvl_2_val[fmt_lvl_2_q]
if fmt_lvl_2_q > fmt_lvl_2_qos_fill
fmt_lvl_2_qos_fill = fmt_lvl_2_q
fmt_lvl_tbl[fmt_lvl_2_key] = fmt_lvl_2_q
fmt_lvl_ptr[fmt_lvl_q + 1] += 1
end
arr_2_lvl_q_2 += 1
end
i = phase_stop_4 + 1
end
end
arr_2_lvl_q = arr_2_lvl_q_step
end
j = phase_stop_2 + 1
end
end
resize!(fmt_lvl_srt, length(fmt_lvl_tbl))
copyto!(fmt_lvl_srt, pairs(fmt_lvl_tbl))
sort!(fmt_lvl_srt, by = hashkeycmp)
for p = 2:fmt_lvl.shape + 1
fmt_lvl_ptr[p] += fmt_lvl_ptr[p - 1]
end
qos = 1 * fmt_lvl.shape
resize!(fmt_lvl_ptr, qos + 1)
qos_2 = fmt_lvl_ptr[end] - 1
resize!(fmt_lvl_srt, qos_2)
resize!(fmt_lvl_2_val, qos_2)
(fmt = Fiber((DenseLevel){Int64}((SparseHashLevel){1, Tuple{Int64}}(fmt_lvl_3, (fmt_lvl_2.shape[1],), fmt_lvl_ptr, fmt_lvl_tbl, fmt_lvl_srt), fmt_lvl.shape)),)
end
Loading

0 comments on commit c95091f

Please sign in to comment.