Skip to content

Commit

Permalink
[NB] record and array update (#8819)
Browse files Browse the repository at this point in the history
* [NB] update strong component solving

 - add correct collection of strong components with size > 1
 - ToDo: allow sliced subsets in strong components with size > 1
 - some comments added

* [NB] update record and array handling
  • Loading branch information
kabdelhak committed Apr 11, 2022
1 parent 834a38b commit 67d7e86
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
18 changes: 18 additions & 0 deletions OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo
Expand Up @@ -1625,6 +1625,24 @@ public
// empty index list indicates no slicing and no rearranging
case _ guard(listEmpty(indices)) then (Pointer.create(eqn), SlicingStatus.UNCHANGED, NBSolve.Status.EXPLICIT);

case RECORD_EQUATION() algorithm
slicing_status := if Equation.size(eqn_ptr) == listLength(indices) then SlicingStatus.TRIVIAL else SlicingStatus.NONTRIVIAL;
if Util.isSome(cref_opt) then
(eqn, funcTree, solve_status, _) := Solve.solveEquation(Pointer.access(eqn_ptr), Util.getOption(cref_opt), funcTree);
else
solve_status := NBSolve.Status.EXPLICIT;
end if;
then (Pointer.create(eqn), slicing_status, solve_status);

case ARRAY_EQUATION() algorithm
slicing_status := if Equation.size(eqn_ptr) == listLength(indices) then SlicingStatus.TRIVIAL else SlicingStatus.NONTRIVIAL;
if Util.isSome(cref_opt) then
(eqn, funcTree, solve_status, _) := Solve.solveEquation(Pointer.access(eqn_ptr), Util.getOption(cref_opt), funcTree);
else
solve_status := NBSolve.Status.EXPLICIT;
end if;
then (Pointer.create(eqn), slicing_status, solve_status);

case FOR_EQUATION() algorithm
// get the sizes of the 'return value' of the equation
dims := Type.arrayDims(Equation.getType(eqn));
Expand Down
16 changes: 13 additions & 3 deletions OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBAdjacency.mo
Expand Up @@ -842,9 +842,19 @@ public
then ();

case (Equation.RECORD_EQUATION(), SOME(mapping)) guard(pseudo) algorithm
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed because record equations are not yet supported:\n"
+ Equation.toString(eqn)});
then fail();
(eqn_scal_idx, eqn_size) := mapping.eqn_AtS[eqn_arr_idx];
(m_part, mode_to_var_part) := Slice.getDependentCrefIndicesPseudoArray(
dependencies = unique_dependencies,
map = map,
mapping = mapping,
eqn_arr_idx = eqn_arr_idx
);
// check for arrayLength(m_part) == eqn_size ?

// add matrix rows to correct locations and update causalize modes
expandRows(m, eqn_scal_idx, m_part);
CausalizeModes.update(modes, eqn_scal_idx, eqn_arr_idx, mode_to_var_part, unique_dependencies);
then ();

case (Equation.ALGORITHM(), SOME(mapping)) guard(pseudo) algorithm
(eqn_scal_idx, eqn_size) := mapping.eqn_AtS[eqn_arr_idx];
Expand Down
3 changes: 1 addition & 2 deletions OMCompiler/Compiler/NBackEnd/Util/NBSlice.mo
Expand Up @@ -319,9 +319,8 @@ public
idx := 1;
for var_scal_idx in listReverse(scal_lst) loop
mode_to_var_row := mode_to_var[idx];
mode_to_var_row[mode] := var_scal_idx;
arrayUpdate(mode_to_var_row, mode, var_scal_idx);
var_scal_idx := -var_scal_idx;
arrayUpdate(mode_to_var, idx, mode_to_var_row);
indices[idx] := var_scal_idx :: indices[idx];
idx := idx + 1;
end for;
Expand Down
16 changes: 14 additions & 2 deletions OMCompiler/Compiler/NFFrontEnd/NFBackendExtension.mo
Expand Up @@ -307,7 +307,7 @@ public

function toString
input VariableAttributes attr;
output String str;
output String str = "";
algorithm
str := match attr
case VAR_ATTR_REAL()
Expand All @@ -329,14 +329,26 @@ public
then attributesToString({("fixed", attr.fixed), ("start", attr.start), ("min", attr.min), ("max", attr.max)}, NONE(), NONE());

case VAR_ATTR_RECORD()
then "Attribute string for RECORD not supported yet";
then List.toString(UnorderedMap.toList(attr.indexMap), function recordString(childrenAttr = attr.childrenAttr), "", "" ,", " , "");

else getInstanceName() + " failed. Attribute string could not be created.";
end match;
// put the string in parentheses only if it is not empty
str := if "" == str then "" else "(" + str + ")";
end toString;

function recordString
input tuple<String, Integer> attr_tpl;
input array<VariableAttributes> childrenAttr;
output String str;
protected
String name;
Integer index;
algorithm
(name, index) := attr_tpl;
str := name + toString(childrenAttr[index]);
end recordString;

function create
input list<tuple<String, Binding>> attrs;
input Type ty;
Expand Down

0 comments on commit 67d7e86

Please sign in to comment.