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).
- property acquired: bool¶
Whether the cown is currently acquired.
- release()¶
Releases the cown.
- property value: T¶
Return the current stored value.
- bocpy.wait(timeout=None)¶
Block until all behaviors complete, with optional timeout.
- @bocpy.when¶
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(rows, columns, values=None)¶
A dense 2-D matrix of double-precision floats.
- T¶
Return a new matrix that is the transpose of this one.
- __init__(*args, **kwargs)¶
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.
- abs()¶
Element-wise absolute value.
- Return type:
Matrix
- acquired¶
Whether the matrix is currently acquired.
- classmethod allclose(lhs, rhs, /, rtol=1e-05, atol=1e-08, equal_nan=False)¶
Check element-wise equality within tolerance.
- ceil()¶
Element-wise ceiling.
- Return type:
Matrix
- clip(min_or_maxval, /, maxval=None)¶
Clip elements to a range.
- Return type:
Matrix
- columns¶
The number of columns in the matrix.
- classmethod concat(values, /, axis=0)¶
Concatenate matrices along an axis.
- Return type:
Matrix
- copy()¶
Return a deep copy.
- Return type:
Matrix
- floor()¶
Element-wise floor.
- Return type:
Matrix
- magnitude(axis=None)¶
Euclidean magnitude.
- Return type:
Union[float, Matrix]
- max(axis=None)¶
Maximum of elements.
- Return type:
Union[float, Matrix]
- mean(axis=None)¶
Mean of elements.
- Return type:
Union[float, Matrix]
- min(axis=None)¶
Minimum of elements.
- Return type:
Union[float, Matrix]
- negate()¶
Element-wise negation.
- Return type:
Matrix
- classmethod normal(mean=0.0, stddev=1.0, /, size=None)¶
Sample from a normal distribution.
- Return type:
Union[float, Matrix]
- classmethod ones(size, /)¶
Create a matrix of ones.
- round()¶
Element-wise rounding.
- Return type:
Matrix
- rows¶
The number of rows in the matrix.
- select(indices, /, axis=0)¶
Select rows or columns by index.
- shape¶
The
(rows, columns)shape of the matrix.
- sum(axis=None)¶
Sum of elements.
- Return type:
Union[float, Matrix]
- transpose()¶
Return a transposed copy.
- Return type:
Matrix
- transpose_in_place()¶
Transpose in place.
- classmethod uniform(minval=0.0, maxval=1.0, /, size=None)¶
Sample from a uniform distribution.
- Return type:
Union[float, Matrix]
- classmethod vector(values, /, as_column=False)¶
Create a vector from a sequence.
- Return type:
Matrix
- w¶
Set the fourth vector component.
- x¶
Set the first vector component.
- y¶
Set the second vector component.
- z¶
Set the third vector component.
- classmethod zeros(size, /)¶
Create a zero-filled matrix.
Messaging¶
- bocpy.send(tag, contents, /)¶
Sends a message.
- bocpy.receive(tags, /, timeout=-1, after=None)¶
Receives a message.
- Return type:
Optional[Any]
- bocpy.set_tags(tags, /)¶
Assigns tags to message queues.
- bocpy.drain(tags, /)¶
Drains all messages for the given tags.
- Return type:
None