# Path: torchdiffeq/_impl/rk_common.py
# class _UncheckedAssign(torch.autograd.Function):
# class RKAdaptiveStepsizeODESolver(AdaptiveStepsizeEventODESolver):
#     def forward(ctx, scratch, value, index):
#     def backward(ctx, grad_scratch):
# def _runge_kutta_step(func, y0, f0, t0, dt, t1, tableau):
# def rk4_step_func(func, t0, dt, t1, y0, f0=None, perturb=False):
# def rk4_alt_step_func(func, t0, dt, t1, y0, f0=None, perturb=False):
#     def __init__(self, func, y0, rtol, atol,
#                  first_step=None,
#                  step_t=None,
#                  jump_t=None,
#                  safety=0.9,
#                  ifactor=10.0,
#                  dfactor=0.2,
#                  max_num_steps=2 ** 31 - 1,
#                  dtype=torch.float64,
#                  **kwargs):
#     def _before_integrate(self, t):
#     def _advance(self, next_t):
#     def _advance_until_event(self, event_fn):
#     def _adaptive_step(self, rk_state):
#     def _interp_fit(self, y0, y1, k, dt):
# def _sort_tvals(tvals, t0):


import torch
from .rk_common import _ButcherTableau, RKAdaptiveStepsizeODESolver


_DORMAND_PRINCE_SHAMPINE_TABLEAU = _ButcherTableau(
    alpha=torch.tensor([1 / 5, 3 / 10, 4 / 5, 8 / 9, 1., 1.], dtype=torch.float64),
    beta=[
        torch.tensor([1 / 5], dtype=torch.float64),
        torch.tensor([3 / 40, 9 / 40], dtype=torch.float64),
        torch.tensor([44 / 45, -56 / 15, 32 / 9], dtype=torch.float64),
        torch.tensor([19372 / 6561, -25360 / 2187, 64448 / 6561, -212 / 729], dtype=torch.float64),
        torch.tensor([9017 / 3168, -355 / 33, 46732 / 5247, 49 / 176, -5103 / 18656], dtype=torch.float64),
        torch.tensor([35 / 384, 0, 500 / 1113, 125 / 192, -2187 / 6784, 11 / 84], dtype=torch.float64),
    ],
    c_sol=torch.tensor([35 / 384, 0, 500 / 1113, 125 / 192, -2187 / 6784, 11 / 84, 0], dtype=torch.float64),
    c_error=torch.tensor([
        35 / 384 - 1951 / 21600,
        0,
        500 / 1113 - 22642 / 50085,
        125 / 192 - 451 / 720,
        -2187 / 6784 - -12231 / 42400,
        11 / 84 - 649 / 6300,
        -1. / 60.,
    ], dtype=torch.float64),
)

DPS_C_MID = torch.tensor([

# Path: torchdiffeq/_impl/rk_common.py
# class _UncheckedAssign(torch.autograd.Function):
# class RKAdaptiveStepsizeODESolver(AdaptiveStepsizeEventODESolver):
#     def forward(ctx, scratch, value, index):
#     def backward(ctx, grad_scratch):
# def _runge_kutta_step(func, y0, f0, t0, dt, t1, tableau):
# def rk4_step_func(func, t0, dt, t1, y0, f0=None, perturb=False):
# def rk4_alt_step_func(func, t0, dt, t1, y0, f0=None, perturb=False):
#     def __init__(self, func, y0, rtol, atol,
#                  first_step=None,
#                  step_t=None,
#                  jump_t=None,
#                  safety=0.9,
#                  ifactor=10.0,
#                  dfactor=0.2,
#                  max_num_steps=2 ** 31 - 1,
#                  dtype=torch.float64,
#                  **kwargs):
#     def _before_integrate(self, t):
#     def _advance(self, next_t):
#     def _advance_until_event(self, event_fn):
#     def _adaptive_step(self, rk_state):
#     def _interp_fit(self, y0, y1, k, dt):
# def _sort_tvals(tvals, t0):


# Path: torchdiffeq/_impl/dopri5.py
import torch
from .rk_common import _ButcherTableau, RKAdaptiveStepsizeODESolver



_DORMAND_PRINCE_SHAMPINE_TABLEAU = _ButcherTableau(
    alpha=torch.tensor([1 / 5, 3 / 10, 4 / 5, 8 / 9, 1., 1.], dtype=torch.float64),
    beta=[
        torch.tensor([1 / 5], dtype=torch.float64),
        torch.tensor([3 / 40, 9 / 40], dtype=torch.float64),
        torch.tensor([44 / 45, -56 / 15, 32 / 9], dtype=torch.float64),
        torch.tensor([19372 / 6561, -25360 / 2187, 64448 / 6561, -212 / 729], dtype=torch.float64),
        torch.tensor([9017 / 3168, -355 / 33, 46732 / 5247, 49 / 176, -5103 / 18656], dtype=torch.float64),
        torch.tensor([35 / 384, 0, 500 / 1113, 125 / 192, -2187 / 6784, 11 / 84], dtype=torch.float64),
    ],
    c_sol=torch.tensor([35 / 384, 0, 500 / 1113, 125 / 192, -2187 / 6784, 11 / 84, 0], dtype=torch.float64),
    c_error=torch.tensor([
        35 / 384 - 1951 / 21600,
        0,
        500 / 1113 - 22642 / 50085,
        125 / 192 - 451 / 720,
        -2187 / 6784 - -12231 / 42400,
        11 / 84 - 649 / 6300,
        -1. / 60.,
    ], dtype=torch.float64),
)

DPS_C_MID = torch.tensor([

    6025192743 / 30085553152 / 2, 0, 51252292925 / 65400821598 / 2, -2691868925 / 45128329728 / 2,