Skip to content

Commit

Permalink
- Type fixes for outerProduct.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20182 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Apr 16, 2014
1 parent 07a0428 commit 0cd7e1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
9 changes: 5 additions & 4 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -9807,8 +9807,9 @@ end matrixToArray;
public function transposeArray
input DAE.Exp inArray;
output DAE.Exp outArray;
output Boolean outWasTransposed;
algorithm
outArray := match(inArray)
(outArray, outWasTransposed) := match(inArray)
local
DAE.Type ty, row_ty;
DAE.Dimension dim1, dim2;
Expand All @@ -9817,7 +9818,7 @@ algorithm
list<list<Exp>> matrix;

case DAE.ARRAY(DAE.T_ARRAY(ty, {dim1, dim2}, ty_src), false, {})
then DAE.ARRAY(DAE.T_ARRAY(ty, {dim2, dim1}, ty_src), false, {});
then (DAE.ARRAY(DAE.T_ARRAY(ty, {dim2, dim1}, ty_src), false, {}), true);

case DAE.ARRAY(DAE.T_ARRAY(ty, {dim1, dim2}, ty_src), false, expl)
equation
Expand All @@ -9826,9 +9827,9 @@ algorithm
matrix = List.transposeList(matrix);
expl = List.map2(matrix, makeArray, row_ty, true);
then
DAE.ARRAY(DAE.T_ARRAY(ty, {dim2, dim1}, ty_src), false, expl);
(DAE.ARRAY(DAE.T_ARRAY(ty, {dim2, dim1}, ty_src), false, expl), true);

else inArray;
else (inArray, false);

end match;
end transposeArray;
Expand Down
23 changes: 12 additions & 11 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -1119,19 +1119,20 @@ algorithm
then e;

// promote 1-dim to 2-dim
case DAE.CALL(path=Absyn.IDENT("promote"),expLst=(DAE.ARRAY(tp1 as DAE.T_ARRAY(dims={_}),sc,es))::DAE.ICONST(1)::{},attr=DAE.CALL_ATTR(ty=tp))
case DAE.CALL(path=Absyn.IDENT("promote"),expLst=(DAE.ARRAY(tp1 as DAE.T_ARRAY(dims={_}),sc,es))::DAE.ICONST(1)::{})
equation
es = List.map2(List.map(es,List.create), Expression.makeArray, Types.liftArray(Types.unliftArray(tp1),DAE.DIM_INTEGER(1)), sc);
e = DAE.ARRAY(tp,false,es);
then e;
tp = Types.liftArray(Types.unliftArray(tp1), DAE.DIM_INTEGER(1));
es = List.map2(List.map(es,List.create), Expression.makeArray, tp, sc);
i = listLength(es);
tp = Expression.liftArrayLeft(tp, DAE.DIM_INTEGER(i));
then
DAE.ARRAY(tp,false,es);

case DAE.CALL(path=Absyn.IDENT("transpose"),expLst=e::{},attr=DAE.CALL_ATTR(ty=tp))
equation
mexpl = List.transposeList(Expression.get2dArrayOrMatrixContent(e));
tp1 = Types.unliftArray(tp);
es = List.map2(mexpl, Expression.makeArray, tp1, not Types.isArray(tp1,{}));
e = Expression.makeArray(es, tp, false);
then e;
(e, true) = Expression.transposeArray(e);
then
e;

case DAE.CALL(path=Absyn.IDENT("symmetric"),expLst=e::{},attr=DAE.CALL_ATTR(ty=_))
equation
Expand Down Expand Up @@ -2232,7 +2233,7 @@ algorithm
mat2 := Expression.matrixToArray(inMatrix2);
// Transpose the second matrix. This makes it easier to do the multiplication,
// since we can do row-row multiplications instead of row-column.
mat2 := Expression.transposeArray(mat2);
(mat2, _) := Expression.transposeArray(mat2);
outProduct := simplifyMatrixProduct2(mat1, mat2);
end simplifyMatrixProduct;

Expand Down Expand Up @@ -5129,7 +5130,7 @@ algorithm
mat2 := Expression.matrixToArray(inMatrix2);
// Transpose the second matrix. This makes it easier to do the multiplication,
// since we can do row-row multiplications instead of row-column.
mat2 := Expression.transposeArray(mat2);
(mat2, _) := Expression.transposeArray(mat2);
outProduct := simplifyMatrixProductOfRecords2(mat1, mat2, mulFunc, sumFunc);
end simplifyMatrixProductOfRecords;

Expand Down

0 comments on commit 0cd7e1d

Please sign in to comment.