Skip to content
Snippets Groups Projects
core_operations.py 1.88 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.basic_operation import BasicOperation
    
    
    class Input(Operation):
    
    	"""Input operation.
    
    	TODO: More info.
    	"""
    
    
    class Constant(BasicOperation):
    
    	"""Constant value operation.
    
    	TODO: More info.
    	"""
    
    
    		"""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")]
    
    
    	def type_name(self) -> GraphIDType:
    
    class Addition(BasicOperation):
    
    	"""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]]
    
    
    	def type_name(self) -> GraphIDType:
    
    
    class ConstantMultiplication(BasicOperation):
    
    	"""Unary constant multiplication operation.
    
    	TODO: More info.
    	"""
    
    
    		"""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")]
    
    
    	def type_name(self) -> GraphIDType:
    
    # TODO: More operations.