Skip to content

Python Interp API

Periodic table lookup with interpolation, backed by interp_table_core.c. Evaluates a complex128 table at arbitrary (fractional) points, wrapping the index modulo the table length so the table is treated as one period of a repeating waveform. Purely a function of (table, method, point) — no running state.

Source: src/doppler/interp/__init__.py


How it works

The table holds one period of n complex samples. A query point selects a sample by index; fractional indices are resolved by the configured method:

  • floortable[floor(point)], no interpolation.
  • nearesttable[round(point)].
  • linear — linear blend of the two bracketing samples.

Indices wrap modulo n, so point may run past the end of the table and land back at the start — the table is one period of a periodic signal.


Examples

Linear interpolation over a ramp

from doppler.interp import InterpolatedTable
import numpy as np

ramp = InterpolatedTable(
    np.array([0.0, 1.0, 2.0], dtype=np.complex128))
ramp.execute(np.array([0.5, 1.1]))   # array([0.5+0.j, 1.1+0.j])

Nearest-sample lookup

from doppler.interp import InterpolatedTable
import numpy as np

t = InterpolatedTable(
    np.array([0.0, 1.0, 2.0], dtype=np.complex128), method="nearest")
t.n   # 3

InterpolatedTable

Create an InterpolatedTable instance.

Parameters:

Name Type Description Default
table NDArray[complex128]

Complex table, one period, length table_len.

required
method Literal['floor', 'nearest', 'linear']

0 = floor, 1 = nearest, 2 = linear.

"linear"

Examples:

>>> from doppler.interp import InterpolatedTable
>>> import numpy as np
>>> t = InterpolatedTable(
...     np.array([0.0, 1.0, 2.0], dtype=np.complex128),
...     method="linear")
>>> t.n
3

n property

n: int

Table length (one period), read-only.

reset

reset() -> None

No-op: InterpolatedTable is purely a function of (table, method, point) with no running state to reset.

Present only to satisfy the common object interface; each execute() depends solely on its inputs, so a call before or after reset() returns identical samples.

Examples:

>>> import numpy as np
>>> from doppler.interp import InterpolatedTable
>>> table = InterpolatedTable(
...     np.array([0.0, 1.0, 2.0], dtype=np.complex128))
>>> table.reset()                     # no running state to clear
>>> table.execute(np.array([1.5]))   # unchanged: (table, point)
array([1.5+0.j])

execute

execute(
    x: NDArray[float64],
    out: NDArray[complex128] | None = None,
) -> NDArray[np.complex128]

Evaluate the table at each of n_in points via periodic interpolation.

Each point is wrapped mod the table length (any real value, any sign) and evaluated per the configured method:

  • floor: nearest index below (table[floor(point) mod n])
  • nearest: closer of the floor/next index (0.5 ties pick floor)
  • linear: linear fit across the two bracketing indices

Parameters:

Name Type Description Default
x NDArray[float64]

Input.

required

Returns:

Type Description
NDArray[complex128]

min(n_in, max_out) interpolated points.

Examples:

>>> from doppler.interp import InterpolatedTable
>>> import numpy as np
>>> ramp = InterpolatedTable(
...     np.array([0.0, 1.0, 2.0], dtype=np.complex128))
>>> ramp.execute(np.array([0.5, 1.1]))
array([0.5+0.j, 1.1+0.j])

execute_max_out

execute_max_out() -> int

No fixed cap -- execute()'s output is always sized to exactly match its own input length, so an out= buffer only ever needs to be at least that many elements (never a larger, unrelated minimum).

Returns:

Type Description
int

Output.

destroy

destroy() -> None

Release the underlying C resources immediately.

Ordinarily unnecessary: the resources are freed when the object is garbage-collected. Call this to release them at a definite point instead, or use the object as a context manager, which calls it on exit.

Idempotent: calling it again on an already-released object does nothing. Every other method raises RuntimeError once it has run.

__enter__

__enter__() -> InterpolatedTable

Enter a context manager, returning this object.

Lets a InterpolatedTable be used in a with statement so its C resources are released deterministically on exit rather than at collection time.

Returns:

Type Description
InterpolatedTable

This same object, not a copy.

__exit__

__exit__(
    exc_type: object | None = ...,
    exc: object | None = ...,
    tb: object | None = ...,
) -> None

Exit a context manager, releasing the InterpolatedTable.

Equivalent to calling destroy(). Returns None, so an exception raised inside the with body propagates normally; this never suppresses one.

Parameters:

Name Type Description Default
exc_type object | None

Exception class, or None. Ignored.

...
exc object | None

Exception instance, or None. Ignored.

...
tb object | None

Traceback object, or None. Ignored.

...