From 3dbb4ab92c58d11d205813ef6c5b0397352904ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20H=C3=A4rnqvist?= <ivaha717@student.liu.se> Date: Fri, 20 Mar 2020 18:33:15 +0100 Subject: [PATCH] Misc. fixes --- b_asic/core_operations.py | 54 +++++++++++++++++++-------------------- b_asic/operation.py | 16 ++++++------ 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/b_asic/core_operations.py b/b_asic/core_operations.py index ce1019f3..d06cbab3 100644 --- a/b_asic/core_operations.py +++ b/b_asic/core_operations.py @@ -35,7 +35,7 @@ class Constant(AbstractOperation): self._output_ports = [OutputPort(0, self)] self._parameters["value"] = value - def evaluate(self) -> Any: + def evaluate(self): return self.param("value") @property @@ -59,7 +59,7 @@ class Addition(AbstractOperation): if source2 is not None: self._input_ports[1].connect_to_port(source2) - def evaluate(self, a, b) -> Any: + def evaluate(self, a, b): return a + b @property @@ -82,11 +82,11 @@ class Subtraction(AbstractOperation): if source2 is not None: self._input_ports[1].connect_to_port(source2) - def evaluate(self, a, b) -> Any: + def evaluate(self, a, b): return a - b @property - def type_name(self) -> GraphIDType: + def type_name(self) -> TypeName: return "sub" @@ -105,11 +105,11 @@ class Multiplication(AbstractOperation): if source2 is not None: self._input_ports[1].connect_to_port(source2) - def evaluate(self, a, b) -> Any: + def evaluate(self, a, b): return a * b @property - def type_name(self) -> GraphIDType: + def type_name(self) -> TypeName: return "mul" @@ -128,11 +128,11 @@ class Division(AbstractOperation): if source2 is not None: self._input_ports[1].connect_to_port(source2) - def evaluate(self, a, b) -> Any: + def evaluate(self, a, b): return a / b @property - def type_name(self) -> GraphIDType: + def type_name(self) -> TypeName: return "div" @@ -150,11 +150,11 @@ class SquareRoot(AbstractOperation): self._input_ports[0].connect_to_port(source1) - def evaluate(self, a) -> Any: + def evaluate(self, a): return sqrt((complex)(a)) @property - def type_name(self) -> GraphIDType: + def type_name(self) -> TypeName: return "sqrt" @@ -172,11 +172,11 @@ class ComplexConjugate(AbstractOperation): self._input_ports[0].connect_to_port(source1) - def evaluate(self, a) -> Any: + def evaluate(self, a): return conjugate(a) @property - def type_name(self) -> GraphIDType: + def type_name(self) -> TypeName: return "conj" @@ -195,13 +195,13 @@ class Max(AbstractOperation): if source2 is not None: self._input_ports[1].connect_to_port(source2) - def evaluate(self, a, b) -> Any: + def evaluate(self, a, b): assert not isinstance(a, complex) and not isinstance(b, complex), \ - ("core_operation.Max does not support complex numbers.") + ("core_operations.Max does not support complex numbers.") return a if a > b else b @property - def type_name(self) -> GraphIDType: + def type_name(self) -> TypeName: return "max" @@ -220,13 +220,13 @@ class Min(AbstractOperation): if source2 is not None: self._input_ports[1].connect_to_port(source2) - def evaluate(self, a, b) -> Any: + def evaluate(self, a, b): assert not isinstance(a, complex) and not isinstance(b, complex), \ - ("core_operation.Min does not support complex numbers.") + ("core_operations.Min does not support complex numbers.") return a if a < b else b @property - def type_name(self) -> GraphIDType: + def type_name(self) -> TypeName: return "min" @@ -244,11 +244,11 @@ class Absolute(AbstractOperation): self._input_ports[0].connect_to_port(source1) - def evaluate(self, a) -> Any: + def evaluate(self, a): return np_abs(a) @property - def type_name(self) -> GraphIDType: + def type_name(self) -> TypeName: return "abs" @@ -266,7 +266,7 @@ class ConstantMultiplication(AbstractOperation): if source1 is not None: self._input_ports[0].connect_to_port(source1) - def evaluate(self, a) -> Any: + def evaluate(self, a): return a * self.param("coefficient") @property @@ -288,11 +288,11 @@ class ConstantAddition(AbstractOperation): if source1 is not None: self._input_ports[0].connect_to_port(source1) - def evaluate(self, a) -> Any: + def evaluate(self, a): return a + self.param("coefficient") @property - def type_name(self) -> GraphIDType: + def type_name(self) -> TypeName: return "cadd" @@ -310,11 +310,11 @@ class ConstantSubtraction(AbstractOperation): if source1 is not None: self._input_ports[0].connect_to_port(source1) - def evaluate(self, a) -> Any: + def evaluate(self, a): return a - self.param("coefficient") @property - def type_name(self) -> GraphIDType: + def type_name(self) -> TypeName: return "csub" @@ -332,9 +332,9 @@ class ConstantDivision(AbstractOperation): if source1 is not None: self._input_ports[0].connect_to_port(source1) - def evaluate(self, a) -> Any: + def evaluate(self, a): return a / self.param("coefficient") @property - def type_name(self) -> GraphIDType: + def type_name(self) -> TypeName: return "cdiv" diff --git a/b_asic/operation.py b/b_asic/operation.py index 75644b73..fc007ffd 100644 --- a/b_asic/operation.py +++ b/b_asic/operation.py @@ -86,9 +86,9 @@ class Operation(GraphComponent): @property @abstractmethod - def neighbours(self) -> "List[Operation]": + def neighbors(self) -> "List[Operation]": """Return all operations that are connected by signals to this operation. - If no neighbours are found this returns an empty list + If no neighbors are found, this returns an empty list. """ raise NotImplementedError @@ -175,17 +175,17 @@ class AbstractOperation(Operation, AbstractGraphComponent): return [self] @property - def neighbours(self) -> List[Operation]: - neighbours: List[Operation] = [] + def neighbors(self) -> List[Operation]: + neighbors: List[Operation] = [] for port in self._input_ports: for signal in port.signals: - neighbours.append(signal.source.operation) + neighbors.append(signal.source.operation) for port in self._output_ports: for signal in port.signals: - neighbours.append(signal.destination.operation) + neighbors.append(signal.destination.operation) - return neighbours + return neighbors def traverse(self) -> Operation: """Traverse the operation tree and return a generator with start point in the operation.""" @@ -198,7 +198,7 @@ class AbstractOperation(Operation, AbstractGraphComponent): while queue: operation = queue.popleft() yield operation - for n_operation in operation.neighbours: + for n_operation in operation.neighbors: if n_operation not in visited: visited.add(n_operation) queue.append(n_operation) -- GitLab