Newer
Older
B-ASIC Core Operations Module.
TODO: More info.
"""

Jacob Wahlman
committed
from b_asic.operation import Operation
from b_asic.basic_operation import BasicOperation

Jacob Wahlman
committed
from b_asic.graph_id import GraphIDType

Jacob Wahlman
committed
# TODO: Implement all functions.

Jacob Wahlman
committed
def __init__(self, value: Number):

Jacob Wahlman
committed
super().__init__()
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:

Jacob Wahlman
committed
return "const"

Jacob Wahlman
committed
def __init__(self):

Jacob Wahlman
committed
super().__init__()
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:

Jacob Wahlman
committed
return "add"
class ConstantMultiplication(BasicOperation):
"""Unary constant multiplication operation.

Jacob Wahlman
committed
def __init__(self, coefficient: Number):
"""Construct a ConstantMultiplication."""

Jacob Wahlman
committed
super().__init__()
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:

Jacob Wahlman
committed
return "const_mul"
# TODO: More operations.