# Path: imusim/maths/integrators.py
# class Integrator(object):
# class RectangleRule(Integrator):
# class TrapeziumRule(Integrator):
# class DoubleIntegrator(object):
#     def __init__(self, initialValue):
#     def __call__(self, sampleValue, dt):
#     def __call__(self, sampleValue, dt):
#     def __init__(self, initialValue):
#     def __call__(self, sampleValue, dt):
#     def __init__(self, initialValue, initialDerivative, method=RectangleRule):
#     def __call__(self, sampleValue, dt):


import numpy as np
from imusim.maths import integrators
from imusim.testing.vectors import assert_vectors_correlated
from imusim.testing.inspection import getImplementations

functions = ( lambda x: x,
        lambda x: x**2,
        lambda x: np.cos(x),
        lambda x: np.e**x )
integrals = ( lambda x: 1/2 * x**2,
        lambda x: 1/3 * x**3,
        lambda x: np.sin(x),
        lambda x: np.e**x)
doubleIntegrals = (lambda x: x**3 / 6,
        lambda x: x**4 / 12,
        lambda x: -np.cos(x),
        lambda x: np.e**x)

def checkIntegral(method, function, integral):
    estimated_integral = np.empty_like(x)
    integrator = method(integral(0))
    for i,s in enumerate(x[1:]):
        estimated_integral[i+1] = integrator(function(s), dt)
    assert_vectors_correlated(estimated_integral[1:], integral(x[1:]))

def checkDoubleIntegral(method, function, integral, doubleIntegral):
    estimated_integral = np.empty_like(x)
    integrator = integrators.DoubleIntegrator(doubleIntegral(0),integral(0),
            method)
    for i,s in enumerate(x[1:]):
        estimated_integral[i+1] = integrator(function(s), dt)
    assert_vectors_correlated(estimated_integral[1:], doubleIntegral(x[1:]))

def testIntegrators():

# Path: imusim/maths/integrators.py
# class Integrator(object):
# class RectangleRule(Integrator):
# class TrapeziumRule(Integrator):
# class DoubleIntegrator(object):
#     def __init__(self, initialValue):
#     def __call__(self, sampleValue, dt):
#     def __call__(self, sampleValue, dt):
#     def __init__(self, initialValue):
#     def __call__(self, sampleValue, dt):
#     def __init__(self, initialValue, initialDerivative, method=RectangleRule):
#     def __call__(self, sampleValue, dt):


# Path: imusim/tests/maths/integrators_test.py
import numpy as np
from imusim.maths import integrators
from imusim.testing.vectors import assert_vectors_correlated
from imusim.testing.inspection import getImplementations


functions = ( lambda x: x,
        lambda x: x**2,
        lambda x: np.cos(x),
        lambda x: np.e**x )
integrals = ( lambda x: 1/2 * x**2,
        lambda x: 1/3 * x**3,
        lambda x: np.sin(x),
        lambda x: np.e**x)
doubleIntegrals = (lambda x: x**3 / 6,
        lambda x: x**4 / 12,
        lambda x: -np.cos(x),
        lambda x: np.e**x)

def checkIntegral(method, function, integral):
    estimated_integral = np.empty_like(x)
    integrator = method(integral(0))
    for i,s in enumerate(x[1:]):
        estimated_integral[i+1] = integrator(function(s), dt)
    assert_vectors_correlated(estimated_integral[1:], integral(x[1:]))

def checkDoubleIntegral(method, function, integral, doubleIntegral):
    estimated_integral = np.empty_like(x)
    integrator = integrators.DoubleIntegrator(doubleIntegral(0),integral(0),
            method)
    for i,s in enumerate(x[1:]):
        estimated_integral[i+1] = integrator(function(s), dt)
    assert_vectors_correlated(estimated_integral[1:], doubleIntegral(x[1:]))

def testIntegrators():

    for method in getImplementations(integrators, integrators.Integrator):