1- import SymbolicUtils: symtype, term, hasmetadata, issym
2- struct MTKConstantCtx end
3-
4- isconstant (x:: Num ) = isconstant (unwrap (x))
51"""
62Test whether `x` is a constant-type Sym.
73"""
84function isconstant (x)
95 x = unwrap (x)
10- x isa Symbolic && getmetadata (x, MTKConstantCtx, false )
6+ x isa Symbolic && ! getmetadata (x, VariableTunable, true )
117end
128
139"""
1612Maps the parameter to a constant. The parameter must have a default.
1713"""
1814function toconstant (s)
19- hasmetadata (s, Symbolics. VariableDefaultValue) ||
20- throw (ArgumentError (" Constant `$(s) ` must be assigned a default value." ))
21- setmetadata (s, MTKConstantCtx, true )
15+ s = toparam (s)
16+ setmetadata (s, VariableTunable, false )
2217end
2318
24- toconstant (s:: Num ) = wrap (toconstant (value (s)))
19+ toconstant (s:: Union{ Num, Symbolics.Arr} ) = wrap (toconstant (value (s)))
2520
2621"""
2722$(SIGNATURES)
@@ -36,15 +31,3 @@ macro constants(xs...)
3631 xs,
3732 toconstant) |> esc
3833end
39-
40- """
41- Substitute all `@constants` in the given expression
42- """
43- function subs_constants (eqs)
44- consts = collect_constants (eqs)
45- if ! isempty (consts)
46- csubs = Dict (c => getdefault (c) for c in consts)
47- eqs = substitute (eqs, csubs)
48- end
49- return eqs
50- end
0 commit comments