|
31 | 31 | import logging |
32 | 32 | import warnings |
33 | 33 | from abc import ABC, abstractmethod |
34 | | -from collections.abc import Hashable, Iterable, Iterator, Sequence, Set as AbstractSet |
| 34 | +from collections.abc import Hashable, Sequence, Set as AbstractSet |
35 | 35 | from dataclasses import dataclass |
36 | 36 | from typing import TYPE_CHECKING, Any, TypeAlias, cast |
37 | 37 |
|
38 | 38 | import numpy as np |
39 | | -from typing_extensions import override |
40 | 39 |
|
41 | 40 | import loopy as lp |
42 | 41 | from pymbolic.mapper.dependency import DependencyMapper |
43 | 42 | from pyopencl.characterize import get_pocl_version |
44 | | -from pytools import T, memoize_method |
| 43 | +from pytools import memoize_method |
45 | 44 | from pytools.tag import Tag, tag_dataclass |
46 | 45 |
|
47 | 46 | import sumpy.symbolic as sym |
|
71 | 70 |
|
72 | 71 | .. autofunction:: to_complex_dtype |
73 | 72 | .. autofunction:: is_obj_array_like |
74 | | -.. autoclass:: OrderedSet |
75 | 73 |
|
76 | 74 | Multi-index Helpers |
77 | 75 | ------------------- |
@@ -368,94 +366,6 @@ def get_kernel(self) -> lp.TranslationUnit: |
368 | 366 | # }}} |
369 | 367 |
|
370 | 368 |
|
371 | | -# {{{ OrderedSet |
372 | | - |
373 | | -# Source: https://code.activestate.com/recipes/576694-orderedset/ |
374 | | -# Author: Raymond Hettinger |
375 | | -# License: MIT |
376 | | - |
377 | | -from collections.abc import MutableSet |
378 | | - |
379 | | - |
380 | | -Link: TypeAlias = "list[Any]" |
381 | | - |
382 | | - |
383 | | -class OrderedSet(MutableSet[T]): |
384 | | - end: Link |
385 | | - map: dict[T, Link] |
386 | | - |
387 | | - def __init__(self, iterable: Iterable[T] | None = None) -> None: |
388 | | - self.end = end = [] |
389 | | - end += [None, end, end] # sentinel node for doubly linked list |
390 | | - self.map = {} # key --> [key, prev, next] |
391 | | - |
392 | | - if iterable is not None: |
393 | | - self |= iterable |
394 | | - |
395 | | - @override |
396 | | - def __len__(self) -> int: |
397 | | - return len(self.map) |
398 | | - |
399 | | - @override |
400 | | - def __contains__(self, key: object) -> bool: |
401 | | - return key in self.map |
402 | | - |
403 | | - @override |
404 | | - def add(self, value: T) -> None: |
405 | | - if value not in self.map: |
406 | | - end = self.end |
407 | | - curr = end[1] |
408 | | - curr[2] = end[1] = self.map[value] = [value, curr, end] |
409 | | - |
410 | | - @override |
411 | | - def discard(self, value: T) -> None: |
412 | | - if value in self.map: |
413 | | - _key, prev, next = self.map.pop(value) |
414 | | - prev[2] = next |
415 | | - next[1] = prev |
416 | | - |
417 | | - @override |
418 | | - def __iter__(self) -> Iterator[T]: |
419 | | - end = self.end |
420 | | - curr = end[2] |
421 | | - while curr is not end: |
422 | | - yield curr[0] |
423 | | - curr = curr[2] |
424 | | - |
425 | | - def __reversed__(self) -> Iterator[T]: |
426 | | - end = self.end |
427 | | - curr = end[1] |
428 | | - while curr is not end: |
429 | | - yield curr[0] |
430 | | - curr = curr[1] |
431 | | - |
432 | | - @override |
433 | | - def pop(self, last: bool = True) -> T: |
434 | | - if not self: |
435 | | - raise KeyError("set is empty") |
436 | | - |
437 | | - key = self.end[1][0] if last else self.end[2][0] |
438 | | - self.discard(key) |
439 | | - |
440 | | - return key |
441 | | - |
442 | | - @override |
443 | | - def __repr__(self) -> str: |
444 | | - if not self: |
445 | | - return f"{self.__class__.__name__}()" |
446 | | - |
447 | | - return f"{self.__class__.__name__}({list(self)!r})" |
448 | | - |
449 | | - @override |
450 | | - def __eq__(self, other: object) -> bool: |
451 | | - if isinstance(other, OrderedSet): |
452 | | - return len(self) == len(other) and list(self) == list(other) |
453 | | - |
454 | | - return set(self) == set(other) |
455 | | - |
456 | | -# }}} |
457 | | - |
458 | | - |
459 | 369 | class KernelCacheMixin(ABC): |
460 | 370 | name: str |
461 | 371 |
|
|
0 commit comments