corelay.processor.flow

Basic flow operation Processors, such as Shaper, Sequential and Parallel

Classes

GroupProcessor

Abstract class for groups of Processors.

Parallel

Processor group calling its children in Parallel.

Sequential

Processor group calling its children in Sequence, feeding the input the first child, and then each output to the next child.

Shaper

Extracts and/ or copies by indices.

class corelay.processor.flow.GroupProcessor(*args, **kwargs)[source]

Bases: Processor

Abstract class for groups of Processors.

children

Child Processors for this group.

Type:

iterable of Processor

class corelay.processor.flow.Parallel(*args, **kwargs)[source]

Bases: GroupProcessor

Processor group calling its children in Parallel.

Examples

>>> Parallel(children=[FunctionProcessor(function=lambda x: x**n) for n in (1, 2, 3, 4)])((2, 2, 2, 2))
[2, 4, 8, 16]
>>> Parallel(children=[FunctionProcessor(function=lambda x: x**n) for n in (1, 2, 3, 4)])(2)
[2, 4, 8, 16]
function(data)[source]

Sequentially get one element from data per child, call all children with this element as input in parallel, and accumulate the outputs.

Parameters:

data (iterable or object) – Iterable from which to pass the elements to the children. If data is not an Iterable, it will be copied as many times as there are children.

Raises:

TypeError – If the number of children and number of data elements mismatch.

class corelay.processor.flow.Sequential(*args, **kwargs)[source]

Bases: GroupProcessor

Processor group calling its children in Sequence, feeding the input the first child, and then each output to the next child.

Examples

>>> Sequential(children=[FunctionProcessor(function=lambda x: c + x) for c in 'abcd'])('=')
'dcba='
function(data)[source]

Feed data forward sequentially, passing each child’s output to the next child.

Parameters:

data (object) – Input data to pass to the first child.

class corelay.processor.flow.Shaper(*args, **kwargs)[source]

Bases: Processor

Extracts and/ or copies by indices.

indices

Iterable of indices to copy/ extract. The resuling output will be a tuple with the same member shape. Each index may be passed an arbitrary amount of times. Outer tuples allow ints and tuples, inner tuples only allow ints.

Type:

iterable of (int or iterable of int)

Examples

>>> Shaper(indices=(0, 1, (0, 1, 2)))(['a', 'b', 'c'])
('a', 'b', ('a', 'b', 'c'))
function(data)[source]

Extracts and/ or copies indices of data.

Parameters:

data (object) – Object from which to extract/ copy elements. If not an iterable, index 0 corresponds to the object itself.

Returns:

The extracted/ copied indices of data.

Return type:

tuple of object

Raises:

TypeError – If an invalid index was accessed for data.