Skip to content

Commit

Permalink
[NB] tidy up equal structures and make it more maintainable (#10155)
Browse files Browse the repository at this point in the history
  • Loading branch information
kabdelhak committed Feb 5, 2023
1 parent 1f1ac7e commit 9dcc679
Showing 1 changed file with 38 additions and 70 deletions.
108 changes: 38 additions & 70 deletions OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBAdjacency.mo
Expand Up @@ -902,91 +902,28 @@ public

case (Equation.FOR_EQUATION(), SOME(mapping)) guard(pseudo) algorithm
// get expanded matrix rows
(eqn_scal_idx, eqn_size) := mapping.eqn_AtS[eqn_arr_idx];
(m_part, mode_to_var_part) := Slice.getDependentCrefIndicesPseudoFor(
dependencies = unique_dependencies,
map = map,
mapping = mapping,
iter = eqn.iter,
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);
fillMatrixArray(unique_dependencies, map, mapping, eqn_arr_idx, m, modes,
function Slice.getDependentCrefIndicesPseudoFor(iter = eqn.iter));
then ();

case (Equation.ARRAY_EQUATION(), SOME(mapping)) guard(pseudo) algorithm
(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);
fillMatrixArray(unique_dependencies, map, mapping, eqn_arr_idx, m, modes, Slice.getDependentCrefIndicesPseudoArray);
then ();

case (Equation.RECORD_EQUATION(), SOME(mapping)) guard(pseudo) algorithm
(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);
fillMatrixArray(unique_dependencies, map, mapping, eqn_arr_idx, m, modes, Slice.getDependentCrefIndicesPseudoArray);
then ();

case (Equation.ALGORITHM(), SOME(mapping)) guard(pseudo) algorithm
(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);
fillMatrixArray(unique_dependencies, map, mapping, eqn_arr_idx, m, modes, Slice.getDependentCrefIndicesPseudoArray);
then ();

case (Equation.IF_EQUATION(), SOME(mapping)) guard(pseudo) algorithm
(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);
fillMatrixArray(unique_dependencies, map, mapping, eqn_arr_idx, m, modes, Slice.getDependentCrefIndicesPseudoArray);
then ();

case (Equation.WHEN_EQUATION(), SOME(mapping)) guard(pseudo) algorithm
(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);
fillMatrixArray(unique_dependencies, map, mapping, eqn_arr_idx, m, modes, Slice.getDependentCrefIndicesPseudoArray);
then ();

case (_, SOME(mapping)) guard(pseudo) algorithm
Expand All @@ -1012,6 +949,37 @@ public
end match;
end fillMatrix;

function fillMatrixArray
input list<ComponentRef> unique_dependencies;
input UnorderedMap<ComponentRef, Integer> map;
input Adjacency.Mapping mapping;
input Integer eqn_arr_idx;
input array<list<Integer>> m;
input CausalizeModes modes;
input getDependentCrefIndices func;
protected
partial function getDependentCrefIndices
input list<ComponentRef> dependencies;
input UnorderedMap<ComponentRef, Integer> map;
input Adjacency.Mapping mapping;
input Integer eqn_arr_idx;
output array<list<Integer>> m_part;
output array<array<Integer>> mode_to_var_part;
end getDependentCrefIndices;
Integer eqn_scal_idx, eqn_size;
array<list<Integer>> m_part;
array<array<Integer>> mode_to_var_part;
algorithm
(eqn_scal_idx, eqn_size) := mapping.eqn_AtS[eqn_arr_idx];
(m_part, mode_to_var_part) := func(unique_dependencies, map, mapping, 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);
if eqn_size > 1 then
CausalizeModes.update(modes, eqn_scal_idx, eqn_arr_idx, mode_to_var_part, unique_dependencies);
end if;
end fillMatrixArray;

function cleanMatrix
input array<list<Integer>> m;
input Option<Mapping> mapping_opt;
Expand Down

0 comments on commit 9dcc679

Please sign in to comment.