[SciPy-Dev] vectorized scipy.integrate.quad
Nathan Woods
charlesnwoods at gmail.com
Mon Sep 28 20:22:13 EDT 2015
The API part is simple. Something like,
try:
func([xes])
except TypeError:
func = lambda xlist: [func x for x in xlist]
A much smarter way would use a class instead of a lambda, but hopefully this conveys the idea.
> On Sep 28, 2015, at 4:28 AM, Christoph Groth <christoph at grothesque.org> wrote:
>
> Nathan Woods wrote:
>
>> Unless I'm mistaken, though, integration of a python function seems
>> unlikely to take advantage of a vectorized C integrator, so the speed
>> ups would be limited to those calling quad with ctypes functions.
>
> What I proposed is making it possible that the integrand gets called
> with a sequence of x-values instead of a single x-value at a time. It
> would be then up to the user-specified integrand function to perform the
> computation. I can think of at least three ways that can provide speed-ups:
>
> • vectorized evaluation using vectorized numpy operations (it should be faster
> to call np.sin(x) once with x being an array of 21 elements than to
> call math.sin(x) 21 times).
>
> • concurrent.futures
>
> • MPI
>
> Is there a problem that I fail to see?
>
>> Also, I think breaking the API would be a bad idea, but you could, for
>> instance, allow quad to accept both numbers and sequences, and then
>> wrap the number in an array before sending it on to the
>> integrator. This would preserve the API, while allowing the desired
>> vectorization.
>
> Of course breaking the API is a bad idea. That’s why I have in mind
> keeping scipy.integrate.quad as it is, and adding a sibling that could
> be called scipy.integrate.vectorized_quad. If the algorithm of
> vectorized_quad remains the same (as planned), quad could be eventually
> implemented as a thin wrapper around vectorized_quad. This would allow
> to remove the unomodified QUADPACK from scipy.
>
> I am sorry, I do not understand your proposal for extending the API in a
> backwards-compatible way without introducing a new function. Could you
> please explain it in more detail?
>
> Christoph
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at scipy.org
> https://mail.scipy.org/mailman/listinfo/scipy-dev
More information about the SciPy-Dev
mailing list