Closed eschnett closed 13 years ago
Subject: Support multi-argument Max/Min
From: Erik Schnetter <eschnetter@perimeterinstitute.ca>
Date: 2011-08-30
Support multi-argument Max and Min calls in Kranc.
diff --git a/Tools/CodeGen/CodeGen.m b/Tools/CodeGen/CodeGen.m
index 93b1740..17654a8 100644
--- repos/Kranc/Tools/CodeGen/CodeGen.m
+++ repos/Kranc/Tools/CodeGen/CodeGen.m
@@ -961,8 +967,9 @@ ReplacePowers[expr_, vectorise_] :=
(* there have been some problems doing the Max/Min
replacement via the preprocessor for C, so we do it
here *)
- rhs = rhs /. Max[xx_, yy_] -> fmax[xx, yy];
- rhs = rhs /. Min[xx_, yy_] -> fmin[xx, yy];
+ (* Note: Mathematica simplifies Max[xx_] -> xx automatically *)
+ rhs = rhs //. Max[xx_, yy__] -> fmax[xx, Max[yy]];
+ rhs = rhs //. Min[xx_, yy__] -> fmin[xx, Min[yy]];
rhs = rhs /. Power[xx_, power_] -> pow[xx, power];
Looks good. Thanks. Please commit.
Pushed.
Support multi-argument Max and Min calls in Kranc.