Changeset e668b3ca in OpenModelica


Ignore:
Timestamp:
2022-05-17T20:22:52+02:00 (2 years ago)
Author:
kabdelhak <karim.abdelhak@…>
Children:
9d6e2961
Parents:
ed50d7d
git-author:
perost <perost86@…> (05/09/22 11:54:20)
git-committer:
kabdelhak <karim.abdelhak@…> (05/17/22 20:22:52)
Message:

Add simplification rules for min({})/max({}) (#8909)

Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/NFFrontEnd/NFSimplifyExp.mo

    rca7559a re668b3ca  
    253253    case "fill"      then simplifyFill(listHead(args), listRest(args), call);
    254254    case "homotopy"  then simplifyHomotopy(args, call);
    255     case "max"       guard listLength(args) == 1 then simplifyReducedArrayConstructor(listHead(args), call);
    256     case "min"       guard listLength(args) == 1 then simplifyReducedArrayConstructor(listHead(args), call);
     255    case "max"       then simplifyMinMax(args, call, isMin = false);
     256    case "min"       then simplifyMinMax(args, call, isMin = true);
    257257    case "ones"      then simplifyFill(Expression.INTEGER(1), args, call);
    258258    case "product"   then simplifySumProduct(listHead(args), call, isSum = false);
     
    265265  end match;
    266266end simplifyBuiltinCall;
     267
     268function simplifyMinMax
     269  input list<Expression> args;
     270  input Call call;
     271  input Boolean isMin;
     272  output Expression exp;
     273protected
     274  Expression arg;
     275  Type ty;
     276algorithm
     277  if listLength(args) == 1 then
     278    arg := listHead(args);
     279    ty := Expression.typeOf(arg);
     280
     281    if Type.isEmptyArray(ty) then
     282      ty := Type.arrayElementType(ty);
     283      exp := if isMin then Expression.makeMaxValue(ty) else
     284                           Expression.makeMinValue(ty);
     285    else
     286      exp := simplifyReducedArrayConstructor(arg, call);
     287    end if;
     288  else
     289    exp := Expression.CALL(call);
     290  end if;
     291end simplifyMinMax;
    267292
    268293function simplifySumProduct
  • testsuite/flattening/modelica/scodeinst/Makefile

    r0f91fa08 re668b3ca  
    525525FuncBuiltinMatrixWrongType1.mo \
    526526FuncBuiltinMax.mo \
     527FuncBuiltinMax2.mo \
    527528FuncBuiltinMin.mo \
     529FuncBuiltinMin2.mo \
    528530FuncBuiltinMod.mo \
    529531FuncBuiltinNdims.mo \
Note: See TracChangeset for help on using the changeset viewer.