Skip to content
Snippets Groups Projects
core_operations.py 2.09 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):
    
    	"""Input operation.
    
    	TODO: More info.
    	"""
    
    
    	@property
    	def type_name(self) -> TypeName:
    		return "in"
    
    	"""Constant value operation.
    
    	TODO: More info.
    	"""
    
    
    	def __init__(self, value: Number, **kwds):
    
    		"""Construct a Constant."""
    
    Kevin Scott's avatar
    Kevin Scott committed
    		self._output_ports = [OutputPort(1, self)] # TODO: Generate appropriate ID for ports.
    
    		self._parameters["value"] = value
    
    	def evaluate(self, inputs: list) -> list:
    		return [self.param("value")]
    
    
    	"""Binary addition operation.
    
    	TODO: More info.
    	"""
    
    
    		"""Construct an Addition."""
    
    Kevin Scott's avatar
    Kevin Scott committed
    		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.
    
    
    	def evaluate(self, inputs: list) -> list:
    		return [inputs[0] + inputs[1]]
    
    
    class ConstantMultiplication(AbstractOperation):
    
    	"""Unary constant multiplication operation.
    
    	TODO: More info.
    	"""
    
    
    	def __init__(self, coefficient: Number, **kwds):
    
    		"""Construct a ConstantMultiplication."""
    
    Kevin Scott's avatar
    Kevin Scott committed
    		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")]