Skip to content

Commit

Permalink
Handle fully qualified reduction expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed Jul 16, 2019
1 parent bda57e7 commit 7b001b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 6 additions & 4 deletions OMCompiler/Compiler/FrontEnd/Static.mo
Expand Up @@ -1713,7 +1713,7 @@ protected function makeReductionFoldExp
protected
String func_name;
algorithm
(outEnv, afoldExp) := match path
(outEnv, afoldExp) := match AbsynUtil.makeNotFullyQualified(path)
local
Absyn.Exp exp;
Absyn.ComponentRef cr, cr1, cr2;
Expand Down Expand Up @@ -1761,7 +1761,7 @@ end makeReductionFoldExp;
protected function reductionType
input FCore.Cache inCache;
input FCore.Graph inEnv;
input Absyn.Path fn;
input Absyn.Path inFn;
input DAE.Exp inExp;
input DAE.Type inType;
input DAE.Type unboxedType;
Expand All @@ -1774,6 +1774,8 @@ protected function reductionType
output DAE.Type resultType;
output Option<Values.Value> defaultValue;
output Absyn.Path outPath;
protected
Absyn.Path fn = AbsynUtil.makeNotFullyQualified(inFn);
algorithm
(outExp, outType, resultType, defaultValue, outPath) := match(fn, unboxedType)
local
Expand Down Expand Up @@ -1951,8 +1953,8 @@ algorithm

else
algorithm
(outCache, fnTypes) := Lookup.lookupFunctionsInEnv(inCache, inEnv, fn, info);
(typeA,typeB,resType,defaultBinding,path) := checkReductionType1(inEnv, fn,fnTypes,info);
(outCache, fnTypes) := Lookup.lookupFunctionsInEnv(inCache, inEnv, inFn, info);
(typeA,typeB,resType,defaultBinding,path) := checkReductionType1(inEnv,inFn,fnTypes,info);
ty2 := if isSome(defaultBinding) then typeB else inType;
(exp,typeA,bindings) := Types.matchTypePolymorphicWithError(inExp, inType,typeA,SOME(path),{},info);
(_,typeB,bindings) := Types.matchTypePolymorphicWithError(DAE.CREF(DAE.CREF_IDENT("$result",DAE.T_ANYTYPE_DEFAULT,{}),DAE.T_ANYTYPE_DEFAULT),ty2,typeB,SOME(path),bindings,info);
Expand Down
6 changes: 5 additions & 1 deletion testsuite/flattening/modelica/operators/Reductions.mo
Expand Up @@ -15,13 +15,15 @@ model Reductions
Real f;
Real g[n,n];
Real h;
Real k;
equation
c = sum(A[i]^2 + B[i]^2 for i in 1:n);
d = product(A[i]^2 + B[i]^2 for i in 1:n);
e = max(A[i]^2 + B[i]^2 for i in 1:n);
f = min(A[i]^2 + B[i]^2 for i in 1:n);
g = {(1/(i+j-1)) for i in 1:n, j in 1:n};
h = sum((1/(i+j-1)) for i in 1:n, j in 1:n);
k = .sum(i for i in 1:n);
end Reductions;

// Result:
Expand Down Expand Up @@ -67,6 +69,7 @@ end Reductions;
// Real g[5,4];
// Real g[5,5];
// Real h;
// Real k;
// equation
// c = A[1] ^ 2.0 + B[1] ^ 2.0 + A[2] ^ 2.0 + B[2] ^ 2.0 + A[3] ^ 2.0 + B[3] ^ 2.0 + A[4] ^ 2.0 + B[4] ^ 2.0 + A[5] ^ 2.0 + B[5] ^ 2.0;
// d = (A[1] ^ 2.0 + B[1] ^ 2.0) * (A[2] ^ 2.0 + B[2] ^ 2.0) * (A[3] ^ 2.0 + B[3] ^ 2.0) * (A[4] ^ 2.0 + B[4] ^ 2.0) * (A[5] ^ 2.0 + B[5] ^ 2.0);
Expand Down Expand Up @@ -97,6 +100,7 @@ end Reductions;
// g[5,3] = 0.1428571428571428;
// g[5,4] = 0.125;
// g[5,5] = 0.1111111111111111;
// h = 6.456349206349207;
// h = 6.456349206349206;
// k = 15.0;
// end Reductions;
// endResult

0 comments on commit 7b001b0

Please sign in to comment.