Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_Transform and Transform Pipeline #10

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions sslt/transforms/Transform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

from typing import Any


class _Transform():
"""
This class represents a transform.
"""

def __call__(self) -> Any:
"""
Placeholder method for calling the transform.
This method should be overridden in subclasses.
"""
raise NotImplementedError()


class TransformPipeline(_Transform):
"""
A pipeline of transforms that can be applied to data sequentially.
"""

def __init__(self, *transforms: _Transform) -> None:
self.transforms = transforms

def __call__(self, x: Any) -> Any:
"""
Apply the transforms in the pipeline to the input data.

Args:
x (Any): The input data to be transformed.

Returns:
Any: The transformed data.
"""
for transform in self.transforms:
x = transform(x)
return x