[AstroPy] Using quantities is slow
derek at astro.physik.uni-goettingen.de
Mon Aug 24 18:32:29 EDT 2015
On 24 Aug 2015, at 3:57 pm, Kevin Gullikson <kevin.gullikson at gmail.com> wrote:
> I am writing an MCMC fitting code, and my current implementation uses the (very useful) astropy quantities framework to take care of unit conversions and such. However, the code is surprisingly slow so I profiled it with %prun and it looks like the quantity utilities that wrap numpy functions are taking a huge chunk of time. Is that just the price of convenience?
I am not an expert on the quantities/units implementation, but I would imagine that they could indeed
introduce a significant overhead, as the class adds a number of validations and checks for a function
calling a quantity object. Especially with rather numerous operations on comparatively small arrays
this could become problematic.
Did you experiment with using decorators as described in
- iiuc this would allow bypassing some of the validations?
Another option might be to only pass plain numpy arrays to the innermost loops of your code with .value,
of course at the expense of some of the convenience gained in the first place...
More information about the AstroPy