.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here ` to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_examples_how-to-use-pipelines_add_additional_tasks.py:
Add additional tasks to your pipelines
======================================
.. code-block:: default
import numpy as np
import imagepypelines as ip
@ip.blockify()
def add1(a, b):
return a+1, b+1
@ip.blockify()
def subtract1(a, b):
return a-1, b-1
@ip.blockify()
def average(x1, x2):
return (x1 + x2) / 2
Our Example Pipeline
--------------------
don't pay too much attention to this, we're just creating a random meaningless
pipeline
.. code-block:: default
pipeline = ip.Pipeline({
'a': ip.Input(0),
'b': ip.Input(1),
('a_plus_1','b_plus_1') : (add1, 'a', 'b'),
('a_minus_1','b_minus_1') : (subtract1, 'a', 'b'),
}
)
Just call the pipeline's `update` function
------------------------------------------
.. code-block:: default
more_tasks = {
'average_a': (average,'a_plus_1','a_minus_1'),
'average_b': (average,'b_plus_1','b_minus_1'),
}
pipeline.update(more_tasks)
Let's process some data!
------------------------
.. code-block:: default
# Let's create the inputs
a = [10]
b = [-10]
# process
processed = pipeline.process(a,b)
# and check
assert processed['average_a'][0] == a[0]
assert processed['average_b'][0] == b[0]
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 0.009 seconds)
.. _sphx_glr_download_examples_how-to-use-pipelines_add_additional_tasks.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: add_additional_tasks.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: add_additional_tasks.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_