Skip to content

Commit 2ef10f7

Browse files
committed
Most code on Result works for AbstractResult now, with caveat of multiple_results
1 parent e2ab41b commit 2ef10f7

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/result.jl

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,23 +220,32 @@ const Results = Union{AbstractResult,AbstractVector{<:PathResult}}
220220
Return all [`PathResult`](@ref)s for which satisfy the given conditions and apply,
221221
if provided, the function `f`.
222222
"""
223-
results(R::Results; kwargs...) = results(identity, R; kwargs...)
223+
results(R::AbstractResult; kwargs...) = results(identity, R; kwargs...)
224224
function results(
225225
f::Function,
226-
R::Results;
226+
R::AbstractResult;
227227
only_real::Bool = false,
228228
real_tol::Float64 = 1e-6,
229229
only_nonsingular::Bool = false,
230230
only_singular::Bool = false,
231231
only_finite::Bool = true,
232232
multiple_results::Bool = false,
233233
)
234+
if multiple_results == false && typeof(R)!=Result
235+
println("Warning: Since result is a ResultIterator, counting multiple results")
236+
multiple_results = true
237+
end
234238
filter_function = r -> (!only_real || is_real(r, real_tol)) &&
235239
(!only_nonsingular || is_nonsingular(r)) &&
236240
(!only_singular || is_singular(r)) &&
237241
(!only_finite || is_finite(r)) &&
238242
(multiple_results || !is_multiple_result(r, R))
239-
imap(f,Iterators.filter(filter_function,R))
243+
return_iter = imap(f,Iterators.filter(filter_function,R))
244+
if typeof(R) == Result
245+
return(collect(return_iter))
246+
else
247+
return(return_iter)
248+
end
240249
end
241250

242251
"""
@@ -289,7 +298,7 @@ julia> solutions(solve(F))
289298
[-3.0 + 0.0im, 0.0 + 0.0im]
290299
```
291300
"""
292-
solutions(result::Results; only_nonsingular = true, kwargs...) =
301+
solutions(result::AbstractResult; only_nonsingular = true, kwargs...) =
293302
results(solution, result; only_nonsingular = only_nonsingular, kwargs...)
294303

295304
"""
@@ -309,7 +318,7 @@ julia> real_solutions(solve(F))
309318
[-3.0, 0.0]
310319
```
311320
"""
312-
function real_solutions(result::Results; tol::Float64 = 1e-6, kwargs...)
321+
function real_solutions(result::AbstractResult; tol::Float64 = 1e-6, kwargs...)
313322
results(real solution, result; only_real = true, real_tol = tol, kwargs...)
314323
end
315324

@@ -321,7 +330,7 @@ Return all [`PathResult`](@ref)s for which the solution is non-singular.
321330
This is just a shorthand for `results(R; only_nonsingular=true, conditions...)`.
322331
For the possible `conditions` see [`results`](@ref).
323332
"""
324-
nonsingular(R::Results; kwargs...) = results(R; only_nonsingular = true, kwargs...)
333+
nonsingular(R::AbstractResult; kwargs...) = results(R; only_nonsingular = true, kwargs...)
325334

326335
"""
327336
singular(result; multiple_results=false, kwargs...)
@@ -331,7 +340,7 @@ If `multiple_results=false` only one point from each cluster of multiple solutio
331340
returned. If `multiple_results = true` all singular solutions in `R` are returned.
332341
For the possible `kwargs` see [`results`](@ref).
333342
"""
334-
function singular(R::Results; kwargs...)
343+
function singular(R::AbstractResult; kwargs...)
335344
results(R; only_singular = true, kwargs...)
336345
end
337346

@@ -361,7 +370,7 @@ at_infinity(R::Results) = filter(is_at_infinity, path_results(R))
361370
362371
The number of solutions. See [`results`](@ref) for the possible options.
363372
"""
364-
nsolutions(R::Results; only_nonsingular = true, options...) =
373+
nsolutions(R::AbstractResult; only_nonsingular = true, options...) =
365374
nresults(R; only_nonsingular = only_nonsingular, options...)
366375

367376
"""
@@ -376,11 +385,12 @@ larger than 1 or the condition number is larger than `tol`.
376385
If `counting_multiplicities=true` the number of singular solutions times their
377386
multiplicities is returned.
378387
"""
379-
function nsingular(R::Results; counting_multiplicities::Bool = false, kwargs...)
380-
S = results(R; only_singular = true, multiple_results = false, kwargs...)
381-
isempty(S) && return 0
382-
counting_multiplicities && return sum(multiplicity, S)
383-
length(S)
388+
function nsingular(R::AbstractResult; counting_multiplicities::Bool = false, kwargs...)
389+
if counting_multiplicities
390+
return(nresults(R; only_singular = true, multiple_results = true, kwargs...))
391+
else
392+
return(nresults(R; only_singular = true, multiple_results = true, kwargs...))
393+
end
384394
end
385395

386396

@@ -417,8 +427,8 @@ nnonsingular(R::AbstractResult) = count(is_nonsingular, R)
417427
418428
The number of real solutions. See also [`is_real`](@ref).
419429
"""
420-
nreal(R::Result; tol = 1e-6) = nresults(R, only_real = true, real_tol = tol)
421-
430+
nreal(R::AbstractResult; tol = 1e-6) = nresults(R, only_real = true, real_tol = tol)
431+
nreal(R::ResultIterator; tol = 1e-6) = nresults(R, only_real = true, real_tol = tol, multiple_results=true)
422432

423433
"""
424434
ntracked(result)

test/result_iterator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@test nsolutions(tsi_total_degree) == 3
1313
@test length(tsi_polyhedral) == 3
1414
@test length(tsi_total_degree) == 6
15-
@test bitmask(tsi_total_degree,isfinite) == Vector{Bool}([1,1,1,0,0,0]) #! Why is this not deterministic?!
15+
@test bitmask(isfinite,tsi_total_degree) == Vector{Bool}([1,1,1,0,0,0]) #! Why is this not deterministic?!
1616

1717
end
1818

0 commit comments

Comments
 (0)