-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
write tests for... #187
Comments
@sbillinge I am trying to write tests for these. Two important questions below: Q1. What's the difference between, for example def __mul__(self, other):
multiplied = deepcopy(self)
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
multiplied.on_tth[1] = other * self.on_tth[1]
multiplied.on_q[1] = other * self.on_q[1]
elif not isinstance(other, DiffractionObject):
raise TypeError("I only know how to multiply two Scattering_object objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(x_grid_emsg)
else:
multiplied.on_tth[1] = self.on_tth[1] * other.on_tth[1]
multiplied.on_q[1] = self.on_q[1] * other.on_q[1]
return multiplied
def __rmul__(self, other):
multiplied = deepcopy(self)
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
multiplied.on_tth[1] = other * self.on_tth[1]
multiplied.on_q[1] = other * self.on_q[1]
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(x_grid_emsg)
else:
multiplied.on_tth[1] = self.on_tth[1] * other.on_tth[1]
multiplied.on_q[1] = self.on_q[1] * other.on_q[1]
return multiplied Q2. We've made I am thinking we might have to change from def __add__(self, other):
summed = deepcopy(self)
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
summed.on_tth[1] = self.on_tth[1] + other
summed.on_q[1] = self.on_q[1] + other
elif not isinstance(other, DiffractionObject):
raise TypeError("I only know how to sum two DiffractionObject objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(x_grid_emsg)
else:
summed.on_tth[1] = self.on_tth[1] + other.on_tth[1]
summed.on_q[1] = self.on_q[1] + other.on_q[1]
return summed to def __add__(self, other):
if not isinstance(other, DiffractionObject):
raise TypeError("I only know how to sum two DiffractionObject objects")
tth_sum = self.on_tth[1] + other.on_tth[1]
return DiffractionObject(xarray=tth_sum, yarray=self.yarray, xtype="tth", wavelength=self.wavelength) The above assumes 1) self's yarray is used in the new object 2) tth xtype is used 3) and the self's wavelength is used. |
they are the same because the mul operation commutes. |
Those arrays are not immutable, we just made them not settable, right? I think we can update them how we want inside a method. |
Right, |
Since 3.6.0 deadline is approaching, I will resolve this issue |
I will keep progress here:
Note to myself: |
Problem
before doing this talk to @yucongalicechen or @sbillinge about new data structure for the arrays in the DOs.
Proposed solution
The text was updated successfully, but these errors were encountered: