Skip to content

Commit

Permalink
Minor fixes: Parameter type declarations, more built-in functions (e.…
Browse files Browse the repository at this point in the history
…g. abs, tan, tanh), and avoid auto temps
  • Loading branch information
stevenrbrandt committed Aug 12, 2015
1 parent da057cf commit 07d7acc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Auxiliary/Grammars/kranc2.peg
Expand Up @@ -19,7 +19,7 @@ dname = D[a-z0-9]*
rawtext = ((?=\}\}){brk}|.)*
rawmath = @m\{\{{rawtext}\}\}
rawc = @c\{\{{rawtext}\}\}
dtensor = {dname}{indices}? ({tensor}|{expr})
dtensor = {dname}{indices}? {tensor}
number = -?[0-9]+(\.[0-9]*|)([eEdD][+-]?[0-9]+|)
func = {name} \( ({expr}( , {expr})*|) \)
neg = -
Expand Down
29 changes: 24 additions & 5 deletions Tools/CodeGen/KrancScript.m
Expand Up @@ -201,8 +201,13 @@
process["func"["name"[name_],exprs__]] :=
Module[
{fns},
fns = {"sin" -> Sin, "cos" -> Cos, "if" -> IfThen, "max" -> Max,
"sqrt" -> Sqrt, "exp" -> Exp};
fns = {"sin" -> Sin, "cos" -> Cos,
"tan" -> Tan, "cot" -> Cot,
"sec" -> Sec, "csc" -> Csc,
"atan" -> ArcTan, "asin" -> ArcSin, "acos" -> ArcCos,
"sinh" -> Sinh, "cosh" -> Cosh, "tanh" -> Tanh,
(* "if" -> IfThen, *) "max" -> Max, "min" -> Min,
"abs"->Abs,"sqrt" -> Sqrt, "exp" -> Exp};
If[MemberQ[First/@fns,name], (name/.fns)@@Map[process,{exprs}],
(* If it's not a function call, it's an explicit multiply *)
process["mul"["mexpr"["mul"["pow"["value"["tensor"["name"[name],"indices"[]]]]]],"mulop"["*"],"mexpr"[exprs]]]]];
Expand Down Expand Up @@ -262,33 +267,47 @@
AllowedValues -> {{Value->ToString[lotmp] <> ":" <> ToString[hitmp]}},
Default -> dtmp}]

process["parameter"["name"[nm_],"type"[desc_],"expr"[exprd_]]] :=
process["parameter"["name"[nm_],"type"[ty_],"expr"[exprd_]]] :=
Module[{dtmp,lotmp,hitmp},
dtmp = process[exprd];
lotmp = "*";
hitmp = "*";
{Name -> ToExpression[nm],
VariableType -> ty,
Description -> "Parameter " <> nm, (*StringTake[desc,{2,StringLength[desc]-1}],*)
AllowedValues -> {{Value->ToString[lotmp] <> ":" <> ToString[hitmp]}},
Default -> dtmp}]

process["parameter"["name"[nm_],"type"[desc_],"quote"[def_]]] :=
process["parameter"["name"[nm_], "type"[ty_], "quote"[desc_], "expr"[exprd_]]] :=
Module[{dtmp,lotmp,hitmp},
dtmp = process[exprd];
lotmp = "*";
hitmp = "*";
{Name -> ToExpression[nm],
VariableType -> ty,
Description -> StringTake[desc,{2,StringLength[desc]-1}],
AllowedValues -> {{Value->ToString[lotmp] <> ":" <> ToString[hitmp]}},
Default -> dtmp}]

process["parameter"["name"[nm_],"type"[ty_],"quote"[desc_]]] :=
Module[{dtmp,lotmp,hitmp},
dtmp = 1.0;
lotmp = "*";
hitmp = "*";
{Name -> ToExpression[nm],
VariableType -> ty,
Description -> StringTake[desc,{2,StringLength[desc]-1}],
AllowedValues -> {{Value->ToString[lotmp] <> ":" <> ToString[hitmp]}},
Default -> dtmp}]

process["parameter"["name"[nm_],"type"["real"],"quote"[desc_],"expr"[def_],"parlo"[le__],"parhi"[re__]]] :=
process["parameter"["name"[nm_],"type"[ty_],"quote"[desc_],"expr"[def_],"parlo"[le__],"parhi"[re__]]] :=
Module[{dtmp,lotmp,hitmp},
dtmp = N[process[def]];
lotmp = processRange[process[le],"Minimum",nm];
hitmp = processRange[process[re],"Maximum",nm];
If[NumberQ[dtmp],1,ThrowError["Default value for parameter "<>nm<>" is not a number"]];
{Name -> ToExpression[nm],
VariableType -> ty,
Description -> StringTake[desc,{2,StringLength[desc]-1}],
AllowedValues -> {{Value->ToString[lotmp] <> ":" <> ToString[hitmp]}},
Default -> dtmp}]
Expand Down

0 comments on commit 07d7acc

Please sign in to comment.