Skip to content

Commit

Permalink
CalculationFunction.m: Don't factor out repeated conditionals if the …
Browse files Browse the repository at this point in the history
…condition contains a gridfunction

This transformation would be wrong in the case of vectorisation.  It is usually used for parameter conditions.
  • Loading branch information
ianhinder committed Jul 17, 2013
1 parent 36671c3 commit 644c8cd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Tools/CodeGen/CalculationFunction.m
Expand Up @@ -873,6 +873,15 @@ pathalogical enough (e.g. {s1 -> s2, s2 -> s1} would not be
(* Replace grid functions with their local forms *)
eqsReplaced = eqs2 /. localMap;

gridFunctionsFreeQ[x_] :=
Module[
{r},
(* Print["groups = ", groups]; *)
(* Print["gridFunctionsFreeQ[", x, "] ="]; *)
r = GridFunctionsInExpression[x, groups/.localMap] === {};
(* Print[" ", r]; *)
r];

(* Construct a list, corresponding to the list of equations,
marking those which need their LHS variables declared. We
declare variables at the same time as assigning to them as it
Expand All @@ -886,7 +895,7 @@ pathalogical enough (e.g. {s1 -> s2, s2 -> s1} would not be
(* Replace consecutive IfThen statements with the same condition by a single IfThenGroup *)
groupedIfs = Thread[{declare, eqsReplaced}] //.
{{x___, {deca_, a_->IfThen[cond_, at_, af_]}, {decb_, b_->IfThen[cond_, bt_, bf_]}, y___} :>
{x, {{deca, decb}, IfThenGroup[cond, {a->at, b->bt}, {a->af, b->bf}]}, y},
{x, {{deca, decb}, IfThenGroup[cond, {a->at, b->bt}, {a->af, b->bf}]}, y} /; gridFunctionsFreeQ[cond],
{x___, {deca_, IfThenGroup[cond_, at_, af_]}, {decb_, b_->IfThen[cond_, bt_, bf_]}, y___} :>
{x, {Join[deca, {decb}], IfThenGroup[cond, Join[at, {b->bt}], Join[af, {b->bf}]]}, y},
{x___, {deca_, IfThenGroup[cond_, at_, af_]}, {decb_, IfThenGroup[cond_, bt_, bf_]}, y___} :>
Expand Down

0 comments on commit 644c8cd

Please sign in to comment.