From 3e0e189b9bc2c07d9f8771e781c031448482a38c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20H=C3=A4rnqvist?= <ivaha717@student.liu.se> Date: Wed, 15 Apr 2020 23:58:00 +0200 Subject: [PATCH] fix order of core_operations, add missing return type annotations on setters --- b_asic/core_operations.py | 68 ++++++++++++++++++------------------ b_asic/special_operations.py | 2 +- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/b_asic/core_operations.py b/b_asic/core_operations.py index 11013c84..517ccd50 100644 --- a/b_asic/core_operations.py +++ b/b_asic/core_operations.py @@ -34,7 +34,7 @@ class Constant(AbstractOperation): return self.param("value") @value.setter - def value(self, value: Number): + def value(self, value: Number) -> None: """Set the constant value of this operation.""" return self.set_param("value", value) @@ -103,36 +103,22 @@ class Division(AbstractOperation): return a / b -class SquareRoot(AbstractOperation): - """Unary square root operation. - TODO: More info. - """ - - def __init__(self, src0: Optional[SignalSourceProvider] = None, name: Name = ""): - super().__init__(input_count = 1, output_count = 1, name = name, input_sources = [src0]) - - @property - def type_name(self) -> TypeName: - return "sqrt" - - def evaluate(self, a): - return sqrt(complex(a)) - - -class ComplexConjugate(AbstractOperation): - """Unary complex conjugate operation. +class Min(AbstractOperation): + """Binary min operation. TODO: More info. """ - def __init__(self, src0: Optional[SignalSourceProvider] = None, name: Name = ""): - super().__init__(input_count = 1, output_count = 1, name = name, input_sources = [src0]) + def __init__(self, src0: Optional[SignalSourceProvider] = None, src1: Optional[SignalSourceProvider] = None, name: Name = ""): + super().__init__(input_count = 2, output_count = 1, name = name, input_sources = [src0, src1]) @property def type_name(self) -> TypeName: - return "conj" + return "min" - def evaluate(self, a): - return conjugate(a) + def evaluate(self, a, b): + assert not isinstance(a, complex) and not isinstance(b, complex), \ + ("core_operations.Min does not support complex numbers.") + return a if a < b else b class Max(AbstractOperation): @@ -153,22 +139,36 @@ class Max(AbstractOperation): return a if a > b else b -class Min(AbstractOperation): - """Binary min operation. +class SquareRoot(AbstractOperation): + """Unary square root operation. TODO: More info. """ - def __init__(self, src0: Optional[SignalSourceProvider] = None, src1: Optional[SignalSourceProvider] = None, name: Name = ""): - super().__init__(input_count = 2, output_count = 1, name = name, input_sources = [src0, src1]) + def __init__(self, src0: Optional[SignalSourceProvider] = None, name: Name = ""): + super().__init__(input_count = 1, output_count = 1, name = name, input_sources = [src0]) @property def type_name(self) -> TypeName: - return "min" + return "sqrt" - def evaluate(self, a, b): - assert not isinstance(a, complex) and not isinstance(b, complex), \ - ("core_operations.Min does not support complex numbers.") - return a if a < b else b + def evaluate(self, a): + return sqrt(complex(a)) + + +class ComplexConjugate(AbstractOperation): + """Unary complex conjugate operation. + TODO: More info. + """ + + def __init__(self, src0: Optional[SignalSourceProvider] = None, name: Name = ""): + super().__init__(input_count = 1, output_count = 1, name = name, input_sources = [src0]) + + @property + def type_name(self) -> TypeName: + return "conj" + + def evaluate(self, a): + return conjugate(a) class Absolute(AbstractOperation): @@ -209,7 +209,7 @@ class ConstantMultiplication(AbstractOperation): return self.param("value") @value.setter - def value(self, value: Number): + def value(self, value: Number) -> None: """Set the constant value of this operation.""" return self.set_param("value", value) diff --git a/b_asic/special_operations.py b/b_asic/special_operations.py index 46796d18..96d341b9 100644 --- a/b_asic/special_operations.py +++ b/b_asic/special_operations.py @@ -33,7 +33,7 @@ class Input(AbstractOperation): return self.param("value") @value.setter - def value(self, value: Number): + def value(self, value: Number) -> None: """Set the current value of this input.""" self.set_param("value", value) -- GitLab