-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05c6fa9
commit 4baac10
Showing
5 changed files
with
219 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright (c) 2022-2023, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import logging | ||
from typing import Any | ||
from typing import Callable | ||
from typing import Generator | ||
from typing import Type | ||
|
||
import mrc | ||
|
||
from morpheus.config import Config | ||
from morpheus.pipeline.single_output_source import SingleOutputSource | ||
from morpheus.pipeline.stage_schema import StageSchema | ||
|
||
logger = logging.getLogger(f"morpheus.{__name__}") | ||
|
||
|
||
class InMemoryDataGenStage(SingleOutputSource): | ||
""" | ||
Source stage that generates data in-memory using a provided generator function. | ||
Parameters | ||
---------- | ||
c : `morpheus.config.Config` | ||
Pipeline configuration instance. | ||
generator : Callable[[], Generator[Any, None, None]] | ||
A generator function that yields data to be processed by the pipeline. | ||
output_data_type : Type | ||
The data type of the objects that the generator yields. | ||
""" | ||
|
||
def __init__(self, c: Config, generator: Callable[[], Generator[Any, None, None]], | ||
output_data_type: Type = Any): | ||
super().__init__(c) | ||
self._generator = generator | ||
self._output_data_type = output_data_type | ||
|
||
@property | ||
def name(self) -> str: | ||
return "in-memory-data-gen" | ||
|
||
def compute_schema(self, schema: StageSchema): | ||
# Set the output schema based on the OutputDataType | ||
schema.output_schema.set_type(self._output_data_type) | ||
|
||
def supports_cpp_node(self): | ||
return False | ||
|
||
def _generate_data(self) -> Generator[Any, None, None]: | ||
yield from self._generator() | ||
|
||
def _build_source(self, builder: mrc.Builder) -> mrc.SegmentObject: | ||
return builder.make_source(self.unique_name, self._generate_data()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters