andgoldschmidt / derivative

Optimal numerical differentiation of noisy time series data in python.
https://derivative.readthedocs.io/en/latest/
Other
55 stars 8 forks source link

Create functional style api #2

Closed andgoldschmidt closed 4 years ago

andgoldschmidt commented 4 years ago

To add backwards compatibility with derivative.py, a function-style api should be implemented on top of this project's derivative interface.

E.g. from derivative.py/derivative/derivative.py on 05/04/2020:

methods = {}

def register(name=""):
    def inner(f):
        n = name or f.__name__
        methods[n] = f
        return f
    return inner

from .loc import *
from .glob import *

def derivative(x, y, kind="finitediff", **kwargs):
    method = methods.get(kind)
    f = lambda y: method(x, y, **kwargs)
    if len(y.shape) > 1:
        return np.apply_along_axis(f, 0, y)
    else:
        return f(y)
andgoldschmidt commented 4 years ago

feature added in version 0.1.1, see commit #https://github.com/andgoldschmidt/primelab/commit/70f89f960487141a6d56dea93e2733e4b71caf5c