Cholesky_decompose runtime error when computing transformed parameters

Hi. Sorry for the delay, I was away from Bayesworld for a while. It shouldn’t be the latter, since I’m setting up the initial covariance matrix in Python and passing it to Stan, there are no NaNs there. The function setting up the covariance matrix is one I posted as a reply for another thread, in any case it’s below:

functions{
matrix_K(vector x, real[] hyperpars, matrix signalCovarianceMatrix, int N, int M, real jitter) {
matrix[M*N, M*N] K;
int sub_l;
int sub_k;

for (l in 1:M) {
    // possibly use specific hyperparameters for task l
    sub_l = (l-1)*N;
    for (k in 1:M) {
         // possibly use specific hyperparameters for task k
        sub_k = (k-1)*N;
        for (i in 1:N) {
            for (j in i:N) {
                K[sub_l+i, sub_k+j] = signalCovarianceMatrix[l,k] * cov_func(i,j,1,1);
                K[sub_k+j, sub_l+i] = K[sub_l+i, sub_k+j];
                if (i==j) {K[sub_l+i, sub_k+j] = K[sub_l+i, sub_k+j] + jitter}
            }
        }
    }
}
}

double cov_func(real xi, real xj, real elll, real ellk){
    cov = exp(-pow(abs(i-j,2)/(pow(elll,2)+pow(elll,2)))

}
}
transformed data {
    real jitter = 1e-8;
    int M = 30
    int N = 15
    vector x = [1..15]
}
parameters {

    cov_matrix[M,M] signalCovarianceMatrix // alternatively just 'matrix' being put together by a function that assures it's symmetric

    real hyperpars[M]; 


}
model{
    matrix[M*N, M*N] K = matrix_K(x, hyperpars, signalCovarianceMatrix, M, N, jitter);

    matrix[M*N, M*N] L = cholesky_decompose(K);
}

from Python, making the initial value of K = np.ones([M*N,M*N])*1e-3; for i in range(M*N): K[i,i] = (1+1e-8); should reproduce the error when the cholesky_decompose is in the transformed parameters block instead of model. I didn’t test this code and I can’t rerun the original model, but unless there’s something really weird there should be no difference except for the matrix/cov_matrix, but because it fails before the first iterations I don’t see why it should make a difference either. I could also put together a full example, but that may take longer to get done and test.