Skip to content

Commit

Permalink
[NF] Evaluate scalar product and power operator
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - OpenModelica/OMCompiler#2348
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 10, 2018
1 parent 5c7b2f0 commit e84261d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -574,6 +574,13 @@ public
end match;
end realValue;

function integerValue
input Expression exp;
output Integer value;
algorithm
INTEGER(value=value) := exp;
end integerValue;

function applySubscripts
input list<Subscript> subscripts;
input output Expression exp;
Expand Down
25 changes: 24 additions & 1 deletion Compiler/NFFrontEnd/NFSimplifyExp.mo
Expand Up @@ -155,7 +155,8 @@ protected
Integer i1, i2;
Real r1, r2;
Boolean b1, b2;
list<Expression> expl = {};
list<Expression> expl = {}, expl1, expl2;
Type ty;

import NFOperator.Op;
algorithm
Expand Down Expand Up @@ -193,6 +194,28 @@ algorithm
case Op.SUB then Expression.REAL(r1 - r2);
case Op.MUL then Expression.REAL(r1 * r2);
case Op.DIV then Expression.REAL(r1 / r2);
case Op.POW then Expression.REAL(r1 ^ r2);
else exp;
end match;

case Expression.BINARY(exp1=Expression.ARRAY(ty=ty, elements=expl1), exp2=Expression.ARRAY(elements=expl2))
then match (exp.operator.op, Type.elementType(ty))
case (Op.SCALAR_PRODUCT, Type.REAL())
algorithm
try
exp1 := Expression.REAL(sum(Expression.realValue(e1)*Expression.realValue(e2) threaded for e1 in expl1, e2 in expl2));
else
exp1 := exp;
end try;
then exp1;
case (Op.SCALAR_PRODUCT, Type.INTEGER())
algorithm
try
exp1 := Expression.INTEGER(sum(Expression.integerValue(e1)*Expression.integerValue(e2) threaded for e1 in expl1, e2 in expl2));
else
exp1 := exp;
end try;
then exp1;
else exp;
end match;

Expand Down

0 comments on commit e84261d

Please sign in to comment.