Skip to content

Commit bc60081

Browse files
authored
[NB] update adjacency (#15693)
- fix mixed dependency: skip to the proper dimension index even if there is reduction from the left
1 parent 3ced57f commit bc60081

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

OMCompiler/Compiler/NBackEnd/Util/NBSlice.mo

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,6 @@ protected
14261426
// II.3 all reduced - full dependency per row. scalarize and add to all rows of the equation
14271427
resolveAllReduced(cref, original_cref, eqn_name, skip_idx, size, iter_size, frames, rep, map, m, mapping, modes);
14281428
end if;
1429-
14301429
end for;
14311430
else
14321431
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed for: " + ComponentRef.toString(original_cref) + "."});
@@ -1543,7 +1542,7 @@ protected
15431542

15441543
// 5. iterate over all equation dimensions and use the map to get the correct dependencies
15451544
key := arrayCreate(listLength(subs), 0);
1546-
resolveEquationDimensions(List.zip(eq_dims, eq_reg), map2, key, m, modes, Mode.create(eqn_name, {original_cref}, false), Pointer.create(skip_idx));
1545+
resolveEquationDimensions(List.zip(eq_dims, eq_reg), regulars, map2, key, m, modes, Mode.create(eqn_name, {original_cref}, false), Pointer.create(skip_idx));
15471546
else
15481547
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed because subscripts, dimensions and dependencies were not of equal length.\n"
15491548
+ "variable subscripts(" + intString(listLength(subs)) + "): " + List.toString(subs, Subscript.toString) + "\n"
@@ -1606,6 +1605,7 @@ protected
16061605
is TRUE if its a regular occurence of the cref and FALSE if its a reduced occurence.
16071606
The key is created from the dimensions and the additional boolean to look up the cref occurence in the map."
16081607
input list<tuple<Dimension, Boolean>> lst "equation dimension and cref regularity tuple list";
1608+
input list<Boolean> regulars "used to skip to the proper index";
16091609
input UnorderedMap<Key, Val2> map "map to look up occurence";
16101610
input Array<Integer> key "mutable key";
16111611
input array<list<Integer>> m "adjacency matrix";
@@ -1614,14 +1614,15 @@ protected
16141614
input Pointer<Integer> eqn_idx_ptr "mutable equation index";
16151615
input Integer index = 1 "dimension index for the key";
16161616
algorithm
1617-
() := match lst
1617+
() := match (lst, regulars)
16181618
local
16191619
Dimension dim;
16201620
list<tuple<Dimension, Boolean>> rest;
16211621
Integer eqn_idx;
16221622
list<Integer> scal_lst;
1623+
list<Boolean> rest_reg;
16231624

1624-
case {} algorithm
1625+
case ({}, _) algorithm
16251626
// no further dimensions. resolve with current key config and bump equation index
16261627
eqn_idx := Pointer.access(eqn_idx_ptr);
16271628
scal_lst := UnorderedMap.getSafe(arrayList(key), map, sourceInfo());
@@ -1631,19 +1632,24 @@ protected
16311632
Pointer.update(eqn_idx_ptr, eqn_idx + 1);
16321633
then ();
16331634

1634-
case (dim, false)::rest algorithm
1635-
// reduced dimension, keep key index at 0 and go deeper with next dimension
1635+
case (_, false::rest_reg) algorithm
1636+
// reduced dimension no overlap, keep key index at 0 and go deeper with next dimension
1637+
resolveEquationDimensions(lst, rest_reg, map, key, m, modes, mode, eqn_idx_ptr, index+1);
1638+
then ();
1639+
1640+
case ((dim, false)::rest, _::rest_reg) algorithm
1641+
// reduced dimension with overlap, keep key index at 0 and go deeper with next dimension
16361642
for i in 1:Dimension.size(dim, true) loop
1637-
resolveEquationDimensions(rest, map, key, m, modes, mode, eqn_idx_ptr, index+1);
1643+
resolveEquationDimensions(rest, rest_reg, map, key, m, modes, mode, eqn_idx_ptr, index+1);
16381644
end for;
16391645
then ();
16401646

1641-
case (dim, true)::rest algorithm
1647+
case ((dim, true)::rest, _::rest_reg) algorithm
16421648
// regular dimension, update key index to corresponding dimension index
16431649
// and go deeper with next dimension
16441650
for i in 1:Dimension.size(dim, true) loop
16451651
arrayUpdate(key, index, i);
1646-
resolveEquationDimensions(rest, map, key, m, modes, mode, eqn_idx_ptr, index+1);
1652+
resolveEquationDimensions(rest, rest_reg, map, key, m, modes, mode, eqn_idx_ptr, index+1);
16471653
end for;
16481654
then ();
16491655
end match;

0 commit comments

Comments
 (0)