Skip to content
Snippets Groups Projects
core_operations.py 2.28 KiB
Newer Older
  • Learn to ignore specific revisions
  • """@package docstring
    
    B-ASIC Core Operations Module.
    TODO: More info.
    """
    
    
    from numbers import Number
    
    
    from b_asic.port import InputPort, OutputPort
    
    from b_asic.abstract_operation import AbstractOperation
    from b_asic.abstract_graph_component import AbstractGraphComponent
    from b_asic.graph_component import Name, TypeName
    
    class Input(Operation, AbstractGraphComponent):
    
    Jacob Wahlman's avatar
    Jacob Wahlman committed
        """Input operation.
        TODO: More info.
        """
    
    Jacob Wahlman's avatar
    Jacob Wahlman committed
        # TODO: Implement all functions.
    
    Jacob Wahlman's avatar
    Jacob Wahlman committed
        @property
        def type_name(self) -> TypeName:
            return "in"
    
    Jacob Wahlman's avatar
    Jacob Wahlman committed
        """Constant value operation.
        TODO: More info.
        """
    
    Jacob Wahlman's avatar
    Jacob Wahlman committed
        def __init__(self, value: Number, **kwds):
            """Construct a Constant."""
            super().__init__(**kwds)
            self._output_ports = [OutputPort(1, self)] # TODO: Generate appropriate ID for ports.
            self._parameters["value"] = value
    
    Jacob Wahlman's avatar
    Jacob Wahlman committed
        def evaluate(self, inputs: list) -> list:
            return [self.param("value")]
    
    Jacob Wahlman's avatar
    Jacob Wahlman committed
        @property
        def type_name(self) -> TypeName:
            return "const"
    
    Jacob Wahlman's avatar
    Jacob Wahlman committed
        """Binary addition operation.
        TODO: More info.
        """
    
    Jacob Wahlman's avatar
    Jacob Wahlman committed
        def __init__(self, **kwds):
            """Construct an Addition."""
            super().__init__(**kwds)
            self._input_ports = [InputPort(1, self), InputPort(1, self)] # TODO: Generate appropriate ID for ports.
            self._output_ports = [OutputPort(1, self)] # TODO: Generate appropriate ID for ports.
    
    Jacob Wahlman's avatar
    Jacob Wahlman committed
        def evaluate(self, inputs: list) -> list:
            return [inputs[0] + inputs[1]]
    
    Jacob Wahlman's avatar
    Jacob Wahlman committed
        @property
        def type_name(self) -> TypeName:
            return "add"
    
    class ConstantMultiplication(AbstractOperation):
    
    Jacob Wahlman's avatar
    Jacob Wahlman committed
        """Unary constant multiplication operation.
        TODO: More info.
        """
    
        def __init__(self, coefficient: Number, **kwds):
            """Construct a ConstantMultiplication."""
            super().__init__(**kwds)
            self._input_ports = [InputPort(1), self] # TODO: Generate appropriate ID for ports.
            self._output_ports = [OutputPort(1, self)] # TODO: Generate appropriate ID for ports.
            self._parameters["coefficient"] = coefficient
    
        def evaluate(self, inputs: list) -> list:
            return [inputs[0] * self.param("coefficient")]
    
        @property
        def type_name(self) -> TypeName:
            return "const_mul"