Skip to content

Commit 3448e6f

Browse files
authored
Merge pull request #5 from JuliaAlgebra/performance-updates
Performance updates
2 parents a23beda + 5556ab7 commit 3448e6f

File tree

12 files changed

+348
-219
lines changed

12 files changed

+348
-219
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ julia> f_1 = x^2 + y^2 - 1;
3838
julia> f_2 = x^2 + y^2 - 4;
3939
julia> f = [f_1; f_2]
4040
julia> regions(f)
41-
RegionsResult with 3 regions:
42-
===============================
41+
egionsResult with 3 regions:
42+
=============================
4343
9 complex critical points
4444
5 real critical points
45-
╭──────────────┬─────────────────────────────────
46-
│ sign pattern │ regions
47-
├──────────────┼─────────────────────────────────
48-
+ + │ number = 1
49-
│ │ χ = 0, μ = [1, 1, 0], unbounded
50-
- - │ number = 1
51-
│ │ χ = 1, μ = [1, 0, 0], bounded
52-
+ - │ number = 1
53-
│ │ χ = 0, μ = [1, 1, 0], bounded
54-
╰──────────────┴─────────────────────────────────
45+
╭──────────────┬───────────────────────╮
46+
│ sign pattern │ regions │
47+
├──────────────┼───────────────────────┤
48+
+ + │ number = 1
49+
│ │ χ = 0, μ = [1, 1, 0] │
50+
- - │ number = 1
51+
│ │ χ = 1, μ = [1, 0, 0] │
52+
+ - │ number = 1
53+
│ │ χ = 0, μ = [1, 1, 0] │
54+
╰──────────────┴───────────────────────╯
5555
```
5656

5757
The output shows that $\mathcal U$ has three regions. The first region has sign pattern $++$. This means that, on this region, both $f_1$ and $f_2$ are positive. On the second region, both $f_1$ and $f_2$ are negative, so it is the contractible region in the middle. The software correctly reports that this region has Euler characteristic 1. The other two regions each have one hole and thus have Euler characteristic 0.

docs/.documenter-siteinfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"documenter":{"julia_version":"1.10.4","generation_timestamp":"2024-09-09T16:35:10","documenter_version":"1.6.0"}}
1+
{"documenter":{"julia_version":"1.10.4","generation_timestamp":"2024-09-12T14:21:35","documenter_version":"1.6.0"}}

docs/index.html

Lines changed: 17 additions & 22 deletions
Large diffs are not rendered by default.

docs/objects.inv

-12 Bytes
Binary file not shown.

docs/search_index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/src/index.md

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ julia> f_1 = x^2 + y^2 - 1;
2727
julia> f_2 = x^2 + y^2 - 4;
2828
julia> f = [f_1; f_2]
2929
julia> C = regions(f)
30-
RegionsResult with 3 regions:
31-
===============================
30+
egionsResult with 3 regions:
31+
=============================
3232
9 complex critical points
3333
5 real critical points
34-
╭──────────────┬─────────────────────────────────
35-
│ sign pattern │ regions
36-
├──────────────┼─────────────────────────────────
37-
+ + │ number = 1
38-
│ │ χ = 0, μ = [1, 1, 0], unbounded
39-
- - │ number = 1
40-
│ │ χ = 1, μ = [1, 0, 0], bounded
41-
+ - │ number = 1
42-
│ │ χ = 0, μ = [1, 1, 0], bounded
43-
╰──────────────┴─────────────────────────────────
34+
╭──────────────┬───────────────────────╮
35+
│ sign pattern │ regions │
36+
├──────────────┼───────────────────────┤
37+
+ + │ number = 1
38+
│ │ χ = 0, μ = [1, 1, 0] │
39+
- - │ number = 1
40+
│ │ χ = 1, μ = [1, 0, 0] │
41+
+ - │ number = 1
42+
│ │ χ = 0, μ = [1, 1, 0] │
43+
╰──────────────┴───────────────────────╯
4444
```
4545

4646
The output shows that $\mathcal U$ has three regions. The first region has sign pattern $++$. This means that, on this region, both $f_1$ and $f_2$ are positive. On the second region, both $f_1$ and $f_2$ are negative, so it is the contractible region in the middle. The software correctly reports that this region has Euler characteristic 1. The other two regions each have one hole and thus have Euler characteristic 0.
@@ -101,24 +101,12 @@ Region
101101

102102
```@docs
103103
regions
104-
affine_regions
105104
projective_regions
106105
```
107106

108107

109108
## Documentation: Helper functions
110109

111-
Functions to call on [Region](@ref).
112-
```@docs
113-
χ
114-
μ
115-
critical_points
116-
is_bounded
117-
is_unbounded
118-
is_undecided
119-
number
120-
```
121-
122110
Functions to call on [RegionsResult](@ref).
123111
```@docs
124112
nregions
@@ -134,4 +122,14 @@ ncritical_complex
134122
ncritical_real
135123
g
136124
variables
125+
```
126+
127+
Functions to call on [Region](@ref).
128+
```@docs
129+
χ
130+
μ
131+
critical_points
132+
is_bounded
133+
is_unbounded
134+
is_undecided
137135
```

src/affine_regions.jl

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,39 @@ function _affine_regions(
4747
f0::System,
4848
progress::Union{Nothing,RegionsProgress};
4949
s::Union{Nothing,Vector{T}} = nothing,
50-
target_parameters::Union{Nothing, Vector{T1}} = nothing,
50+
target_parameters::Union{Nothing,Vector{T1}} = nothing,
5151
epsilon::Float64 = 1e-6,
5252
reltol::Float64 = 1e-6,
5353
abstol::Float64 = 1e-9,
5454
monodromy_options = HC.MonodromyOptions(max_loops_no_progress = 10),
5555
start_pair_using_newton::Bool = false,
5656
seed = nothing,
5757
kwargs...,
58-
) where {T<:Real, T1<:Number}
58+
) where {T<:Real,T1<:Number}
5959

6060
if isnothing(f0)
6161
f = f0
6262
else
63-
variable_list =
64-
f = System(f0(HC.variables(f0), target_parameters), variables = HC.variables(f0))
63+
variable_list =
64+
f = System(
65+
f0(HC.variables(f0), target_parameters),
66+
variables = HC.variables(f0),
67+
)
6568
end
6669

6770
if !isnothing(seed)
6871
Random.seed!(seed)
6972
end
70-
71-
s = set_up_s(s,f)
72-
M_1, f_list = compute_critical_points(f,
73-
s,
74-
monodromy_options,
75-
progress,
76-
start_pair_using_newton;
77-
kwargs...)
73+
74+
s = set_up_s(s, f)
75+
M_1, f_list = compute_critical_points(
76+
f,
77+
s,
78+
monodromy_options,
79+
progress,
80+
start_pair_using_newton;
81+
kwargs...,
82+
)
7883
if isnothing(M_1)
7984
println("Couldn't solve the critical equations")
8085
return nothing
@@ -168,25 +173,25 @@ function compute_critical_points(
168173
monodromy_options::MonodromyOptions,
169174
progress::Union{Nothing,RegionsProgress},
170175
start_pair_using_newton::Bool;
171-
target_parameters::Union{Nothing, Vector{T1}, Vector{Vector{T2}}} = nothing,
176+
target_parameters::Union{Nothing,Vector{T1},Vector{Vector{T2}}} = nothing,
172177
kwargs...,
173-
) where {T<:Real, T1,T2 <: Number}
178+
) where {T<:Real,T1,T2<:Number}
174179

175180
variable_list = HC.variables(f)
176181
parameter_list = HC.parameters(f)
177-
if isnothing(target_parameters)
182+
if isnothing(target_parameters)
178183
if length(parameter_list) > 0
179184
error("Number of parameters don't match.")
180185
end
181-
elseif typeof(target_parameters) <: Vector{Vector{T}} where T<:Number
186+
elseif typeof(target_parameters) <: Vector{Vector{T}} where {T<:Number}
182187
if length(target_parameters[1]) != length(parameter_list)
183188
error("Number of parameters don't match.")
184189
end
185190
elseif length(target_parameters) != length(parameter_list)
186191
error("Number of parameters don't match.")
187192
end
188193

189-
if typeof(target_parameters) <: Vector{T} where T<:Number
194+
if typeof(target_parameters) <: Vector{T} where {T<:Number}
190195
target_parameters = [target_parameters]
191196
end
192197

@@ -221,7 +226,7 @@ function compute_critical_points(
221226
options = monodromy_options,
222227
show_progress = show_progress,
223228
)
224-
if isnothing(target_parameters)
229+
if isnothing(target_parameters)
225230
all_target_parameters = s
226231
else
227232
all_target_parameters = [[s; p] for p in target_parameters]
@@ -265,7 +270,8 @@ function compute_critical_points(
265270
if isnothing(target_parameters)
266271
all_target_parameters = [s; randn(ComplexF64, K - k); 0.0]
267272
else
268-
all_target_parameters = [[s; randn(ComplexF64, K - k); 0.0; p] for p in target_parameters]
273+
all_target_parameters =
274+
[[s; randn(ComplexF64, K - k); 0.0; p] for p in target_parameters]
269275
end
270276
end
271277

@@ -297,6 +303,7 @@ function compute_critical_points(
297303
start_parameters = parameters(M),
298304
target_parameters = all_target_parameters,
299305
show_progress = show_progress,
306+
endgame_options = HC.EndgameOptions(; at_infinity_check = false),
300307
kwargs...,
301308
)
302309

@@ -332,7 +339,8 @@ end
332339
function compute_parameter(J, variable_list, parameter_list, x0, q0)
333340
M =
334341
[
335-
isa(entry, Expression) ? evaluate(entry, variable_list => x0, parameter_list => q0) : entry for
342+
isa(entry, Expression) ?
343+
evaluate(entry, variable_list => x0, parameter_list => q0) : entry for
336344
entry in J
337345
] |> Matrix{ComplexF64}
338346
N = LinearAlgebra.nullspace(M)

src/membership.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function membership(
2929
∇logg::AS;
3030
kwargs...,
3131
) where {AS<:AbstractSystem}
32-
32+
3333
C = _membership(R, p, ∇logg; kwargs...)
3434

3535
return C
@@ -59,6 +59,7 @@ function _membership(
5959
critical_point_index, failed_info =
6060
limit_critical_point(set_up_ode(∇logg), p, critical_points, reltol, abstol)
6161
if critical_point_index == -1
62+
# println(failed_info)
6263
return nothing
6364
end
6465

src/output.jl

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ critical_points(C::Region) = C.critical_points
7171
"""
7272
is_unbounded(C::Region)
7373
74-
Returns a boolean that is `true`, if `C` is undecided.
74+
Returns a boolean that is `true`, if `C` was labelled unbounded.
7575
"""
7676
is_unbounded(C::Region) = C.is_bounded == 0
7777

7878
"""
7979
is_bounded(C::Region)
8080
81-
Returns a boolean that is `true`, if `C` is bounded.
81+
Returns a boolean that is `true`, if `C` was labelled bounded.
8282
"""
8383
is_bounded(C::Region) = C.is_bounded == 1
8484

@@ -139,9 +139,12 @@ C = regions(f)
139139
p = projective_regions(C)
140140
```
141141
"""
142-
function projective_regions(C::RegionsResult)
142+
function projective_regions(C::RegionsResult)
143143
c = regions(C)
144144
p = C.projective_regions
145+
if isnothing(p)
146+
return p
147+
end
145148
P = map(p) do pᵢ
146149
filter(ci -> in(number(ci), pᵢ), c)
147150
end
@@ -159,42 +162,42 @@ nregions(C::RegionsResult) = C.nregions
159162
"""
160163
nbounded(C::RegionsResult)
161164
162-
Returns the number of (weakly) bounded regions in `C`.
165+
Returns the number of regions in `C` that were labelled bounded (if that information was computed).
163166
"""
164167
nbounded(C::RegionsResult) = count(is_bounded, regions(C))
165168

166169
"""
167170
nunbounded(C::RegionsResult)
168171
169-
Returns the number of unbounded regions in `C`.
172+
Returns the number of regions in `C` that were labelled unbounded (if that information was computed).
170173
"""
171174
nunbounded(C::RegionsResult) = count(is_unbounded, regions(C))
172175

173176
"""
174177
nundecided(C::RegionsResult)
175178
176-
Returns the number of regions in `C`, where bounded or unbounded could not be decided.
179+
Returns the number of regions in `C`, where bounded or unbounded could not be decided (if that information was computed).
177180
"""
178181
nundecided(C::RegionsResult) = count(is_undecided, regions(C))
179182

180183
"""
181184
bounded(C::RegionsResult)
182185
183-
Returns the (weakly) bounded regions in `C`.
186+
Returns the regions in `C` that were labelled bounded.
184187
"""
185188
bounded(C::RegionsResult) = filter(is_bounded, regions(C))
186189

187190
"""
188191
unbounded(C::RegionsResult)
189192
190-
Returns the unbounded regions in `C`.
193+
Returns the regions in `C` that were labelled unbounded.
191194
"""
192195
unbounded(C::RegionsResult) = filter(is_unbounded, regions(C))
193196

194197
"""
195198
undecided(C::RegionsResult)
196199
197-
Returns the number of regions in `C`, where bounded or unbounded could not be decided.
200+
Returns the regions in `C` that were labelled undecided.
198201
"""
199202
undecided(C::RegionsResult) = filter(is_undecided, regions(C))
200203

@@ -243,13 +246,13 @@ Returns the order of variables.
243246
"""
244247
function variables(C::RegionsResult)
245248
f, _, _ = g(C)
246-
HC.HC.variables(f)
249+
HC.variables(f)
247250
end
248251

249252
###############
250253
### Show ###
251254
###############
252-
Base.show(C::RegionsResult; crop = true) = Base.show(stdout, R, crop = crop)
255+
Base.show(C::RegionsResult; crop = true) = Base.show(stdout, C, crop = crop)
253256
function Base.show(io::IO, C::RegionsResult; crop = true)
254257

255258
header = "RegionsResult with $(C.nregions) regions:"
@@ -293,7 +296,7 @@ function Base.show(io::IO, C::RegionsResult; crop = true)
293296
end
294297
i += 1
295298
end
296-
299+
297300
end
298301

299302
ds = displaysize()
@@ -340,7 +343,7 @@ function Base.show(io::IO, C::Region)
340343
if isnothing(b)
341344
println(io, " χ = , μ = ")
342345
elseif b == 0
343-
println(io, "χ = , μ = , unbounded")
346+
println(io, "χ = , μ = , unbounded")
344347
elseif b == 1
345348
println(io, "χ = , μ = , bounded")
346349
elseif b == 2

src/path_tracking.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ end
1919
# find the nearest point in a list to a given point
2020
function finding_nearest_point(v, list_of_vectors)
2121
v = reshape(v, length(v))
22-
distances = [norm(v - x) for x in list_of_vectors]
23-
if minimum(distances) < 1e-4
22+
λ = LA.norm(v)
23+
distances = [LA.norm(v - x) for x in list_of_vectors]
24+
if minimum(distances) < 1e-4 * λ
2425
return argmin(distances)
2526
else
2627
return -1
@@ -192,4 +193,4 @@ function limit_critical_point_from_critical_point(
192193

193194
return [starting_point_index, critical_point_index], failed_info
194195
end
195-
end
196+
end

0 commit comments

Comments
 (0)