From 336aca1443b47d047b386b99b3556f71605e4c68 Mon Sep 17 00:00:00 2001 From: guo-yong-zhi <55872791+guo-yong-zhi@users.noreply.github.com> Date: Tue, 6 Jun 2023 00:39:45 +0800 Subject: [PATCH] rename symbols --- Project.toml | 2 +- src/Stuffing.jl | 24 ++++++++++++------------ test/runtests.jl | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Project.toml b/Project.toml index d07e335..f0f08b6 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Stuffing" uuid = "4175e07e-e5b7-423e-8796-3ea7f6d48281" authors = ["guoyongzhi "] -version = "0.9.0" +version = "0.10.0" [deps] Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" diff --git a/src/Stuffing.jl b/src/Stuffing.jl index 4505d67..a0515ba 100644 --- a/src/Stuffing.jl +++ b/src/Stuffing.jl @@ -75,27 +75,27 @@ end QTrees.overlap!(qtrees::AbstractVector{<:ShiftedQTree}; karg...) = QTrees.overlap!(qtrees[1], qtrees[2:end]; karg...) QTrees.overlap(qtrees::AbstractVector{<:ShiftedQTree}; karg...) = QTrees.overlap!(deepcopy(qtrees[1]), qtrees[2:end]; karg...) -function getpositions(mask::ShiftedQTree, qtrees::AbstractVector, inds=:; type=getshift) +function getpositions(mask::ShiftedQTree, qtrees::AbstractVector, inds=:; mode=getshift) msy, msx = getshift(mask) - pos = type.(qtrees[inds]) + pos = mode.(qtrees[inds]) eltype(pos) <: Number && (pos = Ref(pos)) Broadcast.broadcast(p -> (p[2] - msx + 1, p[1] - msy + 1), pos) # 左上角重合时返回(1,1) end -function getpositions(qtrees::AbstractVector{<:ShiftedQTree}, inds=:; type=getshift) +function getpositions(qtrees::AbstractVector{<:ShiftedQTree}, inds=:; mode=getshift) @assert length(qtrees) >= 1 - getpositions(qtrees[1], @view(qtrees[2:end]), inds, type=type) + getpositions(qtrees[1], @view(qtrees[2:end]), inds, mode=mode) end -function setpositions!(mask::ShiftedQTree, qtrees::AbstractVector, inds, x_y; type=setshift!) +function setpositions!(mask::ShiftedQTree, qtrees::AbstractVector, inds, x_y; mode=setshift!) msy, msx = getshift(mask) eltype(x_y) <: Number && (x_y = Ref(x_y)) Broadcast.broadcast(qtrees[inds], x_y) do qt, p - type(qt, (p[2] - 1 + msy, p[1] - 1 + msx)) + mode(qt, (p[2] - 1 + msy, p[1] - 1 + msx)) end x_y end -function setpositions!(qtrees::AbstractVector{<:ShiftedQTree}, inds, x_y; type=setshift!) +function setpositions!(qtrees::AbstractVector{<:ShiftedQTree}, inds, x_y; mode=setshift!) @assert length(qtrees) >= 1 - setpositions!(qtrees[1], @view(qtrees[2:end]), inds, x_y, type=type) + setpositions!(qtrees[1], @view(qtrees[2:end]), inds, x_y, mode=mode) end function packing(mask, objs, args...; background=:auto, maskbackground=:auto, kargs...) @@ -105,14 +105,14 @@ function packing(mask, objs, args...; background=:auto, maskbackground=:auto, ka end function packing!(qts, args...; kargs...) place!(qts) - epochs, ncollection = fit!(qts, args...; kargs...) - @debug "$epochs epochs, $ncollection collections" - if ncollection != 0 + epochs, collisions = fit!(qts, args...; kargs...) + @debug "$epochs epochs, $collisions collisions" + if collisions != 0 colllist = first.(totalcollisions(qts)) get_text(i) = i > 1 ? "obj_$(i - 1)" : "#MASK#" @warn "have $(length(colllist)) collisions:\n" * string([(get_text(i), get_text(j)) for (i, j) in colllist]) end - epochs, ncollection + epochs, collisions end end diff --git a/test/runtests.jl b/test/runtests.jl index 4c68946..3d52b42 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -45,9 +45,9 @@ include("test_fit.jl") setshift!(qts[1], (-1000, -1000)) @test collision(qts[1], qts[2])[1] < 0 - ncollection = -1 + collisions = -1 epochs = 0 - while ncollection != 0 && epochs < 10000 + while collisions != 0 && epochs < 10000 mask = fill(true, 500, 800) # can be any AbstractMatrix objs = [] for i in 1:30 @@ -61,7 +61,7 @@ include("test_fit.jl") setpositions!(qts, :, (200, 300)) ep, nc = packing!(qts, trainer=Trainer.trainepoch_P2!) epochs += ep - ncollection = nc + collisions = nc end getpositions(qts) @test isempty(outofkernelbounds(qts[1], qts[2:end]))