Skip to content

Commit e2ab41b

Browse files
committed
included IterTools to use lazy mapping (imap) and generalized results
1 parent 48ee214 commit e2ab41b

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
1010
ElasticArrays = "fdbdab4c-e67f-52f5-8c3f-e7b388dad3d4"
1111
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
1212
IntervalTrees = "524e6230-43b7-53ae-be76-1e9e4d08d11b"
13+
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
1314
LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637"
1415
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1516
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"

src/result.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Statistic about the number of (real) singular and non-singular solutions etc.
203203
"""
204204
statistics(r; kwargs...) = ResultStatistics(r; kwargs...)
205205

206-
const Results = Union{Result,AbstractVector{<:PathResult}}
206+
const Results = Union{AbstractResult,AbstractVector{<:PathResult}}
207207

208208
"""
209209
results(
@@ -231,13 +231,12 @@ function results(
231231
only_finite::Bool = true,
232232
multiple_results::Bool = false,
233233
)
234-
[
235-
f(r) for r in R if (!only_real || is_real(r, real_tol)) &&
236-
(!only_nonsingular || is_nonsingular(r)) &&
237-
(!only_singular || is_singular(r)) &&
238-
(!only_finite || is_finite(r)) &&
239-
(multiple_results || !is_multiple_result(r, R))
240-
]
234+
filter_function = r -> (!only_real || is_real(r, real_tol)) &&
235+
(!only_nonsingular || is_nonsingular(r)) &&
236+
(!only_singular || is_singular(r)) &&
237+
(!only_finite || is_finite(r)) &&
238+
(multiple_results || !is_multiple_result(r, R))
239+
imap(f,Iterators.filter(filter_function,R))
241240
end
242241

243242
"""

src/solve.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export
1010
bitmask,
1111
bitmask_filter
1212

13+
14+
using IterTools: imap
15+
1316
struct SolveStats
1417
regular::Threads.Atomic{Int}
1518
regular_real::Threads.Atomic{Int}
@@ -109,11 +112,6 @@ end
109112

110113

111114

112-
113-
function nsolutions(iter::ResultIterator)
114-
mapreduce(x->x.return_code==:success,+,iter,init=0)
115-
end
116-
117115
function Base.length(ri::ResultIterator)
118116
if Base.IteratorSize(ri) == Base.SizeUnknown()
119117
k = 0
@@ -149,12 +147,12 @@ function trace(iter::ResultIterator)
149147
mapreduce(x->solution(x),+,iter,init=0.0.*s)
150148
end
151149

152-
function Result(iter::ResultIterator)
153-
C = collect(iter)
150+
function Result(ri::ResultIterator)
151+
C = collect(ri)
154152
for i in 1:length(C)
155153
C[i].path_number = i
156154
end
157-
Result(C; seed = iter.S.seed, start_system = iter.S.start_system)
155+
Result(C; seed = ri.S.seed, start_system = ri.S.start_system)
158156
end
159157

160158

0 commit comments

Comments
 (0)