This piece of code is pretty suspect. Did you mean:
update_mass_matrix! = (jacob, x, p, t) -> begin
# zero out all mass matrix entries
jacob .= 0.0
# compute mass matrix
mass_matrix!(jacob, x, p, (; constants..., t))
# change sign of mass matrix
jacob .*= -1
# return result
return jacob
end
The previous version was relying on M and jacob having the same pointer, but that won’t necessarily always be the case.