From 0fe22a278b19d2f1f16156205fe8b0512435f331 Mon Sep 17 00:00:00 2001 From: hkiel Date: Wed, 16 Mar 2016 14:44:31 +0100 Subject: [PATCH] array optimizsations new function Array.createIntRange() --- Compiler/BackEnd/DAEQuery.mo | 8 +++---- Compiler/BackEnd/DumpGraphML.mo | 9 ++++---- Compiler/BackEnd/HpcOmEqSystems.mo | 2 +- Compiler/BackEnd/Matching.mo | 6 +++--- Compiler/BackEnd/Uncertainties.mo | 4 ++-- Compiler/Script/Refactor.mo | 34 +++++++++++++++--------------- Compiler/Util/Array.mo | 18 +++++++++++++--- 7 files changed, 47 insertions(+), 34 deletions(-) diff --git a/Compiler/BackEnd/DAEQuery.mo b/Compiler/BackEnd/DAEQuery.mo index 7e770ee1142..4602ea9c523 100644 --- a/Compiler/BackEnd/DAEQuery.mo +++ b/Compiler/BackEnd/DAEQuery.mo @@ -187,7 +187,7 @@ protected function getIncidenceMatrix2 "author: adrpo output String strIMatrix; algorithm strIMatrix := - matchcontinue (inStringLstLst,rowIndex) + match (inStringLstLst,rowIndex) local list row; list> rows; @@ -206,7 +206,7 @@ algorithm str = stringAppendList({"{", str1, "},", str2}); then str; - end matchcontinue; + end match; end getIncidenceMatrix2; protected function getIncidenceRow "author: adrpo @@ -216,7 +216,7 @@ protected function getIncidenceRow "author: adrpo output String strRow; algorithm strRow := - matchcontinue (inStringLst) + match (inStringLst) local String s, s2, x; list xs; @@ -228,7 +228,7 @@ algorithm s = stringAppendList({x, ",", s2}); then s; - end matchcontinue; + end match; end getIncidenceRow; public function getVariables "This function returns the variables diff --git a/Compiler/BackEnd/DumpGraphML.mo b/Compiler/BackEnd/DumpGraphML.mo index f2c2a4b0c1e..20374cfecc3 100644 --- a/Compiler/BackEnd/DumpGraphML.mo +++ b/Compiler/BackEnd/DumpGraphML.mo @@ -39,6 +39,7 @@ encapsulated package DumpGraphML public import BackendDAE; public import DAE; +protected import Array; protected import BackendDump; protected import BackendEquation; protected import BackendDAETransform; @@ -81,7 +82,7 @@ algorithm eqns = BackendEquation.getEqnsFromEqSystem(inSystem); funcs = BackendDAEUtil.getFunctions(inShared); (_,m,_) = BackendDAEUtil.getIncidenceMatrix(inSystem,BackendDAE.NORMAL(),SOME(funcs)); - mapIncRowEqn = listArray(List.intRange(arrayLength(m))); + mapIncRowEqn = Array.createIntRange(arrayLength(m)); graphInfo = GraphML.createGraphInfo(); (graphInfo,(_,graph)) = GraphML.addGraph("G",false,graphInfo); ((_,_,(graphInfo,graph))) = BackendVariable.traverseBackendDAEVars(vars,addVarGraph,(numberMode,1,(graphInfo,graph))); @@ -103,7 +104,7 @@ algorithm neqns = BackendDAEUtil.equationArraySize(eqns); //neqns = BackendDAEUtil.equationSize(eqns); eqnsids = List.intRange(neqns); - mapIncRowEqn = listArray(List.intRange(arrayLength(m))); + mapIncRowEqn = Array.createIntRange(arrayLength(m)); ((graphInfo,graph)) = List.fold3(eqnsids,addEqnGraph,eqns,mapIncRowEqn,numberMode,(graphInfo,graph)); ((_,_,graphInfo)) = List.fold(eqnsids,addEdgesGraph,(1,m,graphInfo)); GraphML.dumpGraph(graphInfo,filename); @@ -115,7 +116,7 @@ algorithm eqns = BackendEquation.getEqnsFromEqSystem(inSystem); funcs = BackendDAEUtil.getFunctions(inShared); //(_,m,mt) = BackendDAEUtil.getIncidenceMatrix(inSystem, BackendDAE.NORMAL(), SOME(funcs)); - //mapIncRowEqn = listArray(List.intRange(arrayLength(m))); + //mapIncRowEqn = Array.createIntRange(arrayLength(m)); //(_,m,mt,_,mapIncRowEqn) = BackendDAEUtil.getIncidenceMatrixScalar(inSystem,BackendDAE.SOLVABLE(), SOME(funcs))); (_,m,_,_,mapIncRowEqn) = BackendDAEUtil.getIncidenceMatrixScalar(inSystem,BackendDAE.NORMAL(), SOME(funcs)); graphInfo = GraphML.createGraphInfo(); @@ -643,4 +644,4 @@ algorithm end isUnMarked; annotation(__OpenModelica_Interface="backend"); -end DumpGraphML; \ No newline at end of file +end DumpGraphML; diff --git a/Compiler/BackEnd/HpcOmEqSystems.mo b/Compiler/BackEnd/HpcOmEqSystems.mo index e874c9e744a..7814e1fa939 100644 --- a/Compiler/BackEnd/HpcOmEqSystems.mo +++ b/Compiler/BackEnd/HpcOmEqSystems.mo @@ -1056,7 +1056,7 @@ algorithm sysTmp = BackendDAEUtil.setEqSystMatching(sysTmp, matching); // perform BLT to order the StrongComponents - mapIncRowEqn = listArray(List.intRange(nEqs)); + mapIncRowEqn = Array.createIntRange(nEqs); mapEqnIncRow = Array.map(mapIncRowEqn,List.create); (sysTmp,compsTmp) = BackendDAETransform.strongComponentsScalar(sysTmp,shared,mapEqnIncRow,mapIncRowEqn); compsTmp = listAppend(compsIn,compsTmp); diff --git a/Compiler/BackEnd/Matching.mo b/Compiler/BackEnd/Matching.mo index 76c7f94d8f2..ac50d23487d 100644 --- a/Compiler/BackEnd/Matching.mo +++ b/Compiler/BackEnd/Matching.mo @@ -4715,7 +4715,7 @@ algorithm row_degrees := arrayCreate(ne,0); onerows := getOneRows(ne,mT,row_degrees,{}); onecolums := getOneRows(nv,m,col_degrees,{}); - randarr := listArray(List.intRange(ne)); + randarr := Array.createIntRange(ne); setrandArray(ne,randarr); ks_rand_cheapmatching1(1,ne,onecolums,onerows,col_degrees,row_degrees,randarr,m,mT,ass1,ass2); outUnMatched := getUnassigned(ne,ass1,{}); @@ -6399,9 +6399,9 @@ algorithm equation ne = BackendDAEUtil.systemSize(isyst); nv = BackendVariable.daenumVariables(isyst); - randarr = listArray(List.intRange(ne)); + randarr = Array.createIntRange(ne); setrandArray(ne, randarr); - randarr1 = listArray(List.intRange(nv)); + randarr1 = Array.createIntRange(nv); setrandArray(nv, randarr1); syst.orderedEqs = randSortSystem1( ne, 0, randarr, eqns, BackendEquation.listEquation({}), BackendEquation.equationNth1, BackendEquation.addEquation ); diff --git a/Compiler/BackEnd/Uncertainties.mo b/Compiler/BackEnd/Uncertainties.mo index 059391de067..7de65d47257 100644 --- a/Compiler/BackEnd/Uncertainties.mo +++ b/Compiler/BackEnd/Uncertainties.mo @@ -794,8 +794,8 @@ algorithm Matching.matchingExternalsetIncidenceMatrix(size,size,mx); //BackendDump.dumpIncidenceMatrix(mx); - ass1=listArray(List.fill(0,size)); - ass2=listArray(List.fill(0,size)); + ass1=arrayCreate(size,0); + ass2=arrayCreate(size,0); true = BackendDAEEXT.setAssignment(size,size,ass2,ass1); BackendDAEEXT.matching(size,size,1,-1,1.0,0); diff --git a/Compiler/Script/Refactor.mo b/Compiler/Script/Refactor.mo index 59f35677b87..002a8fe068d 100644 --- a/Compiler/Script/Refactor.mo +++ b/Compiler/Script/Refactor.mo @@ -1238,13 +1238,13 @@ algorithm case(Absyn.MODIFICATION(finalPrefix = fi, eachPrefix = e, path = Absyn.IDENT(name = "pattern"), modification = SOME(Absyn.CLASSMOD( elementArgLst = args ,eqMod = Absyn.EQMOD(exp=Absyn.INTEGER(value = x)))), comment = com, info = mod_info) :: rest,context as ("Line" :: _),res,p) equation - val = arrayGet(listArray(patternMapList),x+1); + val = listGet(patternMapList,x+1); res = transformConnectAnnList(rest,context,res,p); then Absyn.MODIFICATION(fi,e,Absyn.IDENT("pattern"), SOME(Absyn.CLASSMOD(args,Absyn.EQMOD(Absyn.CREF(Absyn.CREF_QUAL("LinePattern", {},Absyn.CREF_IDENT(val, {}))),Absyn.dummyInfo))),com, mod_info):: res; case(Absyn.MODIFICATION(finalPrefix = fi, eachPrefix = e, path = Absyn.IDENT(name = "thickness"), modification = SOME(Absyn.CLASSMOD( elementArgLst = args ,eqMod = Absyn.EQMOD(exp=Absyn.INTEGER(value = x)))), comment = com, info = mod_info) :: rest,context as ("Line" :: _),res,p) equation - thick = arrayGet(listArray(thicknessMapList),x); + thick = listGet(thicknessMapList,x); res = transformConnectAnnList(rest,context,res,p); s = realString(thick); then Absyn.MODIFICATION(fi,e,Absyn.IDENT("thickness"), SOME(Absyn.CLASSMOD(args,Absyn.EQMOD(Absyn.REAL(s),Absyn.dummyInfo))),com,mod_info):: res; @@ -1255,9 +1255,9 @@ algorithm case(Absyn.MODIFICATION(finalPrefix = fi, eachPrefix = e, path = Absyn.IDENT(name = "arrow"), modification = SOME(Absyn.CLASSMOD( elementArgLst = args ,eqMod = Absyn.EQMOD(exp=Absyn.INTEGER(value = x)))), comment = com, info = mod_info) :: rest,context as ("Line" :: _),res,p) equation - arrows = arrayGet(listArray(arrowMapList),x+1); - val1 = arrayGet(listArray(arrows),1); - val2 = arrayGet(listArray(arrows),2); + arrows = listGet(arrowMapList,x+1); + val1 = listGet(arrows,1); + val2 = listGet(arrows,2); res = transformConnectAnnList(rest,context,res,p); then Absyn.MODIFICATION(fi,e,Absyn.IDENT("arrow"), SOME(Absyn.CLASSMOD(args,Absyn.EQMOD(Absyn.ARRAY({Absyn.CREF(Absyn.CREF_QUAL("Arrow", {},Absyn.CREF_IDENT(val1, {}))),Absyn.CREF(Absyn.CREF_QUAL("Arrow",{},Absyn.CREF_IDENT(val2,{})))}),Absyn.dummyInfo))),com, mod_info):: res; @@ -1588,33 +1588,33 @@ algorithm case(Absyn.MODIFICATION(path = Absyn.IDENT(name = "pattern"), modification = SOME(Absyn.CLASSMOD(eqMod = Absyn.EQMOD(exp=Absyn.INTEGER(value = x)) ))) :: rest,context ) equation - val = arrayGet(listArray(patternMapList),x+1); + val = listGet(patternMapList,x+1); restRes = transAnnLstToNamedArgs(rest,context); then Absyn.NAMEDARG("pattern",Absyn.CREF(Absyn.CREF_QUAL("LinePattern", {},Absyn.CREF_IDENT(val, {})))) :: restRes; case(Absyn.MODIFICATION(path = Absyn.IDENT(name = "fillPattern"), modification = SOME(Absyn.CLASSMOD(eqMod = Absyn.EQMOD(exp=Absyn.INTEGER(value = x)) ))) :: rest,context ) equation - val = arrayGet(listArray(fillPatternMapList),x+1); + val = listGet(fillPatternMapList,x+1); restRes = transAnnLstToNamedArgs(rest,context); then Absyn.NAMEDARG("fillPattern",Absyn.CREF(Absyn.CREF_QUAL("FillPattern", {},Absyn.CREF_IDENT(val, {})))) :: restRes; case(Absyn.MODIFICATION(path = Absyn.IDENT(name = "thickness"), modification = SOME(Absyn.CLASSMOD(eqMod = Absyn.EQMOD(exp=Absyn.INTEGER(value = x)) ))) :: rest,context as ("Line" :: _)) equation - thick = arrayGet(listArray(thicknessMapList),x); + thick = listGet(thicknessMapList,x); restRes = transAnnLstToNamedArgs(rest,context); s = realString(thick); then Absyn.NAMEDARG("thickness",Absyn.REAL(s)) :: restRes; case(Absyn.MODIFICATION(path = Absyn.IDENT(name = "thickness"), modification = SOME(Absyn.CLASSMOD(eqMod = Absyn.EQMOD(exp=Absyn.INTEGER(value = x)) ))) :: rest,context ) equation - thick = arrayGet(listArray(thicknessMapList),x); + thick = listGet(thicknessMapList,x); restRes = transAnnLstToNamedArgs(rest,context); s = realString(thick); then Absyn.NAMEDARG("lineThickness",Absyn.REAL(s)) :: restRes; case(Absyn.MODIFICATION(path = Absyn.IDENT(name = "gradient"), modification = SOME(Absyn.CLASSMOD(eqMod = Absyn.EQMOD(exp=Absyn.INTEGER(value = x)) ))) :: rest,context) equation - val = arrayGet(listArray(gradientMapList),x+1); + val = listGet(gradientMapList,x+1); restRes = transAnnLstToNamedArgs(rest,context); then Absyn.NAMEDARG("fillPattern",Absyn.CREF(Absyn.CREF_QUAL("FillPattern", {},Absyn.CREF_IDENT(val, {})))) :: restRes ; @@ -1625,9 +1625,9 @@ algorithm case(Absyn.MODIFICATION(path = Absyn.IDENT(name = "arrow"), modification = SOME(Absyn.CLASSMOD(eqMod = Absyn.EQMOD(exp=Absyn.INTEGER(value = x)) ))) :: rest,context) equation - arrows = arrayGet(listArray(arrowMapList),x+1); - val1 = arrayGet(listArray(arrows),1); - val2 = arrayGet(listArray(arrows),2); + arrows = listGet(arrowMapList,x+1); + val1 = listGet(arrows,1); + val2 = listGet(arrows,2); restRes = transAnnLstToNamedArgs(rest,context); then Absyn.NAMEDARG("arrow",Absyn.ARRAY({Absyn.CREF(Absyn.CREF_QUAL("Arrow", {},Absyn.CREF_IDENT(val1, {}))),Absyn.CREF(Absyn.CREF_QUAL("Arrow",{},Absyn.CREF_IDENT(val2,{})))})):: restRes ; @@ -2155,10 +2155,10 @@ algorithm Integer color; case(color) equation - rcol = arrayGet(listArray(colorMapList),color+1); - color1 = arrayGet(listArray(rcol),1); - color2 = arrayGet(listArray(rcol),2); - color3 = arrayGet(listArray(rcol),3); + rcol = listGet(colorMapList,color+1); + color1 = listGet(rcol,1); + color2 = listGet(rcol,2); + color3 = listGet(rcol,3); then (color1,color2,color3); end match; diff --git a/Compiler/Util/Array.mo b/Compiler/Util/Array.mo index bba998ba08e..cb4da6fe145 100644 --- a/Compiler/Util/Array.mo +++ b/Compiler/Util/Array.mo @@ -37,7 +37,7 @@ encapsulated package Array " protected -import MetaModelica.Dangerous.{arrayGetNoBoundsChecking, arrayCreateNoInit}; +import MetaModelica.Dangerous.{arrayGetNoBoundsChecking, arrayUpdateNoBoundsChecking, arrayCreateNoInit}; public function mapNoCopy "Takes an array and a function over the elements of the array, which is @@ -163,10 +163,10 @@ algorithm // If the array isn't empty, use the first element to create the new array. res := inFunc(arrayGetNoBoundsChecking(inArray, 1)); outArray := arrayCreateNoInit(len, res); - arrayUpdate(outArray, 1, res); + arrayUpdateNoBoundsChecking(outArray, 1, res); for i in 2:len loop - arrayUpdate(outArray, i, inFunc(arrayGetNoBoundsChecking(inArray, i))); + arrayUpdateNoBoundsChecking(outArray, i, inFunc(arrayGetNoBoundsChecking(inArray, i))); end for; end if; end map; @@ -655,6 +655,18 @@ algorithm end for; end copyN; +public function createIntRange + "Creates an array of size inLen with the values set to the range of 1:inLen." + input Integer inLen; + output array outArray; +algorithm + outArray := arrayCreateNoInit(inLen, 0); + + for i in 1:inLen loop + arrayUpdateNoBoundsChecking(outArray, i, i); + end for; +end createIntRange; + public function setRange "Sets the elements in positions inStart to inEnd to inValue." input Integer inStart;