diff options
Diffstat (limited to 'Tools/CodeGen')
-rw-r--r-- | Tools/CodeGen/CalculationFunction.m | 2 | ||||
-rw-r--r-- | Tools/CodeGen/CodeGen.m | 16 |
2 files changed, 15 insertions, 3 deletions
diff --git a/Tools/CodeGen/CalculationFunction.m b/Tools/CodeGen/CalculationFunction.m index 7d395ed..44689ab 100644 --- a/Tools/CodeGen/CalculationFunction.m +++ b/Tools/CodeGen/CalculationFunction.m @@ -652,7 +652,7 @@ equationLoop[eqs_, cleancalc_, gfs_, shorts_, incs_, groups_, pddefs_, {DeclareVariables[localName/@#2, DataType[]],"\n", Conditional[#1, Table[AssignVariableInLoop[localName[var], GridName[var], useVectors], {var, #2}], - Sequence@@If[#3 =!= None, {Table[AssignVariableInLoop[localName[var], #3, useVectors], {var, #2}]}, {}]]}, + Sequence@@If[#3 =!= None, {Table[AssignVariableInLoop[localName[var], #3, False (*useVectors*)], {var, #2}]}, {}]]}, (* else *) {}] &, {Map[#[[2]]&, conds], varsInConds, Map[#[[3]]&, conds]}], "\n"]}}; diff --git a/Tools/CodeGen/CodeGen.m b/Tools/CodeGen/CodeGen.m index fccdb41..5e8cd6a 100644 --- a/Tools/CodeGen/CodeGen.m +++ b/Tools/CodeGen/CodeGen.m @@ -774,12 +774,24 @@ BoundaryWithGhostsLoop[block_] := ]} ]]]}; +(* Remove call to ToReal from condtion. This should really instead be + done much earlier. Sometimes Conditional is called with a + conditional that is an expression, sometimes it is a list of + strings, so we need to handle both cases. *) +(* One approach to remove calls to ToReal is to wrap the condition + into a function call, such as e.g. Cond[x], which is then handled by + the vectorisation code in the same way the IfThen[x,y,z] expression + is handled there. *) +removeToRealFunc[condition_] := Replace[condition, {ToReal[x_] -> x}] +removeToRealString[condition_] := If[StringQ[condition], StringReplace[condition, "ToReal(" ~~ x__ ~~ ")" :> x], condition] +removeToReal[condition_] := Map[removeToRealString, removeToRealFunc[condition]] + Conditional[condition_, block_] := - {"if (", condition, ")\n", + {"if (", removeToReal[condition], ")\n", CBlock[block]}; Conditional[condition_, block1_, block2_] := - {"if (", condition, ")\n", + {"if (", removeToReal[condition], ")\n", CBlock[block1], "else\n", CBlock[block2]}; onceInGridLoop[block_] := |