pipeline computing
Project description
uo
pipeline computing
To install: pip install uo
Overview
The uo package provides a framework for creating and managing computation pipelines. This functionality is particularly useful for scenarios where a sequence of data transformations and computations need to be applied in a specific order. The core of the package is the ComputationPipeline class which allows users to compose a pipeline of callable objects (functions, methods, etc.) that are executed sequentially.
Features
- Composable Pipelines: Easily compose multiple callable objects into a single callable pipeline.
- Flexible Step Definition: Each step in the pipeline can be defined with a callable and its associated method to call, allowing for great flexibility in how operations are performed.
- Partial Argument Binding: Steps can include partial argument binding using the
partialfunction from Python'sfunctools, providing more control over how functions are called within the pipeline.
ComputationPipeline Class
The ComputationPipeline class is designed to chain a sequence of operations together. Each step in the pipeline is defined by a tuple that specifies the name of the step, the object (function or class instance), and optionally, the method name to call on the object (default is __call__). The pipeline can be executed by calling the instance with the appropriate arguments.
Constructor
def __init__(self, steps):
"""
Initializes a new instance of the ComputationPipeline.
:param steps: A list of tuples. Each tuple should contain:
- func_name: A string representing the name of the function or method.
- obj: The function or object that will be called.
- call_method (optional): The method name to call on the object. If not provided, '__call__' is assumed.
"""
Usage Example
# Define a simple pipeline with two steps
f = ComputationPipeline(steps=[
('increment', lambda x: x + 2),
('multiply', lambda x: x * 10)
])
# Execute the pipeline
result = f(1) # (1 + 2) * 10 = 30
print(result) # Output: 30
Advanced Usage
You can also specify methods of objects or use partial functions to pre-specify some arguments:
from functools import partial
# Assuming an object with methods that take additional parameters
class MathOperations:
def multiply(self, x, factor):
return x * factor
def add(self, x, increment):
return x + increment
math_ops = MathOperations()
# Create a pipeline using methods from the MathOperations class
g = ComputationPipeline(steps=[
('add', math_ops, 'add'),
('multiply', partial(math_ops.multiply, factor=5))
])
# Execute the pipeline
result = g(3) # (3 + 0) * 5 = 15
print(result) # Output: 15
This package is ideal for scenarios where data needs to be processed in distinct, sequential steps, such as data preprocessing, feature engineering, or even in a machine learning inference pipeline.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uo-0.0.6.tar.gz.
File metadata
- Download URL: uo-0.0.6.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dfd584619454bcef5df0c3b09a6ad21fc3d082efd5b2c186131aeeb20263c61
|
|
| MD5 |
a986d62d32428bb7b63cce4fd0566b2c
|
|
| BLAKE2b-256 |
f605082690bb7f2e63c305760be31b450f4abdc3686e7bf1fd49a8628d7ccd91
|
File details
Details for the file uo-0.0.6-py3-none-any.whl.
File metadata
- Download URL: uo-0.0.6-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
492b3fd273a35dc9bab4678bf822ca9be9d5e9b6185f9923ba5a8d43a7bb76a2
|
|
| MD5 |
3688077228d764895aec79de6daa12eb
|
|
| BLAKE2b-256 |
250d57dead047e81995f594169f81fb0a1c37c3891a2e6401aed2ed6136a167f
|