Skip to content

Commit

Permalink
Add support for using Sign in a function
Browse files Browse the repository at this point in the history
Also improve support for using StepFunction.
  • Loading branch information
barrywardell committed Mar 7, 2014
1 parent e4a501e commit ebf2eb3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Tools/CodeGen/xTensorKranc.m
Expand Up @@ -65,7 +65,8 @@
DefManifold[KrancManifold, dimension, $KrancIndices];
DefBasis[KrancBasis, TangentKrancManifold, Range[dimension]];
DefInertHead[dot];
DefScalarFunction[StepFunction];
DefInertHead[KrancSign];
DefInertHead[StepFunction];
];

(*************************************************************)
Expand Down Expand Up @@ -181,6 +182,7 @@

krancForm[expr_] :=
expr //. {
KrancSign[x_] :> Sign[x],
Scalar[x_] :> NoScalar[x],
pd_?CovDQ[i__][pd_?CovDQ[j__][t_]] :> pd[j, i][t],
nd_[pd_?CovDQ[i : (_?CIndexQ ..)][t_?xTensorQ[inds___]]] :>
Expand All @@ -199,7 +201,7 @@
InfoMessage[InfoFull, "Expanding tensor expression: ", InputForm[l] -> InputForm[r]];

(* Add brackets to scalars if they aren't present *)
{lhs, rhs} = {l, r} /. {t_?KrancScalarQ[] -> t[], t_?KrancScalarQ -> t[]};
{lhs, rhs} = {l, r} /. {t_?KrancScalarQ[] -> t[], t_?KrancScalarQ -> t[], Sign[t_] :> KrancSign[t]};

(* Check we have a valid tensor equation *)
(* FIXME: Maybe we should find an alternative to Quiet here *)
Expand All @@ -226,7 +228,7 @@
ExpandComponents[x_] :=
Module[{expr},
(* Add brackets to scalars if they aren't present *)
expr = x /. {t_?KrancScalarQ[] -> t[], t_?KrancScalarQ -> t[]};
expr = x /. {t_?KrancScalarQ[] -> t[], t_?KrancScalarQ -> t[], Sign[t_] :> KrancSign[t]};

(* FIXME: Maybe we should find an alternative to Quiet here *)
Check[Quiet[Validate[expr], Validate::unknown], ThrowError["Invalid tensor expression"]];
Expand Down

0 comments on commit ebf2eb3

Please sign in to comment.