Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Added symmetric() implementation


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14075 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 26, 2012
1 parent a39c5c7 commit 34cde47
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ algorithm
Boolean scalar,sc;
list<Values.Value> valueLst;
Integer i,i1,i2,dim;
array<array<DAE.Exp>> marr;

// min/max function on arrays of only 1 element
case (DAE.CALL(path=Absyn.IDENT("min"),expLst={DAE.ARRAY(array={e})})) then e;
Expand Down Expand Up @@ -1066,9 +1067,53 @@ algorithm
e = Expression.makeArray(es, tp, false);
then e;

case DAE.CALL(path=Absyn.IDENT("symmetric"),expLst=e::{},attr=DAE.CALL_ATTR(ty=tp))
equation
{{}} = Expression.get2dArrayOrMatrixContent(e);
then e;

case DAE.CALL(path=Absyn.IDENT("symmetric"),expLst=e::{},attr=DAE.CALL_ATTR(ty=tp))
equation
{{_}} = Expression.get2dArrayOrMatrixContent(e);
then e;

case DAE.CALL(path=Absyn.IDENT("symmetric"),expLst=e::{},attr=DAE.CALL_ATTR(ty=tp))
equation
mexpl = Expression.get2dArrayOrMatrixContent(e);
marr = listArray(List.map(mexpl,listArray));
true = arrayLength(marr) == arrayLength(arrayGet(marr,1));
true = arrayLength(marr) > 1;
simplifySymmetric(marr, arrayLength(marr)-1, arrayLength(marr));
mexpl = List.map(arrayList(marr), arrayList);
tp1 = Types.unliftArray(tp);
es = List.map2(mexpl, Expression.makeArray, tp1, not Types.isArray(tp1,{}));
e = Expression.makeArray(es, tp, false);
then e;

end matchcontinue;
end simplifyBuiltinCalls;

protected function simplifySymmetric
input array<array<DAE.Exp>> marr;
input Integer i1;
input Integer i2;
algorithm
_ := match (marr,i1,i2)
local
array<DAE.Exp> v1,v2;
DAE.Exp exp;
case (_,0,1) then ();
case (_,_,_)
equation
v1 = arrayGet(marr, i1);
v2 = arrayGet(marr, i2);
exp = arrayGet(v1,i2);
_ = arrayUpdate(v2, i1, exp);
simplifySymmetric(marr, Util.if_(i1==1,i2-2,i1-1), Util.if_(i1==1,i2-1,i2));
then ();
end match;
end simplifySymmetric;

protected function simplifyCat
input Integer dim;
input list<DAE.Exp> ies;
Expand Down
44 changes: 44 additions & 0 deletions Compiler/FrontEnd/Static.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3652,6 +3652,49 @@ algorithm
end match;
end makeFillArgListType;

protected function elabBuiltinSymmetric "This function elaborates the builtin operator symmetric"
input Env.Cache inCache;
input Env.Env inEnv;
input list<Absyn.Exp> inAbsynExpLst;
input list<Absyn.NamedArg> inNamedArg;
input Boolean inBoolean;
input Prefix.Prefix inPrefix;
input Absyn.Info info;
output Env.Cache outCache;
output DAE.Exp outExp;
output DAE.Properties outProperties;
algorithm
(outCache,outExp,outProperties) := matchcontinue (inCache,inEnv,inAbsynExpLst,inNamedArg,inBoolean,inPrefix,info)
local
DAE.Type tp;
Boolean sc, impl;
list<DAE.Exp> expl,exp_2;
DAE.Dimension d1,d2;
DAE.Type eltp,newtp;
Integer dim1,dim2,dimMax;
DAE.Properties prop;
DAE.Const c;
list<Env.Frame> env;
Absyn.Exp matexp;
DAE.Exp exp_1,exp;
Env.Cache cache;
Prefix.Prefix pre;
list<list<DAE.Exp>> mexpl,mexp_2;
Integer i;

case (cache,env,{matexp},_,impl,pre,_)
equation
(cache,exp_1,DAE.PROP(DAE.T_ARRAY(dims = {d1}, ty = DAE.T_ARRAY(dims = {d2}, ty = eltp)), c),_)
= elabExp(cache,env, matexp, impl,NONE(),true,pre,info);
newtp = DAE.T_ARRAY(DAE.T_ARRAY(eltp, {d1}, DAE.emptyTypeSource), {d2}, DAE.emptyTypeSource);
tp = Types.simplifyType(newtp);
exp = Expression.makeBuiltinCall("symmetric", {exp_1}, tp);
prop = DAE.PROP(newtp,c);
then
(cache,exp,prop);
end matchcontinue;
end elabBuiltinSymmetric;

protected function elabBuiltinTranspose "function: elabBuiltinTranspose
This function elaborates the builtin operator transpose
The input is the arguments to fill as Absyn.Exp expressions and the environment Env.Env"
Expand Down Expand Up @@ -6210,6 +6253,7 @@ algorithm
case "max" then elabBuiltinMax;
case "min" then elabBuiltinMin;
case "transpose" then elabBuiltinTranspose;
case "symmetric" then elabBuiltinSymmetric;
case "array" then elabBuiltinArray;
case "sum" then elabBuiltinSum;
case "product" then elabBuiltinProduct;
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/meta/meta_modelica_builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ extern modelica_metatype arrayUpdate(modelica_metatype, modelica_integer, modeli
extern modelica_metatype arrayCopy(modelica_metatype);
extern modelica_metatype arrayAdd(modelica_metatype, modelica_metatype);

#define boxptr_listArray listArray
#define boxptr_arrayList arrayList
#define boxptr_arrayCopy arrayCopy
extern modelica_metatype boxptr_arrayNth(modelica_metatype,modelica_metatype);
Expand Down

0 comments on commit 34cde47

Please sign in to comment.