File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ version = "0.1.0"
77DocStringExtensions = " ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
88LinearAlgebra = " 37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
99ModelingToolkit = " 961ee093-0014-501f-94e3-6117800e7a78"
10- OrderedCollections = " bac558e1-5e72-5ebc-8fee-abe8a469f55d"
1110RandomizedLinAlg = " 0448d7d9-159c-5637-8537-fd72090fea46"
1211Setfield = " efcf1570-3423-57d1-acb7-fd33fddbac46"
1312SparseArrays = " 2f01184e-e22b-5df5-ae63-d93ebab69eaf"
@@ -18,7 +17,6 @@ TSVD = "9449cd9e-2762-5aa3-a617-5413e99d722e"
1817[compat ]
1918DocStringExtensions = " 0.8"
2019ModelingToolkit = " 8.21"
21- OrderedCollections = " 1.4"
2220RandomizedLinAlg = " 0.1"
2321Setfield = " 0.8, 1"
2422SymbolicUtils = " 0.19"
Original file line number Diff line number Diff line change 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`.
3535Variables in `vars` must be unique.
3636"""
3737function 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
You can’t perform that action at this time.
0 commit comments