Mutating values in immutable struct (specifically of type ODESolution)

The ODESolution itself appears to be a very big and complicated structure. It probably has a nontrivial custom constructor and Accessors.jl has not been told how to use it.

Even if ODESolution itself is immutable, a Vector (almost?) anywhere is still mutable. You can simply do sol.t .*= myscalingfactor in this case. Recall, this is identical to sol.t .= sol.t .* myscalingfactor. The .= is why this works to update sol.t in-place – no need to make a new Vector and build a new ODESolution around it.

Hopefully there isn’t some dependence on this field baked into other fields. If there is, you could end up with a ODESolution that does not behave as expected.

1 Like