This interface is insane,
sparse_matrix<int rows, int columns, int i_vector, int j_vector> A;
I suggest that sparse matrices have two phases, a construction and use phase. In the construction phase, you can change the sparsity structure by assigning to coefficients or setting blocks or whatever. In the use phase, you cannot change the structure.
Because of the way Stan is designed, we can’t “tie” a reordering to a matrix and have it persist through
sampling.
Time to revisit this design decision? Sorting is costly. I forget which, but one of the sparse Cholesky libraries allows for precomputation of the best sort order. It would be a pity not to take advantage. Also, lots of sanity checks could be saved if we remembered that things worked fine on the first attempt.