Skip to content

Commit

Permalink
Fix simplification of homotopy
Browse files Browse the repository at this point in the history
- Simplify homotopy in SimplifyExp instead of during typing, to avoid
  vectorization issues.
  • Loading branch information
perost committed Jan 14, 2021
1 parent 94acb25 commit 007380c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
23 changes: 0 additions & 23 deletions OMCompiler/Compiler/NFFrontEnd/NFBuiltinCall.mo
Expand Up @@ -122,7 +122,6 @@ public
case "edge" then typeEdgeCall(call, next_context, info);
case "fill" then typeFillCall(call, next_context, info);
case "getInstanceName" then typeGetInstanceName(call);
case "homotopy" then typeHomotopyCall(call, next_context, info);
//case "hold" guard Config.synchronousFeaturesAllowed() then typeHoldCall(call, next_context, info);
//case "initialState" guard Config.synchronousFeaturesAllowed() then typeInitialStateCall(call, next_context, info);
case "initial" then typeDiscreteCall(call, next_context, info);
Expand Down Expand Up @@ -2294,27 +2293,5 @@ protected
callExp := Expression.CALL(Call.unboxArgs(ty_call));
end typeSuperSampleCall;

function typeHomotopyCall
input Call call;
input InstContext.Type context;
input SourceInfo info;
output Expression callExp;
output Type ty;
output Variability var;
output Purity purity = Purity.IMPURE;
protected
Call ty_call;
list<Expression> args;
algorithm
ty_call as Call.TYPED_CALL(arguments = args, ty = ty, var = var) :=
Call.typeMatchNormalCall(call, context, info);

callExp := match Flags.getConfigString(Flags.REPLACE_HOMOTOPY)
case "actual" then listHead(args);
case "simplified" then listHead(listRest(args));
else Expression.CALL(Call.unboxArgs(ty_call));
end match;
end typeHomotopyCall;

annotation(__OpenModelica_Interface="frontend");
end NFBuiltinCall;
1 change: 0 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFFunction.mo
Expand Up @@ -1585,7 +1585,6 @@ uniontype Function
// can have variable number of arguments
case "fill" then true;
case "getInstanceName" then true;
case "homotopy" then true;
// Always discrete.
case "initial" then true;
case "inStream" then true;
Expand Down
13 changes: 13 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFSimplifyExp.mo
Expand Up @@ -236,6 +236,7 @@ algorithm
exp;

case "fill" then simplifyFill(listHead(args), listRest(args), call);
case "homotopy" then simplifyHomotopy(args, call);
case "ones" then simplifyFill(Expression.INTEGER(1), args, call);
case "sum" then simplifySumProduct(listHead(args), call, isSum = true);
case "product" then simplifySumProduct(listHead(args), call, isSum = false);
Expand Down Expand Up @@ -334,6 +335,18 @@ algorithm
end if;
end simplifyFill;

function simplifyHomotopy
input list<Expression> args;
input Call call;
output Expression exp;
algorithm
exp := match Flags.getConfigString(Flags.REPLACE_HOMOTOPY)
case "actual" then listHead(args);
case "simplified" then listHead(listRest(args));
else Expression.CALL(call);
end match;
end simplifyHomotopy;

function simplifyArrayConstructor
input Call call;
output Expression outExp;
Expand Down

0 comments on commit 007380c

Please sign in to comment.