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
@@ -725,24 +678,6 @@ function check_scope_depth(scope, depth)
725678 end
726679end
727680
728- """
729- $(SIGNATURES)
730-
731- find duplicates in an iterable object.
732- """
733- function find_duplicates (xs, :: Val{Ret} = Val (false )) where {Ret}
734- appeared = Set ()
735- duplicates = Set ()
736- for x in xs
737- if x in appeared
738- push! (duplicates, x)
739- else
740- push! (appeared, x)
741- end
742- end
743- return Ret ? (appeared, duplicates) : duplicates
744- end
745-
746681isarray (x) = x isa AbstractArray || x isa Symbolics. Arr
747682
748683function empty_substitutions (sys)
@@ -753,30 +688,6 @@ function get_substitutions(sys)
753688 Dict ([eq. lhs => eq. rhs for eq in observed (sys)])
754689end
755690
756- function mergedefaults (defaults, varmap, vars)
757- defs = if varmap isa Dict
758- merge (defaults, varmap)
759- elseif eltype (varmap) <: Pair
760- merge (defaults, Dict (varmap))
761- elseif eltype (varmap) <: Number
762- merge (defaults, Dict (zip (vars, varmap)))
763- else
764- defaults
765- end
766- end
767-
768- function mergedefaults (defaults, observedmap, varmap, vars)
769- defs = if varmap isa Dict
770- merge (observedmap, defaults, varmap)
771- elseif eltype (varmap) <: Pair
772- merge (observedmap, defaults, Dict (varmap))
773- elseif eltype (varmap) <: Number
774- merge (observedmap, defaults, Dict (zip (vars, varmap)))
775- else
776- merge (observedmap, defaults)
777- end
778- end
779-
780691@noinline function throw_missingvars_in_sys (vars)
781692 throw (ArgumentError (" $vars are either missing from the variable map or missing from the system's unknowns/parameters list." ))
782693end
@@ -831,119 +742,6 @@ function promote_to_concrete(vs; tofloat = true, use_union = true)
831742 return y
832743end
833744
834- struct BitDict <: AbstractDict{Int, Int}
835- keys:: Vector{Int}
836- values:: Vector{Union{Nothing, Int}}
837- end
838- BitDict (n:: Integer ) = BitDict (Int[], Union{Nothing, Int}[nothing for _ in 1 : n])
839- struct BitDictKeySet <: AbstractSet{Int}
840- d:: BitDict
841- end
842-
843- Base. keys (d:: BitDict ) = BitDictKeySet (d)
844- Base. in (v:: Integer , s:: BitDictKeySet ) = s. d. values[v] != = nothing
845- Base. iterate (s:: BitDictKeySet , state... ) = iterate (s. d. keys, state... )
846- function Base. setindex! (d:: BitDict , val:: Integer , ind:: Integer )
847- if 1 <= ind <= length (d. values) && d. values[ind] === nothing
848- push! (d. keys, ind)
849- end
850- d. values[ind] = val
851- end
852- function Base. getindex (d:: BitDict , ind:: Integer )
853- if 1 <= ind <= length (d. values) && d. values[ind] === nothing
854- return d. values[ind]
855- else
856- throw (KeyError (ind))
857- end
858- end
859- function Base. iterate (d:: BitDict , state... )
860- r = Base. iterate (d. keys, state... )
861- r === nothing && return nothing
862- k, state = r
863- (k => d. values[k]), state
864- end
865- function Base. empty! (d:: BitDict )
866- for v in d. keys
867- d. values[v] = nothing
868- end
869- empty! (d. keys)
870- d
871- end
872-
873- abstract type AbstractSimpleTreeIter{T} end
874- Base. IteratorSize (:: Type{<:AbstractSimpleTreeIter} ) = Base. SizeUnknown ()
875- Base. eltype (:: Type{<:AbstractSimpleTreeIter{T}} ) where {T} = childtype (T)
876- has_fast_reverse (:: Type{<:AbstractSimpleTreeIter} ) = true
877- has_fast_reverse (:: T ) where {T <: AbstractSimpleTreeIter } = has_fast_reverse (T)
878- reverse_buffer (it:: AbstractSimpleTreeIter ) = has_fast_reverse (it) ? nothing : eltype (it)[]
879- reverse_children! (:: Nothing , cs) = Iterators. reverse (cs)
880- function reverse_children! (rev_buff, cs)
881- Iterators. reverse (cs)
882- empty! (rev_buff)
883- for c in cs
884- push! (rev_buff, c)
885- end
886- Iterators. reverse (rev_buff)
887- end
888-
889- struct StatefulPreOrderDFS{T} <: AbstractSimpleTreeIter{T}
890- t:: T
891- end
892- function Base. iterate (it:: StatefulPreOrderDFS ,
893- state = (eltype (it)[it. t], reverse_buffer (it)))
894- stack, rev_buff = state
895- isempty (stack) && return nothing
896- t = pop! (stack)
897- for c in reverse_children! (rev_buff, children (t))
898- push! (stack, c)
899- end
900- return t, state
901- end
902- struct StatefulPostOrderDFS{T} <: AbstractSimpleTreeIter{T}
903- t:: T
904- end
905- function Base. iterate (it:: StatefulPostOrderDFS ,
906- state = (eltype (it)[it. t], falses (1 ), reverse_buffer (it)))
907- isempty (state[2 ]) && return nothing
908- vstack, sstack, rev_buff = state
909- while true
910- t = pop! (vstack)
911- isresume = pop! (sstack)
912- isresume && return t, state
913- push! (vstack, t)
914- push! (sstack, true )
915- for c in reverse_children! (rev_buff, children (t))
916- push! (vstack, c)
917- push! (sstack, false )
918- end
919- end
920- end
921-
922- # Note that StatefulBFS also returns the depth.
923- struct StatefulBFS{T} <: AbstractSimpleTreeIter{T}
924- t:: T
925- end
926- Base. eltype (:: Type{<:StatefulBFS{T}} ) where {T} = Tuple{Int, childtype (T)}
927- function Base. iterate (it:: StatefulBFS , queue = (eltype (it)[(0 , it. t)]))
928- isempty (queue) && return nothing
929- lv, t = popfirst! (queue)
930- nextlv = lv + 1
931- for c in children (t)
932- push! (queue, (nextlv, c))
933- end
934- return (lv, t), queue
935- end
936-
937- normalize_to_differential (s) = s
938-
939- function restrict_array_to_union (arr)
940- isempty (arr) && return arr
941- T = foldl (arr; init = Union{}) do prev, cur
942- Union{prev, typeof (cur)}
943- end
944- return Array {T, ndims(arr)} (arr)
945- end
946-
947745function _with_unit (f, x, t, args... )
948746 x = f (x, args... )
949747 if hasmetadata (x, VariableUnit) && (t isa Symbolic && hasmetadata (t, VariableUnit))
@@ -1139,22 +937,6 @@ function similar_variable(var::BasicSymbolic, name = :anon; use_gensym = true)
1139937 return sym
1140938end
1141939
1142- function guesses_from_metadata! (guesses, vars)
1143- varguesses = [getguess (v) for v in vars]
1144- hasaguess = findall (! isnothing, varguesses)
1145- for i in hasaguess
1146- haskey (guesses, vars[i]) && continue
1147- guesses[vars[i]] = varguesses[i]
1148- end
1149- end
1150-
1151- function has_diffvar_type (diffvar)
1152- st = symtype (diffvar)
1153- st === Real || eltype (st) === Real || st === Complex || eltype (st) === Complex ||
1154- st === Number || eltype (st) === Number || st === AbstractFloat ||
1155- eltype (st) === AbstractFloat
1156- end
1157-
1158940"""
1159941 $(TYPEDSIGNATURES)
1160942
0 commit comments