11
11
12
12
get_iv (D:: Differential ) = D. x
13
13
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
28
14
29
15
function detime_dvs (op)
30
16
if ! iscall (op)
@@ -49,24 +35,11 @@ function modified_unknowns!(munknowns, e::Equation, unknownlist = nothing)
49
35
get_variables! (munknowns, e. lhs, unknownlist)
50
36
end
51
37
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
-
63
38
function todict (d)
64
39
eltype (d) <: Pair || throw (ArgumentError (" The variable-value mapping must be a Dict." ))
65
40
d isa Dict ? d : Dict (d)
66
41
end
67
42
68
- _merge (d1, d2) = merge (todict (d1), todict (d2))
69
-
70
43
function _readable_code (ex)
71
44
ex isa Expr || return ex
72
45
if ex. head === :call
248
221
249
222
hasdefault (v) = hasmetadata (v, Symbolics. VariableDefaultValue)
250
223
getdefault (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
255
224
function setdefault (v, val)
256
225
val === nothing ? v : wrap (setdefaultval (unwrap (v), value (val)))
257
226
end
@@ -510,18 +479,6 @@ function collect_applied_operators(x, op)
510
479
end
511
480
end
512
481
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
-
525
482
"""
526
483
$(TYPEDSIGNATURES)
527
484
@@ -725,24 +682,6 @@ function check_scope_depth(scope, depth)
725
682
end
726
683
end
727
684
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
-
746
685
isarray (x) = x isa AbstractArray || x isa Symbolics. Arr
747
686
748
687
function empty_substitutions (sys)
@@ -753,30 +692,6 @@ function get_substitutions(sys)
753
692
Dict ([eq. lhs => eq. rhs for eq in observed (sys)])
754
693
end
755
694
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
-
780
695
@noinline function throw_missingvars_in_sys (vars)
781
696
throw (ArgumentError (" $vars are either missing from the variable map or missing from the system's unknowns/parameters list." ))
782
697
end
@@ -831,119 +746,6 @@ function promote_to_concrete(vs; tofloat = true, use_union = true)
831
746
return y
832
747
end
833
748
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
-
947
749
function _with_unit (f, x, t, args... )
948
750
x = f (x, args... )
949
751
if hasmetadata (x, VariableUnit) && (t isa Symbolic && hasmetadata (t, VariableUnit))
@@ -1139,22 +941,6 @@ function similar_variable(var::BasicSymbolic, name = :anon; use_gensym = true)
1139
941
return sym
1140
942
end
1141
943
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
-
1158
944
"""
1159
945
$(TYPEDSIGNATURES)
1160
946
0 commit comments