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

Commit

Permalink
some minor optimizations
Browse files Browse the repository at this point in the history
- remove a matchcontinue
- do not operate twice on list
- make function tail recursive
- avoid tuples

Belonging to [master]:
  - #1947
  • Loading branch information
hkiel authored and OpenModelica-Hudson committed Oct 26, 2017
1 parent dfbce6c commit 11df6e6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
37 changes: 19 additions & 18 deletions Compiler/BackEnd/AdjacencyMatrix.mo
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,23 @@ public function getOtherEqSysAdjacencyMatrix
input BackendDAE.AdjacencyMatrix mnew;
output BackendDAE.AdjacencyMatrix outMNew;
algorithm
outMNew := matchcontinue (m)
outMNew := match (m)
local
list<Integer> row;

case (_) equation
true = intGt(index, size);
case (_) guard intGt(index, size)
then mnew;

case (_) equation
true = intGt(skip[index], 0);
row = List.select(m[index], Util.intPositive);
row = List.select1r(row, isAssigned, rowskip);
case (_) guard intGt(skip[index], 0)
equation
row = list(r for r guard intGt(r,0) and intGt(rowskip[r], 0) in m[index]);
arrayUpdate(mnew, index, row);
then getOtherEqSysAdjacencyMatrix(m, size, index+1, skip, rowskip, mnew);

case (_) equation
arrayUpdate(mnew,index,{});
then getOtherEqSysAdjacencyMatrix(m, size, index+1, skip, rowskip, mnew);
end matchcontinue;
end match;
end getOtherEqSysAdjacencyMatrix;

protected function isAssigned
Expand All @@ -226,9 +224,13 @@ public function transposeAdjacencyMatrix
input BackendDAE.AdjacencyMatrix m;
input Integer nRowsMt;
output BackendDAE.AdjacencyMatrixT mt;
protected
Integer i = 1;
algorithm
mt := arrayCreate(nRowsMt, {});
((mt, _)) := Array.fold(m, transposeRow, (mt, 1));
for e in m loop
(mt, i) := transposeRow(e, mt, i);
end for;
end transposeAdjacencyMatrix;

protected function transposeRow "author: PA
Expand All @@ -239,25 +241,24 @@ protected function transposeRow "author: PA
inputs: (int list list, int /* row */,int /* iter */)
outputs: int list"
input list<Integer> row;
input tuple<BackendDAE.AdjacencyMatrixT, Integer> inTpl "(m,index)";
output tuple<BackendDAE.AdjacencyMatrixT, Integer> outTpl;
input output BackendDAE.AdjacencyMatrixT mt;
input output Integer indx;
algorithm
outTpl := match (row, inTpl)
(mt, indx) := match (row)
local
Integer i, indx, indx1, iabs;
Integer i, indx1, iabs;
list<Integer> res, col;
BackendDAE.AdjacencyMatrixT mt;

case ({}, (mt, indx))
then ((mt, indx+1));
case {}
then (mt, indx+1);

case (i::res, (mt, indx)) equation
case i::res equation
iabs = intAbs(i);
mt = Array.expand(iabs - arrayLength(mt), mt, {});
col = mt[iabs];
indx1 = if intLt(i, 0) then -indx else indx;
arrayUpdate(mt, iabs, indx1::col);
then transposeRow(res, (mt, indx));
then transposeRow(res, mt, indx);
end match;
end transposeRow;

Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/EvaluateFunctions.mo
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ algorithm
list<DAE.Exp> eLst;
case(DAE.TUPLE(PR = eLst))
algorithm
then List.fold(List.map(eLst,hasUnknownType),boolOr,false);
then List.mapBoolOr(eLst,hasUnknownType);
case(DAE.CREF(ty=DAE.T_UNKNOWN()))
then true;
else
Expand All @@ -634,7 +634,7 @@ algorithm
list<DAE.Exp> eLst;
case(DAE.TUPLE(PR = eLst))
algorithm
then List.fold(List.map(eLst,hasMultipleArrayDimensions),boolOr,false);
then List.mapBoolOr(eLst,hasMultipleArrayDimensions);
case(DAE.CREF(ty=ty))
algorithm
if Types.isArray(ty) then
Expand Down
5 changes: 1 addition & 4 deletions Compiler/FrontEnd/Expression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4726,10 +4726,7 @@ algorithm

case(_, _ :: _ , _)
equation
i = listLength(iDims) - 1;
d = List.last(iDims);
(dims, _) = List.split(iDims,i);

(d, dims) = List.splitLast(iDims);
explst = listToArray3(inList,d,inType);
arrexp = listToArray2(explst,dims,inType);
then
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ algorithm
case (DAE.CALL(path=Absyn.IDENT("max"),expLst={DAE.ARRAY(array=es)},attr=DAE.CALL_ATTR(ty=tp)))
equation
i1 = listLength(es);
es = List.union(es,es);
es = List.union(es,{});
i2 = listLength(es);
if i1 == i2
then
Expand All @@ -1122,7 +1122,7 @@ algorithm
case (DAE.CALL(path=Absyn.IDENT("min"),expLst={DAE.ARRAY(array=es)},attr=DAE.CALL_ATTR(ty=tp)))
equation
i1 = listLength(es);
es = List.union(es,es);
es = List.union(es,{});
i2 = listLength(es);
if i1 == i2
then
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/OperatorOverloading.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2121,8 +2121,8 @@ algorithm
args = List.map(args, List.rest);
tys2 = List.mapMap(args, listHead, Types.funcArgType);
// We only look for constructors that are not of the initial type. Filter duplicates.
tys1 = List.setDifference(List.union(tys1,tys1),{inType1});
tys2 = List.setDifference(List.union(tys2,tys2),{inType2});
tys1 = List.setDifference(List.union(tys1,{}),{inType1});
tys2 = List.setDifference(List.union(tys2,{}),{inType2});
// Get the constructors
(cache,tys1) = getOperatorFuncsOrEmpty(inCache,env,tys1,"'constructor'",info,{});
(cache,tys2) = getOperatorFuncsOrEmpty(cache,env,tys2,"'constructor'",info,{});
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Util/List.mo
Original file line number Diff line number Diff line change
Expand Up @@ -7095,7 +7095,7 @@ algorithm
list<T> rest1,rest2;

case (el1 :: rest1, el2 :: rest2)
then referenceEq(el1,el2) and allReferenceEq(rest1,rest2);
then if referenceEq(el1,el2) then allReferenceEq(rest1,rest2) else false;

case ({},{}) then true;
else false;
Expand Down

0 comments on commit 11df6e6

Please sign in to comment.