blob: b7834d179316b0cccc6b6a310892e06daef1d7c9 [file] [log] [blame]
from typing import (TypeVar, Optional, List, Set)
from pywayang.platforms.python.channels import ChannelDescriptor
class WyOperator:
inputSlot : List[TypeVar]
inputChannel : ChannelDescriptor
inputs : int
outputSlot : List[TypeVar]
OutputChannel: ChannelDescriptor
outputs: int
def __init__(self,
name: str,
input: Optional[TypeVar] = None,
output: Optional[TypeVar] = None,
input_lenght: Optional[int] = 1,
output_lenght: Optional[int] = 1
):
self.name = name
self.inputSlot = input
self.inputs = input_lenght
self.outputSlot = output
self.outputs = output_lenght
def validateInputs(self, vec):
if len(vec) != self.inputs:
raise Exception(
"the inputs channel contains {} elements and need to have {}".format(
len(vec),
self.inputs
)
)
def validateOutputs(self, vec):
if len(vec) != self.outputs:
raise Exception(
"the output channel contains {} elements and need to have {}".format(
len(vec),
self.inputs
)
)
def validateChannels(self, input, output):
self.validateInputs(input)
self.validateOutputs(output)
def getInputChannelDescriptors(self) -> Set[ChannelDescriptor]:
pass
def getOutputChannelDescriptors(self) -> Set[ChannelDescriptor]:
pass
def __str__(self):
return "BaseOperator: \n\t- name: {}\n\t- inputs: {} {}\n\t- outputs: {} {} \n".format(
str(self.name),
str(self.inputs),
str(self.inputSlot),
str(self.outputs),
str(self.outputSlot),
)
def __repr__(self):
return self.__str__()