Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Fix types when simplifying arrays/matrices with 3 dimensions


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9695 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Aug 26, 2011
1 parent ca0858f commit d3e8bf2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
14 changes: 12 additions & 2 deletions Compiler/FrontEnd/ExpressionDump.mo
Expand Up @@ -272,8 +272,18 @@ algorithm
s;

case (DAE.POW(ty = t)) then " ^ ";
case (DAE.ADD_ARR(ty = _)) then " + ";
case (DAE.SUB_ARR(ty = _)) then " - ";
case (DAE.ADD_ARR(ty = t))
equation
ts = typeString(t);
s = stringAppendList({" +<ADD_ARR><", ts, "> "});
then
s;
case (DAE.SUB_ARR(ty = t))
equation
ts = typeString(t);
s = stringAppendList({" -<SUB_ARR><", ts, "> "});
then
s;
case (DAE.MUL_ARR(ty = _)) then " *<MUL_ARRAY> ";
case (DAE.DIV_ARR(ty = _)) then " / ";
case (DAE.POW_ARR(ty = _)) then " ^ ";
Expand Down
55 changes: 39 additions & 16 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -1179,25 +1179,23 @@ algorithm
DAE.Exp e_1,e1,e2,res,s1,a1;
Type tp,atp,atp2;
Boolean b;
Operator op2;
Operator op2,op;

case (e1,DAE.MUL_MATRIX_PRODUCT(ty = tp),e2)
equation
e_1 = simplifyMatrixProduct(e1, e2);
then
e_1;

case(e1,DAE.ADD_ARR(ty = _),e2)
case(e1,op as DAE.ADD_ARR(ty = _),e2)
equation
tp = Expression.typeof(e1);
a1 = simplifyVectorBinary0(e1,DAE.ADD(tp),e2);
a1 = simplifyVectorBinary0(e1,op,e2);
then
a1;

case (e1,DAE.SUB_ARR(ty = _),e2)
case (e1,op as DAE.SUB_ARR(ty = _),e2)
equation
tp = Expression.typeof(e1);
a1 = simplifyVectorBinary0(e1, DAE.SUB(tp), e2);
a1 = simplifyVectorBinary0(e1, op, e2);
then
a1;

Expand Down Expand Up @@ -1403,16 +1401,15 @@ algorithm
then
res;

case (e1,DAE.ADD_ARR(ty = _),e2)
case (e1,op as DAE.ADD_ARR(ty = _),e2)
equation
tp = Expression.typeof(e1);
a1 = simplifyMatrixBinary(e1, DAE.ADD(tp), e2);
a1 = simplifyMatrixBinary(e1, op, e2);
then a1;

case (e1,DAE.SUB_ARR(ty = _),e2)
case (e1,op as DAE.SUB_ARR(ty = _),e2)
equation
tp = Expression.typeof(e1);
a1 = simplifyMatrixBinary(e1, DAE.SUB(tp), e2);
a1 = simplifyMatrixBinary(e1, op, e2);
// print("simplifyMatrixBinary: " +& ExpressionDump.printExpStr(e1) +& "=>" +& ExpressionDump.printExpStr(a1) +& "\n");
then a1;
end matchcontinue;
end simplifyBinaryArray;
Expand Down Expand Up @@ -1644,6 +1641,18 @@ algorithm
then
e2;

case(e1,DAE.ADD_ARR(ty=_),e2)
equation
true = Expression.isZero(e1);
then
e2;

case(e1,DAE.SUB_ARR(ty=_),e2)
equation
true = Expression.isZero(e1);
then
Expression.negate(e2);

case(e1,DAE.SUB(ty=_),e2)
equation
true = Expression.isZero(e1);
Expand Down Expand Up @@ -1797,6 +1806,7 @@ algorithm
case ({(e1,b1)},op,{(e2,b2)})
equation
op2 = removeOperatorDimension(op);
// failure(_ = removeOperatorDimension(op2));
b = b1 or b2;
e = DAE.BINARY(e1,op2,e2);
then {(e,b)}; // resulting operator
Expand Down Expand Up @@ -4022,9 +4032,22 @@ Helper function for simplifyVectorBinary, removes an dimension from the operator
input Operator inop;
output Operator outop;
algorithm outop := match(inop)
local Type ty1,ty2;
case( DAE.ADD(ty=ty1)) equation ty2 = Expression.unliftArray(ty1); then DAE.ADD(ty2);
case( DAE.SUB(ty=ty1)) equation ty2 = Expression.unliftArray(ty1); then DAE.SUB(ty2);
local
Type ty1,ty2;
Boolean b;
Operator op;
case DAE.ADD_ARR(ty=ty1)
equation
ty2 = Expression.unliftArray(ty1);
b = DAEUtil.expTypeArray(ty2);
op = Util.if_(b, DAE.ADD_ARR(ty2), DAE.ADD(ty2));
then op;
case DAE.SUB_ARR(ty=ty1)
equation
ty2 = Expression.unliftArray(ty1);
b = DAEUtil.expTypeArray(ty2);
op = Util.if_(b, DAE.SUB_ARR(ty2), DAE.SUB(ty2));
then op;
end match;
end removeOperatorDimension;

Expand Down

0 comments on commit d3e8bf2

Please sign in to comment.