I am trying to find out what the going definition for an
AbstractArray is in order to properly choose how to dispatch. As usual, this is best understood by an example. Let’s look at two different ways of writing “the same code”.
for i in number_of_iterations du = f(t,u) u += dt*du t += dt end
# Make a cache for du for i in number_of_iterations f!(t,u,du) # update `du` inplace u .+= dt.*du t += dt end
(Yes, for those who know differential equations, this is the Euler method)
If one is doing standard computing and working on arrays, the second method is clearly better because it gets rid of the temporary arrays. However, since I want to provide both support for a broad array of types and good performance, I provide both versions for each method (and there are some good examples which need the first method).
And that’s where the problem comes in. If I only had one method, I would duck type it and leave it for people to see if it works on their weird type. I am kind of thinking that the way to distinguish between the two is by
AbstractArray, but I am wondering if that is specific enough. Specifically, the second one will work on (and be faster) any mutable type which implements broadcasting. Is that what an
AbstractArray is? Or is there a slightly more general trait I can be dispatching on?
[@dlfivefifty would you mind chiming in on how a
Fun fits in? Are they more array-like and should be using the second version in some form?]