1111
1212get_iv (D:: Differential ) = D. x
1313
14- function make_operation (@nospecialize (op), args)
15- if op === (* )
16- args = filter (! _isone, args)
17- if isempty (args)
18- return 1
19- end
20- elseif op === (+ )
21- args = filter (! _iszero, args)
22- if isempty (args)
23- return 0
24- end
25- end
26- return op (args... )
27- end
2814
2915function detime_dvs (op)
3016 if ! iscall (op)
@@ -45,28 +31,11 @@ function retime_dvs(op, dvs, iv)
4531 op
4632end
4733
48- function modified_unknowns! (munknowns, e:: Equation , unknownlist = nothing )
49- get_variables! (munknowns, e. lhs, unknownlist)
50- end
51-
52- macro showarr (x)
53- n = string (x)
54- quote
55- y = $ (esc (x))
56- println ($ n, " = " , summary (y))
57- Base. print_array (stdout , y)
58- println ()
59- y
60- end
61- end
62-
6334function todict (d)
6435 eltype (d) <: Pair || throw (ArgumentError (" The variable-value mapping must be a Dict." ))
6536 d isa Dict ? d : Dict (d)
6637end
6738
68- _merge (d1, d2) = merge (todict (d1), todict (d2))
69-
7039function _readable_code (ex)
7140 ex isa Expr || return ex
7241 if ex. head === :call
248217
249218hasdefault (v) = hasmetadata (v, Symbolics. VariableDefaultValue)
250219getdefault (v) = value (Symbolics. getdefaultval (v))
251- function getdefaulttype (v)
252- def = value (getmetadata (unwrap (v), Symbolics. VariableDefaultValue, nothing ))
253- def === nothing ? Float64 : typeof (def)
254- end
255220function setdefault (v, val)
256221 val === nothing ? v : wrap (setdefaultval (unwrap (v), value (val)))
257222end
@@ -510,18 +475,6 @@ function collect_applied_operators(x, op)
510475 end
511476end
512477
513- function find_derivatives! (vars, expr:: Equation , f = identity)
514- (find_derivatives! (vars, expr. lhs, f); find_derivatives! (vars, expr. rhs, f); vars)
515- end
516- function find_derivatives! (vars, expr, f)
517- ! iscall (O) && return vars
518- operation (O) isa Differential && push! (vars, f (O))
519- for arg in arguments (O)
520- vars! (vars, arg)
521- end
522- return vars
523- end
524-
525478"""
526479 $(TYPEDSIGNATURES)
527480
@@ -728,58 +681,12 @@ function check_scope_depth(scope, depth)
728681 end
729682end
730683
731- """
732- $(SIGNATURES)
733-
734- find duplicates in an iterable object.
735- """
736- function find_duplicates (xs, :: Val{Ret} = Val (false )) where {Ret}
737- appeared = Set ()
738- duplicates = Set ()
739- for x in xs
740- if x in appeared
741- push! (duplicates, x)
742- else
743- push! (appeared, x)
744- end
745- end
746- return Ret ? (appeared, duplicates) : duplicates
747- end
748-
749684isarray (x) = x isa AbstractArray || x isa Symbolics. Arr
750685
751- function empty_substitutions (sys)
752- isempty (observed (sys))
753- end
754-
755686function get_substitutions (sys)
756687 Dict ([eq. lhs => eq. rhs for eq in observed (sys)])
757688end
758689
759- function mergedefaults (defaults, varmap, vars)
760- defs = if varmap isa Dict
761- merge (defaults, varmap)
762- elseif eltype (varmap) <: Pair
763- merge (defaults, Dict (varmap))
764- elseif eltype (varmap) <: Number
765- merge (defaults, Dict (zip (vars, varmap)))
766- else
767- defaults
768- end
769- end
770-
771- function mergedefaults (defaults, observedmap, varmap, vars)
772- defs = if varmap isa Dict
773- merge (observedmap, defaults, varmap)
774- elseif eltype (varmap) <: Pair
775- merge (observedmap, defaults, Dict (varmap))
776- elseif eltype (varmap) <: Number
777- merge (observedmap, defaults, Dict (zip (vars, varmap)))
778- else
779- merge (observedmap, defaults)
780- end
781- end
782-
783690@noinline function throw_missingvars_in_sys (vars)
784691 throw (ArgumentError (" $vars are either missing from the variable map or missing from the system's unknowns/parameters list." ))
785692end
@@ -834,119 +741,6 @@ function promote_to_concrete(vs; tofloat = true, use_union = true)
834741 return y
835742end
836743
837- struct BitDict <: AbstractDict{Int, Int}
838- keys:: Vector{Int}
839- values:: Vector{Union{Nothing, Int}}
840- end
841- BitDict (n:: Integer ) = BitDict (Int[], Union{Nothing, Int}[nothing for _ in 1 : n])
842- struct BitDictKeySet <: AbstractSet{Int}
843- d:: BitDict
844- end
845-
846- Base. keys (d:: BitDict ) = BitDictKeySet (d)
847- Base. in (v:: Integer , s:: BitDictKeySet ) = s. d. values[v] != = nothing
848- Base. iterate (s:: BitDictKeySet , state... ) = iterate (s. d. keys, state... )
849- function Base. setindex! (d:: BitDict , val:: Integer , ind:: Integer )
850- if 1 <= ind <= length (d. values) && d. values[ind] === nothing
851- push! (d. keys, ind)
852- end
853- d. values[ind] = val
854- end
855- function Base. getindex (d:: BitDict , ind:: Integer )
856- if 1 <= ind <= length (d. values) && d. values[ind] === nothing
857- return d. values[ind]
858- else
859- throw (KeyError (ind))
860- end
861- end
862- function Base. iterate (d:: BitDict , state... )
863- r = Base. iterate (d. keys, state... )
864- r === nothing && return nothing
865- k, state = r
866- (k => d. values[k]), state
867- end
868- function Base. empty! (d:: BitDict )
869- for v in d. keys
870- d. values[v] = nothing
871- end
872- empty! (d. keys)
873- d
874- end
875-
876- abstract type AbstractSimpleTreeIter{T} end
877- Base. IteratorSize (:: Type{<:AbstractSimpleTreeIter} ) = Base. SizeUnknown ()
878- Base. eltype (:: Type{<:AbstractSimpleTreeIter{T}} ) where {T} = childtype (T)
879- has_fast_reverse (:: Type{<:AbstractSimpleTreeIter} ) = true
880- has_fast_reverse (:: T ) where {T <: AbstractSimpleTreeIter } = has_fast_reverse (T)
881- reverse_buffer (it:: AbstractSimpleTreeIter ) = has_fast_reverse (it) ? nothing : eltype (it)[]
882- reverse_children! (:: Nothing , cs) = Iterators. reverse (cs)
883- function reverse_children! (rev_buff, cs)
884- Iterators. reverse (cs)
885- empty! (rev_buff)
886- for c in cs
887- push! (rev_buff, c)
888- end
889- Iterators. reverse (rev_buff)
890- end
891-
892- struct StatefulPreOrderDFS{T} <: AbstractSimpleTreeIter{T}
893- t:: T
894- end
895- function Base. iterate (it:: StatefulPreOrderDFS ,
896- state = (eltype (it)[it. t], reverse_buffer (it)))
897- stack, rev_buff = state
898- isempty (stack) && return nothing
899- t = pop! (stack)
900- for c in reverse_children! (rev_buff, children (t))
901- push! (stack, c)
902- end
903- return t, state
904- end
905- struct StatefulPostOrderDFS{T} <: AbstractSimpleTreeIter{T}
906- t:: T
907- end
908- function Base. iterate (it:: StatefulPostOrderDFS ,
909- state = (eltype (it)[it. t], falses (1 ), reverse_buffer (it)))
910- isempty (state[2 ]) && return nothing
911- vstack, sstack, rev_buff = state
912- while true
913- t = pop! (vstack)
914- isresume = pop! (sstack)
915- isresume && return t, state
916- push! (vstack, t)
917- push! (sstack, true )
918- for c in reverse_children! (rev_buff, children (t))
919- push! (vstack, c)
920- push! (sstack, false )
921- end
922- end
923- end
924-
925- # Note that StatefulBFS also returns the depth.
926- struct StatefulBFS{T} <: AbstractSimpleTreeIter{T}
927- t:: T
928- end
929- Base. eltype (:: Type{<:StatefulBFS{T}} ) where {T} = Tuple{Int, childtype (T)}
930- function Base. iterate (it:: StatefulBFS , queue = (eltype (it)[(0 , it. t)]))
931- isempty (queue) && return nothing
932- lv, t = popfirst! (queue)
933- nextlv = lv + 1
934- for c in children (t)
935- push! (queue, (nextlv, c))
936- end
937- return (lv, t), queue
938- end
939-
940- normalize_to_differential (s) = s
941-
942- function restrict_array_to_union (arr)
943- isempty (arr) && return arr
944- T = foldl (arr; init = Union{}) do prev, cur
945- Union{prev, typeof (cur)}
946- end
947- return Array {T, ndims(arr)} (arr)
948- end
949-
950744function _with_unit (f, x, t, args... )
951745 x = f (x, args... )
952746 if hasmetadata (x, VariableUnit) && (t isa Symbolic && hasmetadata (t, VariableUnit))
@@ -1142,22 +936,6 @@ function similar_variable(var::BasicSymbolic, name = :anon; use_gensym = true)
1142936 return sym
1143937end
1144938
1145- function guesses_from_metadata! (guesses, vars)
1146- varguesses = [getguess (v) for v in vars]
1147- hasaguess = findall (! isnothing, varguesses)
1148- for i in hasaguess
1149- haskey (guesses, vars[i]) && continue
1150- guesses[vars[i]] = varguesses[i]
1151- end
1152- end
1153-
1154- function has_diffvar_type (diffvar)
1155- st = symtype (diffvar)
1156- st === Real || eltype (st) === Real || st === Complex || eltype (st) === Complex ||
1157- st === Number || eltype (st) === Number || st === AbstractFloat ||
1158- eltype (st) === AbstractFloat
1159- end
1160-
1161939"""
1162940 $(TYPEDSIGNATURES)
1163941
0 commit comments