Skip to content

Commit

Permalink
[NF] Unlift arrays types when expanding expressions
Browse files Browse the repository at this point in the history
This is now done for element-wise operations and matrix-vector
multiplication. There might be other operations that do not set the type
correctly.

Belonging to [master]:
  - OpenModelica/OMCompiler#2352
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 11, 2018
1 parent 20ca004 commit 45f753c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -753,7 +753,7 @@ public
end for;

newlst := listReverse(newlst);
outExp := arrayFromList(newlst, ty, restdims);
outExp := arrayFromList_impl(newlst, ty, restdims);
end arrayFromList_impl;

function makeEnumLiteral
Expand Down Expand Up @@ -2220,12 +2220,11 @@ public
expl1 := arrayElements(expand(exp1));
expl2 := arrayElements(expand(exp2));
ty := Operator.typeOf(op);

eop := Operator.setType(Type.unliftArray(ty), op);
if Type.dimensionCount(ty) > 1 then
eop := Operator.setType(Type.unliftArray(ty), op);
expl := list(expandBinaryElementWise(e1, eop, e2) threaded for e1 in expl1, e2 in expl2);
else
expl := list(BINARY(e1, op, e2) threaded for e1 in expl1, e2 in expl2);
expl := list(BINARY(e1, eop, e2) threaded for e1 in expl1, e2 in expl2);
end if;

exp := ARRAY(Operator.typeOf(op), expl);
Expand Down Expand Up @@ -2336,20 +2335,20 @@ public
output Expression exp;
protected
list<Expression> expl1, expl2;
Type ty;
Type ty, tyUnlift;
Operator mul_op, add_op;
algorithm
ARRAY(ty, expl1) := exp1;
ARRAY( _, expl2) := exp2;
tyUnlift := Type.unliftArray(ty);

if listEmpty(expl1) then
// Scalar product of two empty arrays. The result is defined in the spec
// by sum, so we return 0 since that's the default value of sum.
exp := makeZero(ty);
exp := makeZero(tyUnlift);
end if;

mul_op := Operator.makeMul(ty);
add_op := Operator.makeAdd(ty);
mul_op := Operator.makeMul(tyUnlift);
add_op := Operator.makeAdd(tyUnlift);
expl1 := list(BINARY(e1, mul_op, e2) threaded for e1 in expl1, e2 in expl2);
exp := List.reduce(expl1, function makeBinaryOp(op = add_op));
end makeScalarProduct;
Expand Down

0 comments on commit 45f753c

Please sign in to comment.