Skip to content
Snippets Groups Projects
Commit 3dbb4ab9 authored by Ivar Härnqvist's avatar Ivar Härnqvist
Browse files

Misc. fixes

parent 7c6cbe75
No related branches found
No related tags found
3 merge requests!67WIP: B-ASIC version 1.0.0 hotfix,!65B-ASIC version 1.0.0,!15Add changes from sprint 1 and 2 to master
...@@ -35,7 +35,7 @@ class Constant(AbstractOperation): ...@@ -35,7 +35,7 @@ class Constant(AbstractOperation):
self._output_ports = [OutputPort(0, self)] self._output_ports = [OutputPort(0, self)]
self._parameters["value"] = value self._parameters["value"] = value
def evaluate(self) -> Any: def evaluate(self):
return self.param("value") return self.param("value")
@property @property
...@@ -59,7 +59,7 @@ class Addition(AbstractOperation): ...@@ -59,7 +59,7 @@ class Addition(AbstractOperation):
if source2 is not None: if source2 is not None:
self._input_ports[1].connect_to_port(source2) self._input_ports[1].connect_to_port(source2)
def evaluate(self, a, b) -> Any: def evaluate(self, a, b):
return a + b return a + b
@property @property
...@@ -82,11 +82,11 @@ class Subtraction(AbstractOperation): ...@@ -82,11 +82,11 @@ class Subtraction(AbstractOperation):
if source2 is not None: if source2 is not None:
self._input_ports[1].connect_to_port(source2) self._input_ports[1].connect_to_port(source2)
def evaluate(self, a, b) -> Any: def evaluate(self, a, b):
return a - b return a - b
@property @property
def type_name(self) -> GraphIDType: def type_name(self) -> TypeName:
return "sub" return "sub"
...@@ -105,11 +105,11 @@ class Multiplication(AbstractOperation): ...@@ -105,11 +105,11 @@ class Multiplication(AbstractOperation):
if source2 is not None: if source2 is not None:
self._input_ports[1].connect_to_port(source2) self._input_ports[1].connect_to_port(source2)
def evaluate(self, a, b) -> Any: def evaluate(self, a, b):
return a * b return a * b
@property @property
def type_name(self) -> GraphIDType: def type_name(self) -> TypeName:
return "mul" return "mul"
...@@ -128,11 +128,11 @@ class Division(AbstractOperation): ...@@ -128,11 +128,11 @@ class Division(AbstractOperation):
if source2 is not None: if source2 is not None:
self._input_ports[1].connect_to_port(source2) self._input_ports[1].connect_to_port(source2)
def evaluate(self, a, b) -> Any: def evaluate(self, a, b):
return a / b return a / b
@property @property
def type_name(self) -> GraphIDType: def type_name(self) -> TypeName:
return "div" return "div"
...@@ -150,11 +150,11 @@ class SquareRoot(AbstractOperation): ...@@ -150,11 +150,11 @@ class SquareRoot(AbstractOperation):
self._input_ports[0].connect_to_port(source1) self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any: def evaluate(self, a):
return sqrt((complex)(a)) return sqrt((complex)(a))
@property @property
def type_name(self) -> GraphIDType: def type_name(self) -> TypeName:
return "sqrt" return "sqrt"
...@@ -172,11 +172,11 @@ class ComplexConjugate(AbstractOperation): ...@@ -172,11 +172,11 @@ class ComplexConjugate(AbstractOperation):
self._input_ports[0].connect_to_port(source1) self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any: def evaluate(self, a):
return conjugate(a) return conjugate(a)
@property @property
def type_name(self) -> GraphIDType: def type_name(self) -> TypeName:
return "conj" return "conj"
...@@ -195,13 +195,13 @@ class Max(AbstractOperation): ...@@ -195,13 +195,13 @@ class Max(AbstractOperation):
if source2 is not None: if source2 is not None:
self._input_ports[1].connect_to_port(source2) 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), \ 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 return a if a > b else b
@property @property
def type_name(self) -> GraphIDType: def type_name(self) -> TypeName:
return "max" return "max"
...@@ -220,13 +220,13 @@ class Min(AbstractOperation): ...@@ -220,13 +220,13 @@ class Min(AbstractOperation):
if source2 is not None: if source2 is not None:
self._input_ports[1].connect_to_port(source2) 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), \ 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 return a if a < b else b
@property @property
def type_name(self) -> GraphIDType: def type_name(self) -> TypeName:
return "min" return "min"
...@@ -244,11 +244,11 @@ class Absolute(AbstractOperation): ...@@ -244,11 +244,11 @@ class Absolute(AbstractOperation):
self._input_ports[0].connect_to_port(source1) self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any: def evaluate(self, a):
return np_abs(a) return np_abs(a)
@property @property
def type_name(self) -> GraphIDType: def type_name(self) -> TypeName:
return "abs" return "abs"
...@@ -266,7 +266,7 @@ class ConstantMultiplication(AbstractOperation): ...@@ -266,7 +266,7 @@ class ConstantMultiplication(AbstractOperation):
if source1 is not None: if source1 is not None:
self._input_ports[0].connect_to_port(source1) self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any: def evaluate(self, a):
return a * self.param("coefficient") return a * self.param("coefficient")
@property @property
...@@ -288,11 +288,11 @@ class ConstantAddition(AbstractOperation): ...@@ -288,11 +288,11 @@ class ConstantAddition(AbstractOperation):
if source1 is not None: if source1 is not None:
self._input_ports[0].connect_to_port(source1) self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any: def evaluate(self, a):
return a + self.param("coefficient") return a + self.param("coefficient")
@property @property
def type_name(self) -> GraphIDType: def type_name(self) -> TypeName:
return "cadd" return "cadd"
...@@ -310,11 +310,11 @@ class ConstantSubtraction(AbstractOperation): ...@@ -310,11 +310,11 @@ class ConstantSubtraction(AbstractOperation):
if source1 is not None: if source1 is not None:
self._input_ports[0].connect_to_port(source1) self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any: def evaluate(self, a):
return a - self.param("coefficient") return a - self.param("coefficient")
@property @property
def type_name(self) -> GraphIDType: def type_name(self) -> TypeName:
return "csub" return "csub"
...@@ -332,9 +332,9 @@ class ConstantDivision(AbstractOperation): ...@@ -332,9 +332,9 @@ class ConstantDivision(AbstractOperation):
if source1 is not None: if source1 is not None:
self._input_ports[0].connect_to_port(source1) self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any: def evaluate(self, a):
return a / self.param("coefficient") return a / self.param("coefficient")
@property @property
def type_name(self) -> GraphIDType: def type_name(self) -> TypeName:
return "cdiv" return "cdiv"
...@@ -86,9 +86,9 @@ class Operation(GraphComponent): ...@@ -86,9 +86,9 @@ class Operation(GraphComponent):
@property @property
@abstractmethod @abstractmethod
def neighbours(self) -> "List[Operation]": def neighbors(self) -> "List[Operation]":
"""Return all operations that are connected by signals to this 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 raise NotImplementedError
...@@ -175,17 +175,17 @@ class AbstractOperation(Operation, AbstractGraphComponent): ...@@ -175,17 +175,17 @@ class AbstractOperation(Operation, AbstractGraphComponent):
return [self] return [self]
@property @property
def neighbours(self) -> List[Operation]: def neighbors(self) -> List[Operation]:
neighbours: List[Operation] = [] neighbors: List[Operation] = []
for port in self._input_ports: for port in self._input_ports:
for signal in port.signals: for signal in port.signals:
neighbours.append(signal.source.operation) neighbors.append(signal.source.operation)
for port in self._output_ports: for port in self._output_ports:
for signal in port.signals: for signal in port.signals:
neighbours.append(signal.destination.operation) neighbors.append(signal.destination.operation)
return neighbours return neighbors
def traverse(self) -> Operation: def traverse(self) -> Operation:
"""Traverse the operation tree and return a generator with start point in the operation.""" """Traverse the operation tree and return a generator with start point in the operation."""
...@@ -198,7 +198,7 @@ class AbstractOperation(Operation, AbstractGraphComponent): ...@@ -198,7 +198,7 @@ class AbstractOperation(Operation, AbstractGraphComponent):
while queue: while queue:
operation = queue.popleft() operation = queue.popleft()
yield operation yield operation
for n_operation in operation.neighbours: for n_operation in operation.neighbors:
if n_operation not in visited: if n_operation not in visited:
visited.add(n_operation) visited.add(n_operation)
queue.append(n_operation) queue.append(n_operation)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment