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

SingleList Level #374

Merged
merged 5 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Finch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export fastfinch, safefinch, debugfinch
export Tensor
export SparseRLE, SparseRLELevel
export SparseList, SparseListLevel
export SingleList, SingleListLevel
export SparseHash, SparseHashLevel
export SparseCOO, SparseCOOLevel
export SparseTriangle, SparseTriangleLevel
Expand Down Expand Up @@ -102,6 +103,7 @@ include("tensors/levels/abstractlevel.jl")
include("tensors/fibers.jl")
include("tensors/levels/sparserlelevels.jl")
include("tensors/levels/sparselistlevels.jl")
include("tensors/levels/singlelistlevels.jl")
include("tensors/levels/sparsehashlevels.jl")
include("tensors/levels/sparsecoolevels.jl")
include("tensors/levels/sparsebytemaplevels.jl")
Expand Down
341 changes: 341 additions & 0 deletions src/tensors/levels/singlelistlevels.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,341 @@
struct SingleListLevel{Ti, Ptr, Idx, Lvl} <: AbstractLevel
lvl::Lvl
shape::Ti
ptr::Ptr
idx::Idx
end
const SingleList = SingleListLevel
SingleListLevel(lvl) = SingleListLevel{Int}(lvl)
SingleListLevel(lvl, shape::Ti) where {Ti} = SingleListLevel{Ti}(lvl, shape)
SingleListLevel{Ti}(lvl) where {Ti} = SingleListLevel{Ti}(lvl, zero(Ti))
SingleListLevel{Ti}(lvl, shape) where {Ti} = SingleListLevel{Ti}(lvl, shape, postype(lvl)[1], Ti[])

Check warning on line 11 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L8-L11

Added lines #L8 - L11 were not covered by tests

SingleListLevel{Ti}(lvl::Lvl, shape, ptr::Ptr, idx::Idx) where {Ti, Lvl, Ptr, Idx} =

Check warning on line 13 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L13

Added line #L13 was not covered by tests
SingleListLevel{Ti, Ptr, Idx, Lvl}(lvl, shape, ptr, idx)

Base.summary(lvl::SingleListLevel) = "SingleList($(summary(lvl.lvl)))"
similar_level(lvl::SingleListLevel) = SingleList(similar_level(lvl.lvl))
similar_level(lvl::SingleListLevel, dim, tail...) = SingleList(similar_level(lvl.lvl, tail...), dim)

Check warning on line 18 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L16-L18

Added lines #L16 - L18 were not covered by tests

function postype(::Type{SingleListLevel{Ti, Ptr, Idx, Lvl}}) where {Ti, Ptr, Idx, Lvl}
return postype(Lvl)

Check warning on line 21 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L20-L21

Added lines #L20 - L21 were not covered by tests
end

function moveto(lvl::SingleListLevel{Ti, Ptr, Idx, Lvl}, Tm) where {Ti, Ptr, Idx, Lvl}
lvl_2 = moveto(lvl.lvl, Tm)
ptr_2 = moveto(lvl.ptr, Tm)
idx_2 = moveto(lvl.idx, Tm)
return SingleListLevel{Ti}(lvl_2, lvl.shape, ptr_2, idx_2)

Check warning on line 28 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L24-L28

Added lines #L24 - L28 were not covered by tests
end

function countstored_level(lvl::SingleListLevel, pos)
countstored_level(lvl.lvl, lvl.ptr[pos + 1] - 1)

Check warning on line 32 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L31-L32

Added lines #L31 - L32 were not covered by tests
end

pattern!(lvl::SingleListLevel{Ti}) where {Ti} =

Check warning on line 35 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L35

Added line #L35 was not covered by tests
SingleListLevel{Ti}(pattern!(lvl.lvl), lvl.shape, lvl.ptr, lvl.idx)

redefault!(lvl::SingleListLevel{Ti}, init) where {Ti} =

Check warning on line 38 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L38

Added line #L38 was not covered by tests
SingleListLevel{Ti}(redefault!(lvl.lvl, init), lvl.shape, lvl.ptr, lvl.idx)

Base.resize!(lvl::SingleListLevel{Ti}, dims...) where {Ti} =

Check warning on line 41 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L41

Added line #L41 was not covered by tests
SingleListLevel{Ti}(resize!(lvl.lvl, dims[1:end-1]...), dims[end], lvl.ptr, lvl.idx)

function Base.show(io::IO, lvl::SingleListLevel{Ti, Ptr, Idx, Lvl}) where {Ti, Lvl, Idx, Ptr}
if get(io, :compact, false)
print(io, "SingleList(")

Check warning on line 46 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L44-L46

Added lines #L44 - L46 were not covered by tests
else
print(io, "SingleList{$Ti}(")

Check warning on line 48 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L48

Added line #L48 was not covered by tests
end
show(io, lvl.lvl)
print(io, ", ")
show(IOContext(io, :typeinfo=>Ti), lvl.shape)
print(io, ", ")
if get(io, :compact, false)
print(io, "…")

Check warning on line 55 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L50-L55

Added lines #L50 - L55 were not covered by tests
else
show(io, lvl.ptr)
print(io, ", ")
show(io, lvl.idx)

Check warning on line 59 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L57-L59

Added lines #L57 - L59 were not covered by tests
end
print(io, ")")

Check warning on line 61 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L61

Added line #L61 was not covered by tests
end

function display_fiber(io::IO, mime::MIME"text/plain", fbr::SubFiber{<:SingleListLevel}, depth)
p = fbr.pos
lvl = fbr.lvl
if p + 1 > length(lvl.ptr)
print(io, "SparseHash(undef...)")
return

Check warning on line 69 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L64-L69

Added lines #L64 - L69 were not covered by tests
end

crds = @view(fbr.lvl.idx[fbr.lvl.ptr[p]:fbr.lvl.ptr[p + 1] - 1])

Check warning on line 72 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L72

Added line #L72 was not covered by tests

print_coord(io, crd) = show(io, crd)
get_fbr(crd) = fbr(crd)

Check warning on line 75 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L74-L75

Added lines #L74 - L75 were not covered by tests

print(io, "SingleList (", default(fbr), ") [", ":,"^(ndims(fbr) - 1), "1:", fbr.lvl.shape, "]")
display_fiber_data(io, mime, fbr, depth, 1, crds, print_coord, get_fbr)

Check warning on line 78 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L77-L78

Added lines #L77 - L78 were not covered by tests
end

@inline level_ndims(::Type{<:SingleListLevel{Ti, Ptr, Idx, Lvl}}) where {Ti, Ptr, Idx, Lvl} = 1 + level_ndims(Lvl)
@inline level_size(lvl::SingleListLevel) = (level_size(lvl.lvl)..., lvl.shape)
@inline level_axes(lvl::SingleListLevel) = (level_axes(lvl.lvl)..., Base.OneTo(lvl.shape))
@inline level_eltype(::Type{<:SingleListLevel{Ti, Ptr, Idx, Lvl}}) where {Ti, Ptr, Idx, Lvl} = level_eltype(Lvl)
@inline level_default(::Type{<:SingleListLevel{Ti, Ptr, Idx, Lvl}}) where {Ti, Ptr, Idx, Lvl} = level_default(Lvl)
data_rep_level(::Type{<:SingleListLevel{Ti, Ptr, Idx, Lvl}}) where {Ti, Ptr, Idx, Lvl} = SparseData(data_rep_level(Lvl))

Check warning on line 86 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L81-L86

Added lines #L81 - L86 were not covered by tests

(fbr::AbstractFiber{<:SingleListLevel})() = fbr
function (fbr::SubFiber{<:SingleListLevel{Ti}})(idxs...) where {Ti}
isempty(idxs) && return fbr
lvl = fbr.lvl
p = fbr.pos
r = searchsorted(@view(lvl.idx[lvl.ptr[p]:lvl.ptr[p + 1] - 1]), idxs[end])
q = lvl.ptr[p] + first(r) - 1
fbr_2 = SubFiber(lvl.lvl, q)
length(r) == 0 ? default(fbr_2) : fbr_2(idxs[1:end-1]...)

Check warning on line 96 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L88-L96

Added lines #L88 - L96 were not covered by tests
end

mutable struct VirtualSingleListLevel <: AbstractVirtualLevel
lvl
ex
Ti
ptr
idx
shape
qos_fill
qos_stop
prev_pos
end

is_level_injective(lvl::VirtualSingleListLevel, ctx) = [is_level_injective(lvl.lvl, ctx)..., false]
is_level_atomic(lvl::VirtualSingleListLevel, ctx) = false

Check warning on line 112 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L111-L112

Added lines #L111 - L112 were not covered by tests

function virtualize(ex, ::Type{SingleListLevel{Ti, Ptr, Idx, Lvl}}, ctx, tag=:lvl) where {Ti, Ptr, Idx, Lvl}
sym = freshen(ctx, tag)
ptr = freshen(ctx, tag, :_ptr)
idx = freshen(ctx, tag, :_idx)
push!(ctx.preamble, quote
$sym = $ex
$ptr = $sym.ptr
$idx = $sym.idx

Check warning on line 121 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L114-L121

Added lines #L114 - L121 were not covered by tests
end)
lvl_2 = virtualize(:($sym.lvl), Lvl, ctx, sym)
shape = value(:($sym.shape), Int)
qos_fill = freshen(ctx, sym, :_qos_fill)
qos_stop = freshen(ctx, sym, :_qos_stop)
prev_pos = freshen(ctx, sym, :_prev_pos)
VirtualSingleListLevel(lvl_2, sym, Ti, ptr, idx, shape, qos_fill, qos_stop, prev_pos)

Check warning on line 128 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L123-L128

Added lines #L123 - L128 were not covered by tests
end
function lower(lvl::VirtualSingleListLevel, ctx::AbstractCompiler, ::DefaultStyle)
quote
$SingleListLevel{$(lvl.Ti)}(

Check warning on line 132 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L130-L132

Added lines #L130 - L132 were not covered by tests
$(ctx(lvl.lvl)),
$(ctx(lvl.shape)),
$(lvl.ptr),
$(lvl.idx),
)
end
end

Base.summary(lvl::VirtualSingleListLevel) = "SingleList($(summary(lvl.lvl)))"

Check warning on line 141 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L141

Added line #L141 was not covered by tests

function virtual_level_size(lvl::VirtualSingleListLevel, ctx)
ext = make_extent(lvl.Ti, literal(lvl.Ti(1)), lvl.shape)
(virtual_level_size(lvl.lvl, ctx)..., ext)

Check warning on line 145 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L143-L145

Added lines #L143 - L145 were not covered by tests
end

function virtual_level_resize!(lvl::VirtualSingleListLevel, ctx, dims...)
lvl.shape = getstop(dims[end])
lvl.lvl = virtual_level_resize!(lvl.lvl, ctx, dims[1:end-1]...)
lvl

Check warning on line 151 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L148-L151

Added lines #L148 - L151 were not covered by tests
end

virtual_level_eltype(lvl::VirtualSingleListLevel) = virtual_level_eltype(lvl.lvl)
virtual_level_default(lvl::VirtualSingleListLevel) = virtual_level_default(lvl.lvl)

Check warning on line 155 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L154-L155

Added lines #L154 - L155 were not covered by tests

postype(lvl::VirtualSingleListLevel) = postype(lvl.lvl)

Check warning on line 157 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L157

Added line #L157 was not covered by tests

function declare_level!(lvl::VirtualSingleListLevel, ctx::AbstractCompiler, pos, init)

Check warning on line 159 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L159

Added line #L159 was not covered by tests
#TODO check that init == default
Ti = lvl.Ti
Tp = postype(lvl)
qos = call(-, call(getindex, :($(lvl.ptr)), call(+, pos, 1)), 1)
push!(ctx.code.preamble, quote
$(lvl.qos_fill) = $(Tp(0))
$(lvl.qos_stop) = $(Tp(0))

Check warning on line 166 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L161-L166

Added lines #L161 - L166 were not covered by tests
end)
if issafe(ctx.mode)
push!(ctx.code.preamble, quote
$(lvl.prev_pos) = $(Tp(0))

Check warning on line 170 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L168-L170

Added lines #L168 - L170 were not covered by tests
end)
end
lvl.lvl = declare_level!(lvl.lvl, ctx, qos, init)
return lvl

Check warning on line 174 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L173-L174

Added lines #L173 - L174 were not covered by tests
end

function trim_level!(lvl::VirtualSingleListLevel, ctx::AbstractCompiler, pos)
qos = freshen(ctx.code, :qos)
Tp = postype(lvl)
push!(ctx.code.preamble, quote
resize!($(lvl.ptr), $(ctx(pos)) + 1)
$qos = $(lvl.ptr)[end] - $(Tp(1))
resize!($(lvl.idx), $qos)

Check warning on line 183 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L177-L183

Added lines #L177 - L183 were not covered by tests
end)
lvl.lvl = trim_level!(lvl.lvl, ctx, value(qos, Tp))
return lvl

Check warning on line 186 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L185-L186

Added lines #L185 - L186 were not covered by tests
end

function assemble_level!(lvl::VirtualSingleListLevel, ctx, pos_start, pos_stop)
pos_start = ctx(cache!(ctx, :p_start, pos_start))
pos_stop = ctx(cache!(ctx, :p_start, pos_stop))
return quote
Finch.resize_if_smaller!($(lvl.ptr), $pos_stop + 1)
Finch.fill_range!($(lvl.ptr), 0, $pos_start + 1, $pos_stop + 1)

Check warning on line 194 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L189-L194

Added lines #L189 - L194 were not covered by tests
end
end

function freeze_level!(lvl::VirtualSingleListLevel, ctx::AbstractCompiler, pos_stop)
p = freshen(ctx.code, :p)
pos_stop = ctx(cache!(ctx, :pos_stop, simplify(pos_stop, ctx)))
qos_stop = freshen(ctx.code, :qos_stop)
push!(ctx.code.preamble, quote
for $p = 1:$pos_stop
$(lvl.ptr)[$p + 1] += $(lvl.ptr)[$p]
end
$qos_stop = $(lvl.ptr)[$pos_stop + 1] - 1

Check warning on line 206 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L198-L206

Added lines #L198 - L206 were not covered by tests
end)
lvl.lvl = freeze_level!(lvl.lvl, ctx, value(qos_stop))
return lvl

Check warning on line 209 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L208-L209

Added lines #L208 - L209 were not covered by tests
end

function thaw_level!(lvl::VirtualSingleListLevel, ctx::AbstractCompiler, pos_stop)
p = freshen(ctx.code, :p)
pos_stop = ctx(cache!(ctx, :pos_stop, simplify(pos_stop, ctx)))
qos_stop = freshen(ctx.code, :qos_stop)
push!(ctx.code.preamble, quote
$(lvl.qos_fill) = $(lvl.ptr)[$pos_stop + 1] - 1
$(lvl.qos_stop) = $(lvl.qos_fill)
$qos_stop = $(lvl.qos_fill)
$(if issafe(ctx.mode)
quote
$(lvl.prev_pos) = Finch.scansearch($(lvl.ptr), $(lvl.qos_stop) + 1, 1, $pos_stop) - 1

Check warning on line 222 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L212-L222

Added lines #L212 - L222 were not covered by tests
end
end)
for $p = $pos_stop:-1:1
$(lvl.ptr)[$p + 1] -= $(lvl.ptr)[$p]
end

Check warning on line 227 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L225-L227

Added lines #L225 - L227 were not covered by tests
end)
lvl.lvl = thaw_level!(lvl.lvl, ctx, value(qos_stop))
return lvl

Check warning on line 230 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L229-L230

Added lines #L229 - L230 were not covered by tests
end

function virtual_moveto_level(lvl::VirtualSingleListLevel, ctx::AbstractCompiler, arch)
ptr_2 = freshen(ctx.code, lvl.ptr)
idx_2 = freshen(ctx.code, lvl.idx)
push!(ctx.code.preamble, quote
$ptr_2 = $(lvl.ptr)
$idx_2 = $(lvl.idx)
$(lvl.ptr) = $moveto($(lvl.ptr), $(ctx(arch)))
$(lvl.idx) = $moveto($(lvl.idx), $(ctx(arch)))

Check warning on line 240 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L233-L240

Added lines #L233 - L240 were not covered by tests
end)
push!(ctx.code.epilogue, quote
$(lvl.ptr) = $ptr_2
$(lvl.idx) = $idx_2

Check warning on line 244 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L242-L244

Added lines #L242 - L244 were not covered by tests
end)
virtual_moveto_level(lvl.lvl, ctx, arch)

Check warning on line 246 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L246

Added line #L246 was not covered by tests
end

function instantiate(fbr::VirtualSubFiber{VirtualSingleListLevel}, ctx, mode::Reader, subprotos, ::Union{typeof(defaultread), typeof(walk)})
(lvl, pos) = (fbr.lvl, fbr.pos)
tag = lvl.ex
Tp = postype(lvl)
Ti = lvl.Ti
my_i = freshen(ctx.code, tag, :_i)
my_q = freshen(ctx.code, tag, :_q)
my_q_stop = freshen(ctx.code, tag, :_q_stop)

Check warning on line 256 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L249-L256

Added lines #L249 - L256 were not covered by tests

Furlable(
body = (ctx, ext) -> Thunk(

Check warning on line 259 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L258-L259

Added lines #L258 - L259 were not covered by tests
preamble = quote
$my_q = $(lvl.ptr)[$(ctx(pos))]
$my_q_stop = $(lvl.ptr)[$(ctx(pos)) + $(Tp(1))]
if $my_q < $my_q_stop
$my_i = $(lvl.idx)[$my_q]

Check warning on line 264 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L261-L264

Added lines #L261 - L264 were not covered by tests
else
$my_i = $(Ti(0))

Check warning on line 266 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L266

Added line #L266 was not covered by tests
end
end,
body = (ctx) -> Sequence([

Check warning on line 269 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L269

Added line #L269 was not covered by tests
Phase(
start = (ctx, ext) -> literal(lvl.Ti(1)),
stop = (ctx, ext) -> value(my_i),
body = (ctx, ext) -> Spike(

Check warning on line 273 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L271-L273

Added lines #L271 - L273 were not covered by tests
body = Fill(virtual_level_default(lvl)),
tail = instantiate(VirtualSubFiber(lvl.lvl, value(my_q, Ti)), ctx, mode, subprotos))
),
Phase(
stop = (ctx, ext) -> lvl.shape,
body = (ctx, ext) -> Run(Fill(virtual_level_default(lvl)))

Check warning on line 279 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L278-L279

Added lines #L278 - L279 were not covered by tests
)
])

)
)
end

instantiate(fbr::VirtualSubFiber{VirtualSingleListLevel}, ctx, mode::Updater, protos) = begin
instantiate(VirtualHollowSubFiber(fbr.lvl, fbr.pos, freshen(ctx.code, :null)), ctx, mode, protos)

Check warning on line 288 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L287-L288

Added lines #L287 - L288 were not covered by tests
end
function instantiate(fbr::VirtualHollowSubFiber{VirtualSingleListLevel}, ctx, mode::Updater, subprotos, ::Union{typeof(defaultupdate), typeof(extrude)})
(lvl, pos) = (fbr.lvl, fbr.pos)
tag = lvl.ex
Tp = postype(lvl)
qos = freshen(ctx.code, tag, :_qos)
qos_fill = lvl.qos_fill
qos_stop = lvl.qos_stop
dirty = freshen(ctx.code, tag, :dirty)

Check warning on line 297 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L290-L297

Added lines #L290 - L297 were not covered by tests

Furlable(
body = (ctx, ext) -> Thunk(

Check warning on line 300 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L299-L300

Added lines #L299 - L300 were not covered by tests
preamble = quote
$qos = $qos_fill + 1
$(lvl.ptr)[$(ctx(pos)) + 1] == 0 || throw(FinchProtocolError("SingleListLevels can only be updated once"))
$(if issafe(ctx.mode)
quote
$(lvl.prev_pos) < $(ctx(pos)) || throw(FinchProtocolError("SingleListLevels cannot be updated multiple times"))

Check warning on line 306 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L302-L306

Added lines #L302 - L306 were not covered by tests
end
end)
end,
body = (ctx) -> Lookup(
body = (ctx, idx) -> Thunk(

Check warning on line 311 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L310-L311

Added lines #L310 - L311 were not covered by tests
preamble = quote
if $qos > $qos_stop
$qos_stop = max($qos_stop << 1, 1)
Finch.resize_if_smaller!($(lvl.idx), $qos_stop)
$(contain(ctx_2->assemble_level!(lvl.lvl, ctx_2, value(qos, Tp), value(qos_stop, Tp)), ctx))

Check warning on line 316 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L313-L316

Added lines #L313 - L316 were not covered by tests
end
$dirty = false

Check warning on line 318 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L318

Added line #L318 was not covered by tests
end,
body = (ctx) -> instantiate(VirtualHollowSubFiber(lvl.lvl, value(qos, Tp), dirty), ctx, mode, subprotos),

Check warning on line 320 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L320

Added line #L320 was not covered by tests
epilogue = quote
if $dirty
$(fbr.dirty) = true
$(lvl.idx)[$qos] = $(ctx(idx))
$qos += $(Tp(1))
$(if issafe(ctx.mode)
quote
$(lvl.prev_pos) = $(ctx(pos))

Check warning on line 328 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L322-L328

Added lines #L322 - L328 were not covered by tests
end
end)
end
end
)
),
epilogue = quote
$(lvl.ptr)[$(ctx(pos)) + 1] += $qos - $qos_fill - 1
$qos_fill = $qos - 1

Check warning on line 337 in src/tensors/levels/singlelistlevels.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/levels/singlelistlevels.jl#L336-L337

Added lines #L336 - L337 were not covered by tests
end
)
)
end
Loading