|
| 1 | +from collections import Mapping |
1 | 2 | from functools import lru_cache
|
2 | 3 | from typing import NamedTuple, Tuple, Union
|
3 | 4 | from warnings import warn
|
@@ -99,8 +100,8 @@ class MinMax(NamedTuple):
|
99 | 100 | xp.uint16: MinMax(0, +65_535),
|
100 | 101 | xp.uint32: MinMax(0, +4_294_967_295),
|
101 | 102 | xp.uint64: MinMax(0, +18_446_744_073_709_551_615),
|
102 |
| - xp.float32: MinMax(-3.4028234663852886e+38, 3.4028234663852886e+38), |
103 |
| - xp.float64: MinMax(-1.7976931348623157e+308, 1.7976931348623157e+308), |
| 103 | + xp.float32: MinMax(-3.4028234663852886e38, 3.4028234663852886e38), |
| 104 | + xp.float64: MinMax(-1.7976931348623157e308, 1.7976931348623157e308), |
104 | 105 | }
|
105 | 106 |
|
106 | 107 | dtype_nbits = {
|
@@ -404,3 +405,28 @@ def fmt_types(types: Tuple[Union[DataType, ScalarType], ...]) -> str:
|
404 | 405 | # i.e. dtype is bool, int, or float
|
405 | 406 | f_types.append(type_.__name__)
|
406 | 407 | return ", ".join(f_types)
|
| 408 | + |
| 409 | + |
| 410 | +class EqualityMapping(Mapping): |
| 411 | + def __init__(self, mapping: Mapping): |
| 412 | + keys = list(mapping.keys()) |
| 413 | + for i, key in enumerate(keys): |
| 414 | + if not (key == key): # specifically test __eq__, not __neq__ |
| 415 | + raise ValueError("Key {key!r} does not have equality with itself") |
| 416 | + other_keys = keys[:] |
| 417 | + other_keys.pop(i) |
| 418 | + for other_key in other_keys: |
| 419 | + if key == other_key: |
| 420 | + raise ValueError("Key {key!r} has equality with key {other_key!r}") |
| 421 | + self._mapping = mapping |
| 422 | + |
| 423 | + def __getitem__(self, key): |
| 424 | + for k, v in self._mapping.items(): |
| 425 | + if key == k: |
| 426 | + return v |
| 427 | + |
| 428 | + def __iter__(self): |
| 429 | + return iter(self._mapping) |
| 430 | + |
| 431 | + def __len__(self): |
| 432 | + return len(self._mapping) |
0 commit comments