Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
B-ASIC Core Operations Module.
TODO: More info.
"""
from b_asic.operation import OperationId, Operation, BasicOperation
from numbers import Number
from typing import final
class Input(Operation):
"""
Input operation.
TODO: More info.
"""
# TODO: Implement.
pass
class Constant(BasicOperation):
"""
Constant value operation.
TODO: More info.
"""
def __init__(self, identifier: OperationId, value: Number):
"""
Construct a Constant.
"""
super().__init__(identifier)
self._output_ports = [OutputPort()] # TODO: Generate appropriate ID for ports.
self._parameters["value"] = value
@final
def evaluate(self, inputs: list) -> list:
return [self.param("value")]
class Addition(BasicOperation):
"""
Binary addition operation.
TODO: More info.
"""
def __init__(self, identifier: OperationId):
"""
Construct an Addition.
"""
super().__init__(identifier)
self._input_ports = [InputPort(), InputPort()] # TODO: Generate appropriate ID for ports.
self._output_ports = [OutputPort()] # TODO: Generate appropriate ID for ports.
@final
def evaluate(self, inputs: list) -> list:
return [inputs[0] + inputs[1]]
class ConstantMultiplication(BasicOperation):
"""
Unary constant multiplication operation.
TODO: More info.
"""
def __init__(self, identifier: OperationId, coefficient: Number):
"""
Construct a ConstantMultiplication.
"""
super().__init__(identifier)
self._input_ports = [InputPort()] # TODO: Generate appropriate ID for ports.
self._output_ports = [OutputPort()] # TODO: Generate appropriate ID for ports.
self._parameters["coefficient"] = coefficient
@final
def evaluate(self, inputs: list) -> list:
return [inputs[0] * self.param("coefficient")]
# TODO: More operations.