API¶
This part of the documentation covers all the interfaces of bocpy.
Behaviors¶
- class bocpy.Cown(value)¶
Lightweight wrapper around the underlying cown capsule.
- acquire()¶
Acquires the cown (required for reading and writing).
- release()¶
Releases the cown.
- bocpy.wait(timeout=None)¶
Block until all behaviors complete, with optional timeout.
- @bocpy.when(*cowns)¶
Decorator to schedule a function as a behavior using given cowns.
This decorator takes a list of zero or more cown objects, which will be passed in the order in which they were provided to the decorated function. The function itself is extracted and run as a behavior once all the cowns are available (i.e., not acquired by other behaviors). Behaviors are scheduled such that deadlock will not occur.
The function itself will be replaced by a Cown which will hold the result of executing the behavior. This Cown can be used for further coordination.
- bocpy.start(worker_count=None, export_dir=None, module=None)¶
Start the behavior scheduler and worker pool.
- Parameters:
worker_count (
Optional[int]) – The number of worker interpreters to start. If None, defaults to the number of available cores minus one.export_dir (
Optional[str]) – The directory to which the target module will be exported for worker import. If None, a temporary directory will be created and removed on shutdown.module (
Optional[tuple[str,str]]) – A tuple of the target module name and file path to export for worker import. If None, the caller’s module will be used.
Math¶
- class bocpy.Matrix¶
A dense 2-D matrix of double-precision floats backed by a C implementation.
Supports element-wise arithmetic (
+,-,*,/), matrix multiplication (@), in-place variants (+=,-=,*=,/=), unary-andabs(), and subscript indexing with integers or slices.- __init__(rows: int, columns: int, values: int | float | Sequence[int | float] | None = None)¶
Create a new rows x columns matrix.
- Parameters:
rows – Number of rows (must be ≥ 1).
columns – Number of columns (must be ≥ 1).
values – Initial values. May be
None(zero-filled), a scalar (broadcast to every element), or a flat sequence of rows x columns numbers in row-major order.