(func, t0, y0, order, rtol, atol, norm, f0=None)
return torch.min(100 * h0, h1).to(t_dtype)
Empirically select a good initial step.

    The algorithm is described in [1]_.

    References
    ----------
    .. [1] E. Hairer, S. P. Norsett G. Wanner, "Solving Ordinary Differential
           Equations I: Nonstiff Problems", Sec. II.4, 2nd edition.
Empirically select a good initial step.
Empirically select a good initial step .
def _select_initial_step(func, t0, y0, order, rtol, atol, norm, f0=None):
    """Empirically select a good initial step.

    The algorithm is described in [1]_.

    References
    ----------
    .. [1] E. Hairer, S. P. Norsett G. Wanner, "Solving Ordinary Differential
           Equations I: Nonstiff Problems", Sec. II.4, 2nd edition.
    """

    dtype = y0.dtype
    device = y0.device
    t_dtype = t0.dtype
    t0 = t0.to(dtype)

    if f0 is None:
        f0 = func(t0, y0)

    scale = atol + torch.abs(y0) * rtol

    d0 = norm(y0 / scale)
    d1 = norm(f0 / scale)

    if d0 < 1e-5 or d1 < 1e-5:
        h0 = torch.tensor(1e-6, dtype=dtype, device=device)
    else:
        h0 = 0.01 * d0 / d1

    y1 = y0 + h0 * f0
    f1 = func(t0 + h0, y1)

    d2 = norm((f1 - f0) / scale) / h0

    if d1 <= 1e-15 and d2 <= 1e-15:
        h1 = torch.max(torch.tensor(1e-6, dtype=dtype, device=device), h0 * 1e-3)
    else:
        h1 = (0.01 / max(d1, d2)) ** (1. / float(order + 1))

    return torch.min(100 * h0, h1).to(t_dtype)
def _select_initial_step ( func , t0 , y0 , order , rtol , atol , norm , f0 = None ) : dtype = y0 . dtype device = y0 . device t_dtype = t0 . dtype t0 = t0 . to ( dtype ) if f0 is None : f0 = func ( t0 , y0 ) scale = atol + torch . abs ( y0 ) * rtol d0 = norm ( y0 / scale ) d1 = norm ( f0 / scale ) if d0 < 1e-5 or d1 < 1e-5 : h0 = torch . tensor ( 1e-6 , dtype = dtype , device = device ) else : h0 = 0.01 * d0 / d1 y1 = y0 + h0 * f0 f1 = func ( t0 + h0 , y1 ) d2 = norm ( ( f1 - f0 ) / scale ) / h0 if d1 <= 1e-15 and d2 <= 1e-15 : h1 = torch . max ( torch . tensor ( 1e-6 , dtype = dtype , device = device ) , h0 * 1e-3 ) else : h1 = ( 0.01 / max ( d1 , d2 ) ) ** ( 1. / float ( order + 1 ) ) return torch . min ( 100 * h0 , h1 ) . to ( t_dtype )