[SciPy-Dev] Choosing the result of dtype for integration

David Hagen david at drhagen.com
Thu Feb 27 20:46:02 EST 2020


I am all for improving handling of complex integration, but I think the
current behavior matches how SciPy handles real and complex domains, namely
by making the user opt into the complex domain. In Matlab log(-1.0) is
3.14i. In NumPy, log(-1.0) is NaN. NumPy and SciPy require the user to be
explicit about working in the complex domain. Matlab happily takes you from
the real domain to the complex domain without warning. I have done a lot of
ODE integration in Matlab, and I always disliked how easily it accepted
complex numbers. If I had a log somewhere in my RHS and it accidentally got
a negative number, the whole thing would keep running and just return a
giant block of complex nonsense. Now, this is a bit different because it is
a lot harder to accidentally get a complex RHS, which is why I am only
weakly in favor of maintaining the status quo.

On Thu, Feb 27, 2020 at 5:45 AM yotam vaknin <tomirendo at gmail.com> wrote:

> Hello list,
>
> I hope I'm now visiting a very old topic, but I wanted to suggest a simple
> change to the integration mechanism.
>
> At this moment, the dtype of the result of an integration is the dtype of
> the initial condition. For example, when using ״solve_ivp" to solve the
> initial value problem
> y0=np.array([1,0] )
> dy/dt= -i H at y0
> which is a very a standard calculation in Quantum Mechanics, the
> integrator will return nonsense, since the process involves complex
> numbers, and the initial conditions were (wrongly assigned to be) real. The
> solution is of course y0=np.array([1,0], dtype=complex), but this is very
> hard to figure out to new users coming from, for e.g., Matlab.
>
> I wanted to suggest that instead of choosing the dtype using the initial
> condition, that the resulting dtype will be the dtype of the derivative (or
> better yet, derivative*dt + initial condition). This will solve the
> problem, and introduce minimal confusing.
>
> Thanks for all of your great work!
>
> Regards,
> Yotam Vaknin
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at python.org
> https://mail.python.org/mailman/listinfo/scipy-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20200227/39a95b45/attachment.html>


More information about the SciPy-Dev mailing list