@@ -39,9 +39,9 @@ class FuzzyWarning(UserWarning):
39
39
pass
40
40
41
41
42
- NO_DOMAIN_TO_COMPARE = FuzzyWarning ( "No domains to compare." )
42
+ NO_DOMAIN_TO_COMPARE = "No domains to compare to."
43
43
CANT_COMPARE_DOMAINS = "Can't compare different domains."
44
- NO_DOMAIN = FuzzyWarning ( "No domain." )
44
+ NO_DOMAIN = "No domain defined."
45
45
46
46
47
47
class Domain :
@@ -296,65 +296,56 @@ def f(x: float):
296
296
def __eq__ (self , other : object ) -> bool :
297
297
"""A set is equal with another if both return the same values over the same range."""
298
298
if self .domain is None or not isinstance (other , Set ) or other .domain is None :
299
- # It would require complete AST analysis to check whether both Sets
299
+ # It would require complete bytecode analysis to check whether both Sets
300
300
# represent the same recursive functions -
301
301
# additionally, there are infinitely many mathematically equivalent
302
302
# functions that don't have the same bytecode...
303
303
raise FuzzyWarning ("Impossible to determine." )
304
- else :
305
- # however, if domains ARE assigned (whether or not it's the same domain),
306
- # we simply can check if they map to the same values
307
- return np .array_equal (self .array (), other .array ())
304
+
305
+ # however, if domains ARE assigned (whether or not it's the same domain),
306
+ # we simply can check if they map to the same values
307
+ return np .array_equal (self .array (), other .array ())
308
308
309
309
def __le__ (self , other : Set ) -> bool :
310
310
"""If this <= other, it means this is a subset of the other."""
311
+ assert self .domain is not None and other .domain is not None , NO_DOMAIN_TO_COMPARE
311
312
assert self .domain == other .domain , CANT_COMPARE_DOMAINS
312
- if self .domain is None or other .domain is None :
313
- raise NO_DOMAIN_TO_COMPARE
314
313
return all (np .less_equal (self .array (), other .array ()))
315
314
316
315
def __lt__ (self , other : Set ) -> bool :
317
316
"""If this < other, it means this is a proper subset of the other."""
317
+ assert self .domain is not None and other .domain is not None , NO_DOMAIN_TO_COMPARE
318
318
assert self .domain == other .domain , CANT_COMPARE_DOMAINS
319
- if self .domain is None or other .domain is None :
320
- raise NO_DOMAIN_TO_COMPARE
321
319
return all (np .less (self .array (), other .array ()))
322
320
323
321
def __ge__ (self , other : Set ) -> bool :
324
322
"""If this >= other, it means this is a superset of the other."""
323
+ assert self .domain is not None and other .domain is not None , NO_DOMAIN_TO_COMPARE
325
324
assert self .domain == other .domain , CANT_COMPARE_DOMAINS
326
- if self .domain is None or other .domain is None :
327
- raise NO_DOMAIN_TO_COMPARE
328
325
return all (np .greater_equal (self .array (), other .array ()))
329
326
330
327
def __gt__ (self , other : Set ) -> bool :
331
328
"""If this > other, it means this is a proper superset of the other."""
329
+ assert self .domain is not None and other .domain is not None , NO_DOMAIN_TO_COMPARE
332
330
assert self .domain == other .domain , CANT_COMPARE_DOMAINS
333
- if self .domain is None or other .domain is None :
334
- raise NO_DOMAIN_TO_COMPARE
335
331
return all (np .greater (self .array (), other .array ()))
336
332
337
333
def __len__ (self ) -> int :
338
334
"""Number of membership values in the set, defined by bounds and resolution of domain."""
339
- if self .domain is None :
340
- raise NO_DOMAIN
335
+ assert self .domain is not None , NO_DOMAIN
341
336
return len (self .array ())
342
337
343
338
@property
344
339
def cardinality (self ) -> float :
345
340
"""The sum of all values in the set."""
346
- if self .domain is None :
347
- raise NO_DOMAIN
341
+ assert self .domain is not None , NO_DOMAIN
348
342
return sum (self .array ())
349
343
350
344
@property
351
345
def relative_cardinality (self ) -> float :
352
346
"""Relative cardinality is the sum of all membership values by float of all values."""
353
- if self .domain is None :
354
- raise NO_DOMAIN
355
- if len (self ) == 0 :
356
- # this is highly unlikely and only possible with res=inf but still..
357
- raise FuzzyWarning ("The domain has no element." )
347
+ assert self .domain is not None , NO_DOMAIN
348
+ assert len (self ) > 0 , "The domain has no element." # only possible with step=inf, but still..
358
349
return self .cardinality / len (self )
359
350
360
351
def concentrated (self ) -> Set :
0 commit comments