pangolin.interface.Interface.overload#
- Interface.overload(*, broadcasting=None)[source]#
Temporarily change this interface’s configuration in the current context.
Unspecified options retain their current values. Overrides may be nested, and the previous configuration is restored on exit, including when an exception occurs. The base configuration and other interfaces are unchanged.
Functions read the effective configuration when called. Saved function references and indexing proxies therefore observe the active override. RVs created inside the context keep this interface, so their syntax uses its restored configuration after the context ends.
- Parameters:
broadcasting (Literal['off', 'simple', 'rank', 'numpy'] | None) – Temporary scalar and vectorized-index broadcasting policy. Omit it or pass
Noneto leave the current policy unchanged.- Raises:
TypeError – If an unknown option is supplied or broadcasting is neither a string nor
None.ValueError – If broadcasting is not a supported mode.
- Return type:
Iterator[None]
Notes
Overrides are context-local, not global mutations. Async tasks inherit the active context when created; subsequent overrides and restoration in one task do not change another task’s configuration. The same context-local mechanism isolates overrides in separate threads.
Examples
>>> from pangolin.interface import Interface >>> pi = Interface(broadcasting="off") >>> normal = pi.normal >>> with pi.overload(broadcasting="simple"): ... y = normal([0, 1], 1) ... print(y.shape) (2,) >>> normal([0, 1], 1) Traceback (most recent call last): ... ValueError: Can't broadcast shapes (2,) and () with broadcasting=OFF >>> y.interface is pi True