examples_element_wrapper module¶
This module contains examples of the ‘element’ wrapper. A function that takes a single element of an input stream and generates a single element of an output stream is an example of a function that is wrapped by the ‘element’ wrapper to create a function on streams.
The module has the following parts: (1) op or simple operator:
single input, single output
- sink:
- single input, no outputs
- source:
- no input, multiple outputs
- split:
- single input, multiple output
- merge:
- multiple input, single output
- general case:
- multiple input, multiple output
All of the first 5 cases are specializations of the general case; however, the syntactic sugar they provide can be helpful.
For each of the above cases we first consider agents that are stateless and then consider agents with state.
-
examples_element_wrapper.
average
(v, state)[source]¶ Parameters: v : number
The next element of the input stream of the agent.
state: (n, cumulative)
The state of the agent where n : number
The value of the next element in the agent’s input stream.
- cumulative : number
The sum of the values that the agent has received on its input stream.
Returns: (mean, state)
mean : floating point number
The average of the values received so far by the agent
state : (n, cumulative)
The new state of the agent.
-
examples_element_wrapper.
cumulative_sum
(v, cumulative)[source]¶ Parameters: v : number
The next element of the input stream of the agent.
cumulative: number
The state of the agent. The state is the sum of all the values received on the agent’s input stream.
Returns: (cumulative, cumulative)
cumulative : number
The state after the transition, i.e., the sum of values received on the agent’s input stream including the value received in this transition.
-
examples_element_wrapper.
file_to_stream
(filename, output_stream, time_period=0)[source]¶ Parameters: filename: str
output_stream: Stream
time_period: int or float, nonnegative