Skip to content

Commit 465c63a

Browse files
committed
Replace OrderedSet with Dict{Symbolic, Int}
1 parent 2ffe076 commit 465c63a

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ version = "0.1.0"
77
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
88
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
99
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
10-
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
1110
RandomizedLinAlg = "0448d7d9-159c-5637-8537-fd72090fea46"
1211
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
1312
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
@@ -18,7 +17,6 @@ TSVD = "9449cd9e-2762-5aa3-a617-5413e99d722e"
1817
[compat]
1918
DocStringExtensions = "0.8"
2019
ModelingToolkit = "8.21"
21-
OrderedCollections = "1.4"
2220
RandomizedLinAlg = "0.1"
2321
Setfield = "0.8, 1"
2422
SymbolicUtils = "0.19"

src/utils.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using OrderedCollections, SparseArrays
1+
using SparseArrays
22

33
"""
44
$(TYPEDSIGNATURES)
@@ -35,12 +35,16 @@ where the constant terms do not contain any variables in `vars`.
3535
Variables in `vars` must be unique.
3636
"""
3737
function linear_terms(exprs::AbstractVector, vars)
38-
vars = OrderedSet(Symbolics.unwrap.(vars))
38+
vars = Symbolics.unwrap.(vars)
3939
exprs = Symbolics.unwrap.(exprs)
4040
linear_I = Int[] # row idx for sparse matrix
4141
linear_J = Int[] # col idx for sparse matrix
4242
linear_V = Float64[] # values
4343
idxmap = Dict(v => i for (i, v) in enumerate(vars))
44+
if length(idxmap) < length(vars)
45+
throw(ArgumentError("vars: $vars are not unique"))
46+
end
47+
vars = keys(idxmap)
4448

4549
# (a function used to avoid code duplication)
4650
# when a linear term is identified, add the indices and value to the sparse matrix

0 commit comments

Comments
 (0)