- Fixed incorrect logic and documentation for division operators (/, //) in the ADC_Result class.
- Verified that both forward and reverse division work correctly with scalars.
This commit is contained in:
@@ -447,13 +447,12 @@ class ADC_Result(Resultable, Drawable, DamarisFFT, Signalpath):
|
|||||||
raise ValueError(f"ValueError: Cannot power raise \"{other.__class__}\" to ADC-Result!")
|
raise ValueError(f"ValueError: Cannot power raise \"{other.__class__}\" to ADC-Result!")
|
||||||
|
|
||||||
def __truediv__(self, other):
|
def __truediv__(self, other):
|
||||||
"Redefining other (scalar) / self"
|
"Redefining self / other (scalar)"
|
||||||
if isinstance(other, int) or isinstance(other, float):
|
if isinstance(other, int) or isinstance(other, float):
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
tmp_y = []
|
tmp_y = []
|
||||||
|
|
||||||
for i in range(self.get_number_of_channels()):
|
for i in range(self.get_number_of_channels()):
|
||||||
tmp_y.append(other / numpy.array(self.y[i], dtype="float32"))
|
tmp_y.append(numpy.array(self.y[i], dtype="float32") / other)
|
||||||
|
|
||||||
r = ADC_Result(x = self.x[:], y = tmp_y, index = self.index[:], sampl_freq = self.sampling_rate, desc = self.description, job_id = self.job_id, job_date = self.job_date)
|
r = ADC_Result(x = self.x[:], y = tmp_y, index = self.index[:], sampl_freq = self.sampling_rate, desc = self.description, job_id = self.job_id, job_date = self.job_date)
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
@@ -463,20 +462,27 @@ class ADC_Result(Resultable, Drawable, DamarisFFT, Signalpath):
|
|||||||
|
|
||||||
def __rtruediv__(self, other):
|
def __rtruediv__(self, other):
|
||||||
"Redefining other (scalar) / self"
|
"Redefining other (scalar) / self"
|
||||||
return self.__truediv__(other)
|
if isinstance(other, int) or isinstance(other, float):
|
||||||
|
self.lock.acquire()
|
||||||
|
tmp_y = []
|
||||||
|
for i in range(self.get_number_of_channels()):
|
||||||
|
tmp_y.append(other / numpy.array(self.y[i], dtype="float32"))
|
||||||
|
r = ADC_Result(x = self.x[:], y = tmp_y, index = self.index[:], sampl_freq = self.sampling_rate, desc = self.description, job_id = self.job_id, job_date = self.job_date)
|
||||||
|
self.lock.release()
|
||||||
|
return r
|
||||||
|
else:
|
||||||
|
raise ValueError(f"ValueError: Cannot divide \"{other.__class__}\" to ADC-Result!")
|
||||||
|
|
||||||
def __floordiv__(self, other):
|
def __floordiv__(self, other):
|
||||||
"Redefining other (scalar) / self"
|
"Redefining self // other (scalar)"
|
||||||
if isinstance(other, float):
|
if isinstance(other, float):
|
||||||
raise ValueError("ValueError: Cannot use floor division (//) on floats! Use \"//\" instead of \"/\"! ")
|
raise ValueError("ValueError: Cannot use floor division (//) on floats! Use \"/\" instead of \"//\"! ")
|
||||||
|
|
||||||
if isinstance(other, int):
|
if isinstance(other, int):
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
tmp_y = []
|
tmp_y = []
|
||||||
|
|
||||||
for i in range(self.get_number_of_channels()):
|
for i in range(self.get_number_of_channels()):
|
||||||
tmp_y.append(other / numpy.array(self.y[i], dtype="float32"))
|
tmp_y.append(numpy.array(self.y[i], dtype="float32") // other)
|
||||||
|
|
||||||
r = ADC_Result(x = self.x[:], y = tmp_y, index = self.index[:], sampl_freq = self.sampling_rate, desc = self.description, job_id = self.job_id, job_date = self.job_date)
|
r = ADC_Result(x = self.x[:], y = tmp_y, index = self.index[:], sampl_freq = self.sampling_rate, desc = self.description, job_id = self.job_id, job_date = self.job_date)
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
return r
|
return r
|
||||||
@@ -484,8 +490,20 @@ class ADC_Result(Resultable, Drawable, DamarisFFT, Signalpath):
|
|||||||
raise ValueError(f"ValueError: Cannot divide \"{other.__class__}\" to ADC-Result!")
|
raise ValueError(f"ValueError: Cannot divide \"{other.__class__}\" to ADC-Result!")
|
||||||
|
|
||||||
def __rfloordiv__(self, other):
|
def __rfloordiv__(self, other):
|
||||||
"Redefining other (scalar) / self"
|
"Redefining other (scalar) // self"
|
||||||
return self.__floordiv__(other)
|
if isinstance(other, float):
|
||||||
|
raise ValueError("ValueError: Cannot use floor division (//) on floats! Use \"/\" instead of \"//\"! ")
|
||||||
|
|
||||||
|
if isinstance(other, int):
|
||||||
|
self.lock.acquire()
|
||||||
|
tmp_y = []
|
||||||
|
for i in range(self.get_number_of_channels()):
|
||||||
|
tmp_y.append(other // numpy.array(self.y[i], dtype="float32"))
|
||||||
|
r = ADC_Result(x = self.x[:], y = tmp_y, index = self.index[:], sampl_freq = self.sampling_rate, desc = self.description, job_id = self.job_id, job_date = self.job_date)
|
||||||
|
self.lock.release()
|
||||||
|
return r
|
||||||
|
else:
|
||||||
|
raise ValueError(f"ValueError: Cannot divide \"{other.__class__}\" to ADC-Result!")
|
||||||
|
|
||||||
|
|
||||||
def __neg__(self):
|
def __neg__(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user