Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 45f753c

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
[NF] Unlift arrays types when expanding expressions
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]: - #2352
1 parent 20ca004 commit 45f753c

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ public
753753
end for;
754754

755755
newlst := listReverse(newlst);
756-
outExp := arrayFromList(newlst, ty, restdims);
756+
outExp := arrayFromList_impl(newlst, ty, restdims);
757757
end arrayFromList_impl;
758758

759759
function makeEnumLiteral
@@ -2220,12 +2220,11 @@ public
22202220
expl1 := arrayElements(expand(exp1));
22212221
expl2 := arrayElements(expand(exp2));
22222222
ty := Operator.typeOf(op);
2223-
2223+
eop := Operator.setType(Type.unliftArray(ty), op);
22242224
if Type.dimensionCount(ty) > 1 then
2225-
eop := Operator.setType(Type.unliftArray(ty), op);
22262225
expl := list(expandBinaryElementWise(e1, eop, e2) threaded for e1 in expl1, e2 in expl2);
22272226
else
2228-
expl := list(BINARY(e1, op, e2) threaded for e1 in expl1, e2 in expl2);
2227+
expl := list(BINARY(e1, eop, e2) threaded for e1 in expl1, e2 in expl2);
22292228
end if;
22302229

22312230
exp := ARRAY(Operator.typeOf(op), expl);
@@ -2336,20 +2335,20 @@ public
23362335
output Expression exp;
23372336
protected
23382337
list<Expression> expl1, expl2;
2339-
Type ty;
2338+
Type ty, tyUnlift;
23402339
Operator mul_op, add_op;
23412340
algorithm
23422341
ARRAY(ty, expl1) := exp1;
23432342
ARRAY( _, expl2) := exp2;
2343+
tyUnlift := Type.unliftArray(ty);
23442344

23452345
if listEmpty(expl1) then
23462346
// Scalar product of two empty arrays. The result is defined in the spec
23472347
// by sum, so we return 0 since that's the default value of sum.
2348-
exp := makeZero(ty);
2348+
exp := makeZero(tyUnlift);
23492349
end if;
2350-
2351-
mul_op := Operator.makeMul(ty);
2352-
add_op := Operator.makeAdd(ty);
2350+
mul_op := Operator.makeMul(tyUnlift);
2351+
add_op := Operator.makeAdd(tyUnlift);
23532352
expl1 := list(BINARY(e1, mul_op, e2) threaded for e1 in expl1, e2 in expl2);
23542353
exp := List.reduce(expl1, function makeBinaryOp(op = add_op));
23552354
end makeScalarProduct;

0 commit comments

Comments
 (0)