Sparse representation: fix bug in output of indices in driver and JSON files

Jacobian column numbers were incorrect (it would return internal derivation
IDs).

Ref. dynare#1859
master
Sébastien Villemot 2022-12-12 13:17:16 +01:00
parent 4f7794a8f9
commit 4aa1ff1f73
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 6 additions and 4 deletions

View File

@ -2247,8 +2247,9 @@ ModelTree::writeDriverSparseIndicesHelper(ostream &output) const
output << "M_." << model_name << "_g" << i << "_sparse_indices = int32([";
for (const auto &[vidx, d] : derivatives[i])
{
for (int it : vidx)
output << it+1 << ' ';
for (bool row_number {true}; // First element of vidx is row number
int it : vidx)
output << (exchange(row_number, false) ? it : getJacobianCol(it, true))+1 << ' ';
output << ';' << endl;
}
output << "]);" << endl;
@ -2304,9 +2305,10 @@ ModelTree::writeJsonSparseIndicesHelper(ostream &output) const
for (bool printed_something2 {false};
int it : vidx)
{
if (exchange(printed_something2, true))
if (printed_something2)
output << ", ";
output << it+1;
// First element of vidx is row number
output << (exchange(printed_something2, true) ? getJacobianCol(it, true) : it)+1;
}
output << ']' << endl;
}