redex.function module

Functions are building blocks for algorithms.

class redex.function.FineCallable(signature: redex.function.Signature)[source]

Bases: object

The callable object with a signature.

signature: redex.function.Signature

a signature of the function.

redex.function.Fn

The function.

alias of Callable[[…], Any]

redex.function.FnIter

A single function or sequence of functions.

alias of Union[Callable[[…], Any], Iterable[Callable[[…], Any]]]

class redex.function.Signature(n_in: int, n_out: int, start_index: int = 0, in_shape: tuple[typing.Any, ...] = ())[source]

Bases: object

The function signature.

The signature describes properties essential for a function to work on the stack. These properties either inferred from function type annotation or set explicitly.

in_shape: tuple[typing.Any, ...] = ()

the shape of inputs with () meaning the function doesn’t have any input arguments.

property index_bounds: tuple[int, int]

index bounds on the stack for inputs.

n_in: int

the number of inputs expected by the function.

n_out: int

the number of outputs of the function.

start_index: int = 0

the index on a stack for the first input.

redex.function.infer_name(func: Callable[[...], Any]) str[source]

Infers a name of the function.

Parameters

func – a function.

Returns

a name of the function or callable object.

redex.function.infer_signature(func: Callable[[...], Any]) redex.function.Signature[source]

Infers a signature of the function.

Parameters

func – a function.

Returns

the function signature.

Raises

ValueError – if the annotation include variadic tuples. Variadic tuples nested in other then tuple annotations (e.g. Sequence(tuple[Any, …])) are fine.