Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/accelerator_partitioner.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/const_fold.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/debug.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/graph_gradual_typechecker.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/merge_matmul.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/meta_tracer.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/normalize.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/optimization.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/partitioner_utils.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/proxy_tensor.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/recording.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/refinement_types.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/rewriter.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/schema_type_annotation.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/sym_node.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/symbolic_shapes.cpython-312.pyc +3 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/unify_refinements.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/validator.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/__init__.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/constraint.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/constraint_generator.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/constraint_transformation.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/operation.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/transform_to_z3.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/util.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/z3_types.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/__init__.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/core.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/dispatch.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/match.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/more.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/unification_tools.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/utils.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/variable.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__init__.py +7 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__pycache__/__init__.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__pycache__/conflict.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__pycache__/core.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__pycache__/dispatcher.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__pycache__/utils.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__pycache__/variadic.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/conflict.py +139 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/core.py +84 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/dispatcher.py +453 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/utils.py +127 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/variadic.py +96 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/passes/__pycache__/__init__.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/passes/__pycache__/_tensorify_python_scalars.cpython-312.pyc +0 -0
- tool_server/.venv/lib/python3.12/site-packages/torch/fx/passes/__pycache__/annotate_getitem_nodes.cpython-312.pyc +0 -0
.gitattributes
CHANGED
|
@@ -4483,3 +4483,4 @@ tool_server/.venv/lib/python3.12/site-packages/torch/backends/_nnapi/__pycache__
|
|
| 4483 |
tool_server/.venv/lib/python3.12/site-packages/torch/distributed/__pycache__/distributed_c10d.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4484 |
tool_server/.venv/lib/python3.12/site-packages/torch/distributed/fsdp/__pycache__/_flat_param.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4485 |
tool_server/.venv/lib/python3.12/site-packages/torch/distributed/fsdp/__pycache__/fully_sharded_data_parallel.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 4483 |
tool_server/.venv/lib/python3.12/site-packages/torch/distributed/__pycache__/distributed_c10d.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4484 |
tool_server/.venv/lib/python3.12/site-packages/torch/distributed/fsdp/__pycache__/_flat_param.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4485 |
tool_server/.venv/lib/python3.12/site-packages/torch/distributed/fsdp/__pycache__/fully_sharded_data_parallel.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 4486 |
+
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/symbolic_shapes.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/accelerator_partitioner.cpython-312.pyc
ADDED
|
Binary file (44.4 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/const_fold.cpython-312.pyc
ADDED
|
Binary file (12.5 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/debug.cpython-312.pyc
ADDED
|
Binary file (1.7 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/graph_gradual_typechecker.cpython-312.pyc
ADDED
|
Binary file (46.9 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/merge_matmul.cpython-312.pyc
ADDED
|
Binary file (6.36 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/meta_tracer.cpython-312.pyc
ADDED
|
Binary file (15.6 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/normalize.cpython-312.pyc
ADDED
|
Binary file (7.34 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/optimization.cpython-312.pyc
ADDED
|
Binary file (24.8 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/partitioner_utils.cpython-312.pyc
ADDED
|
Binary file (12.6 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/proxy_tensor.cpython-312.pyc
ADDED
|
Binary file (97.5 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/recording.cpython-312.pyc
ADDED
|
Binary file (16 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/refinement_types.cpython-312.pyc
ADDED
|
Binary file (1.36 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/rewriter.cpython-312.pyc
ADDED
|
Binary file (7.76 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/schema_type_annotation.cpython-312.pyc
ADDED
|
Binary file (6.53 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/sym_node.cpython-312.pyc
ADDED
|
Binary file (63.6 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/symbolic_shapes.cpython-312.pyc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5525c1f6f8ff8a3f25aa45ec8122798085e518bab5b5147f830966cffd979fe5
|
| 3 |
+
size 291992
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/unify_refinements.cpython-312.pyc
ADDED
|
Binary file (4.57 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/__pycache__/validator.cpython-312.pyc
ADDED
|
Binary file (41.1 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (213 Bytes). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/constraint.cpython-312.pyc
ADDED
|
Binary file (27.5 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/constraint_generator.cpython-312.pyc
ADDED
|
Binary file (62.7 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/constraint_transformation.cpython-312.pyc
ADDED
|
Binary file (45.8 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/operation.cpython-312.pyc
ADDED
|
Binary file (524 Bytes). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/transform_to_z3.cpython-312.pyc
ADDED
|
Binary file (15.6 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/util.cpython-312.pyc
ADDED
|
Binary file (2.1 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/migrate_gradual_types/__pycache__/z3_types.cpython-312.pyc
ADDED
|
Binary file (1.42 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (400 Bytes). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/core.cpython-312.pyc
ADDED
|
Binary file (3.45 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/dispatch.cpython-312.pyc
ADDED
|
Binary file (363 Bytes). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/match.cpython-312.pyc
ADDED
|
Binary file (5.74 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/more.cpython-312.pyc
ADDED
|
Binary file (4.61 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/unification_tools.cpython-312.pyc
ADDED
|
Binary file (13.7 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/utils.cpython-312.pyc
ADDED
|
Binary file (4.38 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/__pycache__/variable.cpython-312.pyc
ADDED
|
Binary file (3.86 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .core import dispatch
|
| 2 |
+
from .dispatcher import (
|
| 3 |
+
Dispatcher,
|
| 4 |
+
halt_ordering,
|
| 5 |
+
MDNotImplementedError,
|
| 6 |
+
restart_ordering,
|
| 7 |
+
)
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (396 Bytes). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__pycache__/conflict.cpython-312.pyc
ADDED
|
Binary file (6.65 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__pycache__/core.cpython-312.pyc
ADDED
|
Binary file (3.21 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__pycache__/dispatcher.cpython-312.pyc
ADDED
|
Binary file (20.1 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__pycache__/utils.cpython-312.pyc
ADDED
|
Binary file (5.38 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/__pycache__/variadic.cpython-312.pyc
ADDED
|
Binary file (4.27 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/conflict.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
import operator
|
| 3 |
+
|
| 4 |
+
from .utils import _toposort, groupby
|
| 5 |
+
from .variadic import isvariadic
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
__all__ = [
|
| 9 |
+
"AmbiguityWarning",
|
| 10 |
+
"supercedes",
|
| 11 |
+
"consistent",
|
| 12 |
+
"ambiguous",
|
| 13 |
+
"ambiguities",
|
| 14 |
+
"super_signature",
|
| 15 |
+
"edge",
|
| 16 |
+
"ordering",
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class AmbiguityWarning(Warning):
|
| 21 |
+
pass
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def supercedes(a, b):
|
| 25 |
+
"""A is consistent and strictly more specific than B"""
|
| 26 |
+
if len(a) < len(b):
|
| 27 |
+
# only case is if a is empty and b is variadic
|
| 28 |
+
return not a and len(b) == 1 and isvariadic(b[-1])
|
| 29 |
+
elif len(a) == len(b):
|
| 30 |
+
return all(map(issubclass, a, b))
|
| 31 |
+
else:
|
| 32 |
+
# len(a) > len(b)
|
| 33 |
+
p1 = 0
|
| 34 |
+
p2 = 0
|
| 35 |
+
while p1 < len(a) and p2 < len(b):
|
| 36 |
+
cur_a = a[p1]
|
| 37 |
+
cur_b = b[p2]
|
| 38 |
+
if not (isvariadic(cur_a) or isvariadic(cur_b)):
|
| 39 |
+
if not issubclass(cur_a, cur_b):
|
| 40 |
+
return False
|
| 41 |
+
p1 += 1
|
| 42 |
+
p2 += 1
|
| 43 |
+
elif isvariadic(cur_a):
|
| 44 |
+
assert p1 == len(a) - 1
|
| 45 |
+
return p2 == len(b) - 1 and issubclass(cur_a, cur_b)
|
| 46 |
+
elif isvariadic(cur_b):
|
| 47 |
+
assert p2 == len(b) - 1
|
| 48 |
+
if not issubclass(cur_a, cur_b):
|
| 49 |
+
return False
|
| 50 |
+
p1 += 1
|
| 51 |
+
return p2 == len(b) - 1 and p1 == len(a)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def consistent(a, b):
|
| 55 |
+
"""It is possible for an argument list to satisfy both A and B"""
|
| 56 |
+
|
| 57 |
+
# Need to check for empty args
|
| 58 |
+
if not a:
|
| 59 |
+
return not b or isvariadic(b[0])
|
| 60 |
+
if not b:
|
| 61 |
+
return not a or isvariadic(a[0])
|
| 62 |
+
|
| 63 |
+
# Non-empty args check for mutual subclasses
|
| 64 |
+
if len(a) == len(b):
|
| 65 |
+
return all(issubclass(aa, bb) or issubclass(bb, aa) for aa, bb in zip(a, b))
|
| 66 |
+
else:
|
| 67 |
+
p1 = 0
|
| 68 |
+
p2 = 0
|
| 69 |
+
while p1 < len(a) and p2 < len(b):
|
| 70 |
+
cur_a = a[p1]
|
| 71 |
+
cur_b = b[p2]
|
| 72 |
+
if not issubclass(cur_b, cur_a) and not issubclass(cur_a, cur_b):
|
| 73 |
+
return False
|
| 74 |
+
if not (isvariadic(cur_a) or isvariadic(cur_b)):
|
| 75 |
+
p1 += 1
|
| 76 |
+
p2 += 1
|
| 77 |
+
elif isvariadic(cur_a):
|
| 78 |
+
p2 += 1
|
| 79 |
+
elif isvariadic(cur_b):
|
| 80 |
+
p1 += 1
|
| 81 |
+
# We only need to check for variadic ends
|
| 82 |
+
# Variadic types are guaranteed to be the last element
|
| 83 |
+
return (
|
| 84 |
+
isvariadic(cur_a) # type: ignore[possibly-undefined]
|
| 85 |
+
and p2 == len(b)
|
| 86 |
+
or isvariadic(cur_b) # type: ignore[possibly-undefined]
|
| 87 |
+
and p1 == len(a)
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def ambiguous(a, b):
|
| 92 |
+
"""A is consistent with B but neither is strictly more specific"""
|
| 93 |
+
return consistent(a, b) and not (supercedes(a, b) or supercedes(b, a))
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def ambiguities(signatures):
|
| 97 |
+
"""All signature pairs such that A is ambiguous with B"""
|
| 98 |
+
signatures = list(map(tuple, signatures))
|
| 99 |
+
return {
|
| 100 |
+
(a, b)
|
| 101 |
+
for a in signatures
|
| 102 |
+
for b in signatures
|
| 103 |
+
if hash(a) < hash(b)
|
| 104 |
+
and ambiguous(a, b)
|
| 105 |
+
and not any(supercedes(c, a) and supercedes(c, b) for c in signatures)
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def super_signature(signatures):
|
| 110 |
+
"""A signature that would break ambiguities"""
|
| 111 |
+
n = len(signatures[0])
|
| 112 |
+
assert all(len(s) == n for s in signatures)
|
| 113 |
+
|
| 114 |
+
return [max((type.mro(sig[i]) for sig in signatures), key=len)[0] for i in range(n)]
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def edge(a, b, tie_breaker=hash):
|
| 118 |
+
"""A should be checked before B
|
| 119 |
+
Tie broken by tie_breaker, defaults to ``hash``
|
| 120 |
+
"""
|
| 121 |
+
# A either supercedes B and B does not supercede A or if B does then call
|
| 122 |
+
# tie_breaker
|
| 123 |
+
return supercedes(a, b) and (
|
| 124 |
+
not supercedes(b, a) or tie_breaker(a) > tie_breaker(b)
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def ordering(signatures):
|
| 129 |
+
"""A sane ordering of signatures to check, first to last
|
| 130 |
+
Topological sort of edges as given by ``edge`` and ``supercedes``
|
| 131 |
+
"""
|
| 132 |
+
signatures = list(map(tuple, signatures))
|
| 133 |
+
edges = [(a, b) for a in signatures for b in signatures if edge(a, b)]
|
| 134 |
+
edges = groupby(operator.itemgetter(0), edges)
|
| 135 |
+
for s in signatures:
|
| 136 |
+
if s not in edges:
|
| 137 |
+
edges[s] = []
|
| 138 |
+
edges = {k: [b for a, b in v] for k, v in edges.items()} # type: ignore[assignment, attr-defined]
|
| 139 |
+
return _toposort(edges)
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/core.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
import inspect
|
| 3 |
+
|
| 4 |
+
from .dispatcher import Dispatcher, MethodDispatcher
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
global_namespace = {} # type: ignore[var-annotated]
|
| 8 |
+
|
| 9 |
+
__all__ = ["dispatch", "ismethod"]
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def dispatch(*types, **kwargs):
|
| 13 |
+
"""Dispatch function on the types of the inputs
|
| 14 |
+
Supports dispatch on all non-keyword arguments.
|
| 15 |
+
Collects implementations based on the function name. Ignores namespaces.
|
| 16 |
+
If ambiguous type signatures occur a warning is raised when the function is
|
| 17 |
+
defined suggesting the additional method to break the ambiguity.
|
| 18 |
+
|
| 19 |
+
Example:
|
| 20 |
+
>>> # xdoctest: +SKIP
|
| 21 |
+
>>> @dispatch(int)
|
| 22 |
+
... def f(x):
|
| 23 |
+
... return x + 1
|
| 24 |
+
>>> @dispatch(float)
|
| 25 |
+
... def f(x):
|
| 26 |
+
... return x - 1
|
| 27 |
+
>>> # xdoctest: +SKIP
|
| 28 |
+
>>> f(3)
|
| 29 |
+
4
|
| 30 |
+
>>> f(3.0)
|
| 31 |
+
2.0
|
| 32 |
+
>>> # Specify an isolated namespace with the namespace keyword argument
|
| 33 |
+
>>> my_namespace = {}
|
| 34 |
+
>>> @dispatch(int, namespace=my_namespace)
|
| 35 |
+
... def foo(x):
|
| 36 |
+
... return x + 1
|
| 37 |
+
>>> # Dispatch on instance methods within classes
|
| 38 |
+
>>> class MyClass(object):
|
| 39 |
+
... @dispatch(list)
|
| 40 |
+
... def __init__(self, data):
|
| 41 |
+
... self.data = data
|
| 42 |
+
...
|
| 43 |
+
... @dispatch(int)
|
| 44 |
+
... def __init__(self, datum):
|
| 45 |
+
... self.data = [datum]
|
| 46 |
+
>>> MyClass([1, 2, 3]).data
|
| 47 |
+
[1, 2, 3]
|
| 48 |
+
>>> MyClass(3).data
|
| 49 |
+
[3]
|
| 50 |
+
"""
|
| 51 |
+
namespace = kwargs.get("namespace", global_namespace)
|
| 52 |
+
|
| 53 |
+
types = tuple(types)
|
| 54 |
+
|
| 55 |
+
def _df(func):
|
| 56 |
+
name = func.__name__
|
| 57 |
+
|
| 58 |
+
if ismethod(func):
|
| 59 |
+
dispatcher = inspect.currentframe().f_back.f_locals.get( # type: ignore[union-attr]
|
| 60 |
+
name, # type: ignore[union-attr]
|
| 61 |
+
MethodDispatcher(name),
|
| 62 |
+
)
|
| 63 |
+
else:
|
| 64 |
+
if name not in namespace:
|
| 65 |
+
namespace[name] = Dispatcher(name)
|
| 66 |
+
dispatcher = namespace[name]
|
| 67 |
+
|
| 68 |
+
dispatcher.add(types, func)
|
| 69 |
+
return dispatcher
|
| 70 |
+
|
| 71 |
+
return _df
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def ismethod(func):
|
| 75 |
+
"""Is func a method?
|
| 76 |
+
Note that this has to work as the method is defined but before the class is
|
| 77 |
+
defined. At this stage methods look like functions.
|
| 78 |
+
"""
|
| 79 |
+
if hasattr(inspect, "signature"):
|
| 80 |
+
signature = inspect.signature(func)
|
| 81 |
+
return signature.parameters.get("self", None) is not None
|
| 82 |
+
else:
|
| 83 |
+
spec = inspect.getfullargspec(func) # type: ignore[union-attr, assignment]
|
| 84 |
+
return spec and spec.args and spec.args[0] == "self"
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/dispatcher.py
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
import inspect
|
| 3 |
+
import itertools as itl
|
| 4 |
+
from typing_extensions import deprecated
|
| 5 |
+
from warnings import warn
|
| 6 |
+
|
| 7 |
+
from .conflict import ambiguities, AmbiguityWarning, ordering, super_signature
|
| 8 |
+
from .utils import expand_tuples
|
| 9 |
+
from .variadic import isvariadic, Variadic
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
__all__ = [
|
| 13 |
+
"MDNotImplementedError",
|
| 14 |
+
"ambiguity_warn",
|
| 15 |
+
"halt_ordering",
|
| 16 |
+
"restart_ordering",
|
| 17 |
+
"variadic_signature_matches_iter",
|
| 18 |
+
"variadic_signature_matches",
|
| 19 |
+
"Dispatcher",
|
| 20 |
+
"source",
|
| 21 |
+
"MethodDispatcher",
|
| 22 |
+
"str_signature",
|
| 23 |
+
"warning_text",
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class MDNotImplementedError(NotImplementedError):
|
| 28 |
+
"""A NotImplementedError for multiple dispatch"""
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def ambiguity_warn(dispatcher, ambiguities):
|
| 32 |
+
"""Raise warning when ambiguity is detected
|
| 33 |
+
Parameters
|
| 34 |
+
----------
|
| 35 |
+
dispatcher : Dispatcher
|
| 36 |
+
The dispatcher on which the ambiguity was detected
|
| 37 |
+
ambiguities : set
|
| 38 |
+
Set of type signature pairs that are ambiguous within this dispatcher
|
| 39 |
+
See Also:
|
| 40 |
+
Dispatcher.add
|
| 41 |
+
warning_text
|
| 42 |
+
"""
|
| 43 |
+
warn(warning_text(dispatcher.name, ambiguities), AmbiguityWarning)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
@deprecated(
|
| 47 |
+
"`halt_ordering` is deprecated, you can safely remove this call.",
|
| 48 |
+
category=FutureWarning,
|
| 49 |
+
)
|
| 50 |
+
def halt_ordering():
|
| 51 |
+
"""Deprecated interface to temporarily disable ordering."""
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
@deprecated(
|
| 55 |
+
"`restart_ordering` is deprecated, if you would like to eagerly order the dispatchers, "
|
| 56 |
+
"you should call the `reorder()` method on each dispatcher.",
|
| 57 |
+
category=FutureWarning,
|
| 58 |
+
)
|
| 59 |
+
def restart_ordering(on_ambiguity=ambiguity_warn):
|
| 60 |
+
"""Deprecated interface to temporarily resume ordering."""
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def variadic_signature_matches_iter(types, full_signature):
|
| 64 |
+
"""Check if a set of input types matches a variadic signature.
|
| 65 |
+
Notes
|
| 66 |
+
-----
|
| 67 |
+
The algorithm is as follows:
|
| 68 |
+
Initialize the current signature to the first in the sequence
|
| 69 |
+
For each type in `types`:
|
| 70 |
+
If the current signature is variadic
|
| 71 |
+
If the type matches the signature
|
| 72 |
+
yield True
|
| 73 |
+
Else
|
| 74 |
+
Try to get the next signature
|
| 75 |
+
If no signatures are left we can't possibly have a match
|
| 76 |
+
so yield False
|
| 77 |
+
Else
|
| 78 |
+
yield True if the type matches the current signature
|
| 79 |
+
Get the next signature
|
| 80 |
+
"""
|
| 81 |
+
sigiter = iter(full_signature)
|
| 82 |
+
sig = next(sigiter)
|
| 83 |
+
for typ in types:
|
| 84 |
+
matches = issubclass(typ, sig)
|
| 85 |
+
yield matches
|
| 86 |
+
if not isvariadic(sig):
|
| 87 |
+
# we're not matching a variadic argument, so move to the next
|
| 88 |
+
# element in the signature
|
| 89 |
+
sig = next(sigiter)
|
| 90 |
+
else:
|
| 91 |
+
try:
|
| 92 |
+
sig = next(sigiter)
|
| 93 |
+
except StopIteration:
|
| 94 |
+
assert isvariadic(sig)
|
| 95 |
+
yield True
|
| 96 |
+
else:
|
| 97 |
+
# We have signature items left over, so all of our arguments
|
| 98 |
+
# haven't matched
|
| 99 |
+
yield False
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def variadic_signature_matches(types, full_signature):
|
| 103 |
+
# No arguments always matches a variadic signature
|
| 104 |
+
assert full_signature
|
| 105 |
+
return all(variadic_signature_matches_iter(types, full_signature))
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class Dispatcher:
|
| 109 |
+
"""Dispatch methods based on type signature
|
| 110 |
+
Use ``dispatch`` to add implementations
|
| 111 |
+
Examples
|
| 112 |
+
--------
|
| 113 |
+
>>> # xdoctest: +SKIP("bad import name")
|
| 114 |
+
>>> from multipledispatch import dispatch
|
| 115 |
+
>>> @dispatch(int)
|
| 116 |
+
... def f(x):
|
| 117 |
+
... return x + 1
|
| 118 |
+
>>> @dispatch(float)
|
| 119 |
+
... def f(x):
|
| 120 |
+
... return x - 1
|
| 121 |
+
>>> f(3)
|
| 122 |
+
4
|
| 123 |
+
>>> f(3.0)
|
| 124 |
+
2.0
|
| 125 |
+
"""
|
| 126 |
+
|
| 127 |
+
__slots__ = "__name__", "name", "funcs", "_ordering", "_cache", "doc"
|
| 128 |
+
|
| 129 |
+
def __init__(self, name, doc=None):
|
| 130 |
+
self.name = self.__name__ = name
|
| 131 |
+
self.funcs = {}
|
| 132 |
+
self.doc = doc
|
| 133 |
+
|
| 134 |
+
self._cache = {}
|
| 135 |
+
|
| 136 |
+
def register(self, *types, **kwargs):
|
| 137 |
+
"""register dispatcher with new implementation
|
| 138 |
+
>>> # xdoctest: +SKIP
|
| 139 |
+
>>> f = Dispatcher("f")
|
| 140 |
+
>>> @f.register(int)
|
| 141 |
+
... def inc(x):
|
| 142 |
+
... return x + 1
|
| 143 |
+
>>> @f.register(float)
|
| 144 |
+
... def dec(x):
|
| 145 |
+
... return x - 1
|
| 146 |
+
>>> @f.register(list)
|
| 147 |
+
... @f.register(tuple)
|
| 148 |
+
... def reverse(x):
|
| 149 |
+
... return x[::-1]
|
| 150 |
+
>>> f(1)
|
| 151 |
+
2
|
| 152 |
+
>>> f(1.0)
|
| 153 |
+
0.0
|
| 154 |
+
>>> f([1, 2, 3])
|
| 155 |
+
[3, 2, 1]
|
| 156 |
+
"""
|
| 157 |
+
|
| 158 |
+
def _df(func):
|
| 159 |
+
self.add(types, func, **kwargs) # type: ignore[call-arg]
|
| 160 |
+
return func
|
| 161 |
+
|
| 162 |
+
return _df
|
| 163 |
+
|
| 164 |
+
@classmethod
|
| 165 |
+
def get_func_params(cls, func):
|
| 166 |
+
if hasattr(inspect, "signature"):
|
| 167 |
+
sig = inspect.signature(func)
|
| 168 |
+
return sig.parameters.values()
|
| 169 |
+
|
| 170 |
+
@classmethod
|
| 171 |
+
def get_func_annotations(cls, func):
|
| 172 |
+
"""get annotations of function positional parameters"""
|
| 173 |
+
params = cls.get_func_params(func)
|
| 174 |
+
if params:
|
| 175 |
+
Parameter = inspect.Parameter
|
| 176 |
+
|
| 177 |
+
params = (
|
| 178 |
+
param
|
| 179 |
+
for param in params
|
| 180 |
+
if param.kind
|
| 181 |
+
in (Parameter.POSITIONAL_ONLY, Parameter.POSITIONAL_OR_KEYWORD)
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
annotations = tuple(param.annotation for param in params)
|
| 185 |
+
|
| 186 |
+
if all(ann is not Parameter.empty for ann in annotations):
|
| 187 |
+
return annotations
|
| 188 |
+
|
| 189 |
+
def add(self, signature, func):
|
| 190 |
+
"""Add new types/method pair to dispatcher
|
| 191 |
+
>>> # xdoctest: +SKIP
|
| 192 |
+
>>> D = Dispatcher("add")
|
| 193 |
+
>>> D.add((int, int), lambda x, y: x + y)
|
| 194 |
+
>>> D.add((float, float), lambda x, y: x + y)
|
| 195 |
+
>>> D(1, 2)
|
| 196 |
+
3
|
| 197 |
+
>>> D(1, 2.0)
|
| 198 |
+
Traceback (most recent call last):
|
| 199 |
+
...
|
| 200 |
+
NotImplementedError: Could not find signature for add: <int, float>
|
| 201 |
+
>>> # When ``add`` detects a warning it calls the ``on_ambiguity`` callback
|
| 202 |
+
>>> # with a dispatcher/itself, and a set of ambiguous type signature pairs
|
| 203 |
+
>>> # as inputs. See ``ambiguity_warn`` for an example.
|
| 204 |
+
"""
|
| 205 |
+
# Handle annotations
|
| 206 |
+
if not signature:
|
| 207 |
+
annotations = self.get_func_annotations(func)
|
| 208 |
+
if annotations:
|
| 209 |
+
signature = annotations
|
| 210 |
+
|
| 211 |
+
# Handle union types
|
| 212 |
+
if any(isinstance(typ, tuple) for typ in signature):
|
| 213 |
+
for typs in expand_tuples(signature):
|
| 214 |
+
self.add(typs, func)
|
| 215 |
+
return
|
| 216 |
+
|
| 217 |
+
new_signature = []
|
| 218 |
+
|
| 219 |
+
for index, typ in enumerate(signature, start=1):
|
| 220 |
+
if not isinstance(typ, (type, list)):
|
| 221 |
+
str_sig = ", ".join(
|
| 222 |
+
c.__name__ if isinstance(c, type) else str(c) for c in signature
|
| 223 |
+
)
|
| 224 |
+
raise TypeError(
|
| 225 |
+
f"Tried to dispatch on non-type: {typ}\n"
|
| 226 |
+
f"In signature: <{str_sig}>\n"
|
| 227 |
+
f"In function: {self.name}"
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
# handle variadic signatures
|
| 231 |
+
if isinstance(typ, list):
|
| 232 |
+
if index != len(signature):
|
| 233 |
+
raise TypeError("Variadic signature must be the last element")
|
| 234 |
+
|
| 235 |
+
if len(typ) != 1:
|
| 236 |
+
raise TypeError(
|
| 237 |
+
"Variadic signature must contain exactly one element. "
|
| 238 |
+
"To use a variadic union type place the desired types "
|
| 239 |
+
"inside of a tuple, e.g., [(int, str)]"
|
| 240 |
+
)
|
| 241 |
+
new_signature.append(Variadic[typ[0]])
|
| 242 |
+
else:
|
| 243 |
+
new_signature.append(typ)
|
| 244 |
+
|
| 245 |
+
self.funcs[tuple(new_signature)] = func
|
| 246 |
+
self._cache.clear()
|
| 247 |
+
|
| 248 |
+
try:
|
| 249 |
+
del self._ordering
|
| 250 |
+
except AttributeError:
|
| 251 |
+
pass
|
| 252 |
+
|
| 253 |
+
@property
|
| 254 |
+
def ordering(self):
|
| 255 |
+
try:
|
| 256 |
+
return self._ordering
|
| 257 |
+
except AttributeError:
|
| 258 |
+
return self.reorder()
|
| 259 |
+
|
| 260 |
+
def reorder(self, on_ambiguity=ambiguity_warn):
|
| 261 |
+
self._ordering = od = ordering(self.funcs)
|
| 262 |
+
amb = ambiguities(self.funcs)
|
| 263 |
+
if amb:
|
| 264 |
+
on_ambiguity(self, amb)
|
| 265 |
+
return od
|
| 266 |
+
|
| 267 |
+
def __call__(self, *args, **kwargs):
|
| 268 |
+
types = tuple([type(arg) for arg in args])
|
| 269 |
+
try:
|
| 270 |
+
func = self._cache[types]
|
| 271 |
+
except KeyError as e:
|
| 272 |
+
func = self.dispatch(*types)
|
| 273 |
+
if not func:
|
| 274 |
+
raise NotImplementedError(
|
| 275 |
+
f"Could not find signature for {self.name}: <{str_signature(types)}>"
|
| 276 |
+
) from e
|
| 277 |
+
self._cache[types] = func
|
| 278 |
+
try:
|
| 279 |
+
return func(*args, **kwargs)
|
| 280 |
+
|
| 281 |
+
except MDNotImplementedError as e:
|
| 282 |
+
funcs = self.dispatch_iter(*types)
|
| 283 |
+
next(funcs) # burn first
|
| 284 |
+
for func in funcs:
|
| 285 |
+
try:
|
| 286 |
+
return func(*args, **kwargs)
|
| 287 |
+
except MDNotImplementedError:
|
| 288 |
+
pass
|
| 289 |
+
|
| 290 |
+
raise NotImplementedError(
|
| 291 |
+
"Matching functions for "
|
| 292 |
+
f"{self.name}: <{str_signature(types)}> found, but none completed successfully",
|
| 293 |
+
) from e
|
| 294 |
+
|
| 295 |
+
def __str__(self):
|
| 296 |
+
return f"<dispatched {self.name}>"
|
| 297 |
+
|
| 298 |
+
__repr__ = __str__
|
| 299 |
+
|
| 300 |
+
def dispatch(self, *types):
|
| 301 |
+
"""Determine appropriate implementation for this type signature
|
| 302 |
+
This method is internal. Users should call this object as a function.
|
| 303 |
+
Implementation resolution occurs within the ``__call__`` method.
|
| 304 |
+
>>> # xdoctest: +SKIP
|
| 305 |
+
>>> from multipledispatch import dispatch
|
| 306 |
+
>>> @dispatch(int)
|
| 307 |
+
... def inc(x):
|
| 308 |
+
... return x + 1
|
| 309 |
+
>>> implementation = inc.dispatch(int)
|
| 310 |
+
>>> implementation(3)
|
| 311 |
+
4
|
| 312 |
+
>>> print(inc.dispatch(float))
|
| 313 |
+
None
|
| 314 |
+
See Also:
|
| 315 |
+
``multipledispatch.conflict`` - module to determine resolution order
|
| 316 |
+
"""
|
| 317 |
+
|
| 318 |
+
if types in self.funcs:
|
| 319 |
+
return self.funcs[types]
|
| 320 |
+
|
| 321 |
+
try:
|
| 322 |
+
return next(self.dispatch_iter(*types))
|
| 323 |
+
except StopIteration:
|
| 324 |
+
return None
|
| 325 |
+
|
| 326 |
+
def dispatch_iter(self, *types):
|
| 327 |
+
n = len(types)
|
| 328 |
+
for signature in self.ordering:
|
| 329 |
+
if len(signature) == n and all(map(issubclass, types, signature)):
|
| 330 |
+
result = self.funcs[signature]
|
| 331 |
+
yield result
|
| 332 |
+
elif len(signature) and isvariadic(signature[-1]):
|
| 333 |
+
if variadic_signature_matches(types, signature):
|
| 334 |
+
result = self.funcs[signature]
|
| 335 |
+
yield result
|
| 336 |
+
|
| 337 |
+
@deprecated(
|
| 338 |
+
"`resolve()` is deprecated, use `dispatch(*types)`", category=FutureWarning
|
| 339 |
+
)
|
| 340 |
+
def resolve(self, types):
|
| 341 |
+
"""Determine appropriate implementation for this type signature
|
| 342 |
+
.. deprecated:: 0.4.4
|
| 343 |
+
Use ``dispatch(*types)`` instead
|
| 344 |
+
"""
|
| 345 |
+
return self.dispatch(*types)
|
| 346 |
+
|
| 347 |
+
def __getstate__(self):
|
| 348 |
+
return {"name": self.name, "funcs": self.funcs}
|
| 349 |
+
|
| 350 |
+
def __setstate__(self, d):
|
| 351 |
+
self.name = d["name"]
|
| 352 |
+
self.funcs = d["funcs"]
|
| 353 |
+
self._ordering = ordering(self.funcs)
|
| 354 |
+
self._cache = {}
|
| 355 |
+
|
| 356 |
+
@property
|
| 357 |
+
def __doc__(self):
|
| 358 |
+
docs = [f"Multiply dispatched method: {self.name}"]
|
| 359 |
+
|
| 360 |
+
if self.doc:
|
| 361 |
+
docs.append(self.doc)
|
| 362 |
+
|
| 363 |
+
other = []
|
| 364 |
+
for sig in self.ordering[::-1]:
|
| 365 |
+
func = self.funcs[sig]
|
| 366 |
+
if func.__doc__:
|
| 367 |
+
s = f"Inputs: <{str_signature(sig)}>\n"
|
| 368 |
+
s += "-" * len(s) + "\n"
|
| 369 |
+
s += func.__doc__.strip()
|
| 370 |
+
docs.append(s)
|
| 371 |
+
else:
|
| 372 |
+
other.append(str_signature(sig))
|
| 373 |
+
|
| 374 |
+
if other:
|
| 375 |
+
docs.append("Other signatures:\n " + "\n ".join(other))
|
| 376 |
+
|
| 377 |
+
return "\n\n".join(docs)
|
| 378 |
+
|
| 379 |
+
def _help(self, *args):
|
| 380 |
+
return self.dispatch(*map(type, args)).__doc__
|
| 381 |
+
|
| 382 |
+
def help(self, *args, **kwargs):
|
| 383 |
+
"""Print docstring for the function corresponding to inputs"""
|
| 384 |
+
print(self._help(*args))
|
| 385 |
+
|
| 386 |
+
def _source(self, *args):
|
| 387 |
+
func = self.dispatch(*map(type, args))
|
| 388 |
+
if not func:
|
| 389 |
+
raise TypeError("No function found")
|
| 390 |
+
return source(func)
|
| 391 |
+
|
| 392 |
+
def source(self, *args, **kwargs):
|
| 393 |
+
"""Print source code for the function corresponding to inputs"""
|
| 394 |
+
print(self._source(*args))
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
def source(func):
|
| 398 |
+
s = f"File: {inspect.getsourcefile(func)}\n\n"
|
| 399 |
+
s = s + inspect.getsource(func)
|
| 400 |
+
return s
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
class MethodDispatcher(Dispatcher):
|
| 404 |
+
"""Dispatch methods based on type signature
|
| 405 |
+
See Also:
|
| 406 |
+
Dispatcher
|
| 407 |
+
"""
|
| 408 |
+
|
| 409 |
+
__slots__ = ("obj", "cls")
|
| 410 |
+
|
| 411 |
+
@classmethod
|
| 412 |
+
def get_func_params(cls, func):
|
| 413 |
+
if hasattr(inspect, "signature"):
|
| 414 |
+
sig = inspect.signature(func)
|
| 415 |
+
return itl.islice(sig.parameters.values(), 1, None)
|
| 416 |
+
|
| 417 |
+
def __get__(self, instance, owner):
|
| 418 |
+
self.obj = instance
|
| 419 |
+
self.cls = owner
|
| 420 |
+
return self
|
| 421 |
+
|
| 422 |
+
def __call__(self, *args, **kwargs):
|
| 423 |
+
types = tuple([type(arg) for arg in args])
|
| 424 |
+
func = self.dispatch(*types)
|
| 425 |
+
if not func:
|
| 426 |
+
raise NotImplementedError(
|
| 427 |
+
f"Could not find signature for {self.name}: <{str_signature(types)}>"
|
| 428 |
+
)
|
| 429 |
+
return func(self.obj, *args, **kwargs)
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
def str_signature(sig):
|
| 433 |
+
"""String representation of type signature
|
| 434 |
+
>>> str_signature((int, float))
|
| 435 |
+
'int, float'
|
| 436 |
+
"""
|
| 437 |
+
return ", ".join(cls.__name__ for cls in sig)
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
def warning_text(name, amb):
|
| 441 |
+
"""The text for ambiguity warnings"""
|
| 442 |
+
text = f"\nAmbiguities exist in dispatched function {name}\n\n"
|
| 443 |
+
text += "The following signatures may result in ambiguous behavior:\n"
|
| 444 |
+
for pair in amb:
|
| 445 |
+
text += "\t" + ", ".join("[" + str_signature(s) + "]" for s in pair) + "\n"
|
| 446 |
+
text += "\n\nConsider making the following additions:\n\n"
|
| 447 |
+
text += "\n\n".join(
|
| 448 |
+
[
|
| 449 |
+
"@dispatch(" + str_signature(super_signature(s)) + f")\ndef {name}(...)"
|
| 450 |
+
for s in amb
|
| 451 |
+
]
|
| 452 |
+
)
|
| 453 |
+
return text
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/utils.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
from collections import OrderedDict
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
__all__ = ["raises", "expand_tuples", "reverse_dict", "groupby", "typename"]
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def raises(err, lamda):
|
| 9 |
+
try:
|
| 10 |
+
lamda()
|
| 11 |
+
return False
|
| 12 |
+
except err:
|
| 13 |
+
return True
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def expand_tuples(L):
|
| 17 |
+
"""
|
| 18 |
+
>>> expand_tuples([1, (2, 3)])
|
| 19 |
+
[(1, 2), (1, 3)]
|
| 20 |
+
>>> expand_tuples([1, 2])
|
| 21 |
+
[(1, 2)]
|
| 22 |
+
"""
|
| 23 |
+
if not L:
|
| 24 |
+
return [()]
|
| 25 |
+
elif not isinstance(L[0], tuple):
|
| 26 |
+
rest = expand_tuples(L[1:])
|
| 27 |
+
return [(L[0],) + t for t in rest]
|
| 28 |
+
else:
|
| 29 |
+
rest = expand_tuples(L[1:])
|
| 30 |
+
return [(item,) + t for t in rest for item in L[0]]
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# Taken from theano/theano/gof/sched.py
|
| 34 |
+
# Avoids licensing issues because this was written by Matthew Rocklin
|
| 35 |
+
def _toposort(edges):
|
| 36 |
+
"""Topological sort algorithm by Kahn [1] - O(nodes + vertices)
|
| 37 |
+
inputs:
|
| 38 |
+
edges - a dict of the form {a: {b, c}} where b and c depend on a
|
| 39 |
+
outputs:
|
| 40 |
+
L - an ordered list of nodes that satisfy the dependencies of edges
|
| 41 |
+
>>> _toposort({1: (2, 3), 2: (3,)})
|
| 42 |
+
[1, 2, 3]
|
| 43 |
+
>>> # Closely follows the wikipedia page [2]
|
| 44 |
+
>>> # [1] Kahn, Arthur B. (1962), "Topological sorting of large networks",
|
| 45 |
+
>>> # Communications of the ACM
|
| 46 |
+
>>> # [2] http://en.wikipedia.org/wiki/Toposort#Algorithms
|
| 47 |
+
"""
|
| 48 |
+
incoming_edges = reverse_dict(edges)
|
| 49 |
+
incoming_edges = OrderedDict((k, set(val)) for k, val in incoming_edges.items())
|
| 50 |
+
S = OrderedDict.fromkeys(v for v in edges if v not in incoming_edges)
|
| 51 |
+
L = []
|
| 52 |
+
|
| 53 |
+
while S:
|
| 54 |
+
n, _ = S.popitem()
|
| 55 |
+
L.append(n)
|
| 56 |
+
for m in edges.get(n, ()):
|
| 57 |
+
assert n in incoming_edges[m]
|
| 58 |
+
incoming_edges[m].remove(n)
|
| 59 |
+
if not incoming_edges[m]:
|
| 60 |
+
S[m] = None
|
| 61 |
+
if any(incoming_edges.get(v, None) for v in edges):
|
| 62 |
+
raise ValueError("Input has cycles")
|
| 63 |
+
return L
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def reverse_dict(d):
|
| 67 |
+
"""Reverses direction of dependence dict
|
| 68 |
+
>>> d = {"a": (1, 2), "b": (2, 3), "c": ()}
|
| 69 |
+
>>> reverse_dict(d) # doctest: +SKIP
|
| 70 |
+
{1: ('a',), 2: ('a', 'b'), 3: ('b',)}
|
| 71 |
+
:note: dict order are not deterministic. As we iterate on the
|
| 72 |
+
input dict, it make the output of this function depend on the
|
| 73 |
+
dict order. So this function output order should be considered
|
| 74 |
+
as undeterministic.
|
| 75 |
+
"""
|
| 76 |
+
result = OrderedDict() # type: ignore[var-annotated]
|
| 77 |
+
for key in d:
|
| 78 |
+
for val in d[key]:
|
| 79 |
+
result[val] = result.get(val, ()) + (key,)
|
| 80 |
+
return result
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
# Taken from toolz
|
| 84 |
+
# Avoids licensing issues because this version was authored by Matthew Rocklin
|
| 85 |
+
def groupby(func, seq):
|
| 86 |
+
"""Group a collection by a key function
|
| 87 |
+
>>> names = ["Alice", "Bob", "Charlie", "Dan", "Edith", "Frank"]
|
| 88 |
+
>>> groupby(len, names) # doctest: +SKIP
|
| 89 |
+
{3: ['Bob', 'Dan'], 5: ['Alice', 'Edith', 'Frank'], 7: ['Charlie']}
|
| 90 |
+
>>> iseven = lambda x: x % 2 == 0
|
| 91 |
+
>>> groupby(iseven, [1, 2, 3, 4, 5, 6, 7, 8]) # doctest: +SKIP
|
| 92 |
+
{False: [1, 3, 5, 7], True: [2, 4, 6, 8]}
|
| 93 |
+
See Also:
|
| 94 |
+
``countby``
|
| 95 |
+
"""
|
| 96 |
+
|
| 97 |
+
d = OrderedDict() # type: ignore[var-annotated]
|
| 98 |
+
for item in seq:
|
| 99 |
+
key = func(item)
|
| 100 |
+
if key not in d:
|
| 101 |
+
d[key] = []
|
| 102 |
+
d[key].append(item)
|
| 103 |
+
return d
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def typename(type):
|
| 107 |
+
"""Get the name of `type`.
|
| 108 |
+
Parameters
|
| 109 |
+
----------
|
| 110 |
+
type : Union[Type, Tuple[Type]]
|
| 111 |
+
Returns
|
| 112 |
+
-------
|
| 113 |
+
str
|
| 114 |
+
The name of `type` or a tuple of the names of the types in `type`.
|
| 115 |
+
Examples
|
| 116 |
+
--------
|
| 117 |
+
>>> typename(int)
|
| 118 |
+
'int'
|
| 119 |
+
>>> typename((int, float))
|
| 120 |
+
'(int, float)'
|
| 121 |
+
"""
|
| 122 |
+
try:
|
| 123 |
+
return type.__name__
|
| 124 |
+
except AttributeError:
|
| 125 |
+
if len(type) == 1:
|
| 126 |
+
return typename(*type)
|
| 127 |
+
return f"({', '.join(map(typename, type))})"
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/variadic.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
from .utils import typename
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
__all__ = ["VariadicSignatureType", "isvariadic", "VariadicSignatureMeta", "Variadic"]
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class VariadicSignatureType(type):
|
| 9 |
+
# checking if subclass is a subclass of self
|
| 10 |
+
def __subclasscheck__(cls, subclass):
|
| 11 |
+
other_type = subclass.variadic_type if isvariadic(subclass) else (subclass,)
|
| 12 |
+
return subclass is cls or all(
|
| 13 |
+
issubclass(other, cls.variadic_type) # type: ignore[attr-defined]
|
| 14 |
+
for other in other_type
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
def __eq__(cls, other):
|
| 18 |
+
"""
|
| 19 |
+
Return True if other has the same variadic type
|
| 20 |
+
Parameters
|
| 21 |
+
----------
|
| 22 |
+
other : object (type)
|
| 23 |
+
The object (type) to check
|
| 24 |
+
Returns
|
| 25 |
+
-------
|
| 26 |
+
bool
|
| 27 |
+
Whether or not `other` is equal to `self`
|
| 28 |
+
"""
|
| 29 |
+
return isvariadic(other) and set(cls.variadic_type) == set(other.variadic_type) # type: ignore[attr-defined]
|
| 30 |
+
|
| 31 |
+
def __hash__(cls):
|
| 32 |
+
return hash((type(cls), frozenset(cls.variadic_type))) # type: ignore[attr-defined]
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def isvariadic(obj):
|
| 36 |
+
"""Check whether the type `obj` is variadic.
|
| 37 |
+
Parameters
|
| 38 |
+
----------
|
| 39 |
+
obj : type
|
| 40 |
+
The type to check
|
| 41 |
+
Returns
|
| 42 |
+
-------
|
| 43 |
+
bool
|
| 44 |
+
Whether or not `obj` is variadic
|
| 45 |
+
Examples
|
| 46 |
+
--------
|
| 47 |
+
>>> # xdoctest: +SKIP
|
| 48 |
+
>>> isvariadic(int)
|
| 49 |
+
False
|
| 50 |
+
>>> isvariadic(Variadic[int])
|
| 51 |
+
True
|
| 52 |
+
"""
|
| 53 |
+
return isinstance(obj, VariadicSignatureType)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class VariadicSignatureMeta(type):
|
| 57 |
+
"""A metaclass that overrides ``__getitem__`` on the class. This is used to
|
| 58 |
+
generate a new type for Variadic signatures. See the Variadic class for
|
| 59 |
+
examples of how this behaves.
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
def __getitem__(cls, variadic_type):
|
| 63 |
+
if not (isinstance(variadic_type, (type, tuple)) or type(variadic_type)):
|
| 64 |
+
raise ValueError(
|
| 65 |
+
"Variadic types must be type or tuple of types"
|
| 66 |
+
" (Variadic[int] or Variadic[(int, float)]"
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
if not isinstance(variadic_type, tuple):
|
| 70 |
+
variadic_type = (variadic_type,)
|
| 71 |
+
return VariadicSignatureType(
|
| 72 |
+
f"Variadic[{typename(variadic_type)}]",
|
| 73 |
+
(),
|
| 74 |
+
dict(variadic_type=variadic_type, __slots__=()),
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class Variadic(metaclass=VariadicSignatureMeta):
|
| 79 |
+
"""A class whose getitem method can be used to generate a new type
|
| 80 |
+
representing a specific variadic signature.
|
| 81 |
+
Examples
|
| 82 |
+
--------
|
| 83 |
+
>>> # xdoctest: +SKIP
|
| 84 |
+
>>> Variadic[int] # any number of int arguments
|
| 85 |
+
<class 'multipledispatch.variadic.Variadic[int]'>
|
| 86 |
+
>>> Variadic[(int, str)] # any number of one of int or str arguments
|
| 87 |
+
<class 'multipledispatch.variadic.Variadic[(int, str)]'>
|
| 88 |
+
>>> issubclass(int, Variadic[int])
|
| 89 |
+
True
|
| 90 |
+
>>> issubclass(int, Variadic[(int, str)])
|
| 91 |
+
True
|
| 92 |
+
>>> issubclass(str, Variadic[(int, str)])
|
| 93 |
+
True
|
| 94 |
+
>>> issubclass(float, Variadic[(int, str)])
|
| 95 |
+
False
|
| 96 |
+
"""
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/passes/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (501 Bytes). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/passes/__pycache__/_tensorify_python_scalars.cpython-312.pyc
ADDED
|
Binary file (15 kB). View file
|
|
|
tool_server/.venv/lib/python3.12/site-packages/torch/fx/passes/__pycache__/annotate_getitem_nodes.cpython-312.pyc
ADDED
|
Binary file (2.99 kB). View file
|
|
|