Skip to content

Commit

Permalink
[NB] apply merge subscripts to scope (#9947)
Browse files Browse the repository at this point in the history
  • Loading branch information
kabdelhak committed Dec 15, 2022
1 parent 25e672f commit bd9195f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo
Expand Up @@ -1600,7 +1600,7 @@ public
rhs := Expression.map(rhs, Expression.repairOperator);
(sub_crefs, _) := Iterator.getFrames(iter);
subs := list(Subscript.fromTypedExp(Expression.fromCref(cref)) for cref in sub_crefs);
lhs := Expression.fromCref(ComponentRef.mergeSubscripts(subs, var.name));
lhs := Expression.fromCref(ComponentRef.mergeSubscripts(subs, var.name, true, true));
eqn := Equation.fromLHSandRHS(lhs, rhs, idx, context, eqnAttr);
eqn := Pointer.create(Equation.FOR_EQUATION(
ty = ComponentRef.getSubscriptedType(var.name),
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NBackEnd/Classes/NBStrongComponent.mo
Expand Up @@ -677,7 +677,7 @@ public
Variable.VARIABLE(name = cref, ty = ty) := Pointer.access(var);
sizes := listReverse(list(Dimension.size(dim) for dim in Type.arrayDims(ty)));
vals := Slice.indexToLocation(var_scal_idx-var_start_idx, sizes);
cref := ComponentRef.mergeSubscripts(list(Subscript.INDEX(Expression.INTEGER(val+1)) for val in vals), cref, false, true);
cref := ComponentRef.mergeSubscripts(list(Subscript.INDEX(Expression.INTEGER(val+1)) for val in vals), cref, true, true);
comp := SLICED_COMPONENT(cref, Slice.SLICE(var, {}), Slice.SLICE(eqn, {}), NBSolve.Status.UNPROCESSED);
else
// case 2: just create a single strong component
Expand Down
12 changes: 6 additions & 6 deletions OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBInitialization.mo
Expand Up @@ -195,17 +195,17 @@ public
algorithm
if BVariable.isDiscreteState(var_ptr) then
// for discrete states change the lhs cref to the $PRE cref
merged_name := ComponentRef.mergeSubscripts(subscripts, name);
merged_name := ComponentRef.mergeSubscripts(subscripts, name, true, true);
name := BVariable.getPreCref(name);
name := ComponentRef.mergeSubscripts(subscripts, name);
name := ComponentRef.mergeSubscripts(subscripts, name, true, true);
var_ptr := BVariable.getVarPointer(name);
elseif BVariable.isPrevious(var_ptr) then
// for previous change the rhs to the start value of the discrete state
merged_name := BVariable.getDiscreteStateCref(name);
merged_name := ComponentRef.mergeSubscripts(subscripts, merged_name);
merged_name := ComponentRef.mergeSubscripts(subscripts, merged_name, true, true);
else
// just apply subscripts and make start var
name := ComponentRef.mergeSubscripts(subscripts, name);
name := ComponentRef.mergeSubscripts(subscripts, name, true, true);
merged_name := name;
end if;
(start_name, start_var) := BVariable.makeStartVar(merged_name);
Expand Down Expand Up @@ -319,8 +319,8 @@ public
frames := List.zip(list(ComponentRef.makeIterator(iter, Type.INTEGER()) for iter in iterators), ranges);

pre_name := BVariable.getPreCref(name);
pre_name := ComponentRef.mergeSubscripts(subscripts, pre_name);
name := ComponentRef.mergeSubscripts(subscripts, name);
pre_name := ComponentRef.mergeSubscripts(subscripts, pre_name, true, true);
name := ComponentRef.mergeSubscripts(subscripts, name, true, true);

pre_eq := Equation.makeAssignment(name, Expression.fromCref(pre_name), idx, NBEquation.PRE_STR, frames, NBEquation.EQ_ATTR_DEFAULT_INITIAL);

Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NBackEnd/Util/NBSlice.mo
Expand Up @@ -436,7 +436,7 @@ public
stripped := ComponentRef.stripSubscriptsAll(row_cref);
for new_subs_single in new_row_cref_subs loop
evaluated_subs := list(Subscript.fromTypedExp(exp) for exp in new_subs_single);
new_row_crefs := ComponentRef.mergeSubscripts(evaluated_subs, stripped, false, true) :: new_row_crefs;
new_row_crefs := ComponentRef.mergeSubscripts(evaluated_subs, stripped, true, true) :: new_row_crefs;
end for;

// get the scalar crefs for each column cref
Expand Down

0 comments on commit bd9195f

Please sign in to comment.