Skip to content

Commit 7ff247f

Browse files
committed
some further clean-up
1 parent f2c646f commit 7ff247f

15 files changed

Lines changed: 162 additions & 130 deletions

File tree

mlscorecheck/check/bundles/retina/_diaretdb1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _prepare_configuration_diaretdb1(
105105
if only_valid:
106106
testsets = [tset for tset in testsets if tset["p"] > 0 and tset["n"] > 0]
107107

108-
return cast(list[Any], testsets if pixel_level else testset)
108+
return cast(list[Any], testsets) if pixel_level else [testset]
109109

110110

111111
def check_diaretdb1_class(

mlscorecheck/individual/_complex_interval.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This module implements the complex interval arithmetics
33
"""
44

5+
from typing import Union
56
from ._interval import Interval, IntervalUnion
67

78
__all__ = ["ComplexInterval"]
@@ -12,7 +13,7 @@ class ComplexInterval:
1213
The class represents a complex interval
1314
"""
1415

15-
def __init__(self, real, imag):
16+
def __init__(self, real: Union[float, Interval, IntervalUnion], imag: Union[float, Interval, IntervalUnion]) -> None:
1617
"""
1718
Constructor of the complex interval
1819
@@ -23,7 +24,7 @@ def __init__(self, real, imag):
2324
self.real = real
2425
self.imag = imag
2526

26-
def __add__(self, other):
27+
def __add__(self, other: "ComplexInterval") -> "ComplexInterval":
2728
"""
2829
Addition operator
2930
@@ -38,7 +39,7 @@ def __add__(self, other):
3839

3940
return ComplexInterval(self.real + other.real, self.imag + other.imag)
4041

41-
def __radd__(self, other):
42+
def __radd__(self, other: Union[float, Interval, IntervalUnion, "ComplexInterval"]) -> "ComplexInterval":
4243
"""
4344
Right addition operator
4445
@@ -50,7 +51,7 @@ def __radd__(self, other):
5051
"""
5152
return self + other
5253

53-
def __sub__(self, other):
54+
def __sub__(self, other: Union[float, Interval, IntervalUnion, "ComplexInterval"]) -> "ComplexInterval":
5455
"""
5556
Subtraction operator
5657
@@ -65,7 +66,7 @@ def __sub__(self, other):
6566

6667
return ComplexInterval(self.real - other.real, self.imag - other.imag)
6768

68-
def __rsub__(self, other):
69+
def __rsub__(self, other: Union[float, Interval, IntervalUnion, "ComplexInterval"]) -> "ComplexInterval":
6970
"""
7071
Right subtraction operator
7172
@@ -77,7 +78,7 @@ def __rsub__(self, other):
7778
"""
7879
return (-1) * self + other
7980

80-
def __mul__(self, other):
81+
def __mul__(self, other: Union[float, Interval, IntervalUnion, "ComplexInterval"]) -> "ComplexInterval":
8182
"""
8283
Multiplication operator
8384
@@ -95,7 +96,7 @@ def __mul__(self, other):
9596
self.real * other.imag + self.imag * other.real,
9697
)
9798

98-
def __rmul__(self, other):
99+
def __rmul__(self, other: Union[float, Interval, IntervalUnion, "ComplexInterval"]) -> "ComplexInterval":
99100
"""
100101
Right multiplication operator
101102
@@ -107,7 +108,7 @@ def __rmul__(self, other):
107108
"""
108109
return self.__mul__(other)
109110

110-
def __truediv__(self, other):
111+
def __truediv__(self, other: Union[float, Interval, IntervalUnion, "ComplexInterval"]) -> "ComplexInterval":
111112
"""
112113
Division operator
113114
@@ -127,7 +128,7 @@ def __truediv__(self, other):
127128
(self.imag * other.real - self.real * other.imag) / norm,
128129
)
129130

130-
def __rtruediv__(self, other):
131+
def __rtruediv__(self, other: Union[float, Interval, IntervalUnion, "ComplexInterval"]) -> "ComplexInterval":
131132
"""
132133
Right division operator
133134
@@ -144,7 +145,7 @@ def __rtruediv__(self, other):
144145

145146
return other / self
146147

147-
def __repr__(self):
148+
def __repr__(self) -> str:
148149
"""
149150
The representation dunder
150151
@@ -180,7 +181,7 @@ def __ne__(self, other) -> bool:
180181
"""
181182
return not self.__eq__(other)
182183

183-
def __neg__(self):
184+
def __neg__(self) -> "ComplexInterval":
184185
"""
185186
The negation operator
186187
@@ -189,7 +190,7 @@ def __neg__(self):
189190
"""
190191
return ComplexInterval(-self.real, -self.imag)
191192

192-
def __pow__(self, other):
193+
def __pow__(self, other: Union[float, int]) -> "ComplexInterval":
193194
"""
194195
The power operator
195196

mlscorecheck/individual/_interval.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
"""
2-
This module implements the interval arithmetics
2+
Interval arithmetics
33
"""
44

5+
from typing import Union
56
import numpy as np
67

8+
from ..core import NUMERICAL_TOLERANCE
9+
710
__all__ = ["Interval", "IntervalUnion", "sqrt"]
811

912

10-
def sqrt(obj):
13+
def sqrt(obj) -> "Interval | IntervalUnion | float":
1114
"""
1215
Square root of an interval or interval union
1316
@@ -28,7 +31,7 @@ class Interval:
2831
The interval abstraction
2932
"""
3033

31-
def __init__(self, lower_bound, upper_bound):
34+
def __init__(self, lower_bound: float, upper_bound: float) -> None:
3235
"""
3336
Constructor of the interval
3437
@@ -56,7 +59,7 @@ def to_tuple(self) -> tuple:
5659
"""
5760
return (self.lower_bound, self.upper_bound)
5861

59-
def contains(self, value) -> bool:
62+
def contains(self, value: float) -> bool:
6063
"""
6164
Check if the interval contains the value
6265
@@ -68,7 +71,7 @@ def contains(self, value) -> bool:
6871
"""
6972
return bool(self.lower_bound <= value <= self.upper_bound)
7073

71-
def intersection(self, other):
74+
def intersection(self, other: "Interval | IntervalUnion") -> "Interval":
7275
"""
7376
Returns the intersection of two intervals
7477
@@ -110,7 +113,7 @@ def integer(self) -> bool:
110113

111114
return bool(np.ceil(self.lower_bound) == np.floor(self.upper_bound))
112115

113-
def shrink_to_integers(self):
116+
def shrink_to_integers(self) -> "Interval":
114117
"""
115118
Shrinks the interval to integers
116119
@@ -140,7 +143,7 @@ def is_empty(self) -> bool:
140143
"""
141144
return bool(self.upper_bound < self.lower_bound)
142145

143-
def __add__(self, other):
146+
def __add__(self, other: Union[int, float, "Interval"]) -> Union["Interval", "IntervalUnion"]:
144147
"""
145148
The addition operator
146149
@@ -164,7 +167,7 @@ def __add__(self, other):
164167
upper_bound=self.upper_bound + other.upper_bound,
165168
)
166169

167-
def __radd__(self, other):
170+
def __radd__(self, other: Union[int, float, "Interval"]) -> Union["Interval", "IntervalUnion"]:
168171
"""
169172
The right hand addition
170173
@@ -176,7 +179,7 @@ def __radd__(self, other):
176179
"""
177180
return self + other
178181

179-
def __sub__(self, other):
182+
def __sub__(self, other: Union[int, float, "Interval"]) -> Union["Interval", "IntervalUnion"]:
180183
"""
181184
The subtraction operator
182185
@@ -200,7 +203,7 @@ def __sub__(self, other):
200203
upper_bound=self.upper_bound - other.lower_bound,
201204
)
202205

203-
def __rsub__(self, other):
206+
def __rsub__(self, other: Union[int, float, "Interval"]) -> Union["Interval", "IntervalUnion"]:
204207
"""
205208
The right hand subtraction
206209
@@ -212,7 +215,7 @@ def __rsub__(self, other):
212215
"""
213216
return (-1) * self + other
214217

215-
def __mul__(self, other):
218+
def __mul__(self, other: Union[int, float, "Interval"]) -> Union["Interval", "IntervalUnion"]:
216219
"""
217220
The multiplication operator
218221
@@ -238,7 +241,7 @@ def __mul__(self, other):
238241

239242
return Interval(min(term0, term1, term2, term3), max(term0, term1, term2, term3))
240243

241-
def __rmul__(self, other):
244+
def __rmul__(self, other: Union[int, float, "Interval"]) -> Union["Interval", "IntervalUnion"]:
242245
"""
243246
The right hand multiplication operator
244247
@@ -250,7 +253,9 @@ def __rmul__(self, other):
250253
"""
251254
return self.__mul__(other)
252255

253-
def __truediv__(self, other):
256+
def __truediv__(
257+
self, other: Union[int, float, "Interval"]
258+
) -> Union["Interval", "IntervalUnion"]:
254259
"""
255260
The division operator
256261
@@ -287,7 +292,9 @@ def __truediv__(self, other):
287292

288293
return IntervalUnion([self * res_0, self * res_1])
289294

290-
def __rtruediv__(self, other):
295+
def __rtruediv__(
296+
self, other: Union[int, float, "Interval"]
297+
) -> Union["Interval", "IntervalUnion"]:
291298
"""
292299
The right hand division operator
293300
@@ -337,7 +344,7 @@ def __ne__(self, other) -> bool:
337344
"""
338345
return not self.__eq__(other)
339346

340-
def __neg__(self):
347+
def __neg__(self) -> "Interval":
341348
"""
342349
The negation operator
343350
@@ -346,7 +353,7 @@ def __neg__(self):
346353
"""
347354
return (-1) * self
348355

349-
def __pow__(self, other):
356+
def __pow__(self, other: Union[int, float]) -> "Interval":
350357
"""
351358
The power operation on the interval
352359
@@ -374,7 +381,7 @@ def __pow__(self, other):
374381

375382
return res
376383

377-
def representing_int(self):
384+
def representing_int(self) -> Union[int, None]:
378385
"""
379386
Returns a representative integer
380387
@@ -383,7 +390,7 @@ def representing_int(self):
383390
"""
384391
shrunk = self.shrink_to_integers()
385392
if not shrunk.is_empty():
386-
return shrunk.lower_bound
393+
return int(shrunk.lower_bound)
387394
return None
388395

389396

@@ -392,7 +399,7 @@ class IntervalUnion:
392399
The interval union abstraction
393400
"""
394401

395-
def __init__(self, intervals):
402+
def __init__(self, intervals: Union["Interval", tuple, list]):
396403
"""
397404
Constructor of the object
398405
@@ -425,7 +432,7 @@ def to_tuple(self) -> list:
425432
"""
426433
return [interval.to_tuple() for interval in self.intervals]
427434

428-
def simplify(self):
435+
def simplify(self) -> None:
429436
"""
430437
Simplify the union of intervals
431438

mlscorecheck/individual/_tptn_solutions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
This is a generated file, do not edit.
44
"""
55

6+
# mypy: ignore-errors
7+
68
# pylint: disable=line-too-long
79
# pylint: disable=too-many-lines
810

0 commit comments

Comments
 (0)