@@ -642,20 +642,16 @@ function DiffEqBase.SDEFunction{iip, specialize}(sys::SDESystem, dvs = unknowns(
642642 _Wfact, _Wfact_t = nothing , nothing
643643 end
644644
645+ M = calculate_massmatrix (sys)
645646 if sparse
646647 uElType = u0 === nothing ? Float64 : eltype (u0)
647- if jac
648- jac_prototype = similar (calculate_jacobian (sys; sparse), uElType)
649- else
650- jac_prototype = similar (jacobian_sparsity (sys), uElType)
651- end
652- W_prototype = similar (W_sparsity (sys), uElType)
648+ jac_prototype = similar (calculate_jacobian (sys; sparse), uElType)
649+ W_prototype = similar (jac_prototype .+ M, uElType)
653650 else
654651 jac_prototype = nothing
655652 W_prototype = nothing
656653 end
657654
658- M = calculate_massmatrix (sys)
659655 _M = (u0 === nothing || M == I) ? M : ArrayInterface. restructure (u0 .* u0' , M)
660656
661657 observedfun = ObservedFunctionCache (
@@ -742,15 +738,14 @@ function SDEFunctionExpr{iip}(sys::SDESystem, dvs = unknowns(sys),
742738 _jac = :nothing
743739 end
744740
745- jac_prototype = if sparse
741+ M = calculate_massmatrix (sys)
742+ if sparse
746743 uElType = u0 === nothing ? Float64 : eltype (u0)
747- if jac
748- similar (calculate_jacobian (sys, sparse = sparse), uElType)
749- else
750- similar (jacobian_sparsity (sys), uElType)
751- end
744+ jac_prototype = similar (calculate_jacobian (sys; sparse), uElType)
745+ W_prototype = similar (jac_prototype .+ M, uElType)
752746 else
753- nothing
747+ jac_prototype = nothing
748+ W_prototype = nothing
754749 end
755750
756751 if Wfact
@@ -763,8 +758,6 @@ function SDEFunctionExpr{iip}(sys::SDESystem, dvs = unknowns(sys),
763758 _Wfact, _Wfact_t = :nothing , :nothing
764759 end
765760
766- M = calculate_massmatrix (sys)
767-
768761 _M = (u0 === nothing || M == I) ? M : ArrayInterface. restructure (u0 .* u0' , M)
769762
770763 ex = quote
0 commit comments