Skip to content

Commit

Permalink
Handle Piecewise[] in code generation
Browse files Browse the repository at this point in the history
Replace Piecewise[] by IfThen[] calls.
Unfortunately, this does not work with vectorisation.
  • Loading branch information
eschnett committed Sep 8, 2012
1 parent a5c9127 commit 84338f2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Tools/CodeGen/CodeGenCactus.m
Expand Up @@ -741,6 +741,16 @@
rhs = rhs /. 8/3 -> keightthird;
rhs = rhs /. -8/3 -> -keightthird;
*)

(* Handle Piecewise function *)
(* TODO: This does not work with vectorisation, since IfThen
there expects a constant condition *)
rhs = rhs /. Piecewise -> piecewise1
//. piecewise1[pairs_List, val_:0] :>
If[pairs==={}, val,
IfThen[First[pairs][[2]],
First[pairs][[1]],
piecewise1[Rest[pairs], val]]];

(* Remove parentheses *)
rhs = rhs //. Parenthesis[xx_] -> xx;
Expand Down

0 comments on commit 84338f2

Please sign in to comment.