Skip to content

Commit 3b16c9c

Browse files
authored
Merge pull request #1771 from SciML/myb/strong_alias
WIP: Strong alias elimination
2 parents 644d76c + b87a2cd commit 3b16c9c

File tree

9 files changed

+483
-385
lines changed

9 files changed

+483
-385
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ RuntimeGeneratedFunctions = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47"
3636
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
3737
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
3838
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
39+
SimpleWeightedGraphs = "47aef6b3-ad0c-573a-a1e2-d07658019622"
3940
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
4041
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
4142
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
@@ -72,6 +73,7 @@ Reexport = "0.2, 1"
7273
RuntimeGeneratedFunctions = "0.4.3, 0.5"
7374
SciMLBase = "1.58.0"
7475
Setfield = "0.7, 0.8, 1"
76+
SimpleWeightedGraphs = "1"
7577
SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 1.0, 2"
7678
StaticArrays = "0.10, 0.11, 0.12, 1.0"
7779
SymbolicUtils = "0.19"
@@ -93,9 +95,9 @@ OptimizationOptimJL = "36348300-93cb-4f02-beb5-3c3902f8871e"
9395
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
9496
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
9597
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
98+
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
9699
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
97100
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
98-
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
99101
SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f"
100102
StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
101103
Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"

src/bipartite_graph.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,19 +470,23 @@ function set_neighbors!(g::BipartiteGraph, i::Integer, new_neighbors)
470470
for n in old_neighbors
471471
@inbounds list = g.badjlist[n]
472472
index = searchsortedfirst(list, i)
473-
deleteat!(list, index)
473+
if 1 <= index <= length(list) && list[index] == i
474+
deleteat!(list, index)
475+
end
474476
end
475477
for n in new_neighbors
476478
@inbounds list = g.badjlist[n]
477479
index = searchsortedfirst(list, i)
478-
insert!(list, index, i)
480+
if !(1 <= index <= length(list) && list[index] == i)
481+
insert!(list, index, i)
482+
end
479483
end
480484
end
481485
if iszero(new_nneighbors) # this handles Tuple as well
482486
# Warning: Aliases old_neighbors
483487
empty!(g.fadjlist[i])
484488
else
485-
g.fadjlist[i] = copy(new_neighbors)
489+
g.fadjlist[i] = unique!(sort(new_neighbors))
486490
end
487491
end
488492

src/structural_transformation/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ highest_order_variable_mask(ts) =
218218

219219
lowest_order_variable_mask(ts) =
220220
let v2d = ts.structure.var_to_diff
221-
v -> isempty(outneighbors(v2d, v))
221+
v -> isempty(inneighbors(v2d, v))
222222
end
223223

224224
function but_ordered_incidence(ts::TearingState, varmask = highest_order_variable_mask(ts))

src/systems/abstractsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ function linearization_function(sys::AbstractSystem, inputs,
10311031
input_idxs = input_idxs,
10321032
sts = states(sys),
10331033
fun = ODEFunction{true, SciMLBase.FullSpecialize}(sys),
1034-
h = ModelingToolkit.build_explicit_observed_function(sys, outputs),
1034+
h = build_explicit_observed_function(sys, outputs),
10351035
chunk = ForwardDiff.Chunk(input_idxs)
10361036

10371037
function (u, p, t)

0 commit comments

Comments
 (0)