odeint_dense
→callableodeint_dense(func: Callable[..., object], y0: State, t0: float, t1: float, rtol: float = 1e-07, atol: float = 1e-09, method: str | ButcherTableau | None = None, options: dict[str, object] | None = None)Solve once across an interval and return a continuous solution.
Where odeint wants the output times up front, this integrates
[t0, t1] a single time and hands back a function of t. Every
step's interpolating polynomial is kept, so any later query costs a
binary search and one polynomial evaluation — no re-integration, and no
commitment to a grid before you know which times you need.
Parameters
funccallablef(t, y) -> dy/dt. Receives the stage time as a
0-D tensor matching y0 in dtype and device, and must return a
tensor with the same shape and device as y0.y0Tensort0. Any shape; must have a floating dtype.t0floatt1 < t0 integrates backwards.t1floatt1 < t0 integrates backwards.rtolfloat= 1e-7atolfloat= 1e-9None selects "dopri5". See odeint for the full list.optionsdict or None= Noneodeint takes them.Returns
callabledense(t) -> Tensor, accepting a float or a 0-D tensor and
returning the state there. Raises ValueError for a time
outside [t0, t1].
Raises
ValueErrort0 and t1 are equal or non-finite, if y0 has a
non-floating dtype, if method names no registered method, if
options holds a key the method does not accept, or if func
returns a tensor whose shape or device differs from y0.TypeErrormethod is neither a string nor a ButcherTableau, or
if func returns something other than a tensor.RuntimeErrormax_num_steps or its step size
collapses.Notes
Memory grows with the number of accepted steps: each keeps a handful of
tensors the size of the state. A long solve over a large state is
therefore much heavier than odeint with return_trajectory=False.
A fixed-step method interpolates with whatever options["interp"]
says, and without step_size its grid is the single interval
[t0, t1] — usually far too coarse, so pass one.
Examples
>>> import lucid, lucid.diffeq as diffeq
>>> y0 = lucid.tensor([1.0], dtype=lucid.float64)
>>> dense = diffeq.odeint_dense(lambda t, y: -y, y0, 0.0, 1.0)
>>> abs(float(dense(0.5).item()) - 0.6065306597) < 1e-7
TrueSee Also
- lucid.diffeq.odeint—Same solvers, output times fixed up front.