Skip to content

Commit

Permalink
add progress keyword (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
p-gw committed Dec 29, 2023
1 parent 63a8a26 commit 692e6b4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
42 changes: 28 additions & 14 deletions src/find.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,40 @@ function _find(
combs = combinations(is, n)

optimal_is = zeros(Int, n)
max_reliability = -Inf
max_reliability = Ref(-Inf)

prog = ProgressBar(transient = true)
if progress
prog = ProgressBar(transient = true)

Progress.with(prog) do
prog_job =
addjob!(prog, N = length(combs), description = "Finding optimal item subset...")
Progress.with(prog) do
prog_job = addjob!(
prog,
N = length(combs),
description = "Finding optimal item subset...",
)

for c in combs
subtest = view(m, :, c)
reliability = method(subtest)

if reliability > max_reliability
max_reliability = reliability
optimal_is = c
for c in combs
_update_reliability!(max_reliability, optimal_is, m, c, method)
update!(prog_job)
end

update!(prog_job)
end
else
for c in combs
_update_reliability!(max_reliability, optimal_is, m, c, method)
end
end

return optimal_is
end

function _update_reliability!(max_reliability, optimal_is, m, c, method)
subtest = view(m, :, c)
reliability = method(subtest)

if reliability > max_reliability[]
max_reliability[] = reliability
optimal_is .= c
end

return nothing
end
2 changes: 1 addition & 1 deletion src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using PrecompileTools

# find
for method in methods
find(m, 2, method)
find(m, 2, method, progress = false)
end
end
end
7 changes: 4 additions & 3 deletions test/find.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

# test
@test_throws ArgumentError find(m, n_items + 2)
@test size(find(m, 2)) == (n_persons, 2)
@test size(find(m, 1)) == (n_persons, 1)
@test size(find(m, 2, progress = false)) == (n_persons, 2)
@test size(find(m, 1, progress = false)) == (n_persons, 1)

@test find(m_extended, n_items) == m
@test find(m_extended, n_items, progress = false) == m
@test find(m, 2, progress = true) == find(m, 2, progress = false)
end

0 comments on commit 692e6b4

Please sign in to comment.