File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ import SymbolicUtils: symtype, term, hasmetadata, issym
2
+ struct MTKConstantCtx end
3
+
4
+ function isconstant (x)
5
+ x = unwrap (x)
6
+ x isa Symbolic && getmetadata (x, MTKConstantCtx, false )
7
+ end
8
+
9
+ """
10
+ toconst(s::Sym)
11
+
12
+ Maps the parameter to a constant. The parameter must have a default.
13
+ """
14
+ function toconst (s)
15
+ if s isa Symbolics. Arr
16
+ Symbolics. wrap (toconst (Symbolics. unwrap (s)))
17
+ elseif s isa AbstractArray
18
+ map (toconst, s)
19
+ else
20
+ assert (hasmetadata (s,VariableDefaultValue))
21
+ setmetadata (s, MTKConstCtx, true )
22
+ end
23
+ end
24
+ toconst (s:: Num ) = wrap (toconst (value (s)))
25
+
26
+ """
27
+ $(SIGNATURES)
28
+
29
+ Define one or more known variables.
30
+ """
31
+ macro constants (xs... )
32
+ Symbolics. _parse_vars (:constants ,
33
+ Real,
34
+ xs,
35
+ toconst) |> esc
36
+ end
You can’t perform that action at this time.
0 commit comments