Skip to content

Commit

Permalink
- Added case for empty vector range expression in reductions.
Browse files Browse the repository at this point in the history
- Added missing changes to testsuite makefile for Reductions testcase.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4856 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Jan 25, 2010
1 parent 5806822 commit 214e8bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
30 changes: 0 additions & 30 deletions Compiler/Codegen.mo
Expand Up @@ -4671,21 +4671,6 @@ algorithm
then
(cfn,tvar,tnr);

/* reduction of empty vector */
case (DAE.REDUCTION(path = Absyn.IDENT(reduction_op), expr = e1, range =
DAE.MATRIX(scalar = {})), tnr, context)
local
String reduction_op, start_value;
equation
ty = Exp.typeof(e1);
ty = Exp.unliftArray(ty);
type_string = expTypeStr(ty, false);
(_, start_value) = makeReductionFunction(reduction_op, ty);
(decl1, var1, tnr) = generateTempDeclWithAssignment(type_string, tnr, "", start_value);
cfn = cAddVariables(cEmptyFunction, {decl1});
then
(cfn, var1, tnr);

/* reduction */
case (DAE.REDUCTION(path = Absyn.IDENT(reduction_op), expr = e1, ident = iter, range = e2), tnr, context)
local
Expand Down Expand Up @@ -5298,21 +5283,6 @@ algorithm
then
(cfn,tvar,tnr);

/* reduction of empty vector */
case (DAE.REDUCTION(path = Absyn.IDENT(reduction_op), expr = e1, range =
DAE.MATRIX(scalar = {})), tnr, context)
local
String reduction_op, start_value;
equation
ty = Exp.typeof(e1);
ty = Exp.unliftArray(ty);
type_string = expTypeStr(ty, false);
(_, start_value) = makeReductionFunction(reduction_op, ty);
(decl1, var1, tnr) = generateTempDeclWithAssignment(type_string, tnr, "", start_value);
cfn = cAddVariables(cEmptyFunction, {decl1});
then
(cfn, var1, tnr);

/* reduction */
case (DAE.REDUCTION(path = Absyn.IDENT(reduction_op), expr = e1, ident = iter, range = e2), tnr, context)
local
Expand Down
22 changes: 22 additions & 0 deletions Compiler/Static.mo
Expand Up @@ -1403,6 +1403,16 @@ algorithm
then
(cache, exp_1, prop, st,dae);

/* reduction with an empty vector as range expression */
case (cache, env, Absyn.CREF_IDENT(reduction_op, {}), _, {(_, SOME(iterexp))}, impl, st, doVect)
local
String reduction_op;
equation
(cache, DAE.MATRIX(DAE.ET_ARRAY(_,_), 0, {}), _, _, dae) = elabExp(cache, env, iterexp, impl, st, doVect);
exp_1 = reductionDefaultValue(reduction_op);
then
(cache, exp_1, DAE.PROP((DAE.T_REAL({}), NONE), DAE.C_CONST), st, dae);

/* min, max, sum and product */
case (cache,env,fn,exp,{(iter,SOME(iterexp))},impl,st,doVect)
equation
Expand Down Expand Up @@ -1430,6 +1440,18 @@ algorithm
end matchcontinue;
end elabCallReduction;

protected function reductionDefaultValue
input String reductionOp;
output DAE.Exp defaultValue;
algorithm
defaultValue := matchcontinue(reductionOp)
case "min" then DAE.RCONST(1e60);
case "max" then DAE.RCONST(-1e60);
case "sum" then DAE.RCONST(0.0);
case "product" then DAE.RCONST(1.0);
end matchcontinue;
end reductionDefaultValue;

protected function elabArrayIterators
"Elaborates array constructors such as 'array(i for i in 1:5)'"
input Env.Cache cache;
Expand Down

0 comments on commit 214e8bd

Please sign in to comment.