Skip to content
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

[FIX] Disable __eq__ and __hash__ because it can be slow #713

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions orangecontrib/spectroscopy/preprocess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ def transformed(self, X, wavenumbers):
polyorder=self.polyorder,
deriv=self.deriv, mode="nearest")

def __eq__(self, other):
def __disabled_eq__(self, other):
return super().__eq__(other) \
and self.window == other.window \
and self.polyorder == other.polyorder \
and self.deriv == other.deriv

def __hash__(self):
def __disabled_hash__(self):
return hash((super().__hash__(), self.window, self.polyorder, self.deriv))


Expand Down Expand Up @@ -342,15 +342,15 @@ def transformed(self, data):
replace_infs(data.X)
return data.X

def __eq__(self, other):
def __disabled_eq__(self, other):
return super().__eq__(other) \
and self.method == other.method \
and self.lower == other.lower \
and self.upper == other.upper \
and self.int_method == other.int_method \
and self.attr == other.attr

def __hash__(self):
def __disabled_hash__(self):
return hash((super().__hash__(), self.method, self.lower,
self.upper, self.int_method, self.attr))

Expand Down Expand Up @@ -470,15 +470,15 @@ def __call__(self, data):
interpfn = interp1d_wo_unknowns_scipy
return interpfn(x, ys, self.points, kind=self.kind)

def __eq__(self, other):
def __disabled_eq__(self, other):
return type(self) is type(other) \
and np.all(self.points == other.points) \
and self.kind == other.kind \
and self.domain == other.domain \
and self.handle_nans == other.handle_nans \
and self.interpfn == other.interpfn

def __hash__(self):
def __disabled_hash__(self):
return hash((type(self), tuple(self.points[:5]), self.kind,
self.domain, self.handle_nans, self.interpfn))

Expand Down
12 changes: 6 additions & 6 deletions orangecontrib/spectroscopy/preprocess/emsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def __call__(self, x):
)
return seg(x)

def __eq__(self, other):
def __disabled_eq__(self, other):
return super().__eq__(other) \
and self.min_ == other.min_ \
and self.max_ == other.max_ \
and self.w == other.w

def __hash__(self):
def __disabled_hash__(self):
return hash((super().__hash__(), self.min_, self.max_, self.w))


Expand All @@ -57,11 +57,11 @@ def __call__(self, x):
)
return seg(x)

def __eq__(self, other):
def __disabled_eq__(self, other):
return super().__eq__(other) \
and self.s == other.s

def __hash__(self):
def __disabled_hash__(self):
return hash((super().__hash__(), self.s))


Expand Down Expand Up @@ -144,7 +144,7 @@ def transformed(self, X, wavenumbers):

return newspectra

def __eq__(self, other):
def __disabled_eq__(self, other):
return CommonDomainRef.__eq__(self, other) \
and table_eq_x(self.badspectra, other.badspectra) \
and self.order == other.order \
Expand All @@ -153,7 +153,7 @@ def __eq__(self, other):
if not isinstance(self.weights, Table)
else table_eq_x(self.weights, other.weights))

def __hash__(self):
def __disabled_hash__(self):
domain = self.badspectra.domain if self.badspectra is not None else None
fv = subset_for_hash(self.badspectra.X) if self.badspectra is not None else None
weights = self.weights if not isinstance(self.weights, Table) \
Expand Down
8 changes: 4 additions & 4 deletions orangecontrib/spectroscopy/preprocess/integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def compute(self, data, common):
x_s, y_s = self.extract_data(data, common)
return self.compute_integral(x_s, y_s)

def __eq__(self, other):
def __disabled_eq__(self, other):
return super().__eq__(other) \
and self.limits == other.limits

def __hash__(self):
def __disabled_hash__(self):
return hash((super().__hash__(), tuple(self.limits)))


Expand Down Expand Up @@ -290,11 +290,11 @@ def transformed(self, data):
x_sorter = np.argsort(x)
return data, x, x_sorter

def __eq__(self, other):
def __disabled_eq__(self, other):
# pylint: disable=useless-parent-delegation
return super().__eq__(other)

def __hash__(self):
def __disabled_hash__(self):
# pylint: disable=useless-parent-delegation
return super().__hash__()

Expand Down
4 changes: 2 additions & 2 deletions orangecontrib/spectroscopy/preprocess/me_emsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def iterate(spectra, correctedFirsIteration, residualsFirstIteration, wavenumber
newspectra = np.hstack((newspectra, numberOfIterations.reshape(-1, 1),RMSEall.reshape(-1, 1)))
return newspectra

def __eq__(self, other):
def __disabled_eq__(self, other):
return CommonDomainRef.__eq__(self, other) \
and self.ncomp == other.ncomp \
and np.array_equal(self.alpha0, other.alpha0) \
Expand All @@ -289,7 +289,7 @@ def __eq__(self, other):
if not isinstance(self.weights, Table)
else table_eq_x(self.weights, other.weights))

def __hash__(self):
def __disabled_hash__(self):
weights = self.weights if not isinstance(self.weights, Table) \
else subset_for_hash(self.weights.X)
return hash((CommonDomainRef.__hash__(self), weights, self.ncomp, tuple(self.alpha0),
Expand Down
8 changes: 4 additions & 4 deletions orangecontrib/spectroscopy/preprocess/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def transformed(self, data):
# Replace infs from either np.true_divide or np.log10
return replace_infs(absd)

def __eq__(self, other):
def __disabled_eq__(self, other):
# pylint: disable=useless-parent-delegation
return super().__eq__(other)

def __hash__(self):
def __disabled_hash__(self):
# pylint: disable=useless-parent-delegation
return super().__hash__()

Expand Down Expand Up @@ -105,11 +105,11 @@ def transformed(self, data):
# Replace infs from either np.true_divide or np.log10
return replace_infs(transd)

def __eq__(self, other):
def __disabled_eq__(self, other):
# pylint: disable=useless-parent-delegation
return super().__eq__(other)

def __hash__(self):
def __disabled_hash__(self):
# pylint: disable=useless-parent-delegation
return super().__hash__()

Expand Down
20 changes: 10 additions & 10 deletions orangecontrib/spectroscopy/preprocess/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def __init__(self, feature, commonfn):
def compute(self, data, common):
return common[:, self.feature]

def __eq__(self, other):
def __disabled_eq__(self, other):
return super().__eq__(other) \
and self.feature == other.feature

def __hash__(self):
def __disabled_hash__(self):
return hash((super().__hash__(), self.feature))


Expand All @@ -83,11 +83,11 @@ def transform_domain(self, data):
def transformed(self, data):
raise NotImplementedError

def __eq__(self, other):
def __disabled_eq__(self, other):
return type(self) is type(other) \
and self.domain == other.domain

def __hash__(self):
def __disabled_hash__(self):
return hash((type(self), self.domain))


Expand All @@ -100,11 +100,11 @@ def __init__(self, reference: Table, domain: Domain):
def interpolate_extend_to(self, interpolate: Table, wavenumbers):
return interpolate_extend_to(interpolate, wavenumbers)

def __eq__(self, other):
def __disabled_eq__(self, other):
return super().__eq__(other) \
and table_eq_x(self.reference, other.reference)

def __hash__(self):
def __disabled_hash__(self):
domain = self.reference.domain if self.reference is not None else None
fv = subset_for_hash(self.reference.X) if self.reference is not None else None
return hash((super().__hash__(), domain, fv))
Expand Down Expand Up @@ -134,11 +134,11 @@ def _restore_order(self, X, mon, xsind, xc):
def transformed(self, X, wavenumbers):
raise NotImplementedError

def __eq__(self, other):
def __disabled_eq__(self, other):
# pylint: disable=useless-parent-delegation
return super().__eq__(other)

def __hash__(self):
def __disabled_hash__(self):
# pylint: disable=useless-parent-delegation
return super().__hash__()

Expand Down Expand Up @@ -178,11 +178,11 @@ def __call__(self, data):
# restore order
return self._restore_order(X, mon, xsind, xc)

def __eq__(self, other):
def __disabled_eq__(self, other):
# pylint: disable=useless-parent-delegation
return super().__eq__(other)

def __hash__(self):
def __disabled_hash__(self):
# pylint: disable=useless-parent-delegation
return super().__hash__()

Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/spectroscopy/tests/test_emsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_multiple_badspectra(self):
fdata.metas,
[[1.375, 1.375, 3.0, 6.0, 2.0]])

def test_eq(self):
def disabled_test_eq(self):
data = Table.from_numpy(None, [[0, 0.25, 4.5, 4.75, 1.0, 1.25,
7.5, 7.75, 2.0, 5.25, 5.5, 2.75]])
data_ref = Table.from_numpy(None, [[0, 0, 2, 2, 0, 0, 3, 3, 0, 0, 0, 0]])
Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/spectroscopy/tests/test_integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_metas_output(self):
self.assertEqual(i[0]["0 - 5"], 8)
self.assertEqual(i[0]["0 - 6"], 3)

def test_eq(self):
def disabled_test_eq(self):
data = Table.from_numpy(None, [[1, 2, 3, 1, 1, 1]])
i1 = Integrate(methods=Integrate.Simple, limits=[[0, 5]])(data)
i2 = Integrate(methods=Integrate.Simple, limits=[[0, 6]])(data)
Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/spectroscopy/tests/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_nan_extend_edges_and_interpolate_mixed(self):
v, n = nan_extend_edges_and_interpolate(xsm, ysm)
np.testing.assert_equal(v[:, mix], exp)

def test_eq(self):
def disabled_test_eq(self):
data = Orange.data.Table("iris")
i1 = Interpolate([0, 1])(data)
i2 = Interpolate([0, 1])(data)
Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/spectroscopy/tests/test_me_emsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_short_reference(self):
# it was crashing before
ME_EMSC(reference=reference)(self.spectra)

def test_eq(self):
def disabled_test_eq(self):
ref = self.reference
spectra = self.spectra
d1 = ME_EMSC(reference=ref, ncomp=False, weights=False, max_iter=1)(spectra)
Expand Down
8 changes: 4 additions & 4 deletions orangecontrib/spectroscopy/tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_roundtrip(self):
calcdata = Absorbance()(Transmittance()(data))
np.testing.assert_allclose(data.X, calcdata.X)

def test_eq(self):
def disabled_test_eq(self):
data = SMALL_COLLAGEN
t1 = Transmittance()(data)
t2 = Transmittance()(data)
Expand Down Expand Up @@ -237,7 +237,7 @@ def test_roundtrip(self):
calcdata = Transmittance()(Absorbance()(data))
np.testing.assert_allclose(data.X, calcdata.X)

def test_eq(self):
def disabled_test_eq(self):
data = SMALL_COLLAGEN
t1 = Absorbance()(data)
t2 = Absorbance()(data)
Expand Down Expand Up @@ -272,7 +272,7 @@ def test_simple(self):
np.testing.assert_almost_equal(fdata.X,
[[4.86857143, 3.47428571, 1.49428571, 0.32857143]])

def test_eq(self):
def disabled_test_eq(self):
data = Table.from_numpy(None, [[2, 1, 2, 2, 3]])
p1 = SavitzkyGolayFiltering(window=5, polyorder=2, deriv=0)(data)
p2 = SavitzkyGolayFiltering(window=5, polyorder=2, deriv=1)(data)
Expand Down Expand Up @@ -447,7 +447,7 @@ def test_SNV_norm(self):
p = Normalize(method=Normalize.SNV, lower=0, upper=2)(data)
np.testing.assert_equal(p.X, q)

def test_eq(self):
def disabled_test_eq(self):
data = Table.from_numpy(None, [[2, 1, 2, 2, 3]])
p1 = Normalize(method=Normalize.MinMax)(data)
p2 = Normalize(method=Normalize.SNV)(data)
Expand Down
Loading