Skip to content

Commit

Permalink
move callbacks to a new function; parallel apppend! avoids calling ca…
Browse files Browse the repository at this point in the history
…llbacks
  • Loading branch information
sadit committed Jun 29, 2021
1 parent 601a4aa commit 808be83
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/graph/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ Note: Parallel construction doesn't trigger callbacks listed in `callback_list',
function Base.append!(index::SearchGraph, db;
parallel=false, parallel_firstblock=30_000, parallel_block=10_000)

@info "inserting $(length(db))"
if parallel
parallel_firstblock = min(length(db), parallel_firstblock)
for i in 1:parallel_firstblock
Expand Down Expand Up @@ -119,7 +118,7 @@ function parallel_append!(INDEXES::Vector{<:SearchGraph}, X::AbstractVector)
end

for i in 1:m
push_neighborhood!(INDEXES[1], X[i], N[i])
push_neighborhood!(INDEXES[1], X[i], N[i]; apply_callbacks=false)
end
end

Expand Down Expand Up @@ -164,27 +163,29 @@ function push_neighborhood!(index::SearchGraph, item, L::Vector{Int32}; apply_ca

push!(index.links, L)

if apply_callbacks
n = length(index.db)

if n >= index.callback_starting
k = ceil(Int, log(index.callback_logbase, 1+n))
k1 = ceil(Int, log(index.callback_logbase, 2+n))
if k != k1
for (name, callback_object) in index.callback_list
index.verbose && println(stderr, "calling callback ", name, "; n=$n")
callback(callback_object, index)
end
end
end
end
apply_callbacks && callbacks(index)

if index.verbose && length(index.db) % 10000 == 0
println(stderr, "added n=$(length(index.db)), neighborhood=$(length(neighbors)), $(string(index.search_algo)), $(typeof(index.neighborhood_algo)), $(now())")
end

end

function callbacks(index::SearchGraph)
n = length(index.db)

if n >= index.callback_starting
k = ceil(Int, log(index.callback_logbase, 1+n))
k1 = ceil(Int, log(index.callback_logbase, 2+n))
if k != k1
for (name, callback_object) in index.callback_list
index.verbose && println(stderr, "calling callback ", name, "; n=$n")
callback(callback_object, index)
end
end
end
end

"""
push!(index::SearchGraph, item)
Expand Down

2 comments on commit 808be83

@sadit
Copy link
Owner Author

@sadit sadit commented on 808be83 Jun 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/39894

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.4 -m "<description of version>" 808be83398c506f0a66fe060fdf16d1572c630c3
git push origin v0.5.4

Please sign in to comment.