Bases: object
Class to predict run time.
Note
Only predict for single varying numeric input parameter.
| Parameters: | func : function 
 args : tuple 
 kwargs : dict 
 | 
|---|
Examples
>>> from astropy.utils.timer import RunTimePredictor
Set up a predictor for  :
:
>>> p = RunTimePredictor(pow, 10)
Give it baseline data to use for prediction and get the function output values:
>>> p.time_func(range(10, 1000, 200))
>>> for input, result in sorted(p.results.items()):
...     print("pow(10, {0})\n{1}".format(input, result))
pow(10, 10)
10000000000
pow(10, 210)
10000000000...
pow(10, 410)
10000000000...
pow(10, 610)
10000000000...
pow(10, 810)
10000000000...
Fit a straight line assuming  relationship
(coefficients are returned):
 relationship
(coefficients are returned):
>>> p.do_fit()  
array([1.16777420e-05,  1.00135803e-08])
Predict run time for  :
:
>>> p.predict_time(5000)  
6.174564361572262e-05
Plot the prediction:
>>> p.plot(xlabeltext='Power of 10')  
 
When the changing argument is not the last, e.g.,
 , something like this might work:
, something like this might work:
>>> p = RunTimePredictor(lambda x: pow(x, 2))
>>> p.time_func([2, 3, 5])
>>> sorted(p.results.items())
[(2, 4), (3, 9), (5, 25)]
Attributes Summary
| results | Function outputs from time_func. | 
Methods Summary
| do_fit([model, fitter, power, min_datapoints]) | Fit a function to the lists of arguments and their respective run time in the cache. | 
| plot([xscale, yscale, xlabeltext, save_as]) | Plot prediction. | 
| predict_time(arg) | Predict run time for given argument. | 
| time_func(arglist) | Time the partial function for a list of single args and store run time in a cache. | 
Attributes Documentation
Function outputs from time_func.
A dictionary mapping input arguments (fixed arguments are not included) to their respective output values.
Methods Documentation
Fit a function to the lists of arguments and their respective run time in the cache.
By default, this does a linear least-square fitting to a straight line on run time w.r.t. argument values raised to the given power, and returns the optimal intercept and slope.
| Parameters: | model : astropy.modeling.Model 
 fitter : astropy.modeling.fitting.Fitter 
 power : int, optional 
 min_datapoints : int, optional 
 | 
|---|---|
| Returns: | a : array_like 
 | 
| Raises: | AssertionError 
 ModelsError 
 | 
Plot prediction.
Note
Uses matplotlib.
| Parameters: | xscale, yscale : {‘linear’, ‘log’, ‘symlog’} 
 xlabeltext : str, optional 
 save_as : str, optional 
 | 
|---|---|
| Raises: | AssertionError 
 | 
Predict run time for given argument. If prediction is already cached, cached value is returned.
| Parameters: | arg : number 
 | 
|---|---|
| Returns: | t_est : float 
 | 
| Raises: | AssertionError 
 | 
Time the partial function for a list of single args and store run time in a cache. This forms a baseline for the prediction.
This also stores function outputs in results.
| Parameters: | arglist : list of numbers 
 | 
|---|