DiscreteCallbacks for ODEs generated from function closures behaving in a way I can't understand

I’m not terribly familiar with how all these pieces fit together and lacking a MWE, I can only guess, sorry! Your code is not very explicit about what’s a matrix and what’s a scalar, so I don’t quite know why you need a temporary array at all.

However, looking through the documentation of the integrator, why not use SciMLBase.get_tmp_cache? According to its documentation, it should be a perfect fit for your usecase:

Returns a tuple of internal cache vectors which are safe to use as temporary arrays. This should be used for integrator interface and callbacks which need arrays to write into in order to be non-allocating. The length of the tuple is dependent on the method.

2 Likes