Skip to content

Commit

Permalink
[janitor] (#12051)
Browse files Browse the repository at this point in the history
  • Loading branch information
phannebohm committed Feb 29, 2024
1 parent ea31049 commit 2eae847
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 52 deletions.
17 changes: 5 additions & 12 deletions OMCompiler/Compiler/BackEnd/Differentiate.mo
Expand Up @@ -2199,7 +2199,7 @@ algorithm
list<Boolean> blst;
list<DAE.Type> tlst;
list<tuple<DAE.Exp,Boolean>> expBoolLst;
String typstring, dastring, funstring, str;
String typstring, dastring, funstring;
list<String> typlststring;
DAE.TailCall tc;
DAE.CallAttributes attr;
Expand Down Expand Up @@ -2309,8 +2309,7 @@ algorithm
else
equation
true = Flags.isSet(Flags.FAILTRACE);
str = "Differentiate.differentiateFunctionCall failed for " + ExpressionDump.printExpStr(inExp) + "\n";
Debug.trace(str);
Debug.trace(getInstanceName() + " failed for " + ExpressionDump.printExpStr(inExp) + "\n");
then fail();
end matchcontinue;
end differentiateFunctionCall;
Expand Down Expand Up @@ -2372,7 +2371,7 @@ algorithm
(mapper, tp) = getFunctionMapper(path, inFunctionTree);
(dpath, blst) = differentiateFunction1(path,mapper, tp, expl, (inDiffwrtCref, inInputData, inDiffType, inFunctionTree));
SOME(DAE.FUNCTION(type_=dtp,inlineType=dinl)) = DAE.AvlTreePathFunction.get(inFunctionTree, dpath);
// check if derivativ function has all expected inputs
// check if derivative function has all expected inputs
(true,_) = checkDerivativeFunctionInputs(blst, tp, dtp);
(expl1,_) = List.splitOnBoolList(expl, blst);
(dexpl, functions) = List.map3Fold(expl1, function differentiateExp(maxIter=maxIter), inDiffwrtCref, inInputData, inDiffType, inFunctionTree);
Expand Down Expand Up @@ -3223,14 +3222,8 @@ algorithm
end getFunctionMapper1;

protected function diffableTypes
input DAE.Type inType;
output Boolean out;
protected
Boolean b[2];
algorithm
b[1] := Types.isRealOrSubTypeReal(inType);
b[2] := Types.isRecord(inType);
out := boolOr(b[1],b[2]);
input DAE.Type inType;
output Boolean out = Types.isRealOrSubTypeReal(inType) or Types.isRecord(inType);
end diffableTypes;


Expand Down
31 changes: 10 additions & 21 deletions OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBAdjacency.mo
Expand Up @@ -290,10 +290,10 @@ public
input Integer eqn_scalar_size;
input Integer eqn_array_size;
output CausalizeModes modes = CAUSALIZE_MODES(
mode_to_var = arrayCreate(eqn_scalar_size, arrayCreate(0,0)),
mode_to_cref = arrayCreate(eqn_array_size, arrayCreate(0,ComponentRef.EMPTY())),
mode_eqns = Pointer.create({})
);
mode_to_var = arrayCreate(eqn_scalar_size, arrayCreate(0,0)),
mode_to_cref = arrayCreate(eqn_array_size, arrayCreate(0,ComponentRef.EMPTY())),
mode_eqns = Pointer.create({})
);
end empty;

function contains
Expand Down Expand Up @@ -1205,7 +1205,7 @@ public
String str1, str2;
algorithm
str1 := List.toString(dep.skip_pos, intString, "", "", ", ", "");
str2 := List.toString(listAppend(List.fill(":", dep.regular), List.fill("-", dep.reduction)), StringUtil.id, "", "", ", ", "");
str2 := List.toString(listAppend(List.fill(":", dep.regular), List.fill("-", dep.reduction)), Util.id, "", "", ", ", "");
str := if str1 == "" or str2 == "" then str1 + str2 else str1 + ", " + str2;
str := "{" + str + "}";
end toString;
Expand Down Expand Up @@ -1346,29 +1346,19 @@ public
end EXPLICIT_NONLINEAR;

record EXPLICIT_LINEAR
Boolean param "true if we need to devide by a parameter to solve";
Option<UnorderedSet<ComponentRef>> vars "variables we need to devide by to solve";
Boolean param "true if we need to divide by a parameter to solve";
Option<UnorderedSet<ComponentRef>> vars "variables we need to divide by to solve";
end EXPLICIT_LINEAR;

function toString
input Solvability sol;
output String str;
protected
function sgnN
input Boolean b;
output String str = if b then "+" else "-";
end sgnN;
function sgnL
input Boolean b1;
input Boolean b2;
output String str = if b2 then "V" elseif b1 then "P" else "C";
end sgnL;
algorithm
str := match sol
case UNSOLVABLE() then "XX";
case IMPLICIT() then "II";
case EXPLICIT_NONLINEAR() then "N" + sgnN(sol.unique);
case EXPLICIT_LINEAR() then "L" + sgnL(sol.param, Util.isSome(sol.vars));
case EXPLICIT_NONLINEAR() then "N" + (if sol.unique then "+" else "-");
case EXPLICIT_LINEAR() then "L" + (if Util.isSome(sol.vars) then "V" elseif sol.param then "P" else "C");
case UNKNOWN() then "||";
else algorithm
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed because of unknown solvability kind."});
Expand Down Expand Up @@ -1811,7 +1801,7 @@ public
input UnorderedMap<ComponentRef, Solvability> sol_map;
input UnorderedSet<ComponentRef> rep_set;
output tuple<UnorderedSet<ComponentRef>, UnorderedSet<ComponentRef>> set_tpl;
protected
protected
UnorderedSet<ComponentRef> set1 "solvable";
UnorderedSet<ComponentRef> set2 "potentially unsolvable";
algorithm
Expand Down Expand Up @@ -1840,4 +1830,3 @@ public

annotation(__OpenModelica_Interface="backend");
end NBAdjacency;

Expand Up @@ -522,4 +522,3 @@ protected

annotation(__OpenModelica_Interface="backend");
end NBResolveSingularities;

6 changes: 3 additions & 3 deletions OMCompiler/Compiler/NBackEnd/Util/NBSlice.mo
Expand Up @@ -440,7 +440,7 @@ public
else
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName()
+ " failed because the equation size " + intString(eqn_size)
+ " could not be devided by the iterator size " + intString(iter_size) + " without rest."});
+ " could not be divided by the iterator size " + intString(iter_size) + " without rest."});
end if;

// create unique array for each equation
Expand Down Expand Up @@ -503,7 +503,7 @@ public
else
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName()
+ " failed because the equation size " + intString(eqn_size)
+ " could not be devided by the iterator size " + intString(iter_size) + " without rest."});
+ " could not be divided by the iterator size " + intString(iter_size) + " without rest."});
end if;

// get row cref lst
Expand Down Expand Up @@ -569,7 +569,7 @@ public
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName()
+ " failed because number of flattened indices " + intString(scal_length)
+ " for dependency " + ComponentRef.toString(dep)
+ " could not be devided by the body size " + intString(body_size) + " without rest."});
+ " could not be divided by the body size " + intString(body_size) + " without rest."});
fail();
end if;

Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/NFFrontEnd/NFSimplifyExp.mo
Expand Up @@ -1330,7 +1330,7 @@ algorithm
tmp := getConstantValue(exp);
result := result * tmp;
end for;
// devide all inverse constants
// divide all inverse constants
for exp in inv_const loop
tmp := getConstantValue(exp);
result := result / tmp;
Expand Down Expand Up @@ -1396,7 +1396,7 @@ algorithm
args := exp.arguments;
new_exp := Expression.negate(new_exp);
else
// create an artificial 1 to devide by the inverse arguments
// create an artificial 1 to divide by the inverse arguments
new_exp := Expression.makeOne(Operator.typeOf(exp.operator));
args := exp.arguments;
inv_args := exp.inv_arguments;
Expand Down
5 changes: 0 additions & 5 deletions OMCompiler/Compiler/Util/StringUtil.mo
Expand Up @@ -49,11 +49,6 @@ constant Integer CHAR_SPACE = 32;
constant Integer CHAR_DASH = 45;
constant Integer CHAR_DOT = 46;

public function id
"wrapper to use with List.toString if the list contains strings"
input output String str;
end id;

public function headline_1
input String title;
output String header;
Expand Down
14 changes: 7 additions & 7 deletions OMCompiler/Compiler/Util/UnorderedSet.mo
Expand Up @@ -649,11 +649,11 @@ public
"set1 / set2"
input UnorderedSet<T> set1;
input UnorderedSet<T> set2;
output UnorderedSet<T> set = UnorderedSet.new<T>(set1.hashFn, set1.eqFn);
output UnorderedSet<T> set = new<T>(set1.hashFn, set1.eqFn);
algorithm
for cref in UnorderedSet.toList(set1) loop
if not UnorderedSet.contains(cref, set2) then
UnorderedSet.add(cref, set);
for cref in toList(set1) loop
if not contains(cref, set2) then
add(cref, set);
end if;
end for;
end difference;
Expand All @@ -664,9 +664,9 @@ public
input UnorderedSet<T> set2;
output UnorderedSet<T> set = difference(set1, set2);
algorithm
for cref in UnorderedSet.toList(set2) loop
if not UnorderedSet.contains(cref, set1) then
UnorderedSet.add(cref, set);
for cref in toList(set2) loop
if not contains(cref, set1) then
add(cref, set);
end if;
end for;
end sym_difference;
Expand Down
1 change: 0 additions & 1 deletion OMCompiler/Compiler/runtime/matching.c
Expand Up @@ -1315,4 +1315,3 @@ void matching(int* col_ptrs, int* col_ids, int* match, int* row_match, int n, in
free(row_ptrs);
}
}

0 comments on commit 2eae847

Please sign in to comment.