koichi12 commited on
Commit
95fc195
·
verified ·
1 Parent(s): a18205e

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/__init__.py +0 -0
  2. tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/cache_mapper.py +76 -0
  3. tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/cache_metadata.py +232 -0
  4. tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/data.py +48 -0
  5. tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/dbfs.py +467 -0
  6. tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/ftp.py +385 -0
  7. tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/libarchive.py +213 -0
  8. tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/local.py +418 -0
  9. tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/memory.py +292 -0
  10. tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/sftp.py +180 -0
  11. tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/tar.py +124 -0
  12. tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/webhdfs.py +486 -0
  13. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/functions/__pycache__/expintegrals.cpython-311.pyc +0 -0
  14. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/functions/__pycache__/qfunctions.cpython-311.pyc +0 -0
  15. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/functions/__pycache__/signals.cpython-311.pyc +0 -0
  16. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/functions/qfunctions.py +280 -0
  17. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/__pycache__/extratest_gamma.cpython-311.pyc +0 -0
  18. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/__pycache__/test_calculus.cpython-311.pyc +0 -0
  19. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/__pycache__/test_eigen.cpython-311.pyc +0 -0
  20. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/__pycache__/test_power.cpython-311.pyc +0 -0
  21. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/__pycache__/test_str.cpython-311.pyc +0 -0
  22. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/extratest_zeta.py +30 -0
  23. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/runtests.py +161 -0
  24. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/test_functions2.py +2384 -0
  25. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/test_ode.py +73 -0
  26. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/test_quad.py +95 -0
  27. tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/test_rootfinding.py +91 -0
  28. tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cuda_nvrtc/lib/__init__.py +0 -0
  29. tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cudnn/__init__.py +0 -0
  30. tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusolver/include/cusolverDn.h +0 -0
  31. tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusolver/include/cusolver_common.h +266 -0
  32. tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusolver/lib/__pycache__/__init__.cpython-311.pyc +0 -0
  33. tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusparse/__init__.py +0 -0
  34. tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusparse/__pycache__/__init__.cpython-311.pyc +0 -0
  35. tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusparse/include/__init__.py +0 -0
  36. tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusparse/include/__pycache__/__init__.cpython-311.pyc +0 -0
  37. tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusparse/include/cusparse_v2.h +54 -0
  38. tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusparse/lib/__init__.py +0 -0
  39. tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/nccl/lib/__pycache__/__init__.cpython-311.pyc +0 -0
  40. tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/__init__.py +128 -0
  41. tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/__init__.cpython-311.pyc +0 -0
  42. tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/_json.cpython-311.pyc +0 -0
  43. tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/base.cpython-311.pyc +0 -0
  44. tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/_json.py +84 -0
  45. tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/importlib/_dists.py +221 -0
  46. tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/pkg_resources.py +301 -0
  47. tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/network/__pycache__/__init__.cpython-311.pyc +0 -0
  48. tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/network/__pycache__/download.cpython-311.pyc +0 -0
  49. tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/network/__pycache__/session.cpython-311.pyc +0 -0
  50. tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/network/__pycache__/utils.cpython-311.pyc +0 -0
tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/__init__.py ADDED
File without changes
tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/cache_mapper.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import abc
4
+ import hashlib
5
+
6
+ from fsspec.implementations.local import make_path_posix
7
+
8
+
9
+ class AbstractCacheMapper(abc.ABC):
10
+ """Abstract super-class for mappers from remote URLs to local cached
11
+ basenames.
12
+ """
13
+
14
+ @abc.abstractmethod
15
+ def __call__(self, path: str) -> str:
16
+ ...
17
+
18
+ def __eq__(self, other: object) -> bool:
19
+ # Identity only depends on class. When derived classes have attributes
20
+ # they will need to be included.
21
+ return isinstance(other, type(self))
22
+
23
+ def __hash__(self) -> int:
24
+ # Identity only depends on class. When derived classes have attributes
25
+ # they will need to be included.
26
+ return hash(type(self))
27
+
28
+
29
+ class BasenameCacheMapper(AbstractCacheMapper):
30
+ """Cache mapper that uses the basename of the remote URL and a fixed number
31
+ of directory levels above this.
32
+
33
+ The default is zero directory levels, meaning different paths with the same
34
+ basename will have the same cached basename.
35
+ """
36
+
37
+ def __init__(self, directory_levels: int = 0):
38
+ if directory_levels < 0:
39
+ raise ValueError(
40
+ "BasenameCacheMapper requires zero or positive directory_levels"
41
+ )
42
+ self.directory_levels = directory_levels
43
+
44
+ # Separator for directories when encoded as strings.
45
+ self._separator = "_@_"
46
+
47
+ def __call__(self, path: str) -> str:
48
+ path = make_path_posix(path)
49
+ prefix, *bits = path.rsplit("/", self.directory_levels + 1)
50
+ if bits:
51
+ return self._separator.join(bits)
52
+ else:
53
+ return prefix # No separator found, simple filename
54
+
55
+ def __eq__(self, other: object) -> bool:
56
+ return super().__eq__(other) and self.directory_levels == other.directory_levels
57
+
58
+ def __hash__(self) -> int:
59
+ return super().__hash__() ^ hash(self.directory_levels)
60
+
61
+
62
+ class HashCacheMapper(AbstractCacheMapper):
63
+ """Cache mapper that uses a hash of the remote URL."""
64
+
65
+ def __call__(self, path: str) -> str:
66
+ return hashlib.sha256(path.encode()).hexdigest()
67
+
68
+
69
+ def create_cache_mapper(same_names: bool) -> AbstractCacheMapper:
70
+ """Factory method to create cache mapper for backward compatibility with
71
+ ``CachingFileSystem`` constructor using ``same_names`` kwarg.
72
+ """
73
+ if same_names:
74
+ return BasenameCacheMapper()
75
+ else:
76
+ return HashCacheMapper()
tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/cache_metadata.py ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import pickle
5
+ import time
6
+ from typing import TYPE_CHECKING
7
+
8
+ from fsspec.utils import atomic_write
9
+
10
+ try:
11
+ import ujson as json
12
+ except ImportError:
13
+ if not TYPE_CHECKING:
14
+ import json
15
+
16
+ if TYPE_CHECKING:
17
+ from typing import Any, Dict, Iterator, Literal
18
+
19
+ from typing_extensions import TypeAlias
20
+
21
+ from .cached import CachingFileSystem
22
+
23
+ Detail: TypeAlias = Dict[str, Any]
24
+
25
+
26
+ class CacheMetadata:
27
+ """Cache metadata.
28
+
29
+ All reading and writing of cache metadata is performed by this class,
30
+ accessing the cached files and blocks is not.
31
+
32
+ Metadata is stored in a single file per storage directory in JSON format.
33
+ For backward compatibility, also reads metadata stored in pickle format
34
+ which is converted to JSON when next saved.
35
+ """
36
+
37
+ def __init__(self, storage: list[str]):
38
+ """
39
+
40
+ Parameters
41
+ ----------
42
+ storage: list[str]
43
+ Directories containing cached files, must be at least one. Metadata
44
+ is stored in the last of these directories by convention.
45
+ """
46
+ if not storage:
47
+ raise ValueError("CacheMetadata expects at least one storage location")
48
+
49
+ self._storage = storage
50
+ self.cached_files: list[Detail] = [{}]
51
+
52
+ # Private attribute to force saving of metadata in pickle format rather than
53
+ # JSON for use in tests to confirm can read both pickle and JSON formats.
54
+ self._force_save_pickle = False
55
+
56
+ def _load(self, fn: str) -> Detail:
57
+ """Low-level function to load metadata from specific file"""
58
+ try:
59
+ with open(fn, "r") as f:
60
+ return json.load(f)
61
+ except ValueError:
62
+ with open(fn, "rb") as f:
63
+ return pickle.load(f)
64
+
65
+ def _save(self, metadata_to_save: Detail, fn: str) -> None:
66
+ """Low-level function to save metadata to specific file"""
67
+ if self._force_save_pickle:
68
+ with atomic_write(fn) as f:
69
+ pickle.dump(metadata_to_save, f)
70
+ else:
71
+ with atomic_write(fn, mode="w") as f:
72
+ json.dump(metadata_to_save, f)
73
+
74
+ def _scan_locations(
75
+ self, writable_only: bool = False
76
+ ) -> Iterator[tuple[str, str, bool]]:
77
+ """Yield locations (filenames) where metadata is stored, and whether
78
+ writable or not.
79
+
80
+ Parameters
81
+ ----------
82
+ writable: bool
83
+ Set to True to only yield writable locations.
84
+
85
+ Returns
86
+ -------
87
+ Yields (str, str, bool)
88
+ """
89
+ n = len(self._storage)
90
+ for i, storage in enumerate(self._storage):
91
+ writable = i == n - 1
92
+ if writable_only and not writable:
93
+ continue
94
+ yield os.path.join(storage, "cache"), storage, writable
95
+
96
+ def check_file(
97
+ self, path: str, cfs: CachingFileSystem | None
98
+ ) -> Literal[False] | tuple[Detail, str]:
99
+ """If path is in cache return its details, otherwise return ``False``.
100
+
101
+ If the optional CachingFileSystem is specified then it is used to
102
+ perform extra checks to reject possible matches, such as if they are
103
+ too old.
104
+ """
105
+ for (fn, base, _), cache in zip(self._scan_locations(), self.cached_files):
106
+ if path not in cache:
107
+ continue
108
+ detail = cache[path].copy()
109
+
110
+ if cfs is not None:
111
+ if cfs.check_files and detail["uid"] != cfs.fs.ukey(path):
112
+ # Wrong file as determined by hash of file properties
113
+ continue
114
+ if cfs.expiry and time.time() - detail["time"] > cfs.expiry:
115
+ # Cached file has expired
116
+ continue
117
+
118
+ fn = os.path.join(base, detail["fn"])
119
+ if os.path.exists(fn):
120
+ return detail, fn
121
+ return False
122
+
123
+ def clear_expired(self, expiry_time: int) -> tuple[list[str], bool]:
124
+ """Remove expired metadata from the cache.
125
+
126
+ Returns names of files corresponding to expired metadata and a boolean
127
+ flag indicating whether the writable cache is empty. Caller is
128
+ responsible for deleting the expired files.
129
+ """
130
+ expired_files = []
131
+ for path, detail in self.cached_files[-1].copy().items():
132
+ if time.time() - detail["time"] > expiry_time:
133
+ fn = detail.get("fn", "")
134
+ if not fn:
135
+ raise RuntimeError(
136
+ f"Cache metadata does not contain 'fn' for {path}"
137
+ )
138
+ fn = os.path.join(self._storage[-1], fn)
139
+ expired_files.append(fn)
140
+ self.cached_files[-1].pop(path)
141
+
142
+ if self.cached_files[-1]:
143
+ cache_path = os.path.join(self._storage[-1], "cache")
144
+ self._save(self.cached_files[-1], cache_path)
145
+
146
+ writable_cache_empty = not self.cached_files[-1]
147
+ return expired_files, writable_cache_empty
148
+
149
+ def load(self) -> None:
150
+ """Load all metadata from disk and store in ``self.cached_files``"""
151
+ cached_files = []
152
+ for fn, _, _ in self._scan_locations():
153
+ if os.path.exists(fn):
154
+ # TODO: consolidate blocks here
155
+ loaded_cached_files = self._load(fn)
156
+ for c in loaded_cached_files.values():
157
+ if isinstance(c["blocks"], list):
158
+ c["blocks"] = set(c["blocks"])
159
+ cached_files.append(loaded_cached_files)
160
+ else:
161
+ cached_files.append({})
162
+ self.cached_files = cached_files or [{}]
163
+
164
+ def on_close_cached_file(self, f: Any, path: str) -> None:
165
+ """Perform side-effect actions on closing a cached file.
166
+
167
+ The actual closing of the file is the responsibility of the caller.
168
+ """
169
+ # File must be writeble, so in self.cached_files[-1]
170
+ c = self.cached_files[-1][path]
171
+ if c["blocks"] is not True and len(c["blocks"]) * f.blocksize >= f.size:
172
+ c["blocks"] = True
173
+
174
+ def pop_file(self, path: str) -> str | None:
175
+ """Remove metadata of cached file.
176
+
177
+ If path is in the cache, return the filename of the cached file,
178
+ otherwise return ``None``. Caller is responsible for deleting the
179
+ cached file.
180
+ """
181
+ details = self.check_file(path, None)
182
+ if not details:
183
+ return None
184
+ _, fn = details
185
+ if fn.startswith(self._storage[-1]):
186
+ self.cached_files[-1].pop(path)
187
+ self.save()
188
+ else:
189
+ raise PermissionError(
190
+ "Can only delete cached file in last, writable cache location"
191
+ )
192
+ return fn
193
+
194
+ def save(self) -> None:
195
+ """Save metadata to disk"""
196
+ for (fn, _, writable), cache in zip(self._scan_locations(), self.cached_files):
197
+ if not writable:
198
+ continue
199
+
200
+ if os.path.exists(fn):
201
+ cached_files = self._load(fn)
202
+ for k, c in cached_files.items():
203
+ if k in cache:
204
+ if c["blocks"] is True or cache[k]["blocks"] is True:
205
+ c["blocks"] = True
206
+ else:
207
+ # self.cached_files[*][*]["blocks"] must continue to
208
+ # point to the same set object so that updates
209
+ # performed by MMapCache are propagated back to
210
+ # self.cached_files.
211
+ blocks = cache[k]["blocks"]
212
+ blocks.update(c["blocks"])
213
+ c["blocks"] = blocks
214
+ c["time"] = max(c["time"], cache[k]["time"])
215
+ c["uid"] = cache[k]["uid"]
216
+
217
+ # Files can be added to cache after it was written once
218
+ for k, c in cache.items():
219
+ if k not in cached_files:
220
+ cached_files[k] = c
221
+ else:
222
+ cached_files = cache
223
+ cache = {k: v.copy() for k, v in cached_files.items()}
224
+ for c in cache.values():
225
+ if isinstance(c["blocks"], set):
226
+ c["blocks"] = list(c["blocks"])
227
+ self._save(cache, fn)
228
+ self.cached_files[-1] = cached_files
229
+
230
+ def update_file(self, path: str, detail: Detail) -> None:
231
+ """Update metadata for specific file in memory, do not save"""
232
+ self.cached_files[-1][path] = detail
tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/data.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import io
3
+ from urllib.parse import unquote
4
+
5
+ from fsspec import AbstractFileSystem
6
+
7
+
8
+ class DataFileSystem(AbstractFileSystem):
9
+ """A handy decoder for data-URLs
10
+
11
+ Example
12
+ -------
13
+ >>> with fsspec.open("data:,Hello%2C%20World%21") as f:
14
+ ... print(f.read())
15
+ b"Hello, World!"
16
+
17
+ """
18
+
19
+ protocol = "data"
20
+
21
+ def __init__(self, **kwargs):
22
+ """No parameters for this filesystem"""
23
+ super().__init__(**kwargs)
24
+
25
+ def cat_file(self, path, start=None, end=None, **kwargs):
26
+ pref, data = path.split(",", 1)
27
+ if pref.endswith("base64"):
28
+ return base64.b64decode(data)[start:end]
29
+ return unquote(data).encode()[start:end]
30
+
31
+ def info(self, path, **kwargs):
32
+ pref, name = path.split(",", 1)
33
+ data = self.cat_file(path)
34
+ mime = pref.split(":", 1)[1].split(";", 1)[0]
35
+ return {"name": name, "size": len(data), "type": "file", "mimetype": mime}
36
+
37
+ def _open(
38
+ self,
39
+ path,
40
+ mode="rb",
41
+ block_size=None,
42
+ autocommit=True,
43
+ cache_options=None,
44
+ **kwargs,
45
+ ):
46
+ if "r" not in mode:
47
+ raise ValueError("Read only filesystem")
48
+ return io.BytesIO(self.cat_file(path))
tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/dbfs.py ADDED
@@ -0,0 +1,467 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import urllib
3
+
4
+ import requests
5
+ import requests.exceptions
6
+ from requests.adapters import HTTPAdapter, Retry
7
+
8
+ from fsspec import AbstractFileSystem
9
+ from fsspec.spec import AbstractBufferedFile
10
+
11
+
12
+ class DatabricksException(Exception):
13
+ """
14
+ Helper class for exceptions raised in this module.
15
+ """
16
+
17
+ def __init__(self, error_code, message):
18
+ """Create a new DatabricksException"""
19
+ super().__init__(message)
20
+
21
+ self.error_code = error_code
22
+ self.message = message
23
+
24
+
25
+ class DatabricksFileSystem(AbstractFileSystem):
26
+ """
27
+ Get access to the Databricks filesystem implementation over HTTP.
28
+ Can be used inside and outside of a databricks cluster.
29
+ """
30
+
31
+ def __init__(self, instance, token, **kwargs):
32
+ """
33
+ Create a new DatabricksFileSystem.
34
+
35
+ Parameters
36
+ ----------
37
+ instance: str
38
+ The instance URL of the databricks cluster.
39
+ For example for an Azure databricks cluster, this
40
+ has the form adb-<some-number>.<two digits>.azuredatabricks.net.
41
+ token: str
42
+ Your personal token. Find out more
43
+ here: https://docs.databricks.com/dev-tools/api/latest/authentication.html
44
+ """
45
+ self.instance = instance
46
+ self.token = token
47
+ self.session = requests.Session()
48
+ self.retries = Retry(
49
+ total=10,
50
+ backoff_factor=0.05,
51
+ status_forcelist=[408, 429, 500, 502, 503, 504],
52
+ )
53
+
54
+ self.session.mount("https://", HTTPAdapter(max_retries=self.retries))
55
+ self.session.headers.update({"Authorization": f"Bearer {self.token}"})
56
+
57
+ super().__init__(**kwargs)
58
+
59
+ def ls(self, path, detail=True, **kwargs):
60
+ """
61
+ List the contents of the given path.
62
+
63
+ Parameters
64
+ ----------
65
+ path: str
66
+ Absolute path
67
+ detail: bool
68
+ Return not only the list of filenames,
69
+ but also additional information on file sizes
70
+ and types.
71
+ """
72
+ out = self._ls_from_cache(path)
73
+ if not out:
74
+ try:
75
+ r = self._send_to_api(
76
+ method="get", endpoint="list", json={"path": path}
77
+ )
78
+ except DatabricksException as e:
79
+ if e.error_code == "RESOURCE_DOES_NOT_EXIST":
80
+ raise FileNotFoundError(e.message)
81
+
82
+ raise e
83
+ files = r["files"]
84
+ out = [
85
+ {
86
+ "name": o["path"],
87
+ "type": "directory" if o["is_dir"] else "file",
88
+ "size": o["file_size"],
89
+ }
90
+ for o in files
91
+ ]
92
+ self.dircache[path] = out
93
+
94
+ if detail:
95
+ return out
96
+ return [o["name"] for o in out]
97
+
98
+ def makedirs(self, path, exist_ok=True):
99
+ """
100
+ Create a given absolute path and all of its parents.
101
+
102
+ Parameters
103
+ ----------
104
+ path: str
105
+ Absolute path to create
106
+ exist_ok: bool
107
+ If false, checks if the folder
108
+ exists before creating it (and raises an
109
+ Exception if this is the case)
110
+ """
111
+ if not exist_ok:
112
+ try:
113
+ # If the following succeeds, the path is already present
114
+ self._send_to_api(
115
+ method="get", endpoint="get-status", json={"path": path}
116
+ )
117
+ raise FileExistsError(f"Path {path} already exists")
118
+ except DatabricksException as e:
119
+ if e.error_code == "RESOURCE_DOES_NOT_EXIST":
120
+ pass
121
+
122
+ try:
123
+ self._send_to_api(method="post", endpoint="mkdirs", json={"path": path})
124
+ except DatabricksException as e:
125
+ if e.error_code == "RESOURCE_ALREADY_EXISTS":
126
+ raise FileExistsError(e.message)
127
+
128
+ raise e
129
+ self.invalidate_cache(self._parent(path))
130
+
131
+ def mkdir(self, path, create_parents=True, **kwargs):
132
+ """
133
+ Create a given absolute path and all of its parents.
134
+
135
+ Parameters
136
+ ----------
137
+ path: str
138
+ Absolute path to create
139
+ create_parents: bool
140
+ Whether to create all parents or not.
141
+ "False" is not implemented so far.
142
+ """
143
+ if not create_parents:
144
+ raise NotImplementedError
145
+
146
+ self.mkdirs(path, **kwargs)
147
+
148
+ def rm(self, path, recursive=False, **kwargs):
149
+ """
150
+ Remove the file or folder at the given absolute path.
151
+
152
+ Parameters
153
+ ----------
154
+ path: str
155
+ Absolute path what to remove
156
+ recursive: bool
157
+ Recursively delete all files in a folder.
158
+ """
159
+ try:
160
+ self._send_to_api(
161
+ method="post",
162
+ endpoint="delete",
163
+ json={"path": path, "recursive": recursive},
164
+ )
165
+ except DatabricksException as e:
166
+ # This is not really an exception, it just means
167
+ # not everything was deleted so far
168
+ if e.error_code == "PARTIAL_DELETE":
169
+ self.rm(path=path, recursive=recursive)
170
+ elif e.error_code == "IO_ERROR":
171
+ # Using the same exception as the os module would use here
172
+ raise OSError(e.message)
173
+
174
+ raise e
175
+ self.invalidate_cache(self._parent(path))
176
+
177
+ def mv(
178
+ self, source_path, destination_path, recursive=False, maxdepth=None, **kwargs
179
+ ):
180
+ """
181
+ Move a source to a destination path.
182
+
183
+ A note from the original [databricks API manual]
184
+ (https://docs.databricks.com/dev-tools/api/latest/dbfs.html#move).
185
+
186
+ When moving a large number of files the API call will time out after
187
+ approximately 60s, potentially resulting in partially moved data.
188
+ Therefore, for operations that move more than 10k files, we strongly
189
+ discourage using the DBFS REST API.
190
+
191
+ Parameters
192
+ ----------
193
+ source_path: str
194
+ From where to move (absolute path)
195
+ destination_path: str
196
+ To where to move (absolute path)
197
+ recursive: bool
198
+ Not implemented to far.
199
+ maxdepth:
200
+ Not implemented to far.
201
+ """
202
+ if recursive:
203
+ raise NotImplementedError
204
+ if maxdepth:
205
+ raise NotImplementedError
206
+
207
+ try:
208
+ self._send_to_api(
209
+ method="post",
210
+ endpoint="move",
211
+ json={"source_path": source_path, "destination_path": destination_path},
212
+ )
213
+ except DatabricksException as e:
214
+ if e.error_code == "RESOURCE_DOES_NOT_EXIST":
215
+ raise FileNotFoundError(e.message)
216
+ elif e.error_code == "RESOURCE_ALREADY_EXISTS":
217
+ raise FileExistsError(e.message)
218
+
219
+ raise e
220
+ self.invalidate_cache(self._parent(source_path))
221
+ self.invalidate_cache(self._parent(destination_path))
222
+
223
+ def _open(self, path, mode="rb", block_size="default", **kwargs):
224
+ """
225
+ Overwrite the base class method to make sure to create a DBFile.
226
+ All arguments are copied from the base method.
227
+
228
+ Only the default blocksize is allowed.
229
+ """
230
+ return DatabricksFile(self, path, mode=mode, block_size=block_size, **kwargs)
231
+
232
+ def _send_to_api(self, method, endpoint, json):
233
+ """
234
+ Send the given json to the DBFS API
235
+ using a get or post request (specified by the argument `method`).
236
+
237
+ Parameters
238
+ ----------
239
+ method: str
240
+ Which http method to use for communication; "get" or "post".
241
+ endpoint: str
242
+ Where to send the request to (last part of the API URL)
243
+ json: dict
244
+ Dictionary of information to send
245
+ """
246
+ if method == "post":
247
+ session_call = self.session.post
248
+ elif method == "get":
249
+ session_call = self.session.get
250
+ else:
251
+ raise ValueError(f"Do not understand method {method}")
252
+
253
+ url = urllib.parse.urljoin(f"https://{self.instance}/api/2.0/dbfs/", endpoint)
254
+
255
+ r = session_call(url, json=json)
256
+
257
+ # The DBFS API will return a json, also in case of an exception.
258
+ # We want to preserve this information as good as possible.
259
+ try:
260
+ r.raise_for_status()
261
+ except requests.HTTPError as e:
262
+ # try to extract json error message
263
+ # if that fails, fall back to the original exception
264
+ try:
265
+ exception_json = e.response.json()
266
+ except Exception:
267
+ raise e
268
+
269
+ raise DatabricksException(**exception_json)
270
+
271
+ return r.json()
272
+
273
+ def _create_handle(self, path, overwrite=True):
274
+ """
275
+ Internal function to create a handle, which can be used to
276
+ write blocks of a file to DBFS.
277
+ A handle has a unique identifier which needs to be passed
278
+ whenever written during this transaction.
279
+ The handle is active for 10 minutes - after that a new
280
+ write transaction needs to be created.
281
+ Make sure to close the handle after you are finished.
282
+
283
+ Parameters
284
+ ----------
285
+ path: str
286
+ Absolute path for this file.
287
+ overwrite: bool
288
+ If a file already exist at this location, either overwrite
289
+ it or raise an exception.
290
+ """
291
+ try:
292
+ r = self._send_to_api(
293
+ method="post",
294
+ endpoint="create",
295
+ json={"path": path, "overwrite": overwrite},
296
+ )
297
+ return r["handle"]
298
+ except DatabricksException as e:
299
+ if e.error_code == "RESOURCE_ALREADY_EXISTS":
300
+ raise FileExistsError(e.message)
301
+
302
+ raise e
303
+
304
+ def _close_handle(self, handle):
305
+ """
306
+ Close a handle, which was opened by :func:`_create_handle`.
307
+
308
+ Parameters
309
+ ----------
310
+ handle: str
311
+ Which handle to close.
312
+ """
313
+ try:
314
+ self._send_to_api(method="post", endpoint="close", json={"handle": handle})
315
+ except DatabricksException as e:
316
+ if e.error_code == "RESOURCE_DOES_NOT_EXIST":
317
+ raise FileNotFoundError(e.message)
318
+
319
+ raise e
320
+
321
+ def _add_data(self, handle, data):
322
+ """
323
+ Upload data to an already opened file handle
324
+ (opened by :func:`_create_handle`).
325
+ The maximal allowed data size is 1MB after
326
+ conversion to base64.
327
+ Remember to close the handle when you are finished.
328
+
329
+ Parameters
330
+ ----------
331
+ handle: str
332
+ Which handle to upload data to.
333
+ data: bytes
334
+ Block of data to add to the handle.
335
+ """
336
+ data = base64.b64encode(data).decode()
337
+ try:
338
+ self._send_to_api(
339
+ method="post",
340
+ endpoint="add-block",
341
+ json={"handle": handle, "data": data},
342
+ )
343
+ except DatabricksException as e:
344
+ if e.error_code == "RESOURCE_DOES_NOT_EXIST":
345
+ raise FileNotFoundError(e.message)
346
+ elif e.error_code == "MAX_BLOCK_SIZE_EXCEEDED":
347
+ raise ValueError(e.message)
348
+
349
+ raise e
350
+
351
+ def _get_data(self, path, start, end):
352
+ """
353
+ Download data in bytes from a given absolute path in a block
354
+ from [start, start+length].
355
+ The maximum number of allowed bytes to read is 1MB.
356
+
357
+ Parameters
358
+ ----------
359
+ path: str
360
+ Absolute path to download data from
361
+ start: int
362
+ Start position of the block
363
+ end: int
364
+ End position of the block
365
+ """
366
+ try:
367
+ r = self._send_to_api(
368
+ method="get",
369
+ endpoint="read",
370
+ json={"path": path, "offset": start, "length": end - start},
371
+ )
372
+ return base64.b64decode(r["data"])
373
+ except DatabricksException as e:
374
+ if e.error_code == "RESOURCE_DOES_NOT_EXIST":
375
+ raise FileNotFoundError(e.message)
376
+ elif e.error_code in ["INVALID_PARAMETER_VALUE", "MAX_READ_SIZE_EXCEEDED"]:
377
+ raise ValueError(e.message)
378
+
379
+ raise e
380
+
381
+ def invalidate_cache(self, path=None):
382
+ if path is None:
383
+ self.dircache.clear()
384
+ else:
385
+ self.dircache.pop(path, None)
386
+ super().invalidate_cache(path)
387
+
388
+
389
+ class DatabricksFile(AbstractBufferedFile):
390
+ """
391
+ Helper class for files referenced in the DatabricksFileSystem.
392
+ """
393
+
394
+ DEFAULT_BLOCK_SIZE = 1 * 2**20 # only allowed block size
395
+
396
+ def __init__(
397
+ self,
398
+ fs,
399
+ path,
400
+ mode="rb",
401
+ block_size="default",
402
+ autocommit=True,
403
+ cache_type="readahead",
404
+ cache_options=None,
405
+ **kwargs,
406
+ ):
407
+ """
408
+ Create a new instance of the DatabricksFile.
409
+
410
+ The blocksize needs to be the default one.
411
+ """
412
+ if block_size is None or block_size == "default":
413
+ block_size = self.DEFAULT_BLOCK_SIZE
414
+
415
+ assert (
416
+ block_size == self.DEFAULT_BLOCK_SIZE
417
+ ), f"Only the default block size is allowed, not {block_size}"
418
+
419
+ super().__init__(
420
+ fs,
421
+ path,
422
+ mode=mode,
423
+ block_size=block_size,
424
+ autocommit=autocommit,
425
+ cache_type=cache_type,
426
+ cache_options=cache_options or {},
427
+ **kwargs,
428
+ )
429
+
430
+ def _initiate_upload(self):
431
+ """Internal function to start a file upload"""
432
+ self.handle = self.fs._create_handle(self.path)
433
+
434
+ def _upload_chunk(self, final=False):
435
+ """Internal function to add a chunk of data to a started upload"""
436
+ self.buffer.seek(0)
437
+ data = self.buffer.getvalue()
438
+
439
+ data_chunks = [
440
+ data[start:end] for start, end in self._to_sized_blocks(len(data))
441
+ ]
442
+
443
+ for data_chunk in data_chunks:
444
+ self.fs._add_data(handle=self.handle, data=data_chunk)
445
+
446
+ if final:
447
+ self.fs._close_handle(handle=self.handle)
448
+ return True
449
+
450
+ def _fetch_range(self, start, end):
451
+ """Internal function to download a block of data"""
452
+ return_buffer = b""
453
+ length = end - start
454
+ for chunk_start, chunk_end in self._to_sized_blocks(length, start):
455
+ return_buffer += self.fs._get_data(
456
+ path=self.path, start=chunk_start, end=chunk_end
457
+ )
458
+
459
+ return return_buffer
460
+
461
+ def _to_sized_blocks(self, length, start=0):
462
+ """Helper function to split a range from 0 to total_length into bloksizes"""
463
+ end = start + length
464
+ for data_chunk in range(start, end, self.blocksize):
465
+ data_start = data_chunk
466
+ data_end = min(end, data_chunk + self.blocksize)
467
+ yield data_start, data_end
tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/ftp.py ADDED
@@ -0,0 +1,385 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ import uuid
4
+ import warnings
5
+ from ftplib import FTP, Error, error_perm
6
+ from typing import Any
7
+
8
+ from ..spec import AbstractBufferedFile, AbstractFileSystem
9
+ from ..utils import infer_storage_options, isfilelike
10
+
11
+
12
+ class FTPFileSystem(AbstractFileSystem):
13
+ """A filesystem over classic FTP"""
14
+
15
+ root_marker = "/"
16
+ cachable = False
17
+ protocol = "ftp"
18
+
19
+ def __init__(
20
+ self,
21
+ host,
22
+ port=21,
23
+ username=None,
24
+ password=None,
25
+ acct=None,
26
+ block_size=None,
27
+ tempdir=None,
28
+ timeout=30,
29
+ encoding="utf-8",
30
+ **kwargs,
31
+ ):
32
+ """
33
+ You can use _get_kwargs_from_urls to get some kwargs from
34
+ a reasonable FTP url.
35
+
36
+ Authentication will be anonymous if username/password are not
37
+ given.
38
+
39
+ Parameters
40
+ ----------
41
+ host: str
42
+ The remote server name/ip to connect to
43
+ port: int
44
+ Port to connect with
45
+ username: str or None
46
+ If authenticating, the user's identifier
47
+ password: str of None
48
+ User's password on the server, if using
49
+ acct: str or None
50
+ Some servers also need an "account" string for auth
51
+ block_size: int or None
52
+ If given, the read-ahead or write buffer size.
53
+ tempdir: str
54
+ Directory on remote to put temporary files when in a transaction
55
+ timeout: int
56
+ Timeout of the ftp connection in seconds
57
+ encoding: str
58
+ Encoding to use for directories and filenames in FTP connection
59
+ """
60
+ super().__init__(**kwargs)
61
+ self.host = host
62
+ self.port = port
63
+ self.tempdir = tempdir or "/tmp"
64
+ self.cred = username, password, acct
65
+ self.timeout = timeout
66
+ self.encoding = encoding
67
+ if block_size is not None:
68
+ self.blocksize = block_size
69
+ else:
70
+ self.blocksize = 2**16
71
+ self._connect()
72
+
73
+ def _connect(self):
74
+ if sys.version_info >= (3, 9):
75
+ self.ftp = FTP(timeout=self.timeout, encoding=self.encoding)
76
+ elif self.encoding:
77
+ warnings.warn("`encoding` not supported for python<3.9, ignoring")
78
+ self.ftp = FTP(timeout=self.timeout)
79
+ else:
80
+ self.ftp = FTP(timeout=self.timeout)
81
+ self.ftp.connect(self.host, self.port)
82
+ self.ftp.login(*self.cred)
83
+
84
+ @classmethod
85
+ def _strip_protocol(cls, path):
86
+ return "/" + infer_storage_options(path)["path"].lstrip("/").rstrip("/")
87
+
88
+ @staticmethod
89
+ def _get_kwargs_from_urls(urlpath):
90
+ out = infer_storage_options(urlpath)
91
+ out.pop("path", None)
92
+ out.pop("protocol", None)
93
+ return out
94
+
95
+ def ls(self, path, detail=True, **kwargs):
96
+ path = self._strip_protocol(path)
97
+ out = []
98
+ if path not in self.dircache:
99
+ try:
100
+ try:
101
+ out = [
102
+ (fn, details)
103
+ for (fn, details) in self.ftp.mlsd(path)
104
+ if fn not in [".", ".."]
105
+ and details["type"] not in ["pdir", "cdir"]
106
+ ]
107
+ except error_perm:
108
+ out = _mlsd2(self.ftp, path) # Not platform independent
109
+ for fn, details in out:
110
+ if path == "/":
111
+ path = "" # just for forming the names, below
112
+ details["name"] = "/".join([path, fn.lstrip("/")])
113
+ if details["type"] == "file":
114
+ details["size"] = int(details["size"])
115
+ else:
116
+ details["size"] = 0
117
+ if details["type"] == "dir":
118
+ details["type"] = "directory"
119
+ self.dircache[path] = out
120
+ except Error:
121
+ try:
122
+ info = self.info(path)
123
+ if info["type"] == "file":
124
+ out = [(path, info)]
125
+ except (Error, IndexError):
126
+ raise FileNotFoundError(path)
127
+ files = self.dircache.get(path, out)
128
+ if not detail:
129
+ return sorted([fn for fn, details in files])
130
+ return [details for fn, details in files]
131
+
132
+ def info(self, path, **kwargs):
133
+ # implement with direct method
134
+ path = self._strip_protocol(path)
135
+ if path == "/":
136
+ # special case, since this dir has no real entry
137
+ return {"name": "/", "size": 0, "type": "directory"}
138
+ files = self.ls(self._parent(path).lstrip("/"), True)
139
+ try:
140
+ out = [f for f in files if f["name"] == path][0]
141
+ except IndexError:
142
+ raise FileNotFoundError(path)
143
+ return out
144
+
145
+ def get_file(self, rpath, lpath, **kwargs):
146
+ if self.isdir(rpath):
147
+ if not os.path.exists(lpath):
148
+ os.mkdir(lpath)
149
+ return
150
+ if isfilelike(lpath):
151
+ outfile = lpath
152
+ else:
153
+ outfile = open(lpath, "wb")
154
+
155
+ def cb(x):
156
+ outfile.write(x)
157
+
158
+ self.ftp.retrbinary(
159
+ f"RETR {rpath}",
160
+ blocksize=self.blocksize,
161
+ callback=cb,
162
+ )
163
+ if not isfilelike(lpath):
164
+ outfile.close()
165
+
166
+ def cat_file(self, path, start=None, end=None, **kwargs):
167
+ if end is not None:
168
+ return super().cat_file(path, start, end, **kwargs)
169
+ out = []
170
+
171
+ def cb(x):
172
+ out.append(x)
173
+
174
+ try:
175
+ self.ftp.retrbinary(
176
+ f"RETR {path}",
177
+ blocksize=self.blocksize,
178
+ rest=start,
179
+ callback=cb,
180
+ )
181
+ except (Error, error_perm) as orig_exc:
182
+ raise FileNotFoundError(path) from orig_exc
183
+ return b"".join(out)
184
+
185
+ def _open(
186
+ self,
187
+ path,
188
+ mode="rb",
189
+ block_size=None,
190
+ cache_options=None,
191
+ autocommit=True,
192
+ **kwargs,
193
+ ):
194
+ path = self._strip_protocol(path)
195
+ block_size = block_size or self.blocksize
196
+ return FTPFile(
197
+ self,
198
+ path,
199
+ mode=mode,
200
+ block_size=block_size,
201
+ tempdir=self.tempdir,
202
+ autocommit=autocommit,
203
+ cache_options=cache_options,
204
+ )
205
+
206
+ def _rm(self, path):
207
+ path = self._strip_protocol(path)
208
+ self.ftp.delete(path)
209
+ self.invalidate_cache(self._parent(path))
210
+
211
+ def rm(self, path, recursive=False, maxdepth=None):
212
+ paths = self.expand_path(path, recursive=recursive, maxdepth=maxdepth)
213
+ for p in reversed(paths):
214
+ if self.isfile(p):
215
+ self.rm_file(p)
216
+ else:
217
+ self.rmdir(p)
218
+
219
+ def mkdir(self, path: str, create_parents: bool = True, **kwargs: Any) -> None:
220
+ path = self._strip_protocol(path)
221
+ parent = self._parent(path)
222
+ if parent != self.root_marker and not self.exists(parent) and create_parents:
223
+ self.mkdir(parent, create_parents=create_parents)
224
+
225
+ self.ftp.mkd(path)
226
+ self.invalidate_cache(self._parent(path))
227
+
228
+ def makedirs(self, path: str, exist_ok: bool = False) -> None:
229
+ path = self._strip_protocol(path)
230
+ if self.exists(path):
231
+ # NB: "/" does not "exist" as it has no directory entry
232
+ if not exist_ok:
233
+ raise FileExistsError(f"{path} exists without `exist_ok`")
234
+ # exists_ok=True -> no-op
235
+ else:
236
+ self.mkdir(path, create_parents=True)
237
+
238
+ def rmdir(self, path):
239
+ path = self._strip_protocol(path)
240
+ self.ftp.rmd(path)
241
+ self.invalidate_cache(self._parent(path))
242
+
243
+ def mv(self, path1, path2, **kwargs):
244
+ path1 = self._strip_protocol(path1)
245
+ path2 = self._strip_protocol(path2)
246
+ self.ftp.rename(path1, path2)
247
+ self.invalidate_cache(self._parent(path1))
248
+ self.invalidate_cache(self._parent(path2))
249
+
250
+ def __del__(self):
251
+ self.ftp.close()
252
+
253
+ def invalidate_cache(self, path=None):
254
+ if path is None:
255
+ self.dircache.clear()
256
+ else:
257
+ self.dircache.pop(path, None)
258
+ super().invalidate_cache(path)
259
+
260
+
261
+ class TransferDone(Exception):
262
+ """Internal exception to break out of transfer"""
263
+
264
+ pass
265
+
266
+
267
+ class FTPFile(AbstractBufferedFile):
268
+ """Interact with a remote FTP file with read/write buffering"""
269
+
270
+ def __init__(
271
+ self,
272
+ fs,
273
+ path,
274
+ mode="rb",
275
+ block_size="default",
276
+ autocommit=True,
277
+ cache_type="readahead",
278
+ cache_options=None,
279
+ **kwargs,
280
+ ):
281
+ super().__init__(
282
+ fs,
283
+ path,
284
+ mode=mode,
285
+ block_size=block_size,
286
+ autocommit=autocommit,
287
+ cache_type=cache_type,
288
+ cache_options=cache_options,
289
+ **kwargs,
290
+ )
291
+ if not autocommit:
292
+ self.target = self.path
293
+ self.path = "/".join([kwargs["tempdir"], str(uuid.uuid4())])
294
+
295
+ def commit(self):
296
+ self.fs.mv(self.path, self.target)
297
+
298
+ def discard(self):
299
+ self.fs.rm(self.path)
300
+
301
+ def _fetch_range(self, start, end):
302
+ """Get bytes between given byte limits
303
+
304
+ Implemented by raising an exception in the fetch callback when the
305
+ number of bytes received reaches the requested amount.
306
+
307
+ Will fail if the server does not respect the REST command on
308
+ retrieve requests.
309
+ """
310
+ out = []
311
+ total = [0]
312
+
313
+ def callback(x):
314
+ total[0] += len(x)
315
+ if total[0] > end - start:
316
+ out.append(x[: (end - start) - total[0]])
317
+ if end < self.size:
318
+ raise TransferDone
319
+ else:
320
+ out.append(x)
321
+
322
+ if total[0] == end - start and end < self.size:
323
+ raise TransferDone
324
+
325
+ try:
326
+ self.fs.ftp.retrbinary(
327
+ f"RETR {self.path}",
328
+ blocksize=self.blocksize,
329
+ rest=start,
330
+ callback=callback,
331
+ )
332
+ except TransferDone:
333
+ try:
334
+ # stop transfer, we got enough bytes for this block
335
+ self.fs.ftp.abort()
336
+ self.fs.ftp.getmultiline()
337
+ except Error:
338
+ self.fs._connect()
339
+
340
+ return b"".join(out)
341
+
342
+ def _upload_chunk(self, final=False):
343
+ self.buffer.seek(0)
344
+ self.fs.ftp.storbinary(
345
+ f"STOR {self.path}", self.buffer, blocksize=self.blocksize, rest=self.offset
346
+ )
347
+ return True
348
+
349
+
350
+ def _mlsd2(ftp, path="."):
351
+ """
352
+ Fall back to using `dir` instead of `mlsd` if not supported.
353
+
354
+ This parses a Linux style `ls -l` response to `dir`, but the response may
355
+ be platform dependent.
356
+
357
+ Parameters
358
+ ----------
359
+ ftp: ftplib.FTP
360
+ path: str
361
+ Expects to be given path, but defaults to ".".
362
+ """
363
+ lines = []
364
+ minfo = []
365
+ ftp.dir(path, lines.append)
366
+ for line in lines:
367
+ split_line = line.split()
368
+ if len(split_line) < 9:
369
+ continue
370
+ this = (
371
+ split_line[-1],
372
+ {
373
+ "modify": " ".join(split_line[5:8]),
374
+ "unix.owner": split_line[2],
375
+ "unix.group": split_line[3],
376
+ "unix.mode": split_line[0],
377
+ "size": split_line[4],
378
+ },
379
+ )
380
+ if "d" == this[1]["unix.mode"][0]:
381
+ this[1]["type"] = "dir"
382
+ else:
383
+ this[1]["type"] = "file"
384
+ minfo.append(this)
385
+ return minfo
tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/libarchive.py ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from contextlib import contextmanager
2
+ from ctypes import (
3
+ CFUNCTYPE,
4
+ POINTER,
5
+ c_int,
6
+ c_longlong,
7
+ c_void_p,
8
+ cast,
9
+ create_string_buffer,
10
+ )
11
+
12
+ import libarchive
13
+ import libarchive.ffi as ffi
14
+
15
+ from fsspec import open_files
16
+ from fsspec.archive import AbstractArchiveFileSystem
17
+ from fsspec.implementations.memory import MemoryFile
18
+ from fsspec.utils import DEFAULT_BLOCK_SIZE
19
+
20
+ # Libarchive requires seekable files or memory only for certain archive
21
+ # types. However, since we read the directory first to cache the contents
22
+ # and also allow random access to any file, the file-like object needs
23
+ # to be seekable no matter what.
24
+
25
+ # Seek call-backs (not provided in the libarchive python wrapper)
26
+ SEEK_CALLBACK = CFUNCTYPE(c_longlong, c_int, c_void_p, c_longlong, c_int)
27
+ read_set_seek_callback = ffi.ffi(
28
+ "read_set_seek_callback", [ffi.c_archive_p, SEEK_CALLBACK], c_int, ffi.check_int
29
+ )
30
+ new_api = hasattr(ffi, "NO_OPEN_CB")
31
+
32
+
33
+ @contextmanager
34
+ def custom_reader(file, format_name="all", filter_name="all", block_size=ffi.page_size):
35
+ """Read an archive from a seekable file-like object.
36
+
37
+ The `file` object must support the standard `readinto` and 'seek' methods.
38
+ """
39
+ buf = create_string_buffer(block_size)
40
+ buf_p = cast(buf, c_void_p)
41
+
42
+ def read_func(archive_p, context, ptrptr):
43
+ # readinto the buffer, returns number of bytes read
44
+ length = file.readinto(buf)
45
+ # write the address of the buffer into the pointer
46
+ ptrptr = cast(ptrptr, POINTER(c_void_p))
47
+ ptrptr[0] = buf_p
48
+ # tell libarchive how much data was written into the buffer
49
+ return length
50
+
51
+ def seek_func(archive_p, context, offset, whence):
52
+ file.seek(offset, whence)
53
+ # tell libarchvie the current position
54
+ return file.tell()
55
+
56
+ read_cb = ffi.READ_CALLBACK(read_func)
57
+ seek_cb = SEEK_CALLBACK(seek_func)
58
+
59
+ if new_api:
60
+ open_cb = ffi.NO_OPEN_CB
61
+ close_cb = ffi.NO_CLOSE_CB
62
+ else:
63
+ open_cb = libarchive.read.OPEN_CALLBACK(ffi.VOID_CB)
64
+ close_cb = libarchive.read.CLOSE_CALLBACK(ffi.VOID_CB)
65
+
66
+ with libarchive.read.new_archive_read(format_name, filter_name) as archive_p:
67
+ read_set_seek_callback(archive_p, seek_cb)
68
+ ffi.read_open(archive_p, None, open_cb, read_cb, close_cb)
69
+ yield libarchive.read.ArchiveRead(archive_p)
70
+
71
+
72
+ class LibArchiveFileSystem(AbstractArchiveFileSystem):
73
+ """Compressed archives as a file-system (read-only)
74
+
75
+ Supports the following formats:
76
+ tar, pax , cpio, ISO9660, zip, mtree, shar, ar, raw, xar, lha/lzh, rar
77
+ Microsoft CAB, 7-Zip, WARC
78
+
79
+ See the libarchive documentation for further restrictions.
80
+ https://www.libarchive.org/
81
+
82
+ Keeps file object open while instance lives. It only works in seekable
83
+ file-like objects. In case the filesystem does not support this kind of
84
+ file object, it is recommended to cache locally.
85
+
86
+ This class is pickleable, but not necessarily thread-safe (depends on the
87
+ platform). See libarchive documentation for details.
88
+ """
89
+
90
+ root_marker = ""
91
+ protocol = "libarchive"
92
+ cachable = False
93
+
94
+ def __init__(
95
+ self,
96
+ fo="",
97
+ mode="r",
98
+ target_protocol=None,
99
+ target_options=None,
100
+ block_size=DEFAULT_BLOCK_SIZE,
101
+ **kwargs,
102
+ ):
103
+ """
104
+ Parameters
105
+ ----------
106
+ fo: str or file-like
107
+ Contains ZIP, and must exist. If a str, will fetch file using
108
+ :meth:`~fsspec.open_files`, which must return one file exactly.
109
+ mode: str
110
+ Currently, only 'r' accepted
111
+ target_protocol: str (optional)
112
+ If ``fo`` is a string, this value can be used to override the
113
+ FS protocol inferred from a URL
114
+ target_options: dict (optional)
115
+ Kwargs passed when instantiating the target FS, if ``fo`` is
116
+ a string.
117
+ """
118
+ super().__init__(self, **kwargs)
119
+ if mode != "r":
120
+ raise ValueError("Only read from archive files accepted")
121
+ if isinstance(fo, str):
122
+ files = open_files(fo, protocol=target_protocol, **(target_options or {}))
123
+ if len(files) != 1:
124
+ raise ValueError(
125
+ f'Path "{fo}" did not resolve to exactly one file: "{files}"'
126
+ )
127
+ fo = files[0]
128
+ self.of = fo
129
+ self.fo = fo.__enter__() # the whole instance is a context
130
+ self.block_size = block_size
131
+ self.dir_cache = None
132
+
133
+ @contextmanager
134
+ def _open_archive(self):
135
+ self.fo.seek(0)
136
+ with custom_reader(self.fo, block_size=self.block_size) as arc:
137
+ yield arc
138
+
139
+ @classmethod
140
+ def _strip_protocol(cls, path):
141
+ # file paths are always relative to the archive root
142
+ return super()._strip_protocol(path).lstrip("/")
143
+
144
+ def _get_dirs(self):
145
+ fields = {
146
+ "name": "pathname",
147
+ "size": "size",
148
+ "created": "ctime",
149
+ "mode": "mode",
150
+ "uid": "uid",
151
+ "gid": "gid",
152
+ "mtime": "mtime",
153
+ }
154
+
155
+ if self.dir_cache is not None:
156
+ return
157
+
158
+ self.dir_cache = {}
159
+ list_names = []
160
+ with self._open_archive() as arc:
161
+ for entry in arc:
162
+ if not entry.isdir and not entry.isfile:
163
+ # Skip symbolic links, fifo entries, etc.
164
+ continue
165
+ self.dir_cache.update(
166
+ {
167
+ dirname: {"name": dirname, "size": 0, "type": "directory"}
168
+ for dirname in self._all_dirnames(set(entry.name))
169
+ }
170
+ )
171
+ f = {key: getattr(entry, fields[key]) for key in fields}
172
+ f["type"] = "directory" if entry.isdir else "file"
173
+ list_names.append(entry.name)
174
+
175
+ self.dir_cache[f["name"]] = f
176
+ # libarchive does not seem to return an entry for the directories (at least
177
+ # not in all formats), so get the directories names from the files names
178
+ self.dir_cache.update(
179
+ {
180
+ dirname: {"name": dirname, "size": 0, "type": "directory"}
181
+ for dirname in self._all_dirnames(list_names)
182
+ }
183
+ )
184
+
185
+ def _open(
186
+ self,
187
+ path,
188
+ mode="rb",
189
+ block_size=None,
190
+ autocommit=True,
191
+ cache_options=None,
192
+ **kwargs,
193
+ ):
194
+ path = self._strip_protocol(path)
195
+ if mode != "rb":
196
+ raise NotImplementedError
197
+
198
+ data = bytes()
199
+ with self._open_archive() as arc:
200
+ for entry in arc:
201
+ if entry.pathname != path:
202
+ continue
203
+
204
+ if entry.size == 0:
205
+ # empty file, so there are no blocks
206
+ break
207
+
208
+ for block in entry.get_blocks(entry.size):
209
+ data = block
210
+ break
211
+ else:
212
+ raise ValueError
213
+ return MemoryFile(fs=self, path=path, data=data)
tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/local.py ADDED
@@ -0,0 +1,418 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ import io
3
+ import logging
4
+ import os
5
+ import os.path as osp
6
+ import re
7
+ import shutil
8
+ import stat
9
+ import tempfile
10
+
11
+ from fsspec import AbstractFileSystem
12
+ from fsspec.compression import compr
13
+ from fsspec.core import get_compression
14
+ from fsspec.utils import isfilelike, stringify_path
15
+
16
+ logger = logging.getLogger("fsspec.local")
17
+
18
+
19
+ class LocalFileSystem(AbstractFileSystem):
20
+ """Interface to files on local storage
21
+
22
+ Parameters
23
+ ----------
24
+ auto_mkdir: bool
25
+ Whether, when opening a file, the directory containing it should
26
+ be created (if it doesn't already exist). This is assumed by pyarrow
27
+ code.
28
+ """
29
+
30
+ root_marker = "/"
31
+ protocol = "file", "local"
32
+ local_file = True
33
+
34
+ def __init__(self, auto_mkdir=False, **kwargs):
35
+ super().__init__(**kwargs)
36
+ self.auto_mkdir = auto_mkdir
37
+
38
+ @property
39
+ def fsid(self):
40
+ return "local"
41
+
42
+ def mkdir(self, path, create_parents=True, **kwargs):
43
+ path = self._strip_protocol(path)
44
+ if self.exists(path):
45
+ raise FileExistsError(path)
46
+ if create_parents:
47
+ self.makedirs(path, exist_ok=True)
48
+ else:
49
+ os.mkdir(path, **kwargs)
50
+
51
+ def makedirs(self, path, exist_ok=False):
52
+ path = self._strip_protocol(path)
53
+ os.makedirs(path, exist_ok=exist_ok)
54
+
55
+ def rmdir(self, path):
56
+ path = self._strip_protocol(path)
57
+ os.rmdir(path)
58
+
59
+ def ls(self, path, detail=False, **kwargs):
60
+ path = self._strip_protocol(path)
61
+ info = self.info(path)
62
+ if info["type"] == "directory":
63
+ with os.scandir(path) as it:
64
+ infos = [self.info(f) for f in it]
65
+ else:
66
+ infos = [info]
67
+
68
+ if not detail:
69
+ return [i["name"] for i in infos]
70
+ return infos
71
+
72
+ def info(self, path, **kwargs):
73
+ if isinstance(path, os.DirEntry):
74
+ # scandir DirEntry
75
+ out = path.stat(follow_symlinks=False)
76
+ link = path.is_symlink()
77
+ if path.is_dir(follow_symlinks=False):
78
+ t = "directory"
79
+ elif path.is_file(follow_symlinks=False):
80
+ t = "file"
81
+ else:
82
+ t = "other"
83
+ path = self._strip_protocol(path.path)
84
+ else:
85
+ # str or path-like
86
+ path = self._strip_protocol(path)
87
+ out = os.stat(path, follow_symlinks=False)
88
+ link = stat.S_ISLNK(out.st_mode)
89
+ if link:
90
+ out = os.stat(path, follow_symlinks=True)
91
+ if stat.S_ISDIR(out.st_mode):
92
+ t = "directory"
93
+ elif stat.S_ISREG(out.st_mode):
94
+ t = "file"
95
+ else:
96
+ t = "other"
97
+ result = {
98
+ "name": path,
99
+ "size": out.st_size,
100
+ "type": t,
101
+ "created": out.st_ctime,
102
+ "islink": link,
103
+ }
104
+ for field in ["mode", "uid", "gid", "mtime", "ino", "nlink"]:
105
+ result[field] = getattr(out, f"st_{field}")
106
+ if result["islink"]:
107
+ result["destination"] = os.readlink(path)
108
+ try:
109
+ out2 = os.stat(path, follow_symlinks=True)
110
+ result["size"] = out2.st_size
111
+ except OSError:
112
+ result["size"] = 0
113
+ return result
114
+
115
+ def lexists(self, path, **kwargs):
116
+ return osp.lexists(path)
117
+
118
+ def cp_file(self, path1, path2, **kwargs):
119
+ path1 = self._strip_protocol(path1).rstrip("/")
120
+ path2 = self._strip_protocol(path2).rstrip("/")
121
+ if self.auto_mkdir:
122
+ self.makedirs(self._parent(path2), exist_ok=True)
123
+ if self.isfile(path1):
124
+ shutil.copyfile(path1, path2)
125
+ elif self.isdir(path1):
126
+ self.mkdirs(path2, exist_ok=True)
127
+ else:
128
+ raise FileNotFoundError(path1)
129
+
130
+ def get_file(self, path1, path2, callback=None, **kwargs):
131
+ if isfilelike(path2):
132
+ with open(path1, "rb") as f:
133
+ shutil.copyfileobj(f, path2)
134
+ else:
135
+ return self.cp_file(path1, path2, **kwargs)
136
+
137
+ def put_file(self, path1, path2, callback=None, **kwargs):
138
+ return self.cp_file(path1, path2, **kwargs)
139
+
140
+ def mv_file(self, path1, path2, **kwargs):
141
+ path1 = self._strip_protocol(path1).rstrip("/")
142
+ path2 = self._strip_protocol(path2).rstrip("/")
143
+ shutil.move(path1, path2)
144
+
145
+ def link(self, src, dst, **kwargs):
146
+ src = self._strip_protocol(src)
147
+ dst = self._strip_protocol(dst)
148
+ os.link(src, dst, **kwargs)
149
+
150
+ def symlink(self, src, dst, **kwargs):
151
+ src = self._strip_protocol(src)
152
+ dst = self._strip_protocol(dst)
153
+ os.symlink(src, dst, **kwargs)
154
+
155
+ def islink(self, path) -> bool:
156
+ return os.path.islink(self._strip_protocol(path))
157
+
158
+ def rm_file(self, path):
159
+ os.remove(self._strip_protocol(path))
160
+
161
+ def rm(self, path, recursive=False, maxdepth=None):
162
+ if not isinstance(path, list):
163
+ path = [path]
164
+
165
+ for p in path:
166
+ p = self._strip_protocol(p).rstrip("/")
167
+ if self.isdir(p):
168
+ if not recursive:
169
+ raise ValueError("Cannot delete directory, set recursive=True")
170
+ if osp.abspath(p) == os.getcwd():
171
+ raise ValueError("Cannot delete current working directory")
172
+ shutil.rmtree(p)
173
+ else:
174
+ os.remove(p)
175
+
176
+ def unstrip_protocol(self, name):
177
+ name = self._strip_protocol(name) # normalise for local/win/...
178
+ return f"file://{name}"
179
+
180
+ def _open(self, path, mode="rb", block_size=None, **kwargs):
181
+ path = self._strip_protocol(path)
182
+ if self.auto_mkdir and "w" in mode:
183
+ self.makedirs(self._parent(path), exist_ok=True)
184
+ return LocalFileOpener(path, mode, fs=self, **kwargs)
185
+
186
+ def touch(self, path, truncate=True, **kwargs):
187
+ path = self._strip_protocol(path)
188
+ if self.auto_mkdir:
189
+ self.makedirs(self._parent(path), exist_ok=True)
190
+ if self.exists(path):
191
+ os.utime(path, None)
192
+ else:
193
+ open(path, "a").close()
194
+ if truncate:
195
+ os.truncate(path, 0)
196
+
197
+ def created(self, path):
198
+ info = self.info(path=path)
199
+ return datetime.datetime.fromtimestamp(
200
+ info["created"], tz=datetime.timezone.utc
201
+ )
202
+
203
+ def modified(self, path):
204
+ info = self.info(path=path)
205
+ return datetime.datetime.fromtimestamp(info["mtime"], tz=datetime.timezone.utc)
206
+
207
+ @classmethod
208
+ def _parent(cls, path):
209
+ path = cls._strip_protocol(path).rstrip("/")
210
+ if "/" in path:
211
+ return path.rsplit("/", 1)[0]
212
+ else:
213
+ return cls.root_marker
214
+
215
+ @classmethod
216
+ def _strip_protocol(cls, path):
217
+ path = stringify_path(path)
218
+ if path.startswith("file://"):
219
+ path = path[7:]
220
+ elif path.startswith("file:"):
221
+ path = path[5:]
222
+ elif path.startswith("local://"):
223
+ path = path[8:]
224
+ elif path.startswith("local:"):
225
+ path = path[6:]
226
+ return make_path_posix(path).rstrip("/") or cls.root_marker
227
+
228
+ def _isfilestore(self):
229
+ # Inheriting from DaskFileSystem makes this False (S3, etc. were)
230
+ # the original motivation. But we are a posix-like file system.
231
+ # See https://github.com/dask/dask/issues/5526
232
+ return True
233
+
234
+ def chmod(self, path, mode):
235
+ path = stringify_path(path)
236
+ return os.chmod(path, mode)
237
+
238
+
239
+ def make_path_posix(path, sep=os.sep):
240
+ """Make path generic"""
241
+ if isinstance(path, (list, set, tuple)):
242
+ return type(path)(make_path_posix(p) for p in path)
243
+ if "~" in path:
244
+ path = osp.expanduser(path)
245
+ if sep == "/":
246
+ # most common fast case for posix
247
+ if path.startswith("/"):
248
+ return path
249
+ if path.startswith("./"):
250
+ path = path[2:]
251
+ return f"{os.getcwd()}/{path}"
252
+ if (
253
+ (sep not in path and "/" not in path)
254
+ or (sep == "/" and not path.startswith("/"))
255
+ or (sep == "\\" and ":" not in path and not path.startswith("\\\\"))
256
+ ):
257
+ # relative path like "path" or "rel\\path" (win) or rel/path"
258
+ if os.sep == "\\":
259
+ # abspath made some more '\\' separators
260
+ return make_path_posix(osp.abspath(path))
261
+ else:
262
+ return f"{os.getcwd()}/{path}"
263
+ if path.startswith("file://"):
264
+ path = path[7:]
265
+ if re.match("/[A-Za-z]:", path):
266
+ # for windows file URI like "file:///C:/folder/file"
267
+ # or "file:///C:\\dir\\file"
268
+ path = path[1:].replace("\\", "/").replace("//", "/")
269
+ if path.startswith("\\\\"):
270
+ # special case for windows UNC/DFS-style paths, do nothing,
271
+ # just flip the slashes around (case below does not work!)
272
+ return path.replace("\\", "/")
273
+ if re.match("[A-Za-z]:", path):
274
+ # windows full path like "C:\\local\\path"
275
+ return path.lstrip("\\").replace("\\", "/").replace("//", "/")
276
+ if path.startswith("\\"):
277
+ # windows network path like "\\server\\path"
278
+ return "/" + path.lstrip("\\").replace("\\", "/").replace("//", "/")
279
+ return path
280
+
281
+
282
+ def trailing_sep(path):
283
+ """Return True if the path ends with a path separator.
284
+
285
+ A forward slash is always considered a path separator, even on Operating
286
+ Systems that normally use a backslash.
287
+ """
288
+ # TODO: if all incoming paths were posix-compliant then separator would
289
+ # always be a forward slash, simplifying this function.
290
+ # See https://github.com/fsspec/filesystem_spec/pull/1250
291
+ return path.endswith(os.sep) or (os.altsep is not None and path.endswith(os.altsep))
292
+
293
+
294
+ class LocalFileOpener(io.IOBase):
295
+ def __init__(
296
+ self, path, mode, autocommit=True, fs=None, compression=None, **kwargs
297
+ ):
298
+ logger.debug("open file: %s", path)
299
+ self.path = path
300
+ self.mode = mode
301
+ self.fs = fs
302
+ self.f = None
303
+ self.autocommit = autocommit
304
+ self.compression = get_compression(path, compression)
305
+ self.blocksize = io.DEFAULT_BUFFER_SIZE
306
+ self._open()
307
+
308
+ def _open(self):
309
+ if self.f is None or self.f.closed:
310
+ if self.autocommit or "w" not in self.mode:
311
+ self.f = open(self.path, mode=self.mode)
312
+ if self.compression:
313
+ compress = compr[self.compression]
314
+ self.f = compress(self.f, mode=self.mode)
315
+ else:
316
+ # TODO: check if path is writable?
317
+ i, name = tempfile.mkstemp()
318
+ os.close(i) # we want normal open and normal buffered file
319
+ self.temp = name
320
+ self.f = open(name, mode=self.mode)
321
+ if "w" not in self.mode:
322
+ self.size = self.f.seek(0, 2)
323
+ self.f.seek(0)
324
+ self.f.size = self.size
325
+
326
+ def _fetch_range(self, start, end):
327
+ # probably only used by cached FS
328
+ if "r" not in self.mode:
329
+ raise ValueError
330
+ self._open()
331
+ self.f.seek(start)
332
+ return self.f.read(end - start)
333
+
334
+ def __setstate__(self, state):
335
+ self.f = None
336
+ loc = state.pop("loc", None)
337
+ self.__dict__.update(state)
338
+ if "r" in state["mode"]:
339
+ self.f = None
340
+ self._open()
341
+ self.f.seek(loc)
342
+
343
+ def __getstate__(self):
344
+ d = self.__dict__.copy()
345
+ d.pop("f")
346
+ if "r" in self.mode:
347
+ d["loc"] = self.f.tell()
348
+ else:
349
+ if not self.f.closed:
350
+ raise ValueError("Cannot serialise open write-mode local file")
351
+ return d
352
+
353
+ def commit(self):
354
+ if self.autocommit:
355
+ raise RuntimeError("Can only commit if not already set to autocommit")
356
+ shutil.move(self.temp, self.path)
357
+
358
+ def discard(self):
359
+ if self.autocommit:
360
+ raise RuntimeError("Cannot discard if set to autocommit")
361
+ os.remove(self.temp)
362
+
363
+ def readable(self) -> bool:
364
+ return True
365
+
366
+ def writable(self) -> bool:
367
+ return "r" not in self.mode
368
+
369
+ def read(self, *args, **kwargs):
370
+ return self.f.read(*args, **kwargs)
371
+
372
+ def write(self, *args, **kwargs):
373
+ return self.f.write(*args, **kwargs)
374
+
375
+ def tell(self, *args, **kwargs):
376
+ return self.f.tell(*args, **kwargs)
377
+
378
+ def seek(self, *args, **kwargs):
379
+ return self.f.seek(*args, **kwargs)
380
+
381
+ def seekable(self, *args, **kwargs):
382
+ return self.f.seekable(*args, **kwargs)
383
+
384
+ def readline(self, *args, **kwargs):
385
+ return self.f.readline(*args, **kwargs)
386
+
387
+ def readlines(self, *args, **kwargs):
388
+ return self.f.readlines(*args, **kwargs)
389
+
390
+ def close(self):
391
+ return self.f.close()
392
+
393
+ def truncate(self, size=None) -> int:
394
+ return self.f.truncate(size)
395
+
396
+ @property
397
+ def closed(self):
398
+ return self.f.closed
399
+
400
+ def fileno(self):
401
+ return self.raw.fileno()
402
+
403
+ def flush(self) -> None:
404
+ self.f.flush()
405
+
406
+ def __iter__(self):
407
+ return self.f.__iter__()
408
+
409
+ def __getattr__(self, item):
410
+ return getattr(self.f, item)
411
+
412
+ def __enter__(self):
413
+ self._incontext = True
414
+ return self
415
+
416
+ def __exit__(self, exc_type, exc_value, traceback):
417
+ self._incontext = False
418
+ self.f.__exit__(exc_type, exc_value, traceback)
tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/memory.py ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ from datetime import datetime, timezone
5
+ from errno import ENOTEMPTY
6
+ from io import BytesIO
7
+ from typing import Any, ClassVar
8
+
9
+ from fsspec import AbstractFileSystem
10
+
11
+ logger = logging.getLogger("fsspec.memoryfs")
12
+
13
+
14
+ class MemoryFileSystem(AbstractFileSystem):
15
+ """A filesystem based on a dict of BytesIO objects
16
+
17
+ This is a global filesystem so instances of this class all point to the same
18
+ in memory filesystem.
19
+ """
20
+
21
+ store: ClassVar[dict[str, Any]] = {} # global, do not overwrite!
22
+ pseudo_dirs = [""] # global, do not overwrite!
23
+ protocol = "memory"
24
+ root_marker = "/"
25
+
26
+ @classmethod
27
+ def _strip_protocol(cls, path):
28
+ if path.startswith("memory://"):
29
+ path = path[len("memory://") :]
30
+ if "::" in path or "://" in path:
31
+ return path.rstrip("/")
32
+ path = path.lstrip("/").rstrip("/")
33
+ return "/" + path if path else ""
34
+
35
+ def ls(self, path, detail=True, **kwargs):
36
+ path = self._strip_protocol(path)
37
+ if path in self.store:
38
+ # there is a key with this exact name
39
+ if not detail:
40
+ return [path]
41
+ return [
42
+ {
43
+ "name": path,
44
+ "size": self.store[path].size,
45
+ "type": "file",
46
+ "created": self.store[path].created.timestamp(),
47
+ }
48
+ ]
49
+ paths = set()
50
+ starter = path + "/"
51
+ out = []
52
+ for p2 in tuple(self.store):
53
+ if p2.startswith(starter):
54
+ if "/" not in p2[len(starter) :]:
55
+ # exact child
56
+ out.append(
57
+ {
58
+ "name": p2,
59
+ "size": self.store[p2].size,
60
+ "type": "file",
61
+ "created": self.store[p2].created.timestamp(),
62
+ }
63
+ )
64
+ elif len(p2) > len(starter):
65
+ # implied child directory
66
+ ppath = starter + p2[len(starter) :].split("/", 1)[0]
67
+ if ppath not in paths:
68
+ out = out or []
69
+ out.append(
70
+ {
71
+ "name": ppath,
72
+ "size": 0,
73
+ "type": "directory",
74
+ }
75
+ )
76
+ paths.add(ppath)
77
+ for p2 in self.pseudo_dirs:
78
+ if p2.startswith(starter):
79
+ if "/" not in p2[len(starter) :]:
80
+ # exact child pdir
81
+ if p2 not in paths:
82
+ out.append({"name": p2, "size": 0, "type": "directory"})
83
+ paths.add(p2)
84
+ else:
85
+ # directory implied by deeper pdir
86
+ ppath = starter + p2[len(starter) :].split("/", 1)[0]
87
+ if ppath not in paths:
88
+ out.append({"name": ppath, "size": 0, "type": "directory"})
89
+ paths.add(ppath)
90
+ if not out:
91
+ if path in self.pseudo_dirs:
92
+ # empty dir
93
+ return []
94
+ raise FileNotFoundError(path)
95
+ if detail:
96
+ return out
97
+ return sorted([f["name"] for f in out])
98
+
99
+ def mkdir(self, path, create_parents=True, **kwargs):
100
+ path = self._strip_protocol(path)
101
+ if path in self.store or path in self.pseudo_dirs:
102
+ raise FileExistsError(path)
103
+ if self._parent(path).strip("/") and self.isfile(self._parent(path)):
104
+ raise NotADirectoryError(self._parent(path))
105
+ if create_parents and self._parent(path).strip("/"):
106
+ try:
107
+ self.mkdir(self._parent(path), create_parents, **kwargs)
108
+ except FileExistsError:
109
+ pass
110
+ if path and path not in self.pseudo_dirs:
111
+ self.pseudo_dirs.append(path)
112
+
113
+ def makedirs(self, path, exist_ok=False):
114
+ try:
115
+ self.mkdir(path, create_parents=True)
116
+ except FileExistsError:
117
+ if not exist_ok:
118
+ raise
119
+
120
+ def pipe_file(self, path, value, **kwargs):
121
+ """Set the bytes of given file
122
+
123
+ Avoids copies of the data if possible
124
+ """
125
+ self.open(path, "wb", data=value)
126
+
127
+ def rmdir(self, path):
128
+ path = self._strip_protocol(path)
129
+ if path == "":
130
+ # silently avoid deleting FS root
131
+ return
132
+ if path in self.pseudo_dirs:
133
+ if not self.ls(path):
134
+ self.pseudo_dirs.remove(path)
135
+ else:
136
+ raise OSError(ENOTEMPTY, "Directory not empty", path)
137
+ else:
138
+ raise FileNotFoundError(path)
139
+
140
+ def info(self, path, **kwargs):
141
+ path = self._strip_protocol(path)
142
+ if path in self.pseudo_dirs or any(
143
+ p.startswith(path + "/") for p in list(self.store) + self.pseudo_dirs
144
+ ):
145
+ return {
146
+ "name": path,
147
+ "size": 0,
148
+ "type": "directory",
149
+ }
150
+ elif path in self.store:
151
+ filelike = self.store[path]
152
+ return {
153
+ "name": path,
154
+ "size": filelike.size,
155
+ "type": "file",
156
+ "created": getattr(filelike, "created", None),
157
+ }
158
+ else:
159
+ raise FileNotFoundError(path)
160
+
161
+ def _open(
162
+ self,
163
+ path,
164
+ mode="rb",
165
+ block_size=None,
166
+ autocommit=True,
167
+ cache_options=None,
168
+ **kwargs,
169
+ ):
170
+ path = self._strip_protocol(path)
171
+ if path in self.pseudo_dirs:
172
+ raise IsADirectoryError(path)
173
+ parent = path
174
+ while len(parent) > 1:
175
+ parent = self._parent(parent)
176
+ if self.isfile(parent):
177
+ raise FileExistsError(parent)
178
+ if mode in ["rb", "ab", "r+b"]:
179
+ if path in self.store:
180
+ f = self.store[path]
181
+ if mode == "ab":
182
+ # position at the end of file
183
+ f.seek(0, 2)
184
+ else:
185
+ # position at the beginning of file
186
+ f.seek(0)
187
+ return f
188
+ else:
189
+ raise FileNotFoundError(path)
190
+ elif mode == "wb":
191
+ m = MemoryFile(self, path, kwargs.get("data"))
192
+ if not self._intrans:
193
+ m.commit()
194
+ return m
195
+ else:
196
+ name = self.__class__.__name__
197
+ raise ValueError(f"unsupported file mode for {name}: {mode!r}")
198
+
199
+ def cp_file(self, path1, path2, **kwargs):
200
+ path1 = self._strip_protocol(path1)
201
+ path2 = self._strip_protocol(path2)
202
+ if self.isfile(path1):
203
+ self.store[path2] = MemoryFile(
204
+ self, path2, self.store[path1].getvalue()
205
+ ) # implicit copy
206
+ elif self.isdir(path1):
207
+ if path2 not in self.pseudo_dirs:
208
+ self.pseudo_dirs.append(path2)
209
+ else:
210
+ raise FileNotFoundError(path1)
211
+
212
+ def cat_file(self, path, start=None, end=None, **kwargs):
213
+ path = self._strip_protocol(path)
214
+ try:
215
+ return bytes(self.store[path].getbuffer()[start:end])
216
+ except KeyError:
217
+ raise FileNotFoundError(path)
218
+
219
+ def _rm(self, path):
220
+ path = self._strip_protocol(path)
221
+ try:
222
+ del self.store[path]
223
+ except KeyError as e:
224
+ raise FileNotFoundError(path) from e
225
+
226
+ def modified(self, path):
227
+ path = self._strip_protocol(path)
228
+ try:
229
+ return self.store[path].modified
230
+ except KeyError:
231
+ raise FileNotFoundError(path)
232
+
233
+ def created(self, path):
234
+ path = self._strip_protocol(path)
235
+ try:
236
+ return self.store[path].created
237
+ except KeyError:
238
+ raise FileNotFoundError(path)
239
+
240
+ def rm(self, path, recursive=False, maxdepth=None):
241
+ if isinstance(path, str):
242
+ path = self._strip_protocol(path)
243
+ else:
244
+ path = [self._strip_protocol(p) for p in path]
245
+ paths = self.expand_path(path, recursive=recursive, maxdepth=maxdepth)
246
+ for p in reversed(paths):
247
+ # If the expanded path doesn't exist, it is only because the expanded
248
+ # path was a directory that does not exist in self.pseudo_dirs. This
249
+ # is possible if you directly create files without making the
250
+ # directories first.
251
+ if not self.exists(p):
252
+ continue
253
+ if self.isfile(p):
254
+ self.rm_file(p)
255
+ else:
256
+ self.rmdir(p)
257
+
258
+
259
+ class MemoryFile(BytesIO):
260
+ """A BytesIO which can't close and works as a context manager
261
+
262
+ Can initialise with data. Each path should only be active once at any moment.
263
+
264
+ No need to provide fs, path if auto-committing (default)
265
+ """
266
+
267
+ def __init__(self, fs=None, path=None, data=None):
268
+ logger.debug("open file %s", path)
269
+ self.fs = fs
270
+ self.path = path
271
+ self.created = datetime.now(tz=timezone.utc)
272
+ self.modified = datetime.now(tz=timezone.utc)
273
+ if data:
274
+ super().__init__(data)
275
+ self.seek(0)
276
+
277
+ @property
278
+ def size(self):
279
+ return self.getbuffer().nbytes
280
+
281
+ def __enter__(self):
282
+ return self
283
+
284
+ def close(self):
285
+ pass
286
+
287
+ def discard(self):
288
+ pass
289
+
290
+ def commit(self):
291
+ self.fs.store[self.path] = self
292
+ self.modified = datetime.now(tz=timezone.utc)
tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/sftp.py ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ import logging
3
+ import os
4
+ import types
5
+ import uuid
6
+ from stat import S_ISDIR, S_ISLNK
7
+
8
+ import paramiko
9
+
10
+ from .. import AbstractFileSystem
11
+ from ..utils import infer_storage_options
12
+
13
+ logger = logging.getLogger("fsspec.sftp")
14
+
15
+
16
+ class SFTPFileSystem(AbstractFileSystem):
17
+ """Files over SFTP/SSH
18
+
19
+ Peer-to-peer filesystem over SSH using paramiko.
20
+
21
+ Note: if using this with the ``open`` or ``open_files``, with full URLs,
22
+ there is no way to tell if a path is relative, so all paths are assumed
23
+ to be absolute.
24
+ """
25
+
26
+ protocol = "sftp", "ssh"
27
+
28
+ def __init__(self, host, **ssh_kwargs):
29
+ """
30
+
31
+ Parameters
32
+ ----------
33
+ host: str
34
+ Hostname or IP as a string
35
+ temppath: str
36
+ Location on the server to put files, when within a transaction
37
+ ssh_kwargs: dict
38
+ Parameters passed on to connection. See details in
39
+ https://docs.paramiko.org/en/3.3/api/client.html#paramiko.client.SSHClient.connect
40
+ May include port, username, password...
41
+ """
42
+ if self._cached:
43
+ return
44
+ super().__init__(**ssh_kwargs)
45
+ self.temppath = ssh_kwargs.pop("temppath", "/tmp") # remote temp directory
46
+ self.host = host
47
+ self.ssh_kwargs = ssh_kwargs
48
+ self._connect()
49
+
50
+ def _connect(self):
51
+ logger.debug("Connecting to SFTP server %s", self.host)
52
+ self.client = paramiko.SSHClient()
53
+ self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
54
+ self.client.connect(self.host, **self.ssh_kwargs)
55
+ self.ftp = self.client.open_sftp()
56
+
57
+ @classmethod
58
+ def _strip_protocol(cls, path):
59
+ return infer_storage_options(path)["path"]
60
+
61
+ @staticmethod
62
+ def _get_kwargs_from_urls(urlpath):
63
+ out = infer_storage_options(urlpath)
64
+ out.pop("path", None)
65
+ out.pop("protocol", None)
66
+ return out
67
+
68
+ def mkdir(self, path, create_parents=True, mode=511):
69
+ logger.debug("Creating folder %s", path)
70
+ if self.exists(path):
71
+ raise FileExistsError(f"File exists: {path}")
72
+
73
+ if create_parents:
74
+ self.makedirs(path)
75
+ else:
76
+ self.ftp.mkdir(path, mode)
77
+
78
+ def makedirs(self, path, exist_ok=False, mode=511):
79
+ if self.exists(path) and not exist_ok:
80
+ raise FileExistsError(f"File exists: {path}")
81
+
82
+ parts = path.split("/")
83
+ new_path = "/" if path[:1] == "/" else ""
84
+
85
+ for part in parts:
86
+ if part:
87
+ new_path = f"{new_path}/{part}" if new_path else part
88
+ if not self.exists(new_path):
89
+ self.ftp.mkdir(new_path, mode)
90
+
91
+ def rmdir(self, path):
92
+ logger.debug("Removing folder %s", path)
93
+ self.ftp.rmdir(path)
94
+
95
+ def info(self, path):
96
+ stat = self._decode_stat(self.ftp.stat(path))
97
+ stat["name"] = path
98
+ return stat
99
+
100
+ @staticmethod
101
+ def _decode_stat(stat, parent_path=None):
102
+ if S_ISDIR(stat.st_mode):
103
+ t = "directory"
104
+ elif S_ISLNK(stat.st_mode):
105
+ t = "link"
106
+ else:
107
+ t = "file"
108
+ out = {
109
+ "name": "",
110
+ "size": stat.st_size,
111
+ "type": t,
112
+ "uid": stat.st_uid,
113
+ "gid": stat.st_gid,
114
+ "time": datetime.datetime.fromtimestamp(
115
+ stat.st_atime, tz=datetime.timezone.utc
116
+ ),
117
+ "mtime": datetime.datetime.fromtimestamp(
118
+ stat.st_mtime, tz=datetime.timezone.utc
119
+ ),
120
+ }
121
+ if parent_path:
122
+ out["name"] = "/".join([parent_path.rstrip("/"), stat.filename])
123
+ return out
124
+
125
+ def ls(self, path, detail=False):
126
+ logger.debug("Listing folder %s", path)
127
+ stats = [self._decode_stat(stat, path) for stat in self.ftp.listdir_iter(path)]
128
+ if detail:
129
+ return stats
130
+ else:
131
+ paths = [stat["name"] for stat in stats]
132
+ return sorted(paths)
133
+
134
+ def put(self, lpath, rpath, callback=None, **kwargs):
135
+ logger.debug("Put file %s into %s", lpath, rpath)
136
+ self.ftp.put(lpath, rpath)
137
+
138
+ def get_file(self, rpath, lpath, **kwargs):
139
+ if self.isdir(rpath):
140
+ os.makedirs(lpath, exist_ok=True)
141
+ else:
142
+ self.ftp.get(self._strip_protocol(rpath), lpath)
143
+
144
+ def _open(self, path, mode="rb", block_size=None, **kwargs):
145
+ """
146
+ block_size: int or None
147
+ If 0, no buffering, if 1, line buffering, if >1, buffer that many
148
+ bytes, if None use default from paramiko.
149
+ """
150
+ logger.debug("Opening file %s", path)
151
+ if kwargs.get("autocommit", True) is False:
152
+ # writes to temporary file, move on commit
153
+ path2 = "/".join([self.temppath, str(uuid.uuid4())])
154
+ f = self.ftp.open(path2, mode, bufsize=block_size if block_size else -1)
155
+ f.temppath = path2
156
+ f.targetpath = path
157
+ f.fs = self
158
+ f.commit = types.MethodType(commit_a_file, f)
159
+ f.discard = types.MethodType(discard_a_file, f)
160
+ else:
161
+ f = self.ftp.open(path, mode, bufsize=block_size if block_size else -1)
162
+ return f
163
+
164
+ def _rm(self, path):
165
+ if self.isdir(path):
166
+ self.ftp.rmdir(path)
167
+ else:
168
+ self.ftp.remove(path)
169
+
170
+ def mv(self, old, new):
171
+ logger.debug("Renaming %s into %s", old, new)
172
+ self.ftp.posix_rename(old, new)
173
+
174
+
175
+ def commit_a_file(self):
176
+ self.fs.mv(self.temppath, self.targetpath)
177
+
178
+
179
+ def discard_a_file(self):
180
+ self.fs._rm(self.temppath)
tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/tar.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ import tarfile
3
+
4
+ import fsspec
5
+ from fsspec.archive import AbstractArchiveFileSystem
6
+ from fsspec.compression import compr
7
+ from fsspec.utils import infer_compression
8
+
9
+ typemap = {b"0": "file", b"5": "directory"}
10
+
11
+ logger = logging.getLogger("tar")
12
+
13
+
14
+ class TarFileSystem(AbstractArchiveFileSystem):
15
+ """Compressed Tar archives as a file-system (read-only)
16
+
17
+ Supports the following formats:
18
+ tar.gz, tar.bz2, tar.xz
19
+ """
20
+
21
+ root_marker = ""
22
+ protocol = "tar"
23
+ cachable = False
24
+
25
+ def __init__(
26
+ self,
27
+ fo="",
28
+ index_store=None,
29
+ target_options=None,
30
+ target_protocol=None,
31
+ compression=None,
32
+ **kwargs,
33
+ ):
34
+ super().__init__(**kwargs)
35
+ target_options = target_options or {}
36
+
37
+ if isinstance(fo, str):
38
+ self.of = fsspec.open(fo, protocol=target_protocol, **target_options)
39
+ fo = self.of.open() # keep the reference
40
+
41
+ # Try to infer compression.
42
+ if compression is None:
43
+ name = None
44
+
45
+ # Try different ways to get hold of the filename. `fo` might either
46
+ # be a `fsspec.LocalFileOpener`, an `io.BufferedReader` or an
47
+ # `fsspec.AbstractFileSystem` instance.
48
+ try:
49
+ # Amended io.BufferedReader or similar.
50
+ # This uses a "protocol extension" where original filenames are
51
+ # propagated to archive-like filesystems in order to let them
52
+ # infer the right compression appropriately.
53
+ if hasattr(fo, "original"):
54
+ name = fo.original
55
+
56
+ # fsspec.LocalFileOpener
57
+ elif hasattr(fo, "path"):
58
+ name = fo.path
59
+
60
+ # io.BufferedReader
61
+ elif hasattr(fo, "name"):
62
+ name = fo.name
63
+
64
+ # fsspec.AbstractFileSystem
65
+ elif hasattr(fo, "info"):
66
+ name = fo.info()["name"]
67
+
68
+ except Exception as ex:
69
+ logger.warning(
70
+ f"Unable to determine file name, not inferring compression: {ex}"
71
+ )
72
+
73
+ if name is not None:
74
+ compression = infer_compression(name)
75
+ logger.info(f"Inferred compression {compression} from file name {name}")
76
+
77
+ if compression is not None:
78
+ # TODO: tarfile already implements compression with modes like "'r:gz'",
79
+ # but then would seek to offset in the file work?
80
+ fo = compr[compression](fo)
81
+
82
+ self._fo_ref = fo
83
+ self.fo = fo # the whole instance is a context
84
+ self.tar = tarfile.TarFile(fileobj=self.fo)
85
+ self.dir_cache = None
86
+
87
+ self.index_store = index_store
88
+ self.index = None
89
+ self._index()
90
+
91
+ def _index(self):
92
+ # TODO: load and set saved index, if exists
93
+ out = {}
94
+ for ti in self.tar:
95
+ info = ti.get_info()
96
+ info["type"] = typemap.get(info["type"], "file")
97
+ name = ti.get_info()["name"].rstrip("/")
98
+ out[name] = (info, ti.offset_data)
99
+
100
+ self.index = out
101
+ # TODO: save index to self.index_store here, if set
102
+
103
+ def _get_dirs(self):
104
+ if self.dir_cache is not None:
105
+ return
106
+
107
+ # This enables ls to get directories as children as well as files
108
+ self.dir_cache = {
109
+ dirname: {"name": dirname, "size": 0, "type": "directory"}
110
+ for dirname in self._all_dirnames(self.tar.getnames())
111
+ }
112
+ for member in self.tar.getmembers():
113
+ info = member.get_info()
114
+ info["name"] = info["name"].rstrip("/")
115
+ info["type"] = typemap.get(info["type"], "file")
116
+ self.dir_cache[info["name"]] = info
117
+
118
+ def _open(self, path, mode="rb", **kwargs):
119
+ if mode != "rb":
120
+ raise ValueError("Read-only filesystem implementation")
121
+ details, offset = self.index[path]
122
+ if details["type"] != "file":
123
+ raise ValueError("Can only handle regular files")
124
+ return self.tar.extractfile(path)
tuning-competition-baseline/.venv/lib/python3.11/site-packages/fsspec/implementations/webhdfs.py ADDED
@@ -0,0 +1,486 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # https://hadoop.apache.org/docs/r1.0.4/webhdfs.html
2
+
3
+ import logging
4
+ import os
5
+ import secrets
6
+ import shutil
7
+ import tempfile
8
+ import uuid
9
+ from contextlib import suppress
10
+ from urllib.parse import quote
11
+
12
+ import requests
13
+
14
+ from ..spec import AbstractBufferedFile, AbstractFileSystem
15
+ from ..utils import infer_storage_options, tokenize
16
+
17
+ logger = logging.getLogger("webhdfs")
18
+
19
+
20
+ class WebHDFS(AbstractFileSystem):
21
+ """
22
+ Interface to HDFS over HTTP using the WebHDFS API. Supports also HttpFS gateways.
23
+
24
+ Four auth mechanisms are supported:
25
+
26
+ insecure: no auth is done, and the user is assumed to be whoever they
27
+ say they are (parameter ``user``), or a predefined value such as
28
+ "dr.who" if not given
29
+ spnego: when kerberos authentication is enabled, auth is negotiated by
30
+ requests_kerberos https://github.com/requests/requests-kerberos .
31
+ This establishes a session based on existing kinit login and/or
32
+ specified principal/password; parameters are passed with ``kerb_kwargs``
33
+ token: uses an existing Hadoop delegation token from another secured
34
+ service. Indeed, this client can also generate such tokens when
35
+ not insecure. Note that tokens expire, but can be renewed (by a
36
+ previously specified user) and may allow for proxying.
37
+ basic-auth: used when both parameter ``user`` and parameter ``password``
38
+ are provided.
39
+
40
+ """
41
+
42
+ tempdir = str(tempfile.gettempdir())
43
+ protocol = "webhdfs", "webHDFS"
44
+
45
+ def __init__(
46
+ self,
47
+ host,
48
+ port=50070,
49
+ kerberos=False,
50
+ token=None,
51
+ user=None,
52
+ password=None,
53
+ proxy_to=None,
54
+ kerb_kwargs=None,
55
+ data_proxy=None,
56
+ use_https=False,
57
+ session_cert=None,
58
+ session_verify=True,
59
+ **kwargs,
60
+ ):
61
+ """
62
+ Parameters
63
+ ----------
64
+ host: str
65
+ Name-node address
66
+ port: int
67
+ Port for webHDFS
68
+ kerberos: bool
69
+ Whether to authenticate with kerberos for this connection
70
+ token: str or None
71
+ If given, use this token on every call to authenticate. A user
72
+ and user-proxy may be encoded in the token and should not be also
73
+ given
74
+ user: str or None
75
+ If given, assert the user name to connect with
76
+ password: str or None
77
+ If given, assert the password to use for basic auth. If password
78
+ is provided, user must be provided also
79
+ proxy_to: str or None
80
+ If given, the user has the authority to proxy, and this value is
81
+ the user in who's name actions are taken
82
+ kerb_kwargs: dict
83
+ Any extra arguments for HTTPKerberosAuth, see
84
+ `<https://github.com/requests/requests-kerberos/blob/master/requests_kerberos/kerberos_.py>`_
85
+ data_proxy: dict, callable or None
86
+ If given, map data-node addresses. This can be necessary if the
87
+ HDFS cluster is behind a proxy, running on Docker or otherwise has
88
+ a mismatch between the host-names given by the name-node and the
89
+ address by which to refer to them from the client. If a dict,
90
+ maps host names ``host->data_proxy[host]``; if a callable, full
91
+ URLs are passed, and function must conform to
92
+ ``url->data_proxy(url)``.
93
+ use_https: bool
94
+ Whether to connect to the Name-node using HTTPS instead of HTTP
95
+ session_cert: str or Tuple[str, str] or None
96
+ Path to a certificate file, or tuple of (cert, key) files to use
97
+ for the requests.Session
98
+ session_verify: str, bool or None
99
+ Path to a certificate file to use for verifying the requests.Session.
100
+ kwargs
101
+ """
102
+ if self._cached:
103
+ return
104
+ super().__init__(**kwargs)
105
+ self.url = (
106
+ f"{'https' if use_https else 'http'}://{host}:{port}/webhdfs/v1" # noqa
107
+ )
108
+ self.kerb = kerberos
109
+ self.kerb_kwargs = kerb_kwargs or {}
110
+ self.pars = {}
111
+ self.proxy = data_proxy or {}
112
+ if token is not None:
113
+ if user is not None or proxy_to is not None:
114
+ raise ValueError(
115
+ "If passing a delegation token, must not set "
116
+ "user or proxy_to, as these are encoded in the"
117
+ " token"
118
+ )
119
+ self.pars["delegation"] = token
120
+ self.user = user
121
+ self.password = password
122
+
123
+ if password is not None:
124
+ if user is None:
125
+ raise ValueError(
126
+ "If passing a password, the user must also be"
127
+ "set in order to set up the basic-auth"
128
+ )
129
+ else:
130
+ if user is not None:
131
+ self.pars["user.name"] = user
132
+
133
+ if proxy_to is not None:
134
+ self.pars["doas"] = proxy_to
135
+ if kerberos and user is not None:
136
+ raise ValueError(
137
+ "If using Kerberos auth, do not specify the "
138
+ "user, this is handled by kinit."
139
+ )
140
+
141
+ self.session_cert = session_cert
142
+ self.session_verify = session_verify
143
+
144
+ self._connect()
145
+
146
+ self._fsid = f"webhdfs_{tokenize(host, port)}"
147
+
148
+ @property
149
+ def fsid(self):
150
+ return self._fsid
151
+
152
+ def _connect(self):
153
+ self.session = requests.Session()
154
+
155
+ if self.session_cert:
156
+ self.session.cert = self.session_cert
157
+
158
+ self.session.verify = self.session_verify
159
+
160
+ if self.kerb:
161
+ from requests_kerberos import HTTPKerberosAuth
162
+
163
+ self.session.auth = HTTPKerberosAuth(**self.kerb_kwargs)
164
+
165
+ if self.user is not None and self.password is not None:
166
+ from requests.auth import HTTPBasicAuth
167
+
168
+ self.session.auth = HTTPBasicAuth(self.user, self.password)
169
+
170
+ def _call(self, op, method="get", path=None, data=None, redirect=True, **kwargs):
171
+ url = self._apply_proxy(self.url + quote(path or "", safe="/="))
172
+ args = kwargs.copy()
173
+ args.update(self.pars)
174
+ args["op"] = op.upper()
175
+ logger.debug("sending %s with %s", url, method)
176
+ out = self.session.request(
177
+ method=method.upper(),
178
+ url=url,
179
+ params=args,
180
+ data=data,
181
+ allow_redirects=redirect,
182
+ )
183
+ if out.status_code in [400, 401, 403, 404, 500]:
184
+ try:
185
+ err = out.json()
186
+ msg = err["RemoteException"]["message"]
187
+ exp = err["RemoteException"]["exception"]
188
+ except (ValueError, KeyError):
189
+ pass
190
+ else:
191
+ if exp in ["IllegalArgumentException", "UnsupportedOperationException"]:
192
+ raise ValueError(msg)
193
+ elif exp in ["SecurityException", "AccessControlException"]:
194
+ raise PermissionError(msg)
195
+ elif exp in ["FileNotFoundException"]:
196
+ raise FileNotFoundError(msg)
197
+ else:
198
+ raise RuntimeError(msg)
199
+ out.raise_for_status()
200
+ return out
201
+
202
+ def _open(
203
+ self,
204
+ path,
205
+ mode="rb",
206
+ block_size=None,
207
+ autocommit=True,
208
+ replication=None,
209
+ permissions=None,
210
+ **kwargs,
211
+ ):
212
+ """
213
+
214
+ Parameters
215
+ ----------
216
+ path: str
217
+ File location
218
+ mode: str
219
+ 'rb', 'wb', etc.
220
+ block_size: int
221
+ Client buffer size for read-ahead or write buffer
222
+ autocommit: bool
223
+ If False, writes to temporary file that only gets put in final
224
+ location upon commit
225
+ replication: int
226
+ Number of copies of file on the cluster, write mode only
227
+ permissions: str or int
228
+ posix permissions, write mode only
229
+ kwargs
230
+
231
+ Returns
232
+ -------
233
+ WebHDFile instance
234
+ """
235
+ block_size = block_size or self.blocksize
236
+ return WebHDFile(
237
+ self,
238
+ path,
239
+ mode=mode,
240
+ block_size=block_size,
241
+ tempdir=self.tempdir,
242
+ autocommit=autocommit,
243
+ replication=replication,
244
+ permissions=permissions,
245
+ )
246
+
247
+ @staticmethod
248
+ def _process_info(info):
249
+ info["type"] = info["type"].lower()
250
+ info["size"] = info["length"]
251
+ return info
252
+
253
+ @classmethod
254
+ def _strip_protocol(cls, path):
255
+ return infer_storage_options(path)["path"]
256
+
257
+ @staticmethod
258
+ def _get_kwargs_from_urls(urlpath):
259
+ out = infer_storage_options(urlpath)
260
+ out.pop("path", None)
261
+ out.pop("protocol", None)
262
+ if "username" in out:
263
+ out["user"] = out.pop("username")
264
+ return out
265
+
266
+ def info(self, path):
267
+ out = self._call("GETFILESTATUS", path=path)
268
+ info = out.json()["FileStatus"]
269
+ info["name"] = path
270
+ return self._process_info(info)
271
+
272
+ def ls(self, path, detail=False):
273
+ out = self._call("LISTSTATUS", path=path)
274
+ infos = out.json()["FileStatuses"]["FileStatus"]
275
+ for info in infos:
276
+ self._process_info(info)
277
+ info["name"] = path.rstrip("/") + "/" + info["pathSuffix"]
278
+ if detail:
279
+ return sorted(infos, key=lambda i: i["name"])
280
+ else:
281
+ return sorted(info["name"] for info in infos)
282
+
283
+ def content_summary(self, path):
284
+ """Total numbers of files, directories and bytes under path"""
285
+ out = self._call("GETCONTENTSUMMARY", path=path)
286
+ return out.json()["ContentSummary"]
287
+
288
+ def ukey(self, path):
289
+ """Checksum info of file, giving method and result"""
290
+ out = self._call("GETFILECHECKSUM", path=path, redirect=False)
291
+ if "Location" in out.headers:
292
+ location = self._apply_proxy(out.headers["Location"])
293
+ out2 = self.session.get(location)
294
+ out2.raise_for_status()
295
+ return out2.json()["FileChecksum"]
296
+ else:
297
+ out.raise_for_status()
298
+ return out.json()["FileChecksum"]
299
+
300
+ def home_directory(self):
301
+ """Get user's home directory"""
302
+ out = self._call("GETHOMEDIRECTORY")
303
+ return out.json()["Path"]
304
+
305
+ def get_delegation_token(self, renewer=None):
306
+ """Retrieve token which can give the same authority to other uses
307
+
308
+ Parameters
309
+ ----------
310
+ renewer: str or None
311
+ User who may use this token; if None, will be current user
312
+ """
313
+ if renewer:
314
+ out = self._call("GETDELEGATIONTOKEN", renewer=renewer)
315
+ else:
316
+ out = self._call("GETDELEGATIONTOKEN")
317
+ t = out.json()["Token"]
318
+ if t is None:
319
+ raise ValueError("No token available for this user/security context")
320
+ return t["urlString"]
321
+
322
+ def renew_delegation_token(self, token):
323
+ """Make token live longer. Returns new expiry time"""
324
+ out = self._call("RENEWDELEGATIONTOKEN", method="put", token=token)
325
+ return out.json()["long"]
326
+
327
+ def cancel_delegation_token(self, token):
328
+ """Stop the token from being useful"""
329
+ self._call("CANCELDELEGATIONTOKEN", method="put", token=token)
330
+
331
+ def chmod(self, path, mod):
332
+ """Set the permission at path
333
+
334
+ Parameters
335
+ ----------
336
+ path: str
337
+ location to set (file or directory)
338
+ mod: str or int
339
+ posix epresentation or permission, give as oct string, e.g, '777'
340
+ or 0o777
341
+ """
342
+ self._call("SETPERMISSION", method="put", path=path, permission=mod)
343
+
344
+ def chown(self, path, owner=None, group=None):
345
+ """Change owning user and/or group"""
346
+ kwargs = {}
347
+ if owner is not None:
348
+ kwargs["owner"] = owner
349
+ if group is not None:
350
+ kwargs["group"] = group
351
+ self._call("SETOWNER", method="put", path=path, **kwargs)
352
+
353
+ def set_replication(self, path, replication):
354
+ """
355
+ Set file replication factor
356
+
357
+ Parameters
358
+ ----------
359
+ path: str
360
+ File location (not for directories)
361
+ replication: int
362
+ Number of copies of file on the cluster. Should be smaller than
363
+ number of data nodes; normally 3 on most systems.
364
+ """
365
+ self._call("SETREPLICATION", path=path, method="put", replication=replication)
366
+
367
+ def mkdir(self, path, **kwargs):
368
+ self._call("MKDIRS", method="put", path=path)
369
+
370
+ def makedirs(self, path, exist_ok=False):
371
+ if exist_ok is False and self.exists(path):
372
+ raise FileExistsError(path)
373
+ self.mkdir(path)
374
+
375
+ def mv(self, path1, path2, **kwargs):
376
+ self._call("RENAME", method="put", path=path1, destination=path2)
377
+
378
+ def rm(self, path, recursive=False, **kwargs):
379
+ self._call(
380
+ "DELETE",
381
+ method="delete",
382
+ path=path,
383
+ recursive="true" if recursive else "false",
384
+ )
385
+
386
+ def rm_file(self, path, **kwargs):
387
+ self.rm(path)
388
+
389
+ def cp_file(self, lpath, rpath, **kwargs):
390
+ with self.open(lpath) as lstream:
391
+ tmp_fname = "/".join([self._parent(rpath), f".tmp.{secrets.token_hex(16)}"])
392
+ # Perform an atomic copy (stream to a temporary file and
393
+ # move it to the actual destination).
394
+ try:
395
+ with self.open(tmp_fname, "wb") as rstream:
396
+ shutil.copyfileobj(lstream, rstream)
397
+ self.mv(tmp_fname, rpath)
398
+ except BaseException: # noqa
399
+ with suppress(FileNotFoundError):
400
+ self.rm(tmp_fname)
401
+ raise
402
+
403
+ def _apply_proxy(self, location):
404
+ if self.proxy and callable(self.proxy):
405
+ location = self.proxy(location)
406
+ elif self.proxy:
407
+ # as a dict
408
+ for k, v in self.proxy.items():
409
+ location = location.replace(k, v, 1)
410
+ return location
411
+
412
+
413
+ class WebHDFile(AbstractBufferedFile):
414
+ """A file living in HDFS over webHDFS"""
415
+
416
+ def __init__(self, fs, path, **kwargs):
417
+ super().__init__(fs, path, **kwargs)
418
+ kwargs = kwargs.copy()
419
+ if kwargs.get("permissions", None) is None:
420
+ kwargs.pop("permissions", None)
421
+ if kwargs.get("replication", None) is None:
422
+ kwargs.pop("replication", None)
423
+ self.permissions = kwargs.pop("permissions", 511)
424
+ tempdir = kwargs.pop("tempdir")
425
+ if kwargs.pop("autocommit", False) is False:
426
+ self.target = self.path
427
+ self.path = os.path.join(tempdir, str(uuid.uuid4()))
428
+
429
+ def _upload_chunk(self, final=False):
430
+ """Write one part of a multi-block file upload
431
+
432
+ Parameters
433
+ ==========
434
+ final: bool
435
+ This is the last block, so should complete file, if
436
+ self.autocommit is True.
437
+ """
438
+ out = self.fs.session.post(
439
+ self.location,
440
+ data=self.buffer.getvalue(),
441
+ headers={"content-type": "application/octet-stream"},
442
+ )
443
+ out.raise_for_status()
444
+ return True
445
+
446
+ def _initiate_upload(self):
447
+ """Create remote file/upload"""
448
+ kwargs = self.kwargs.copy()
449
+ if "a" in self.mode:
450
+ op, method = "APPEND", "POST"
451
+ else:
452
+ op, method = "CREATE", "PUT"
453
+ kwargs["overwrite"] = "true"
454
+ out = self.fs._call(op, method, self.path, redirect=False, **kwargs)
455
+ location = self.fs._apply_proxy(out.headers["Location"])
456
+ if "w" in self.mode:
457
+ # create empty file to append to
458
+ out2 = self.fs.session.put(
459
+ location, headers={"content-type": "application/octet-stream"}
460
+ )
461
+ out2.raise_for_status()
462
+ # after creating empty file, change location to append to
463
+ out2 = self.fs._call("APPEND", "POST", self.path, redirect=False, **kwargs)
464
+ self.location = self.fs._apply_proxy(out2.headers["Location"])
465
+
466
+ def _fetch_range(self, start, end):
467
+ start = max(start, 0)
468
+ end = min(self.size, end)
469
+ if start >= end or start >= self.size:
470
+ return b""
471
+ out = self.fs._call(
472
+ "OPEN", path=self.path, offset=start, length=end - start, redirect=False
473
+ )
474
+ out.raise_for_status()
475
+ if "Location" in out.headers:
476
+ location = out.headers["Location"]
477
+ out2 = self.fs.session.get(self.fs._apply_proxy(location))
478
+ return out2.content
479
+ else:
480
+ return out.content
481
+
482
+ def commit(self):
483
+ self.fs.mv(self.path, self.target)
484
+
485
+ def discard(self):
486
+ self.fs.rm(self.path)
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/functions/__pycache__/expintegrals.cpython-311.pyc ADDED
Binary file (23.7 kB). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/functions/__pycache__/qfunctions.cpython-311.pyc ADDED
Binary file (10.2 kB). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/functions/__pycache__/signals.cpython-311.pyc ADDED
Binary file (1.86 kB). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/functions/qfunctions.py ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .functions import defun, defun_wrapped
2
+
3
+ @defun
4
+ def qp(ctx, a, q=None, n=None, **kwargs):
5
+ r"""
6
+ Evaluates the q-Pochhammer symbol (or q-rising factorial)
7
+
8
+ .. math ::
9
+
10
+ (a; q)_n = \prod_{k=0}^{n-1} (1-a q^k)
11
+
12
+ where `n = \infty` is permitted if `|q| < 1`. Called with two arguments,
13
+ ``qp(a,q)`` computes `(a;q)_{\infty}`; with a single argument, ``qp(q)``
14
+ computes `(q;q)_{\infty}`. The special case
15
+
16
+ .. math ::
17
+
18
+ \phi(q) = (q; q)_{\infty} = \prod_{k=1}^{\infty} (1-q^k) =
19
+ \sum_{k=-\infty}^{\infty} (-1)^k q^{(3k^2-k)/2}
20
+
21
+ is also known as the Euler function, or (up to a factor `q^{-1/24}`)
22
+ the Dedekind eta function.
23
+
24
+ **Examples**
25
+
26
+ If `n` is a positive integer, the function amounts to a finite product::
27
+
28
+ >>> from mpmath import *
29
+ >>> mp.dps = 25; mp.pretty = True
30
+ >>> qp(2,3,5)
31
+ -725305.0
32
+ >>> fprod(1-2*3**k for k in range(5))
33
+ -725305.0
34
+ >>> qp(2,3,0)
35
+ 1.0
36
+
37
+ Complex arguments are allowed::
38
+
39
+ >>> qp(2-1j, 0.75j)
40
+ (0.4628842231660149089976379 + 4.481821753552703090628793j)
41
+
42
+ The regular Pochhammer symbol `(a)_n` is obtained in the
43
+ following limit as `q \to 1`::
44
+
45
+ >>> a, n = 4, 7
46
+ >>> limit(lambda q: qp(q**a,q,n) / (1-q)**n, 1)
47
+ 604800.0
48
+ >>> rf(a,n)
49
+ 604800.0
50
+
51
+ The Taylor series of the reciprocal Euler function gives
52
+ the partition function `P(n)`, i.e. the number of ways of writing
53
+ `n` as a sum of positive integers::
54
+
55
+ >>> taylor(lambda q: 1/qp(q), 0, 10)
56
+ [1.0, 1.0, 2.0, 3.0, 5.0, 7.0, 11.0, 15.0, 22.0, 30.0, 42.0]
57
+
58
+ Special values include::
59
+
60
+ >>> qp(0)
61
+ 1.0
62
+ >>> findroot(diffun(qp), -0.4) # location of maximum
63
+ -0.4112484791779547734440257
64
+ >>> qp(_)
65
+ 1.228348867038575112586878
66
+
67
+ The q-Pochhammer symbol is related to the Jacobi theta functions.
68
+ For example, the following identity holds::
69
+
70
+ >>> q = mpf(0.5) # arbitrary
71
+ >>> qp(q)
72
+ 0.2887880950866024212788997
73
+ >>> root(3,-2)*root(q,-24)*jtheta(2,pi/6,root(q,6))
74
+ 0.2887880950866024212788997
75
+
76
+ """
77
+ a = ctx.convert(a)
78
+ if n is None:
79
+ n = ctx.inf
80
+ else:
81
+ n = ctx.convert(n)
82
+ if n < 0:
83
+ raise ValueError("n cannot be negative")
84
+ if q is None:
85
+ q = a
86
+ else:
87
+ q = ctx.convert(q)
88
+ if n == 0:
89
+ return ctx.one + 0*(a+q)
90
+ infinite = (n == ctx.inf)
91
+ same = (a == q)
92
+ if infinite:
93
+ if abs(q) >= 1:
94
+ if same and (q == -1 or q == 1):
95
+ return ctx.zero * q
96
+ raise ValueError("q-function only defined for |q| < 1")
97
+ elif q == 0:
98
+ return ctx.one - a
99
+ maxterms = kwargs.get('maxterms', 50*ctx.prec)
100
+ if infinite and same:
101
+ # Euler's pentagonal theorem
102
+ def terms():
103
+ t = 1
104
+ yield t
105
+ k = 1
106
+ x1 = q
107
+ x2 = q**2
108
+ while 1:
109
+ yield (-1)**k * x1
110
+ yield (-1)**k * x2
111
+ x1 *= q**(3*k+1)
112
+ x2 *= q**(3*k+2)
113
+ k += 1
114
+ if k > maxterms:
115
+ raise ctx.NoConvergence
116
+ return ctx.sum_accurately(terms)
117
+ # return ctx.nprod(lambda k: 1-a*q**k, [0,n-1])
118
+ def factors():
119
+ k = 0
120
+ r = ctx.one
121
+ while 1:
122
+ yield 1 - a*r
123
+ r *= q
124
+ k += 1
125
+ if k >= n:
126
+ return
127
+ if k > maxterms:
128
+ raise ctx.NoConvergence
129
+ return ctx.mul_accurately(factors)
130
+
131
+ @defun_wrapped
132
+ def qgamma(ctx, z, q, **kwargs):
133
+ r"""
134
+ Evaluates the q-gamma function
135
+
136
+ .. math ::
137
+
138
+ \Gamma_q(z) = \frac{(q; q)_{\infty}}{(q^z; q)_{\infty}} (1-q)^{1-z}.
139
+
140
+
141
+ **Examples**
142
+
143
+ Evaluation for real and complex arguments::
144
+
145
+ >>> from mpmath import *
146
+ >>> mp.dps = 25; mp.pretty = True
147
+ >>> qgamma(4,0.75)
148
+ 4.046875
149
+ >>> qgamma(6,6)
150
+ 121226245.0
151
+ >>> qgamma(3+4j, 0.5j)
152
+ (0.1663082382255199834630088 + 0.01952474576025952984418217j)
153
+
154
+ The q-gamma function satisfies a functional equation similar
155
+ to that of the ordinary gamma function::
156
+
157
+ >>> q = mpf(0.25)
158
+ >>> z = mpf(2.5)
159
+ >>> qgamma(z+1,q)
160
+ 1.428277424823760954685912
161
+ >>> (1-q**z)/(1-q)*qgamma(z,q)
162
+ 1.428277424823760954685912
163
+
164
+ """
165
+ if abs(q) > 1:
166
+ return ctx.qgamma(z,1/q)*q**((z-2)*(z-1)*0.5)
167
+ return ctx.qp(q, q, None, **kwargs) / \
168
+ ctx.qp(q**z, q, None, **kwargs) * (1-q)**(1-z)
169
+
170
+ @defun_wrapped
171
+ def qfac(ctx, z, q, **kwargs):
172
+ r"""
173
+ Evaluates the q-factorial,
174
+
175
+ .. math ::
176
+
177
+ [n]_q! = (1+q)(1+q+q^2)\cdots(1+q+\cdots+q^{n-1})
178
+
179
+ or more generally
180
+
181
+ .. math ::
182
+
183
+ [z]_q! = \frac{(q;q)_z}{(1-q)^z}.
184
+
185
+ **Examples**
186
+
187
+ >>> from mpmath import *
188
+ >>> mp.dps = 25; mp.pretty = True
189
+ >>> qfac(0,0)
190
+ 1.0
191
+ >>> qfac(4,3)
192
+ 2080.0
193
+ >>> qfac(5,6)
194
+ 121226245.0
195
+ >>> qfac(1+1j, 2+1j)
196
+ (0.4370556551322672478613695 + 0.2609739839216039203708921j)
197
+
198
+ """
199
+ if ctx.isint(z) and ctx._re(z) > 0:
200
+ n = int(ctx._re(z))
201
+ return ctx.qp(q, q, n, **kwargs) / (1-q)**n
202
+ return ctx.qgamma(z+1, q, **kwargs)
203
+
204
+ @defun
205
+ def qhyper(ctx, a_s, b_s, q, z, **kwargs):
206
+ r"""
207
+ Evaluates the basic hypergeometric series or hypergeometric q-series
208
+
209
+ .. math ::
210
+
211
+ \,_r\phi_s \left[\begin{matrix}
212
+ a_1 & a_2 & \ldots & a_r \\
213
+ b_1 & b_2 & \ldots & b_s
214
+ \end{matrix} ; q,z \right] =
215
+ \sum_{n=0}^\infty
216
+ \frac{(a_1;q)_n, \ldots, (a_r;q)_n}
217
+ {(b_1;q)_n, \ldots, (b_s;q)_n}
218
+ \left((-1)^n q^{n\choose 2}\right)^{1+s-r}
219
+ \frac{z^n}{(q;q)_n}
220
+
221
+ where `(a;q)_n` denotes the q-Pochhammer symbol (see :func:`~mpmath.qp`).
222
+
223
+ **Examples**
224
+
225
+ Evaluation works for real and complex arguments::
226
+
227
+ >>> from mpmath import *
228
+ >>> mp.dps = 25; mp.pretty = True
229
+ >>> qhyper([0.5], [2.25], 0.25, 4)
230
+ -0.1975849091263356009534385
231
+ >>> qhyper([0.5], [2.25], 0.25-0.25j, 4)
232
+ (2.806330244925716649839237 + 3.568997623337943121769938j)
233
+ >>> qhyper([1+j], [2,3+0.5j], 0.25, 3+4j)
234
+ (9.112885171773400017270226 - 1.272756997166375050700388j)
235
+
236
+ Comparing with a summation of the defining series, using
237
+ :func:`~mpmath.nsum`::
238
+
239
+ >>> b, q, z = 3, 0.25, 0.5
240
+ >>> qhyper([], [b], q, z)
241
+ 0.6221136748254495583228324
242
+ >>> nsum(lambda n: z**n / qp(q,q,n)/qp(b,q,n) * q**(n*(n-1)), [0,inf])
243
+ 0.6221136748254495583228324
244
+
245
+ """
246
+ #a_s = [ctx._convert_param(a)[0] for a in a_s]
247
+ #b_s = [ctx._convert_param(b)[0] for b in b_s]
248
+ #q = ctx._convert_param(q)[0]
249
+ a_s = [ctx.convert(a) for a in a_s]
250
+ b_s = [ctx.convert(b) for b in b_s]
251
+ q = ctx.convert(q)
252
+ z = ctx.convert(z)
253
+ r = len(a_s)
254
+ s = len(b_s)
255
+ d = 1+s-r
256
+ maxterms = kwargs.get('maxterms', 50*ctx.prec)
257
+ def terms():
258
+ t = ctx.one
259
+ yield t
260
+ qk = 1
261
+ k = 0
262
+ x = 1
263
+ while 1:
264
+ for a in a_s:
265
+ p = 1 - a*qk
266
+ t *= p
267
+ for b in b_s:
268
+ p = 1 - b*qk
269
+ if not p:
270
+ raise ValueError
271
+ t /= p
272
+ t *= z
273
+ x *= (-1)**d * qk ** d
274
+ qk *= q
275
+ t /= (1 - qk)
276
+ k += 1
277
+ yield t * x
278
+ if k > maxterms:
279
+ raise ctx.NoConvergence
280
+ return ctx.sum_accurately(terms)
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/__pycache__/extratest_gamma.cpython-311.pyc ADDED
Binary file (11.4 kB). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/__pycache__/test_calculus.cpython-311.pyc ADDED
Binary file (14 kB). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/__pycache__/test_eigen.cpython-311.pyc ADDED
Binary file (8.47 kB). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/__pycache__/test_power.cpython-311.pyc ADDED
Binary file (9.16 kB). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/__pycache__/test_str.cpython-311.pyc ADDED
Binary file (1.06 kB). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/extratest_zeta.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mpmath import zetazero
2
+ from timeit import default_timer as clock
3
+
4
+ def test_zetazero():
5
+ cases = [\
6
+ (399999999, 156762524.6750591511),
7
+ (241389216, 97490234.2276711795),
8
+ (526196239, 202950727.691229534),
9
+ (542964976, 209039046.578535272),
10
+ (1048449112, 388858885.231056486),
11
+ (1048449113, 388858885.384337406),
12
+ (1048449114, 388858886.002285122),
13
+ (1048449115, 388858886.00239369),
14
+ (1048449116, 388858886.690745053)
15
+ ]
16
+ for n, v in cases:
17
+ print(n, v)
18
+ t1 = clock()
19
+ ok = zetazero(n).ae(complex(0.5,v))
20
+ t2 = clock()
21
+ print("ok =", ok, ("(time = %s)" % round(t2-t1,3)))
22
+ print("Now computing two huge zeros (this may take hours)")
23
+ print("Computing zetazero(8637740722917)")
24
+ ok = zetazero(8637740722917).ae(complex(0.5,2124447368584.39296466152))
25
+ print("ok =", ok)
26
+ ok = zetazero(8637740722918).ae(complex(0.5,2124447368584.39298170604))
27
+ print("ok =", ok)
28
+
29
+ if __name__ == "__main__":
30
+ test_zetazero()
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/runtests.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ """
4
+ python runtests.py -py
5
+ Use py.test to run tests (more useful for debugging)
6
+
7
+ python runtests.py -coverage
8
+ Generate test coverage report. Statistics are written to /tmp
9
+
10
+ python runtests.py -profile
11
+ Generate profile stats (this is much slower)
12
+
13
+ python runtests.py -nogmpy
14
+ Run tests without using GMPY even if it exists
15
+
16
+ python runtests.py -strict
17
+ Enforce extra tests in normalize()
18
+
19
+ python runtests.py -local
20
+ Insert '../..' at the beginning of sys.path to use local mpmath
21
+
22
+ python runtests.py -skip ...
23
+ Skip tests from the listed modules
24
+
25
+ Additional arguments are used to filter the tests to run. Only files that have
26
+ one of the arguments in their name are executed.
27
+
28
+ """
29
+
30
+ import sys, os, traceback
31
+
32
+ profile = False
33
+ if "-profile" in sys.argv:
34
+ sys.argv.remove('-profile')
35
+ profile = True
36
+
37
+ coverage = False
38
+ if "-coverage" in sys.argv:
39
+ sys.argv.remove('-coverage')
40
+ coverage = True
41
+
42
+ if "-nogmpy" in sys.argv:
43
+ sys.argv.remove('-nogmpy')
44
+ os.environ['MPMATH_NOGMPY'] = 'Y'
45
+
46
+ if "-strict" in sys.argv:
47
+ sys.argv.remove('-strict')
48
+ os.environ['MPMATH_STRICT'] = 'Y'
49
+
50
+ if "-local" in sys.argv:
51
+ sys.argv.remove('-local')
52
+ importdir = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),
53
+ '../..'))
54
+ else:
55
+ importdir = ''
56
+
57
+ # TODO: add a flag for this
58
+ testdir = ''
59
+
60
+ def testit(importdir='', testdir='', exit_on_fail=False):
61
+ """Run all tests in testdir while importing from importdir."""
62
+ if importdir:
63
+ sys.path.insert(1, importdir)
64
+ if testdir:
65
+ sys.path.insert(1, testdir)
66
+ import os.path
67
+ import mpmath
68
+ print("mpmath imported from %s" % os.path.dirname(mpmath.__file__))
69
+ print("mpmath backend: %s" % mpmath.libmp.backend.BACKEND)
70
+ print("mpmath mp class: %s" % repr(mpmath.mp))
71
+ print("mpmath version: %s" % mpmath.__version__)
72
+ print("Python version: %s" % sys.version)
73
+ print("")
74
+ if "-py" in sys.argv:
75
+ sys.argv.remove('-py')
76
+ import py
77
+ py.test.cmdline.main()
78
+ else:
79
+ import glob
80
+ from timeit import default_timer as clock
81
+ modules = []
82
+ args = sys.argv[1:]
83
+ excluded = []
84
+ if '-skip' in args:
85
+ excluded = args[args.index('-skip')+1:]
86
+ args = args[:args.index('-skip')]
87
+ # search for tests in directory of this file if not otherwise specified
88
+ if not testdir:
89
+ pattern = os.path.dirname(sys.argv[0])
90
+ else:
91
+ pattern = testdir
92
+ if pattern:
93
+ pattern += '/'
94
+ pattern += 'test*.py'
95
+ # look for tests (respecting specified filter)
96
+ for f in glob.glob(pattern):
97
+ name = os.path.splitext(os.path.basename(f))[0]
98
+ # If run as a script, only run tests given as args, if any are given
99
+ if args and __name__ == "__main__":
100
+ ok = False
101
+ for arg in args:
102
+ if arg in name:
103
+ ok = True
104
+ break
105
+ if not ok:
106
+ continue
107
+ elif name in excluded:
108
+ continue
109
+ module = __import__(name)
110
+ priority = module.__dict__.get('priority', 100)
111
+ if priority == 666:
112
+ modules = [[priority, name, module]]
113
+ break
114
+ modules.append([priority, name, module])
115
+ # execute tests
116
+ modules.sort()
117
+ tstart = clock()
118
+ for priority, name, module in modules:
119
+ print(name)
120
+ for f in sorted(module.__dict__.keys()):
121
+ if f.startswith('test_'):
122
+ if coverage and ('numpy' in f):
123
+ continue
124
+ sys.stdout.write(" " + f[5:].ljust(25) + " ")
125
+ t1 = clock()
126
+ try:
127
+ module.__dict__[f]()
128
+ except:
129
+ etype, evalue, trb = sys.exc_info()
130
+ if etype in (KeyboardInterrupt, SystemExit):
131
+ raise
132
+ print("")
133
+ print("TEST FAILED!")
134
+ print("")
135
+ traceback.print_exc()
136
+ if exit_on_fail:
137
+ return
138
+ t2 = clock()
139
+ print("ok " + " " + ("%.7f" % (t2-t1)) + " s")
140
+ tend = clock()
141
+ print("")
142
+ print("finished tests in " + ("%.2f" % (tend-tstart)) + " seconds")
143
+ # clean sys.path
144
+ if importdir:
145
+ sys.path.remove(importdir)
146
+ if testdir:
147
+ sys.path.remove(testdir)
148
+
149
+ if __name__ == '__main__':
150
+ if profile:
151
+ import cProfile
152
+ cProfile.run("testit('%s', '%s')" % (importdir, testdir), sort=1)
153
+ elif coverage:
154
+ import trace
155
+ tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix],
156
+ trace=0, count=1)
157
+ tracer.run('testit(importdir, testdir)')
158
+ r = tracer.results()
159
+ r.write_results(show_missing=True, summary=True, coverdir="/tmp")
160
+ else:
161
+ testit(importdir, testdir)
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/test_functions2.py ADDED
@@ -0,0 +1,2384 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ import pytest
3
+ from mpmath import *
4
+
5
+ def test_bessel():
6
+ mp.dps = 15
7
+ assert j0(1).ae(0.765197686557966551)
8
+ assert j0(pi).ae(-0.304242177644093864)
9
+ assert j0(1000).ae(0.0247866861524201746)
10
+ assert j0(-25).ae(0.0962667832759581162)
11
+ assert j1(1).ae(0.440050585744933516)
12
+ assert j1(pi).ae(0.284615343179752757)
13
+ assert j1(1000).ae(0.00472831190708952392)
14
+ assert j1(-25).ae(0.125350249580289905)
15
+ assert besselj(5,1).ae(0.000249757730211234431)
16
+ assert besselj(5+0j,1).ae(0.000249757730211234431)
17
+ assert besselj(5,pi).ae(0.0521411843671184747)
18
+ assert besselj(5,1000).ae(0.00502540694523318607)
19
+ assert besselj(5,-25).ae(0.0660079953984229934)
20
+ assert besselj(-3,2).ae(-0.128943249474402051)
21
+ assert besselj(-4,2).ae(0.0339957198075684341)
22
+ assert besselj(3,3+2j).ae(0.424718794929639595942 + 0.625665327745785804812j)
23
+ assert besselj(0.25,4).ae(-0.374760630804249715)
24
+ assert besselj(1+2j,3+4j).ae(0.319247428741872131 - 0.669557748880365678j)
25
+ assert (besselj(3, 10**10) * 10**5).ae(0.76765081748139204023)
26
+ assert bessely(-0.5, 0) == 0
27
+ assert bessely(0.5, 0) == -inf
28
+ assert bessely(1.5, 0) == -inf
29
+ assert bessely(0,0) == -inf
30
+ assert bessely(-0.4, 0) == -inf
31
+ assert bessely(-0.6, 0) == inf
32
+ assert bessely(-1, 0) == inf
33
+ assert bessely(-1.4, 0) == inf
34
+ assert bessely(-1.6, 0) == -inf
35
+ assert bessely(-1, 0) == inf
36
+ assert bessely(-2, 0) == -inf
37
+ assert bessely(-3, 0) == inf
38
+ assert bessely(0.5, 0) == -inf
39
+ assert bessely(1, 0) == -inf
40
+ assert bessely(1.5, 0) == -inf
41
+ assert bessely(2, 0) == -inf
42
+ assert bessely(2.5, 0) == -inf
43
+ assert bessely(3, 0) == -inf
44
+ assert bessely(0,0.5).ae(-0.44451873350670655715)
45
+ assert bessely(1,0.5).ae(-1.4714723926702430692)
46
+ assert bessely(-1,0.5).ae(1.4714723926702430692)
47
+ assert bessely(3.5,0.5).ae(-138.86400867242488443)
48
+ assert bessely(0,3+4j).ae(4.6047596915010138655-8.8110771408232264208j)
49
+ assert bessely(0,j).ae(-0.26803248203398854876+1.26606587775200833560j)
50
+ assert (bessely(3, 10**10) * 10**5).ae(0.21755917537013204058)
51
+ assert besseli(0,0) == 1
52
+ assert besseli(1,0) == 0
53
+ assert besseli(2,0) == 0
54
+ assert besseli(-1,0) == 0
55
+ assert besseli(-2,0) == 0
56
+ assert besseli(0,0.5).ae(1.0634833707413235193)
57
+ assert besseli(1,0.5).ae(0.25789430539089631636)
58
+ assert besseli(-1,0.5).ae(0.25789430539089631636)
59
+ assert besseli(3.5,0.5).ae(0.00068103597085793815863)
60
+ assert besseli(0,3+4j).ae(-3.3924877882755196097-1.3239458916287264815j)
61
+ assert besseli(0,j).ae(besselj(0,1))
62
+ assert (besseli(3, 10**10) * mpf(10)**(-4342944813)).ae(4.2996028505491271875)
63
+ assert besselk(0,0) == inf
64
+ assert besselk(1,0) == inf
65
+ assert besselk(2,0) == inf
66
+ assert besselk(-1,0) == inf
67
+ assert besselk(-2,0) == inf
68
+ assert besselk(0,0.5).ae(0.92441907122766586178)
69
+ assert besselk(1,0.5).ae(1.6564411200033008937)
70
+ assert besselk(-1,0.5).ae(1.6564411200033008937)
71
+ assert besselk(3.5,0.5).ae(207.48418747548460607)
72
+ assert besselk(0,3+4j).ae(-0.007239051213570155013+0.026510418350267677215j)
73
+ assert besselk(0,j).ae(-0.13863371520405399968-1.20196971531720649914j)
74
+ assert (besselk(3, 10**10) * mpf(10)**4342944824).ae(1.1628981033356187851)
75
+ # test for issue 331, bug reported by Michael Hartmann
76
+ for n in range(10,100,10):
77
+ mp.dps = n
78
+ assert besseli(91.5,24.7708).ae("4.00830632138673963619656140653537080438462342928377020695738635559218797348548092636896796324190271316137982810144874264e-41")
79
+
80
+ def test_bessel_zeros():
81
+ mp.dps = 15
82
+ assert besseljzero(0,1).ae(2.40482555769577276869)
83
+ assert besseljzero(2,1).ae(5.1356223018406825563)
84
+ assert besseljzero(1,50).ae(157.86265540193029781)
85
+ assert besseljzero(10,1).ae(14.475500686554541220)
86
+ assert besseljzero(0.5,3).ae(9.4247779607693797153)
87
+ assert besseljzero(2,1,1).ae(3.0542369282271403228)
88
+ assert besselyzero(0,1).ae(0.89357696627916752158)
89
+ assert besselyzero(2,1).ae(3.3842417671495934727)
90
+ assert besselyzero(1,50).ae(156.29183520147840108)
91
+ assert besselyzero(10,1).ae(12.128927704415439387)
92
+ assert besselyzero(0.5,3).ae(7.8539816339744830962)
93
+ assert besselyzero(2,1,1).ae(5.0025829314460639452)
94
+
95
+ def test_hankel():
96
+ mp.dps = 15
97
+ assert hankel1(0,0.5).ae(0.93846980724081290423-0.44451873350670655715j)
98
+ assert hankel1(1,0.5).ae(0.2422684576748738864-1.4714723926702430692j)
99
+ assert hankel1(-1,0.5).ae(-0.2422684576748738864+1.4714723926702430692j)
100
+ assert hankel1(1.5,0.5).ae(0.0917016996256513026-2.5214655504213378514j)
101
+ assert hankel1(1.5,3+4j).ae(0.0066806866476728165382-0.0036684231610839127106j)
102
+ assert hankel2(0,0.5).ae(0.93846980724081290423+0.44451873350670655715j)
103
+ assert hankel2(1,0.5).ae(0.2422684576748738864+1.4714723926702430692j)
104
+ assert hankel2(-1,0.5).ae(-0.2422684576748738864-1.4714723926702430692j)
105
+ assert hankel2(1.5,0.5).ae(0.0917016996256513026+2.5214655504213378514j)
106
+ assert hankel2(1.5,3+4j).ae(14.783528526098567526-7.397390270853446512j)
107
+
108
+ def test_struve():
109
+ mp.dps = 15
110
+ assert struveh(2,3).ae(0.74238666967748318564)
111
+ assert struveh(-2.5,3).ae(0.41271003220971599344)
112
+ assert struvel(2,3).ae(1.7476573277362782744)
113
+ assert struvel(-2.5,3).ae(1.5153394466819651377)
114
+
115
+ def test_whittaker():
116
+ mp.dps = 15
117
+ assert whitm(2,3,4).ae(49.753745589025246591)
118
+ assert whitw(2,3,4).ae(14.111656223052932215)
119
+
120
+ def test_kelvin():
121
+ mp.dps = 15
122
+ assert ber(2,3).ae(0.80836846563726819091)
123
+ assert ber(3,4).ae(-0.28262680167242600233)
124
+ assert ber(-3,2).ae(-0.085611448496796363669)
125
+ assert bei(2,3).ae(-0.89102236377977331571)
126
+ assert bei(-3,2).ae(-0.14420994155731828415)
127
+ assert ker(2,3).ae(0.12839126695733458928)
128
+ assert ker(-3,2).ae(-0.29802153400559142783)
129
+ assert ker(0.5,3).ae(-0.085662378535217097524)
130
+ assert kei(2,3).ae(0.036804426134164634000)
131
+ assert kei(-3,2).ae(0.88682069845786731114)
132
+ assert kei(0.5,3).ae(0.013633041571314302948)
133
+
134
+ def test_hyper_misc():
135
+ mp.dps = 15
136
+ assert hyp0f1(1,0) == 1
137
+ assert hyp1f1(1,2,0) == 1
138
+ assert hyp1f2(1,2,3,0) == 1
139
+ assert hyp2f1(1,2,3,0) == 1
140
+ assert hyp2f2(1,2,3,4,0) == 1
141
+ assert hyp2f3(1,2,3,4,5,0) == 1
142
+ # Degenerate case: 0F0
143
+ assert hyper([],[],0) == 1
144
+ assert hyper([],[],-2).ae(exp(-2))
145
+ # Degenerate case: 1F0
146
+ assert hyper([2],[],1.5) == 4
147
+ #
148
+ assert hyp2f1((1,3),(2,3),(5,6),mpf(27)/32).ae(1.6)
149
+ assert hyp2f1((1,4),(1,2),(3,4),mpf(80)/81).ae(1.8)
150
+ assert hyp2f1((2,3),(1,1),(3,2),(2+j)/3).ae(1.327531603558679093+0.439585080092769253j)
151
+ mp.dps = 25
152
+ v = mpc('1.2282306665029814734863026', '-0.1225033830118305184672133')
153
+ assert hyper([(3,4),2+j,1],[1,5,j/3],mpf(1)/5+j/8).ae(v)
154
+ mp.dps = 15
155
+
156
+ def test_elliptic_integrals():
157
+ mp.dps = 15
158
+ assert ellipk(0).ae(pi/2)
159
+ assert ellipk(0.5).ae(gamma(0.25)**2/(4*sqrt(pi)))
160
+ assert ellipk(1) == inf
161
+ assert ellipk(1+0j) == inf
162
+ assert ellipk(-1).ae('1.3110287771460599052')
163
+ assert ellipk(-2).ae('1.1714200841467698589')
164
+ assert isinstance(ellipk(-2), mpf)
165
+ assert isinstance(ellipe(-2), mpf)
166
+ assert ellipk(-50).ae('0.47103424540873331679')
167
+ mp.dps = 30
168
+ n1 = +fraction(99999,100000)
169
+ n2 = +fraction(100001,100000)
170
+ mp.dps = 15
171
+ assert ellipk(n1).ae('7.1427724505817781901')
172
+ assert ellipk(n2).ae(mpc('7.1427417367963090109', '-1.5707923998261688019'))
173
+ assert ellipe(n1).ae('1.0000332138990829170')
174
+ v = ellipe(n2)
175
+ assert v.real.ae('0.999966786328145474069137')
176
+ assert (v.imag*10**6).ae('7.853952181727432')
177
+ assert ellipk(2).ae(mpc('1.3110287771460599052', '-1.3110287771460599052'))
178
+ assert ellipk(50).ae(mpc('0.22326753950210985451', '-0.47434723226254522087'))
179
+ assert ellipk(3+4j).ae(mpc('0.91119556380496500866', '0.63133428324134524388'))
180
+ assert ellipk(3-4j).ae(mpc('0.91119556380496500866', '-0.63133428324134524388'))
181
+ assert ellipk(-3+4j).ae(mpc('0.95357894880405122483', '0.23093044503746114444'))
182
+ assert ellipk(-3-4j).ae(mpc('0.95357894880405122483', '-0.23093044503746114444'))
183
+ assert isnan(ellipk(nan))
184
+ assert isnan(ellipe(nan))
185
+ assert ellipk(inf) == 0
186
+ assert isinstance(ellipk(inf), mpc)
187
+ assert ellipk(-inf) == 0
188
+ assert ellipk(1+0j) == inf
189
+ assert ellipe(0).ae(pi/2)
190
+ assert ellipe(0.5).ae(pi**(mpf(3)/2)/gamma(0.25)**2 +gamma(0.25)**2/(8*sqrt(pi)))
191
+ assert ellipe(1) == 1
192
+ assert ellipe(1+0j) == 1
193
+ assert ellipe(inf) == mpc(0,inf)
194
+ assert ellipe(-inf) == inf
195
+ assert ellipe(3+4j).ae(1.4995535209333469543-1.5778790079127582745j)
196
+ assert ellipe(3-4j).ae(1.4995535209333469543+1.5778790079127582745j)
197
+ assert ellipe(-3+4j).ae(2.5804237855343377803-0.8306096791000413778j)
198
+ assert ellipe(-3-4j).ae(2.5804237855343377803+0.8306096791000413778j)
199
+ assert ellipe(2).ae(0.59907011736779610372+0.59907011736779610372j)
200
+ assert ellipe('1e-1000000000').ae(pi/2)
201
+ assert ellipk('1e-1000000000').ae(pi/2)
202
+ assert ellipe(-pi).ae(2.4535865983838923)
203
+ mp.dps = 50
204
+ assert ellipk(1/pi).ae('1.724756270009501831744438120951614673874904182624739673')
205
+ assert ellipe(1/pi).ae('1.437129808135123030101542922290970050337425479058225712')
206
+ assert ellipk(-10*pi).ae('0.5519067523886233967683646782286965823151896970015484512')
207
+ assert ellipe(-10*pi).ae('5.926192483740483797854383268707108012328213431657645509')
208
+ v = ellipk(pi)
209
+ assert v.real.ae('0.973089521698042334840454592642137667227167622330325225')
210
+ assert v.imag.ae('-1.156151296372835303836814390793087600271609993858798016')
211
+ v = ellipe(pi)
212
+ assert v.real.ae('0.4632848917264710404078033487934663562998345622611263332')
213
+ assert v.imag.ae('1.0637961621753130852473300451583414489944099504180510966')
214
+ mp.dps = 15
215
+
216
+ def test_exp_integrals():
217
+ mp.dps = 15
218
+ x = +e
219
+ z = e + sqrt(3)*j
220
+ assert ei(x).ae(8.21168165538361560)
221
+ assert li(x).ae(1.89511781635593676)
222
+ assert si(x).ae(1.82104026914756705)
223
+ assert ci(x).ae(0.213958001340379779)
224
+ assert shi(x).ae(4.11520706247846193)
225
+ assert chi(x).ae(4.09647459290515367)
226
+ assert fresnels(x).ae(0.437189718149787643)
227
+ assert fresnelc(x).ae(0.401777759590243012)
228
+ assert airyai(x).ae(0.0108502401568586681)
229
+ assert airybi(x).ae(8.98245748585468627)
230
+ assert ei(z).ae(3.72597969491314951 + 7.34213212314224421j)
231
+ assert li(z).ae(2.28662658112562502 + 1.50427225297269364j)
232
+ assert si(z).ae(2.48122029237669054 + 0.12684703275254834j)
233
+ assert ci(z).ae(0.169255590269456633 - 0.892020751420780353j)
234
+ assert shi(z).ae(1.85810366559344468 + 3.66435842914920263j)
235
+ assert chi(z).ae(1.86787602931970484 + 3.67777369399304159j)
236
+ assert fresnels(z/3).ae(0.034534397197008182 + 0.754859844188218737j)
237
+ assert fresnelc(z/3).ae(1.261581645990027372 + 0.417949198775061893j)
238
+ assert airyai(z).ae(-0.0162552579839056062 - 0.0018045715700210556j)
239
+ assert airybi(z).ae(-4.98856113282883371 + 2.08558537872180623j)
240
+ assert li(0) == 0.0
241
+ assert li(1) == -inf
242
+ assert li(inf) == inf
243
+ assert isinstance(li(0.7), mpf)
244
+ assert si(inf).ae(pi/2)
245
+ assert si(-inf).ae(-pi/2)
246
+ assert ci(inf) == 0
247
+ assert ci(0) == -inf
248
+ assert isinstance(ei(-0.7), mpf)
249
+ assert airyai(inf) == 0
250
+ assert airybi(inf) == inf
251
+ assert airyai(-inf) == 0
252
+ assert airybi(-inf) == 0
253
+ assert fresnels(inf) == 0.5
254
+ assert fresnelc(inf) == 0.5
255
+ assert fresnels(-inf) == -0.5
256
+ assert fresnelc(-inf) == -0.5
257
+ assert shi(0) == 0
258
+ assert shi(inf) == inf
259
+ assert shi(-inf) == -inf
260
+ assert chi(0) == -inf
261
+ assert chi(inf) == inf
262
+
263
+ def test_ei():
264
+ mp.dps = 15
265
+ assert ei(0) == -inf
266
+ assert ei(inf) == inf
267
+ assert ei(-inf) == -0.0
268
+ assert ei(20+70j).ae(6.1041351911152984397e6 - 2.7324109310519928872e6j)
269
+ # tests for the asymptotic expansion
270
+ # values checked with Mathematica ExpIntegralEi
271
+ mp.dps = 50
272
+ r = ei(20000)
273
+ s = '3.8781962825045010930273870085501819470698476975019e+8681'
274
+ assert str(r) == s
275
+ r = ei(-200)
276
+ s = '-6.8852261063076355977108174824557929738368086933303e-90'
277
+ assert str(r) == s
278
+ r =ei(20000 + 10*j)
279
+ sre = '-3.255138234032069402493850638874410725961401274106e+8681'
280
+ sim = '-2.1081929993474403520785942429469187647767369645423e+8681'
281
+ assert str(r.real) == sre and str(r.imag) == sim
282
+ mp.dps = 15
283
+ # More asymptotic expansions
284
+ assert chi(-10**6+100j).ae('1.3077239389562548386e+434288 + 7.6808956999707408158e+434287j')
285
+ assert shi(-10**6+100j).ae('-1.3077239389562548386e+434288 - 7.6808956999707408158e+434287j')
286
+ mp.dps = 15
287
+ assert ei(10j).ae(-0.0454564330044553726+3.2291439210137706686j)
288
+ assert ei(100j).ae(-0.0051488251426104921+3.1330217936839529126j)
289
+ u = ei(fmul(10**20, j, exact=True))
290
+ assert u.real.ae(-6.4525128526578084421345e-21, abs_eps=0, rel_eps=8*eps)
291
+ assert u.imag.ae(pi)
292
+ assert ei(-10j).ae(-0.0454564330044553726-3.2291439210137706686j)
293
+ assert ei(-100j).ae(-0.0051488251426104921-3.1330217936839529126j)
294
+ u = ei(fmul(-10**20, j, exact=True))
295
+ assert u.real.ae(-6.4525128526578084421345e-21, abs_eps=0, rel_eps=8*eps)
296
+ assert u.imag.ae(-pi)
297
+ assert ei(10+10j).ae(-1576.1504265768517448+436.9192317011328140j)
298
+ u = ei(-10+10j)
299
+ assert u.real.ae(7.6698978415553488362543e-7, abs_eps=0, rel_eps=8*eps)
300
+ assert u.imag.ae(3.141595611735621062025)
301
+
302
+ def test_e1():
303
+ mp.dps = 15
304
+ assert e1(0) == inf
305
+ assert e1(inf) == 0
306
+ assert e1(-inf) == mpc(-inf, -pi)
307
+ assert e1(10j).ae(0.045456433004455372635 + 0.087551267423977430100j)
308
+ assert e1(100j).ae(0.0051488251426104921444 - 0.0085708599058403258790j)
309
+ assert e1(fmul(10**20, j, exact=True)).ae(6.4525128526578084421e-21 - 7.6397040444172830039e-21j, abs_eps=0, rel_eps=8*eps)
310
+ assert e1(-10j).ae(0.045456433004455372635 - 0.087551267423977430100j)
311
+ assert e1(-100j).ae(0.0051488251426104921444 + 0.0085708599058403258790j)
312
+ assert e1(fmul(-10**20, j, exact=True)).ae(6.4525128526578084421e-21 + 7.6397040444172830039e-21j, abs_eps=0, rel_eps=8*eps)
313
+
314
+ def test_expint():
315
+ mp.dps = 15
316
+ assert expint(0,0) == inf
317
+ assert expint(0,1).ae(1/e)
318
+ assert expint(0,1.5).ae(2/exp(1.5)/3)
319
+ assert expint(1,1).ae(-ei(-1))
320
+ assert expint(2,0).ae(1)
321
+ assert expint(3,0).ae(1/2.)
322
+ assert expint(4,0).ae(1/3.)
323
+ assert expint(-2, 0.5).ae(26/sqrt(e))
324
+ assert expint(-1,-1) == 0
325
+ assert expint(-2,-1).ae(-e)
326
+ assert expint(5.5, 0).ae(2/9.)
327
+ assert expint(2.00000001,0).ae(100000000./100000001)
328
+ assert expint(2+3j,4-j).ae(0.0023461179581675065414+0.0020395540604713669262j)
329
+ assert expint('1.01', '1e-1000').ae(99.9999999899412802)
330
+ assert expint('1.000000000001', 3.5).ae(0.00697013985754701819446)
331
+ assert expint(2,3).ae(3*ei(-3)+exp(-3))
332
+ assert (expint(10,20)*10**10).ae(0.694439055541231353)
333
+ assert expint(3,inf) == 0
334
+ assert expint(3.2,inf) == 0
335
+ assert expint(3.2+2j,inf) == 0
336
+ assert expint(1,3j).ae(-0.11962978600800032763 + 0.27785620120457163717j)
337
+ assert expint(1,3).ae(0.013048381094197037413)
338
+ assert expint(1,-3).ae(-ei(3)-pi*j)
339
+ #assert expint(3) == expint(1,3)
340
+ assert expint(1,-20).ae(-25615652.66405658882 - 3.1415926535897932385j)
341
+ assert expint(1000000,0).ae(1./999999)
342
+ assert expint(0,2+3j).ae(-0.025019798357114678171 + 0.027980439405104419040j)
343
+ assert expint(-1,2+3j).ae(-0.022411973626262070419 + 0.038058922011377716932j)
344
+ assert expint(-1.5,0) == inf
345
+
346
+ def test_trig_integrals():
347
+ mp.dps = 30
348
+ assert si(mpf(1)/1000000).ae('0.000000999999999999944444444444446111')
349
+ assert ci(mpf(1)/1000000).ae('-13.2382948930629912435014366276')
350
+ assert si(10**10).ae('1.5707963267075846569685111517747537')
351
+ assert ci(10**10).ae('-4.87506025174822653785729773959e-11')
352
+ assert si(10**100).ae(pi/2)
353
+ assert (ci(10**100)*10**100).ae('-0.372376123661276688262086695553')
354
+ assert si(-3) == -si(3)
355
+ assert ci(-3).ae(ci(3) + pi*j)
356
+ # Test complex structure
357
+ mp.dps = 15
358
+ assert mp.ci(50).ae(-0.0056283863241163054402)
359
+ assert mp.ci(50+2j).ae(-0.018378282946133067149+0.070352808023688336193j)
360
+ assert mp.ci(20j).ae(1.28078263320282943611e7+1.5707963267949j)
361
+ assert mp.ci(-2+20j).ae(-4.050116856873293505e6+1.207476188206989909e7j)
362
+ assert mp.ci(-50+2j).ae(-0.0183782829461330671+3.0712398455661049023j)
363
+ assert mp.ci(-50).ae(-0.0056283863241163054+3.1415926535897932385j)
364
+ assert mp.ci(-50-2j).ae(-0.0183782829461330671-3.0712398455661049023j)
365
+ assert mp.ci(-2-20j).ae(-4.050116856873293505e6-1.207476188206989909e7j)
366
+ assert mp.ci(-20j).ae(1.28078263320282943611e7-1.5707963267949j)
367
+ assert mp.ci(50-2j).ae(-0.018378282946133067149-0.070352808023688336193j)
368
+ assert mp.si(50).ae(1.5516170724859358947)
369
+ assert mp.si(50+2j).ae(1.497884414277228461-0.017515007378437448j)
370
+ assert mp.si(20j).ae(1.2807826332028294459e7j)
371
+ assert mp.si(-2+20j).ae(-1.20747603112735722103e7-4.050116856873293554e6j)
372
+ assert mp.si(-50+2j).ae(-1.497884414277228461-0.017515007378437448j)
373
+ assert mp.si(-50).ae(-1.5516170724859358947)
374
+ assert mp.si(-50-2j).ae(-1.497884414277228461+0.017515007378437448j)
375
+ assert mp.si(-2-20j).ae(-1.20747603112735722103e7+4.050116856873293554e6j)
376
+ assert mp.si(-20j).ae(-1.2807826332028294459e7j)
377
+ assert mp.si(50-2j).ae(1.497884414277228461+0.017515007378437448j)
378
+ assert mp.chi(50j).ae(-0.0056283863241163054+1.5707963267948966192j)
379
+ assert mp.chi(-2+50j).ae(-0.0183782829461330671+1.6411491348185849554j)
380
+ assert mp.chi(-20).ae(1.28078263320282943611e7+3.1415926535898j)
381
+ assert mp.chi(-20-2j).ae(-4.050116856873293505e6+1.20747571696809187053e7j)
382
+ assert mp.chi(-2-50j).ae(-0.0183782829461330671-1.6411491348185849554j)
383
+ assert mp.chi(-50j).ae(-0.0056283863241163054-1.5707963267948966192j)
384
+ assert mp.chi(2-50j).ae(-0.0183782829461330671-1.500443518771208283j)
385
+ assert mp.chi(20-2j).ae(-4.050116856873293505e6-1.20747603112735722951e7j)
386
+ assert mp.chi(20).ae(1.2807826332028294361e7)
387
+ assert mp.chi(2+50j).ae(-0.0183782829461330671+1.500443518771208283j)
388
+ assert mp.shi(50j).ae(1.5516170724859358947j)
389
+ assert mp.shi(-2+50j).ae(0.017515007378437448+1.497884414277228461j)
390
+ assert mp.shi(-20).ae(-1.2807826332028294459e7)
391
+ assert mp.shi(-20-2j).ae(4.050116856873293554e6-1.20747603112735722103e7j)
392
+ assert mp.shi(-2-50j).ae(0.017515007378437448-1.497884414277228461j)
393
+ assert mp.shi(-50j).ae(-1.5516170724859358947j)
394
+ assert mp.shi(2-50j).ae(-0.017515007378437448-1.497884414277228461j)
395
+ assert mp.shi(20-2j).ae(-4.050116856873293554e6-1.20747603112735722103e7j)
396
+ assert mp.shi(20).ae(1.2807826332028294459e7)
397
+ assert mp.shi(2+50j).ae(-0.017515007378437448+1.497884414277228461j)
398
+ def ae(x,y,tol=1e-12):
399
+ return abs(x-y) <= abs(y)*tol
400
+ assert fp.ci(fp.inf) == 0
401
+ assert ae(fp.ci(fp.ninf), fp.pi*1j)
402
+ assert ae(fp.si(fp.inf), fp.pi/2)
403
+ assert ae(fp.si(fp.ninf), -fp.pi/2)
404
+ assert fp.si(0) == 0
405
+ assert ae(fp.ci(50), -0.0056283863241163054402)
406
+ assert ae(fp.ci(50+2j), -0.018378282946133067149+0.070352808023688336193j)
407
+ assert ae(fp.ci(20j), 1.28078263320282943611e7+1.5707963267949j)
408
+ assert ae(fp.ci(-2+20j), -4.050116856873293505e6+1.207476188206989909e7j)
409
+ assert ae(fp.ci(-50+2j), -0.0183782829461330671+3.0712398455661049023j)
410
+ assert ae(fp.ci(-50), -0.0056283863241163054+3.1415926535897932385j)
411
+ assert ae(fp.ci(-50-2j), -0.0183782829461330671-3.0712398455661049023j)
412
+ assert ae(fp.ci(-2-20j), -4.050116856873293505e6-1.207476188206989909e7j)
413
+ assert ae(fp.ci(-20j), 1.28078263320282943611e7-1.5707963267949j)
414
+ assert ae(fp.ci(50-2j), -0.018378282946133067149-0.070352808023688336193j)
415
+ assert ae(fp.si(50), 1.5516170724859358947)
416
+ assert ae(fp.si(50+2j), 1.497884414277228461-0.017515007378437448j)
417
+ assert ae(fp.si(20j), 1.2807826332028294459e7j)
418
+ assert ae(fp.si(-2+20j), -1.20747603112735722103e7-4.050116856873293554e6j)
419
+ assert ae(fp.si(-50+2j), -1.497884414277228461-0.017515007378437448j)
420
+ assert ae(fp.si(-50), -1.5516170724859358947)
421
+ assert ae(fp.si(-50-2j), -1.497884414277228461+0.017515007378437448j)
422
+ assert ae(fp.si(-2-20j), -1.20747603112735722103e7+4.050116856873293554e6j)
423
+ assert ae(fp.si(-20j), -1.2807826332028294459e7j)
424
+ assert ae(fp.si(50-2j), 1.497884414277228461+0.017515007378437448j)
425
+ assert ae(fp.chi(50j), -0.0056283863241163054+1.5707963267948966192j)
426
+ assert ae(fp.chi(-2+50j), -0.0183782829461330671+1.6411491348185849554j)
427
+ assert ae(fp.chi(-20), 1.28078263320282943611e7+3.1415926535898j)
428
+ assert ae(fp.chi(-20-2j), -4.050116856873293505e6+1.20747571696809187053e7j)
429
+ assert ae(fp.chi(-2-50j), -0.0183782829461330671-1.6411491348185849554j)
430
+ assert ae(fp.chi(-50j), -0.0056283863241163054-1.5707963267948966192j)
431
+ assert ae(fp.chi(2-50j), -0.0183782829461330671-1.500443518771208283j)
432
+ assert ae(fp.chi(20-2j), -4.050116856873293505e6-1.20747603112735722951e7j)
433
+ assert ae(fp.chi(20), 1.2807826332028294361e7)
434
+ assert ae(fp.chi(2+50j), -0.0183782829461330671+1.500443518771208283j)
435
+ assert ae(fp.shi(50j), 1.5516170724859358947j)
436
+ assert ae(fp.shi(-2+50j), 0.017515007378437448+1.497884414277228461j)
437
+ assert ae(fp.shi(-20), -1.2807826332028294459e7)
438
+ assert ae(fp.shi(-20-2j), 4.050116856873293554e6-1.20747603112735722103e7j)
439
+ assert ae(fp.shi(-2-50j), 0.017515007378437448-1.497884414277228461j)
440
+ assert ae(fp.shi(-50j), -1.5516170724859358947j)
441
+ assert ae(fp.shi(2-50j), -0.017515007378437448-1.497884414277228461j)
442
+ assert ae(fp.shi(20-2j), -4.050116856873293554e6-1.20747603112735722103e7j)
443
+ assert ae(fp.shi(20), 1.2807826332028294459e7)
444
+ assert ae(fp.shi(2+50j), -0.017515007378437448+1.497884414277228461j)
445
+
446
+ def test_airy():
447
+ mp.dps = 15
448
+ assert (airyai(10)*10**10).ae(1.1047532552898687)
449
+ assert (airybi(10)/10**9).ae(0.45564115354822515)
450
+ assert (airyai(1000)*10**9158).ae(9.306933063179556004)
451
+ assert (airybi(1000)/10**9154).ae(5.4077118391949465477)
452
+ assert airyai(-1000).ae(0.055971895773019918842)
453
+ assert airybi(-1000).ae(-0.083264574117080633012)
454
+ assert (airyai(100+100j)*10**188).ae(2.9099582462207032076 + 2.353013591706178756j)
455
+ assert (airybi(100+100j)/10**185).ae(1.7086751714463652039 - 3.1416590020830804578j)
456
+
457
+ def test_hyper_0f1():
458
+ mp.dps = 15
459
+ v = 8.63911136507950465
460
+ assert hyper([],[(1,3)],1.5).ae(v)
461
+ assert hyper([],[1/3.],1.5).ae(v)
462
+ assert hyp0f1(1/3.,1.5).ae(v)
463
+ assert hyp0f1((1,3),1.5).ae(v)
464
+ # Asymptotic expansion
465
+ assert hyp0f1(3,1e9).ae('4.9679055380347771271e+27455')
466
+ assert hyp0f1(3,1e9j).ae('-2.1222788784457702157e+19410 + 5.0840597555401854116e+19410j')
467
+
468
+ def test_hyper_1f1():
469
+ mp.dps = 15
470
+ v = 1.2917526488617656673
471
+ assert hyper([(1,2)],[(3,2)],0.7).ae(v)
472
+ assert hyper([(1,2)],[(3,2)],0.7+0j).ae(v)
473
+ assert hyper([0.5],[(3,2)],0.7).ae(v)
474
+ assert hyper([0.5],[1.5],0.7).ae(v)
475
+ assert hyper([0.5],[(3,2)],0.7+0j).ae(v)
476
+ assert hyper([0.5],[1.5],0.7+0j).ae(v)
477
+ assert hyper([(1,2)],[1.5+0j],0.7).ae(v)
478
+ assert hyper([0.5+0j],[1.5],0.7).ae(v)
479
+ assert hyper([0.5+0j],[1.5+0j],0.7+0j).ae(v)
480
+ assert hyp1f1(0.5,1.5,0.7).ae(v)
481
+ assert hyp1f1((1,2),1.5,0.7).ae(v)
482
+ # Asymptotic expansion
483
+ assert hyp1f1(2,3,1e10).ae('2.1555012157015796988e+4342944809')
484
+ assert (hyp1f1(2,3,1e10j)*10**10).ae(-0.97501205020039745852 - 1.7462392454512132074j)
485
+ # Shouldn't use asymptotic expansion
486
+ assert hyp1f1(-2, 1, 10000).ae(49980001)
487
+ # Bug
488
+ assert hyp1f1(1j,fraction(1,3),0.415-69.739j).ae(25.857588206024346592 + 15.738060264515292063j)
489
+
490
+ def test_hyper_2f1():
491
+ mp.dps = 15
492
+ v = 1.0652207633823291032
493
+ assert hyper([(1,2), (3,4)], [2], 0.3).ae(v)
494
+ assert hyper([(1,2), 0.75], [2], 0.3).ae(v)
495
+ assert hyper([0.5, 0.75], [2.0], 0.3).ae(v)
496
+ assert hyper([0.5, 0.75], [2.0], 0.3+0j).ae(v)
497
+ assert hyper([0.5+0j, (3,4)], [2.0], 0.3+0j).ae(v)
498
+ assert hyper([0.5+0j, (3,4)], [2.0], 0.3).ae(v)
499
+ assert hyper([0.5, (3,4)], [2.0+0j], 0.3).ae(v)
500
+ assert hyper([0.5+0j, 0.75+0j], [2.0+0j], 0.3+0j).ae(v)
501
+ v = 1.09234681096223231717 + 0.18104859169479360380j
502
+ assert hyper([(1,2),0.75+j], [2], 0.5).ae(v)
503
+ assert hyper([0.5,0.75+j], [2.0], 0.5).ae(v)
504
+ assert hyper([0.5,0.75+j], [2.0], 0.5+0j).ae(v)
505
+ assert hyper([0.5,0.75+j], [2.0+0j], 0.5+0j).ae(v)
506
+ v = 0.9625 - 0.125j
507
+ assert hyper([(3,2),-1],[4], 0.1+j/3).ae(v)
508
+ assert hyper([1.5,-1.0],[4], 0.1+j/3).ae(v)
509
+ assert hyper([1.5,-1.0],[4+0j], 0.1+j/3).ae(v)
510
+ assert hyper([1.5+0j,-1.0+0j],[4+0j], 0.1+j/3).ae(v)
511
+ v = 1.02111069501693445001 - 0.50402252613466859521j
512
+ assert hyper([(2,10),(3,10)],[(4,10)],1.5).ae(v)
513
+ assert hyper([0.2,(3,10)],[0.4+0j],1.5).ae(v)
514
+ assert hyper([0.2,(3,10)],[0.4+0j],1.5+0j).ae(v)
515
+ v = 0.76922501362865848528 + 0.32640579593235886194j
516
+ assert hyper([(2,10),(3,10)],[(4,10)],4+2j).ae(v)
517
+ assert hyper([0.2,(3,10)],[0.4+0j],4+2j).ae(v)
518
+ assert hyper([0.2,(3,10)],[(4,10)],4+2j).ae(v)
519
+
520
+ def test_hyper_2f1_hard():
521
+ mp.dps = 15
522
+ # Singular cases
523
+ assert hyp2f1(2,-1,-1,3).ae(7)
524
+ assert hyp2f1(2,-1,-1,3,eliminate_all=True).ae(0.25)
525
+ assert hyp2f1(2,-2,-2,3).ae(34)
526
+ assert hyp2f1(2,-2,-2,3,eliminate_all=True).ae(0.25)
527
+ assert hyp2f1(2,-2,-3,3) == 14
528
+ assert hyp2f1(2,-3,-2,3) == inf
529
+ assert hyp2f1(2,-1.5,-1.5,3) == 0.25
530
+ assert hyp2f1(1,2,3,0) == 1
531
+ assert hyp2f1(0,1,0,0) == 1
532
+ assert hyp2f1(0,0,0,0) == 1
533
+ assert isnan(hyp2f1(1,1,0,0))
534
+ assert hyp2f1(2,-1,-5, 0.25+0.25j).ae(1.1+0.1j)
535
+ assert hyp2f1(2,-5,-5, 0.25+0.25j, eliminate=False).ae(163./128 + 125./128*j)
536
+ assert hyp2f1(0.7235, -1, -5, 0.3).ae(1.04341)
537
+ assert hyp2f1(0.7235, -5, -5, 0.3, eliminate=False).ae(1.2939225017815903812)
538
+ assert hyp2f1(-1,-2,4,1) == 1.5
539
+ assert hyp2f1(1,2,-3,1) == inf
540
+ assert hyp2f1(-2,-2,1,1) == 6
541
+ assert hyp2f1(1,-2,-4,1).ae(5./3)
542
+ assert hyp2f1(0,-6,-4,1) == 1
543
+ assert hyp2f1(0,-3,-4,1) == 1
544
+ assert hyp2f1(0,0,0,1) == 1
545
+ assert hyp2f1(1,0,0,1,eliminate=False) == 1
546
+ assert hyp2f1(1,1,0,1) == inf
547
+ assert hyp2f1(1,-6,-4,1) == inf
548
+ assert hyp2f1(-7.2,-0.5,-4.5,1) == 0
549
+ assert hyp2f1(-7.2,-1,-2,1).ae(-2.6)
550
+ assert hyp2f1(1,-0.5,-4.5, 1) == inf
551
+ assert hyp2f1(1,0.5,-4.5, 1) == -inf
552
+ # Check evaluation on / close to unit circle
553
+ z = exp(j*pi/3)
554
+ w = (nthroot(2,3)+1)*exp(j*pi/12)/nthroot(3,4)**3
555
+ assert hyp2f1('1/2','1/6','1/3', z).ae(w)
556
+ assert hyp2f1('1/2','1/6','1/3', z.conjugate()).ae(w.conjugate())
557
+ assert hyp2f1(0.25, (1,3), 2, '0.999').ae(1.06826449496030635)
558
+ assert hyp2f1(0.25, (1,3), 2, '1.001').ae(1.06867299254830309446-0.00001446586793975874j)
559
+ assert hyp2f1(0.25, (1,3), 2, -1).ae(0.96656584492524351673)
560
+ assert hyp2f1(0.25, (1,3), 2, j).ae(0.99041766248982072266+0.03777135604180735522j)
561
+ assert hyp2f1(2,3,5,'0.99').ae(27.699347904322690602)
562
+ assert hyp2f1((3,2),-0.5,3,'0.99').ae(0.68403036843911661388)
563
+ assert hyp2f1(2,3,5,1j).ae(0.37290667145974386127+0.59210004902748285917j)
564
+ assert fsum([hyp2f1((7,10),(2,3),(-1,2), 0.95*exp(j*k)) for k in range(1,15)]).ae(52.851400204289452922+6.244285013912953225j)
565
+ assert fsum([hyp2f1((7,10),(2,3),(-1,2), 1.05*exp(j*k)) for k in range(1,15)]).ae(54.506013786220655330-3.000118813413217097j)
566
+ assert fsum([hyp2f1((7,10),(2,3),(-1,2), exp(j*k)) for k in range(1,15)]).ae(55.792077935955314887+1.731986485778500241j)
567
+ assert hyp2f1(2,2.5,-3.25,0.999).ae(218373932801217082543180041.33)
568
+ # Branches
569
+ assert hyp2f1(1,1,2,1.01).ae(4.5595744415723676911-3.1104877758314784539j)
570
+ assert hyp2f1(1,1,2,1.01+0.1j).ae(2.4149427480552782484+1.4148224796836938829j)
571
+ assert hyp2f1(1,1,2,3+4j).ae(0.14576709331407297807+0.48379185417980360773j)
572
+ assert hyp2f1(1,1,2,4).ae(-0.27465307216702742285 - 0.78539816339744830962j)
573
+ assert hyp2f1(1,1,2,-4).ae(0.40235947810852509365)
574
+ # Other:
575
+ # Cancellation with a large parameter involved (bug reported on sage-devel)
576
+ assert hyp2f1(112, (51,10), (-9,10), -0.99999).ae(-1.6241361047970862961e-24, abs_eps=0, rel_eps=eps*16)
577
+
578
+ def test_hyper_3f2_etc():
579
+ assert hyper([1,2,3],[1.5,8],-1).ae(0.67108992351533333030)
580
+ assert hyper([1,2,3,4],[5,6,7], -1).ae(0.90232988035425506008)
581
+ assert hyper([1,2,3],[1.25,5], 1).ae(28.924181329701905701)
582
+ assert hyper([1,2,3,4],[5,6,7],5).ae(1.5192307344006649499-1.1529845225075537461j)
583
+ assert hyper([1,2,3,4,5],[6,7,8,9],-1).ae(0.96288759462882357253)
584
+ assert hyper([1,2,3,4,5],[6,7,8,9],1).ae(1.0428697385885855841)
585
+ assert hyper([1,2,3,4,5],[6,7,8,9],5).ae(1.33980653631074769423-0.07143405251029226699j)
586
+ assert hyper([1,2.79,3.08,4.37],[5.2,6.1,7.3],5).ae(1.0996321464692607231-1.7748052293979985001j)
587
+ assert hyper([1,1,1],[1,2],1) == inf
588
+ assert hyper([1,1,1],[2,(101,100)],1).ae(100.01621213528313220)
589
+ # slow -- covered by doctests
590
+ #assert hyper([1,1,1],[2,3],0.9999).ae(1.2897972005319693905)
591
+
592
+ def test_hyper_u():
593
+ mp.dps = 15
594
+ assert hyperu(2,-3,0).ae(0.05)
595
+ assert hyperu(2,-3.5,0).ae(4./99)
596
+ assert hyperu(2,0,0) == 0.5
597
+ assert hyperu(-5,1,0) == -120
598
+ assert hyperu(-5,2,0) == inf
599
+ assert hyperu(-5,-2,0) == 0
600
+ assert hyperu(7,7,3).ae(0.00014681269365593503986) #exp(3)*gammainc(-6,3)
601
+ assert hyperu(2,-3,4).ae(0.011836478100271995559)
602
+ assert hyperu(3,4,5).ae(1./125)
603
+ assert hyperu(2,3,0.0625) == 256
604
+ assert hyperu(-1,2,0.25+0.5j) == -1.75+0.5j
605
+ assert hyperu(0.5,1.5,7.25).ae(2/sqrt(29))
606
+ assert hyperu(2,6,pi).ae(0.55804439825913399130)
607
+ assert (hyperu((3,2),8,100+201j)*10**4).ae(-0.3797318333856738798 - 2.9974928453561707782j)
608
+ assert (hyperu((5,2),(-1,2),-5000)*10**10).ae(-5.6681877926881664678j)
609
+ # XXX: fails because of undetected cancellation in low level series code
610
+ # Alternatively: could use asymptotic series here, if convergence test
611
+ # tweaked back to recognize this one
612
+ #assert (hyperu((5,2),(-1,2),-500)*10**7).ae(-1.82526906001593252847j)
613
+
614
+ def test_hyper_2f0():
615
+ mp.dps = 15
616
+ assert hyper([1,2],[],3) == hyp2f0(1,2,3)
617
+ assert hyp2f0(2,3,7).ae(0.0116108068639728714668 - 0.0073727413865865802130j)
618
+ assert hyp2f0(2,3,0) == 1
619
+ assert hyp2f0(0,0,0) == 1
620
+ assert hyp2f0(-1,-1,1).ae(2)
621
+ assert hyp2f0(-4,1,1.5).ae(62.5)
622
+ assert hyp2f0(-4,1,50).ae(147029801)
623
+ assert hyp2f0(-4,1,0.0001).ae(0.99960011997600240000)
624
+ assert hyp2f0(0.5,0.25,0.001).ae(1.0001251174078538115)
625
+ assert hyp2f0(0.5,0.25,3+4j).ae(0.85548875824755163518 + 0.21636041283392292973j)
626
+ # Important: cancellation check
627
+ assert hyp2f0((1,6),(5,6),-0.02371708245126284498).ae(0.996785723120804309)
628
+ # Should be exact; polynomial case
629
+ assert hyp2f0(-2,1,0.5+0.5j,zeroprec=200) == 0
630
+ assert hyp2f0(1,-2,0.5+0.5j,zeroprec=200) == 0
631
+ # There used to be a bug in thresholds that made one of the following hang
632
+ for d in [15, 50, 80]:
633
+ mp.dps = d
634
+ assert hyp2f0(1.5, 0.5, 0.009).ae('1.006867007239309717945323585695344927904000945829843527398772456281301440034218290443367270629519483 + 1.238277162240704919639384945859073461954721356062919829456053965502443570466701567100438048602352623e-46j')
635
+
636
+ def test_hyper_1f2():
637
+ mp.dps = 15
638
+ assert hyper([1],[2,3],4) == hyp1f2(1,2,3,4)
639
+ a1,b1,b2 = (1,10),(2,3),1./16
640
+ assert hyp1f2(a1,b1,b2,10).ae(298.7482725554557568)
641
+ assert hyp1f2(a1,b1,b2,100).ae(224128961.48602947604)
642
+ assert hyp1f2(a1,b1,b2,1000).ae(1.1669528298622675109e+27)
643
+ assert hyp1f2(a1,b1,b2,10000).ae(2.4780514622487212192e+86)
644
+ assert hyp1f2(a1,b1,b2,100000).ae(1.3885391458871523997e+274)
645
+ assert hyp1f2(a1,b1,b2,1000000).ae('9.8851796978960318255e+867')
646
+ assert hyp1f2(a1,b1,b2,10**7).ae('1.1505659189516303646e+2746')
647
+ assert hyp1f2(a1,b1,b2,10**8).ae('1.4672005404314334081e+8685')
648
+ assert hyp1f2(a1,b1,b2,10**20).ae('3.6888217332150976493e+8685889636')
649
+ assert hyp1f2(a1,b1,b2,10*j).ae(-16.163252524618572878 - 44.321567896480184312j)
650
+ assert hyp1f2(a1,b1,b2,100*j).ae(61938.155294517848171 + 637349.45215942348739j)
651
+ assert hyp1f2(a1,b1,b2,1000*j).ae(8455057657257695958.7 + 6261969266997571510.6j)
652
+ assert hyp1f2(a1,b1,b2,10000*j).ae(-8.9771211184008593089e+60 + 4.6550528111731631456e+59j)
653
+ assert hyp1f2(a1,b1,b2,100000*j).ae(2.6398091437239324225e+193 + 4.1658080666870618332e+193j)
654
+ assert hyp1f2(a1,b1,b2,1000000*j).ae('3.5999042951925965458e+613 + 1.5026014707128947992e+613j')
655
+ assert hyp1f2(a1,b1,b2,10**7*j).ae('-8.3208715051623234801e+1939 - 3.6752883490851869429e+1941j')
656
+ assert hyp1f2(a1,b1,b2,10**8*j).ae('2.0724195707891484454e+6140 - 1.3276619482724266387e+6141j')
657
+ assert hyp1f2(a1,b1,b2,10**20*j).ae('-1.1734497974795488504e+6141851462 + 1.1498106965385471542e+6141851462j')
658
+
659
+ def test_hyper_2f3():
660
+ mp.dps = 15
661
+ assert hyper([1,2],[3,4,5],6) == hyp2f3(1,2,3,4,5,6)
662
+ a1,a2,b1,b2,b3 = (1,10),(2,3),(3,10), 2, 1./16
663
+ # Check asymptotic expansion
664
+ assert hyp2f3(a1,a2,b1,b2,b3,10).ae(128.98207160698659976)
665
+ assert hyp2f3(a1,a2,b1,b2,b3,1000).ae(6.6309632883131273141e25)
666
+ assert hyp2f3(a1,a2,b1,b2,b3,10000).ae(4.6863639362713340539e84)
667
+ assert hyp2f3(a1,a2,b1,b2,b3,100000).ae(8.6632451236103084119e271)
668
+ assert hyp2f3(a1,a2,b1,b2,b3,10**6).ae('2.0291718386574980641e865')
669
+ assert hyp2f3(a1,a2,b1,b2,b3,10**7).ae('7.7639836665710030977e2742')
670
+ assert hyp2f3(a1,a2,b1,b2,b3,10**8).ae('3.2537462584071268759e8681')
671
+ assert hyp2f3(a1,a2,b1,b2,b3,10**20).ae('1.2966030542911614163e+8685889627')
672
+ assert hyp2f3(a1,a2,b1,b2,b3,10*j).ae(-18.551602185587547854 - 13.348031097874113552j)
673
+ assert hyp2f3(a1,a2,b1,b2,b3,100*j).ae(78634.359124504488695 + 74459.535945281973996j)
674
+ assert hyp2f3(a1,a2,b1,b2,b3,1000*j).ae(597682550276527901.59 - 65136194809352613.078j)
675
+ assert hyp2f3(a1,a2,b1,b2,b3,10000*j).ae(-1.1779696326238582496e+59 + 1.2297607505213133872e+59j)
676
+ assert hyp2f3(a1,a2,b1,b2,b3,100000*j).ae(2.9844228969804380301e+191 + 7.5587163231490273296e+190j)
677
+ assert hyp2f3(a1,a2,b1,b2,b3,1000000*j).ae('7.4859161049322370311e+610 - 2.8467477015940090189e+610j')
678
+ assert hyp2f3(a1,a2,b1,b2,b3,10**7*j).ae('-1.7477645579418800826e+1938 - 1.7606522995808116405e+1938j')
679
+ assert hyp2f3(a1,a2,b1,b2,b3,10**8*j).ae('-1.6932731942958401784e+6137 - 2.4521909113114629368e+6137j')
680
+ assert hyp2f3(a1,a2,b1,b2,b3,10**20*j).ae('-2.0988815677627225449e+6141851451 + 5.7708223542739208681e+6141851452j')
681
+
682
+ def test_hyper_2f2():
683
+ mp.dps = 15
684
+ assert hyper([1,2],[3,4],5) == hyp2f2(1,2,3,4,5)
685
+ a1,a2,b1,b2 = (3,10),4,(1,2),1./16
686
+ assert hyp2f2(a1,a2,b1,b2,10).ae(448225936.3377556696)
687
+ assert hyp2f2(a1,a2,b1,b2,10000).ae('1.2012553712966636711e+4358')
688
+ assert hyp2f2(a1,a2,b1,b2,-20000).ae(-0.04182343755661214626)
689
+ assert hyp2f2(a1,a2,b1,b2,10**20).ae('1.1148680024303263661e+43429448190325182840')
690
+
691
+ def test_orthpoly():
692
+ mp.dps = 15
693
+ assert jacobi(-4,2,3,0.7).ae(22800./4913)
694
+ assert jacobi(3,2,4,5.5) == 4133.125
695
+ assert jacobi(1.5,5/6.,4,0).ae(-1.0851951434075508417)
696
+ assert jacobi(-2, 1, 2, 4).ae(-0.16)
697
+ assert jacobi(2, -1, 2.5, 4).ae(34.59375)
698
+ #assert jacobi(2, -1, 2, 4) == 28.5
699
+ assert legendre(5, 7) == 129367
700
+ assert legendre(0.5,0).ae(0.53935260118837935667)
701
+ assert legendre(-1,-1) == 1
702
+ assert legendre(0,-1) == 1
703
+ assert legendre(0, 1) == 1
704
+ assert legendre(1, -1) == -1
705
+ assert legendre(7, 1) == 1
706
+ assert legendre(7, -1) == -1
707
+ assert legendre(8,1.5).ae(15457523./32768)
708
+ assert legendre(j,-j).ae(2.4448182735671431011 + 0.6928881737669934843j)
709
+ assert chebyu(5,1) == 6
710
+ assert chebyt(3,2) == 26
711
+ assert legendre(3.5,-1) == inf
712
+ assert legendre(4.5,-1) == -inf
713
+ assert legendre(3.5+1j,-1) == mpc(inf,inf)
714
+ assert legendre(4.5+1j,-1) == mpc(-inf,-inf)
715
+ assert laguerre(4, -2, 3).ae(-1.125)
716
+ assert laguerre(3, 1+j, 0.5).ae(0.2291666666666666667 + 2.5416666666666666667j)
717
+
718
+ def test_hermite():
719
+ mp.dps = 15
720
+ assert hermite(-2, 0).ae(0.5)
721
+ assert hermite(-1, 0).ae(0.88622692545275801365)
722
+ assert hermite(0, 0).ae(1)
723
+ assert hermite(1, 0) == 0
724
+ assert hermite(2, 0).ae(-2)
725
+ assert hermite(0, 2).ae(1)
726
+ assert hermite(1, 2).ae(4)
727
+ assert hermite(1, -2).ae(-4)
728
+ assert hermite(2, -2).ae(14)
729
+ assert hermite(0.5, 0).ae(0.69136733903629335053)
730
+ assert hermite(9, 0) == 0
731
+ assert hermite(4,4).ae(3340)
732
+ assert hermite(3,4).ae(464)
733
+ assert hermite(-4,4).ae(0.00018623860287512396181)
734
+ assert hermite(-3,4).ae(0.0016540169879668766270)
735
+ assert hermite(9, 2.5j).ae(13638725j)
736
+ assert hermite(9, -2.5j).ae(-13638725j)
737
+ assert hermite(9, 100).ae(511078883759363024000)
738
+ assert hermite(9, -100).ae(-511078883759363024000)
739
+ assert hermite(9, 100j).ae(512922083920643024000j)
740
+ assert hermite(9, -100j).ae(-512922083920643024000j)
741
+ assert hermite(-9.5, 2.5j).ae(-2.9004951258126778174e-6 + 1.7601372934039951100e-6j)
742
+ assert hermite(-9.5, -2.5j).ae(-2.9004951258126778174e-6 - 1.7601372934039951100e-6j)
743
+ assert hermite(-9.5, 100).ae(1.3776300722767084162e-22, abs_eps=0, rel_eps=eps)
744
+ assert hermite(-9.5, -100).ae('1.3106082028470671626e4355')
745
+ assert hermite(-9.5, 100j).ae(-9.7900218581864768430e-23 - 9.7900218581864768430e-23j, abs_eps=0, rel_eps=eps)
746
+ assert hermite(-9.5, -100j).ae(-9.7900218581864768430e-23 + 9.7900218581864768430e-23j, abs_eps=0, rel_eps=eps)
747
+ assert hermite(2+3j, -1-j).ae(851.3677063883687676 - 1496.4373467871007997j)
748
+
749
+ def test_gegenbauer():
750
+ mp.dps = 15
751
+ assert gegenbauer(1,2,3).ae(12)
752
+ assert gegenbauer(2,3,4).ae(381)
753
+ assert gegenbauer(0,0,0) == 0
754
+ assert gegenbauer(2,-1,3) == 0
755
+ assert gegenbauer(-7, 0.5, 3).ae(8989)
756
+ assert gegenbauer(1, -0.5, 3).ae(-3)
757
+ assert gegenbauer(1, -1.5, 3).ae(-9)
758
+ assert gegenbauer(1, -0.5, 3).ae(-3)
759
+ assert gegenbauer(-0.5, -0.5, 3).ae(-2.6383553159023906245)
760
+ assert gegenbauer(2+3j, 1-j, 3+4j).ae(14.880536623203696780 + 20.022029711598032898j)
761
+ #assert gegenbauer(-2, -0.5, 3).ae(-12)
762
+
763
+ def test_legenp():
764
+ mp.dps = 15
765
+ assert legenp(2,0,4) == legendre(2,4)
766
+ assert legenp(-2, -1, 0.5).ae(0.43301270189221932338)
767
+ assert legenp(-2, -1, 0.5, type=3).ae(0.43301270189221932338j)
768
+ assert legenp(-2, 1, 0.5).ae(-0.86602540378443864676)
769
+ assert legenp(2+j, 3+4j, -j).ae(134742.98773236786148 + 429782.72924463851745j)
770
+ assert legenp(2+j, 3+4j, -j, type=3).ae(802.59463394152268507 - 251.62481308942906447j)
771
+ assert legenp(2,4,3).ae(0)
772
+ assert legenp(2,4,3,type=3).ae(0)
773
+ assert legenp(2,1,0.5).ae(-1.2990381056766579701)
774
+ assert legenp(2,1,0.5,type=3).ae(1.2990381056766579701j)
775
+ assert legenp(3,2,3).ae(-360)
776
+ assert legenp(3,3,3).ae(240j*2**0.5)
777
+ assert legenp(3,4,3).ae(0)
778
+ assert legenp(0,0.5,2).ae(0.52503756790433198939 - 0.52503756790433198939j)
779
+ assert legenp(-1,-0.5,2).ae(0.60626116232846498110 + 0.60626116232846498110j)
780
+ assert legenp(-2,0.5,2).ae(1.5751127037129959682 - 1.5751127037129959682j)
781
+ assert legenp(-2,0.5,-0.5).ae(-0.85738275810499171286)
782
+
783
+ def test_legenq():
784
+ mp.dps = 15
785
+ f = legenq
786
+ # Evaluation at poles
787
+ assert isnan(f(3,2,1))
788
+ assert isnan(f(3,2,-1))
789
+ assert isnan(f(3,2,1,type=3))
790
+ assert isnan(f(3,2,-1,type=3))
791
+ # Evaluation at 0
792
+ assert f(0,1,0,type=2).ae(-1)
793
+ assert f(-2,2,0,type=2,zeroprec=200).ae(0)
794
+ assert f(1.5,3,0,type=2).ae(-2.2239343475841951023)
795
+ assert f(0,1,0,type=3).ae(j)
796
+ assert f(-2,2,0,type=3,zeroprec=200).ae(0)
797
+ assert f(1.5,3,0,type=3).ae(2.2239343475841951022*(1-1j))
798
+ # Standard case, degree 0
799
+ assert f(0,0,-1.5).ae(-0.8047189562170501873 + 1.5707963267948966192j)
800
+ assert f(0,0,-0.5).ae(-0.54930614433405484570)
801
+ assert f(0,0,0,zeroprec=200).ae(0)
802
+ assert f(0,0,0.5).ae(0.54930614433405484570)
803
+ assert f(0,0,1.5).ae(0.8047189562170501873 - 1.5707963267948966192j)
804
+ assert f(0,0,-1.5,type=3).ae(-0.80471895621705018730)
805
+ assert f(0,0,-0.5,type=3).ae(-0.5493061443340548457 - 1.5707963267948966192j)
806
+ assert f(0,0,0,type=3).ae(-1.5707963267948966192j)
807
+ assert f(0,0,0.5,type=3).ae(0.5493061443340548457 - 1.5707963267948966192j)
808
+ assert f(0,0,1.5,type=3).ae(0.80471895621705018730)
809
+ # Standard case, degree 1
810
+ assert f(1,0,-1.5).ae(0.2070784343255752810 - 2.3561944901923449288j)
811
+ assert f(1,0,-0.5).ae(-0.72534692783297257715)
812
+ assert f(1,0,0).ae(-1)
813
+ assert f(1,0,0.5).ae(-0.72534692783297257715)
814
+ assert f(1,0,1.5).ae(0.2070784343255752810 - 2.3561944901923449288j)
815
+ # Standard case, degree 2
816
+ assert f(2,0,-1.5).ae(-0.0635669991240192885 + 4.5160394395353277803j)
817
+ assert f(2,0,-0.5).ae(0.81866326804175685571)
818
+ assert f(2,0,0,zeroprec=200).ae(0)
819
+ assert f(2,0,0.5).ae(-0.81866326804175685571)
820
+ assert f(2,0,1.5).ae(0.0635669991240192885 - 4.5160394395353277803j)
821
+ # Misc orders and degrees
822
+ assert f(2,3,1.5,type=2).ae(-5.7243340223994616228j)
823
+ assert f(2,3,1.5,type=3).ae(-5.7243340223994616228)
824
+ assert f(2,3,0.5,type=2).ae(-12.316805742712016310)
825
+ assert f(2,3,0.5,type=3).ae(-12.316805742712016310j)
826
+ assert f(2,3,-1.5,type=2).ae(-5.7243340223994616228j)
827
+ assert f(2,3,-1.5,type=3).ae(5.7243340223994616228)
828
+ assert f(2,3,-0.5,type=2).ae(-12.316805742712016310)
829
+ assert f(2,3,-0.5,type=3).ae(-12.316805742712016310j)
830
+ assert f(2+3j, 3+4j, 0.5, type=3).ae(0.0016119404873235186807 - 0.0005885900510718119836j)
831
+ assert f(2+3j, 3+4j, -1.5, type=3).ae(0.008451400254138808670 + 0.020645193304593235298j)
832
+ assert f(-2.5,1,-1.5).ae(3.9553395527435335749j)
833
+ assert f(-2.5,1,-0.5).ae(1.9290561746445456908)
834
+ assert f(-2.5,1,0).ae(1.2708196271909686299)
835
+ assert f(-2.5,1,0.5).ae(-0.31584812990742202869)
836
+ assert f(-2.5,1,1.5).ae(-3.9553395527435335742 + 0.2993235655044701706j)
837
+ assert f(-2.5,1,-1.5,type=3).ae(0.29932356550447017254j)
838
+ assert f(-2.5,1,-0.5,type=3).ae(-0.3158481299074220287 - 1.9290561746445456908j)
839
+ assert f(-2.5,1,0,type=3).ae(1.2708196271909686292 - 1.2708196271909686299j)
840
+ assert f(-2.5,1,0.5,type=3).ae(1.9290561746445456907 + 0.3158481299074220287j)
841
+ assert f(-2.5,1,1.5,type=3).ae(-0.29932356550447017254)
842
+
843
+ def test_agm():
844
+ mp.dps = 15
845
+ assert agm(0,0) == 0
846
+ assert agm(0,1) == 0
847
+ assert agm(1,1) == 1
848
+ assert agm(7,7) == 7
849
+ assert agm(j,j) == j
850
+ assert (1/agm(1,sqrt(2))).ae(0.834626841674073186)
851
+ assert agm(1,2).ae(1.4567910310469068692)
852
+ assert agm(1,3).ae(1.8636167832448965424)
853
+ assert agm(1,j).ae(0.599070117367796104+0.599070117367796104j)
854
+ assert agm(2) == agm(1,2)
855
+ assert agm(-3,4).ae(0.63468509766550907+1.3443087080896272j)
856
+
857
+ def test_gammainc():
858
+ mp.dps = 15
859
+ assert gammainc(2,5).ae(6*exp(-5))
860
+ assert gammainc(2,0,5).ae(1-6*exp(-5))
861
+ assert gammainc(2,3,5).ae(-6*exp(-5)+4*exp(-3))
862
+ assert gammainc(-2.5,-0.5).ae(-0.9453087204829418812-5.3164237738936178621j)
863
+ assert gammainc(0,2,4).ae(0.045121158298212213088)
864
+ assert gammainc(0,3).ae(0.013048381094197037413)
865
+ assert gammainc(0,2+j,1-j).ae(0.00910653685850304839-0.22378752918074432574j)
866
+ assert gammainc(0,1-j).ae(0.00028162445198141833+0.17932453503935894015j)
867
+ assert gammainc(3,4,5,True).ae(0.11345128607046320253)
868
+ assert gammainc(3.5,0,inf).ae(gamma(3.5))
869
+ assert gammainc(-150.5,500).ae('6.9825435345798951153e-627')
870
+ assert gammainc(-150.5,800).ae('4.6885137549474089431e-788')
871
+ assert gammainc(-3.5, -20.5).ae(0.27008820585226911 - 1310.31447140574997636j)
872
+ assert gammainc(-3.5, -200.5).ae(0.27008820585226911 - 5.3264597096208368435e76j) # XXX real part
873
+ assert gammainc(0,0,2) == inf
874
+ assert gammainc(1,b=1).ae(0.6321205588285576784)
875
+ assert gammainc(3,2,2) == 0
876
+ assert gammainc(2,3+j,3-j).ae(-0.28135485191849314194j)
877
+ assert gammainc(4+0j,1).ae(5.8860710587430771455)
878
+ # GH issue #301
879
+ assert gammainc(-1,-1).ae(-0.8231640121031084799 + 3.1415926535897932385j)
880
+ assert gammainc(-2,-1).ae(1.7707229202810768576 - 1.5707963267948966192j)
881
+ assert gammainc(-3,-1).ae(-1.4963349162467073643 + 0.5235987755982988731j)
882
+ assert gammainc(-4,-1).ae(1.05365418617643814992 - 0.13089969389957471827j)
883
+ # Regularized upper gamma
884
+ assert isnan(gammainc(0, 0, regularized=True))
885
+ assert gammainc(-1, 0, regularized=True) == inf
886
+ assert gammainc(1, 0, regularized=True) == 1
887
+ assert gammainc(0, 5, regularized=True) == 0
888
+ assert gammainc(0, 2+3j, regularized=True) == 0
889
+ assert gammainc(0, 5000, regularized=True) == 0
890
+ assert gammainc(0, 10**30, regularized=True) == 0
891
+ assert gammainc(-1, 5, regularized=True) == 0
892
+ assert gammainc(-1, 5000, regularized=True) == 0
893
+ assert gammainc(-1, 10**30, regularized=True) == 0
894
+ assert gammainc(-1, -5, regularized=True) == 0
895
+ assert gammainc(-1, -5000, regularized=True) == 0
896
+ assert gammainc(-1, -10**30, regularized=True) == 0
897
+ assert gammainc(-1, 3+4j, regularized=True) == 0
898
+ assert gammainc(1, 5, regularized=True).ae(exp(-5))
899
+ assert gammainc(1, 5000, regularized=True).ae(exp(-5000))
900
+ assert gammainc(1, 10**30, regularized=True).ae(exp(-10**30))
901
+ assert gammainc(1, 3+4j, regularized=True).ae(exp(-3-4j))
902
+ assert gammainc(-1000000,2).ae('1.3669297209397347754e-301037', abs_eps=0, rel_eps=8*eps)
903
+ assert gammainc(-1000000,2,regularized=True) == 0
904
+ assert gammainc(-1000000,3+4j).ae('-1.322575609404222361e-698979 - 4.9274570591854533273e-698978j', abs_eps=0, rel_eps=8*eps)
905
+ assert gammainc(-1000000,3+4j,regularized=True) == 0
906
+ assert gammainc(2+3j, 4+5j, regularized=True).ae(0.085422013530993285774-0.052595379150390078503j)
907
+ assert gammainc(1000j, 1000j, regularized=True).ae(0.49702647628921131761 + 0.00297355675013575341j)
908
+ # Generalized
909
+ assert gammainc(3,4,2) == -gammainc(3,2,4)
910
+ assert gammainc(4, 2, 3).ae(1.2593494302978947396)
911
+ assert gammainc(4, 2, 3, regularized=True).ae(0.20989157171631578993)
912
+ assert gammainc(0, 2, 3).ae(0.035852129613864082155)
913
+ assert gammainc(0, 2, 3, regularized=True) == 0
914
+ assert gammainc(-1, 2, 3).ae(0.015219822548487616132)
915
+ assert gammainc(-1, 2, 3, regularized=True) == 0
916
+ assert gammainc(0, 2, 3).ae(0.035852129613864082155)
917
+ assert gammainc(0, 2, 3, regularized=True) == 0
918
+ # Should use upper gammas
919
+ assert gammainc(5, 10000, 12000).ae('1.1359381951461801687e-4327', abs_eps=0, rel_eps=8*eps)
920
+ # Should use lower gammas
921
+ assert gammainc(10000, 2, 3).ae('8.1244514125995785934e4765')
922
+ # GH issue 306
923
+ assert gammainc(3,-1-1j) == 0
924
+ assert gammainc(3,-1+1j) == 0
925
+ assert gammainc(2,-1) == 0
926
+ assert gammainc(2,-1+0j) == 0
927
+ assert gammainc(2+0j,-1) == 0
928
+
929
+ def test_gammainc_expint_n():
930
+ # These tests are intended to check all cases of the low-level code
931
+ # for upper gamma and expint with small integer index.
932
+ # Need to cover positive/negative arguments; small/large/huge arguments
933
+ # for both positive and negative indices, as well as indices 0 and 1
934
+ # which may be special-cased
935
+ mp.dps = 15
936
+ assert expint(-3,3.5).ae(0.021456366563296693987)
937
+ assert expint(-2,3.5).ae(0.014966633183073309405)
938
+ assert expint(-1,3.5).ae(0.011092916359219041088)
939
+ assert expint(0,3.5).ae(0.0086278238349481430685)
940
+ assert expint(1,3.5).ae(0.0069701398575483929193)
941
+ assert expint(2,3.5).ae(0.0058018939208991255223)
942
+ assert expint(3,3.5).ae(0.0049453773495857807058)
943
+ assert expint(-3,-3.5).ae(-4.6618170604073311319)
944
+ assert expint(-2,-3.5).ae(-5.5996974157555515963)
945
+ assert expint(-1,-3.5).ae(-6.7582555017739415818)
946
+ assert expint(0,-3.5).ae(-9.4615577024835182145)
947
+ assert expint(1,-3.5).ae(-13.925353995152335292 - 3.1415926535897932385j)
948
+ assert expint(2,-3.5).ae(-15.62328702434085977 - 10.995574287564276335j)
949
+ assert expint(3,-3.5).ae(-10.783026313250347722 - 19.242255003237483586j)
950
+ assert expint(-3,350).ae(2.8614825451252838069e-155, abs_eps=0, rel_eps=8*eps)
951
+ assert expint(-2,350).ae(2.8532837224504675901e-155, abs_eps=0, rel_eps=8*eps)
952
+ assert expint(-1,350).ae(2.8451316155828634555e-155, abs_eps=0, rel_eps=8*eps)
953
+ assert expint(0,350).ae(2.8370258275042797989e-155, abs_eps=0, rel_eps=8*eps)
954
+ assert expint(1,350).ae(2.8289659656701459404e-155, abs_eps=0, rel_eps=8*eps)
955
+ assert expint(2,350).ae(2.8209516419468505006e-155, abs_eps=0, rel_eps=8*eps)
956
+ assert expint(3,350).ae(2.8129824725501272171e-155, abs_eps=0, rel_eps=8*eps)
957
+ assert expint(-3,-350).ae(-2.8528796154044839443e+149)
958
+ assert expint(-2,-350).ae(-2.8610072121701264351e+149)
959
+ assert expint(-1,-350).ae(-2.8691813842677537647e+149)
960
+ assert expint(0,-350).ae(-2.8774025343659421709e+149)
961
+ u = expint(1,-350)
962
+ assert u.ae(-2.8856710698020863568e+149)
963
+ assert u.imag.ae(-3.1415926535897932385)
964
+ u = expint(2,-350)
965
+ assert u.ae(-2.8939874026504650534e+149)
966
+ assert u.imag.ae(-1099.5574287564276335)
967
+ u = expint(3,-350)
968
+ assert u.ae(-2.9023519497915044349e+149)
969
+ assert u.imag.ae(-192422.55003237483586)
970
+ assert expint(-3,350000000000000000000000).ae('2.1592908471792544286e-152003068666138139677919', abs_eps=0, rel_eps=8*eps)
971
+ assert expint(-2,350000000000000000000000).ae('2.1592908471792544286e-152003068666138139677919', abs_eps=0, rel_eps=8*eps)
972
+ assert expint(-1,350000000000000000000000).ae('2.1592908471792544286e-152003068666138139677919', abs_eps=0, rel_eps=8*eps)
973
+ assert expint(0,350000000000000000000000).ae('2.1592908471792544286e-152003068666138139677919', abs_eps=0, rel_eps=8*eps)
974
+ assert expint(1,350000000000000000000000).ae('2.1592908471792544286e-152003068666138139677919', abs_eps=0, rel_eps=8*eps)
975
+ assert expint(2,350000000000000000000000).ae('2.1592908471792544286e-152003068666138139677919', abs_eps=0, rel_eps=8*eps)
976
+ assert expint(3,350000000000000000000000).ae('2.1592908471792544286e-152003068666138139677919', abs_eps=0, rel_eps=8*eps)
977
+ assert expint(-3,-350000000000000000000000).ae('-3.7805306852415755699e+152003068666138139677871')
978
+ assert expint(-2,-350000000000000000000000).ae('-3.7805306852415755699e+152003068666138139677871')
979
+ assert expint(-1,-350000000000000000000000).ae('-3.7805306852415755699e+152003068666138139677871')
980
+ assert expint(0,-350000000000000000000000).ae('-3.7805306852415755699e+152003068666138139677871')
981
+ u = expint(1,-350000000000000000000000)
982
+ assert u.ae('-3.7805306852415755699e+152003068666138139677871')
983
+ assert u.imag.ae(-3.1415926535897932385)
984
+ u = expint(2,-350000000000000000000000)
985
+ assert u.imag.ae(-1.0995574287564276335e+24)
986
+ assert u.ae('-3.7805306852415755699e+152003068666138139677871')
987
+ u = expint(3,-350000000000000000000000)
988
+ assert u.imag.ae(-1.9242255003237483586e+47)
989
+ assert u.ae('-3.7805306852415755699e+152003068666138139677871')
990
+ # Small case; no branch cut
991
+ assert gammainc(-3,3.5).ae(0.00010020262545203707109)
992
+ assert gammainc(-2,3.5).ae(0.00040370427343557393517)
993
+ assert gammainc(-1,3.5).ae(0.0016576839773997501492)
994
+ assert gammainc(0,3.5).ae(0.0069701398575483929193)
995
+ assert gammainc(1,3.5).ae(0.03019738342231850074)
996
+ assert gammainc(2,3.5).ae(0.13588822540043325333)
997
+ assert gammainc(3,3.5).ae(0.64169439772426814072)
998
+ # Small case; with branch cut
999
+ assert gammainc(-3,-3.5).ae(0.03595832954467563286 + 0.52359877559829887308j)
1000
+ assert gammainc(-2,-3.5).ae(-0.88024704597962022221 - 1.5707963267948966192j)
1001
+ assert gammainc(-1,-3.5).ae(4.4637962926688170771 + 3.1415926535897932385j)
1002
+ assert gammainc(0,-3.5).ae(-13.925353995152335292 - 3.1415926535897932385j)
1003
+ assert gammainc(1,-3.5).ae(33.115451958692313751)
1004
+ assert gammainc(2,-3.5).ae(-82.788629896730784377)
1005
+ assert gammainc(3,-3.5).ae(240.08702670051927469)
1006
+ # Asymptotic case; no branch cut
1007
+ assert gammainc(-3,350).ae(6.5424095113340358813e-163, abs_eps=0, rel_eps=8*eps)
1008
+ assert gammainc(-2,350).ae(2.296312222489899769e-160, abs_eps=0, rel_eps=8*eps)
1009
+ assert gammainc(-1,350).ae(8.059861834133858573e-158, abs_eps=0, rel_eps=8*eps)
1010
+ assert gammainc(0,350).ae(2.8289659656701459404e-155, abs_eps=0, rel_eps=8*eps)
1011
+ assert gammainc(1,350).ae(9.9295903962649792963e-153, abs_eps=0, rel_eps=8*eps)
1012
+ assert gammainc(2,350).ae(3.485286229089007733e-150, abs_eps=0, rel_eps=8*eps)
1013
+ assert gammainc(3,350).ae(1.2233453960006379793e-147, abs_eps=0, rel_eps=8*eps)
1014
+ # Asymptotic case; branch cut
1015
+ u = gammainc(-3,-350)
1016
+ assert u.ae(6.7889565783842895085e+141)
1017
+ assert u.imag.ae(0.52359877559829887308)
1018
+ u = gammainc(-2,-350)
1019
+ assert u.ae(-2.3692668977889832121e+144)
1020
+ assert u.imag.ae(-1.5707963267948966192)
1021
+ u = gammainc(-1,-350)
1022
+ assert u.ae(8.2685354361441858669e+146)
1023
+ assert u.imag.ae(3.1415926535897932385)
1024
+ u = gammainc(0,-350)
1025
+ assert u.ae(-2.8856710698020863568e+149)
1026
+ assert u.imag.ae(-3.1415926535897932385)
1027
+ u = gammainc(1,-350)
1028
+ assert u.ae(1.0070908870280797598e+152)
1029
+ assert u.imag == 0
1030
+ u = gammainc(2,-350)
1031
+ assert u.ae(-3.5147471957279983618e+154)
1032
+ assert u.imag == 0
1033
+ u = gammainc(3,-350)
1034
+ assert u.ae(1.2266568422179417091e+157)
1035
+ assert u.imag == 0
1036
+ # Extreme asymptotic case
1037
+ assert gammainc(-3,350000000000000000000000).ae('5.0362468738874738859e-152003068666138139677990', abs_eps=0, rel_eps=8*eps)
1038
+ assert gammainc(-2,350000000000000000000000).ae('1.7626864058606158601e-152003068666138139677966', abs_eps=0, rel_eps=8*eps)
1039
+ assert gammainc(-1,350000000000000000000000).ae('6.1694024205121555102e-152003068666138139677943', abs_eps=0, rel_eps=8*eps)
1040
+ assert gammainc(0,350000000000000000000000).ae('2.1592908471792544286e-152003068666138139677919', abs_eps=0, rel_eps=8*eps)
1041
+ assert gammainc(1,350000000000000000000000).ae('7.5575179651273905e-152003068666138139677896', abs_eps=0, rel_eps=8*eps)
1042
+ assert gammainc(2,350000000000000000000000).ae('2.645131287794586675e-152003068666138139677872', abs_eps=0, rel_eps=8*eps)
1043
+ assert gammainc(3,350000000000000000000000).ae('9.2579595072810533625e-152003068666138139677849', abs_eps=0, rel_eps=8*eps)
1044
+ u = gammainc(-3,-350000000000000000000000)
1045
+ assert u.ae('8.8175642804468234866e+152003068666138139677800')
1046
+ assert u.imag.ae(0.52359877559829887308)
1047
+ u = gammainc(-2,-350000000000000000000000)
1048
+ assert u.ae('-3.0861474981563882203e+152003068666138139677824')
1049
+ assert u.imag.ae(-1.5707963267948966192)
1050
+ u = gammainc(-1,-350000000000000000000000)
1051
+ assert u.ae('1.0801516243547358771e+152003068666138139677848')
1052
+ assert u.imag.ae(3.1415926535897932385)
1053
+ u = gammainc(0,-350000000000000000000000)
1054
+ assert u.ae('-3.7805306852415755699e+152003068666138139677871')
1055
+ assert u.imag.ae(-3.1415926535897932385)
1056
+ assert gammainc(1,-350000000000000000000000).ae('1.3231857398345514495e+152003068666138139677895')
1057
+ assert gammainc(2,-350000000000000000000000).ae('-4.6311500894209300731e+152003068666138139677918')
1058
+ assert gammainc(3,-350000000000000000000000).ae('1.6209025312973255256e+152003068666138139677942')
1059
+
1060
+ def test_incomplete_beta():
1061
+ mp.dps = 15
1062
+ assert betainc(-2,-3,0.5,0.75).ae(63.4305673311255413583969)
1063
+ assert betainc(4.5,0.5+2j,2.5,6).ae(0.2628801146130621387903065 + 0.5162565234467020592855378j)
1064
+ assert betainc(4,5,0,6).ae(90747.77142857142857142857)
1065
+
1066
+ def test_erf():
1067
+ mp.dps = 15
1068
+ assert erf(0) == 0
1069
+ assert erf(1).ae(0.84270079294971486934)
1070
+ assert erf(3+4j).ae(-120.186991395079444098 - 27.750337293623902498j)
1071
+ assert erf(-4-3j).ae(-0.99991066178539168236 + 0.00004972026054496604j)
1072
+ assert erf(pi).ae(0.99999112385363235839)
1073
+ assert erf(1j).ae(1.6504257587975428760j)
1074
+ assert erf(-1j).ae(-1.6504257587975428760j)
1075
+ assert isinstance(erf(1), mpf)
1076
+ assert isinstance(erf(-1), mpf)
1077
+ assert isinstance(erf(0), mpf)
1078
+ assert isinstance(erf(0j), mpc)
1079
+ assert erf(inf) == 1
1080
+ assert erf(-inf) == -1
1081
+ assert erfi(0) == 0
1082
+ assert erfi(1/pi).ae(0.371682698493894314)
1083
+ assert erfi(inf) == inf
1084
+ assert erfi(-inf) == -inf
1085
+ assert erf(1+0j) == erf(1)
1086
+ assert erfc(1+0j) == erfc(1)
1087
+ assert erf(0.2+0.5j).ae(1 - erfc(0.2+0.5j))
1088
+ assert erfc(0) == 1
1089
+ assert erfc(1).ae(1-erf(1))
1090
+ assert erfc(-1).ae(1-erf(-1))
1091
+ assert erfc(1/pi).ae(1-erf(1/pi))
1092
+ assert erfc(-10) == 2
1093
+ assert erfc(-1000000) == 2
1094
+ assert erfc(-inf) == 2
1095
+ assert erfc(inf) == 0
1096
+ assert isnan(erfc(nan))
1097
+ assert (erfc(10**4)*mpf(10)**43429453).ae('3.63998738656420')
1098
+ assert erf(8+9j).ae(-1072004.2525062051158 + 364149.91954310255423j)
1099
+ assert erfc(8+9j).ae(1072005.2525062051158 - 364149.91954310255423j)
1100
+ assert erfc(-8-9j).ae(-1072003.2525062051158 + 364149.91954310255423j)
1101
+ mp.dps = 50
1102
+ # This one does not use the asymptotic series
1103
+ assert (erfc(10)*10**45).ae('2.0884875837625447570007862949577886115608181193212')
1104
+ # This one does
1105
+ assert (erfc(50)*10**1088).ae('2.0709207788416560484484478751657887929322509209954')
1106
+ mp.dps = 15
1107
+ assert str(erfc(10**50)) == '3.66744826532555e-4342944819032518276511289189166050822943970058036665661144537831658646492088707747292249493384317534'
1108
+ assert erfinv(0) == 0
1109
+ assert erfinv(0.5).ae(0.47693627620446987338)
1110
+ assert erfinv(-0.5).ae(-0.47693627620446987338)
1111
+ assert erfinv(1) == inf
1112
+ assert erfinv(-1) == -inf
1113
+ assert erf(erfinv(0.95)).ae(0.95)
1114
+ assert erf(erfinv(0.999999999995)).ae(0.999999999995)
1115
+ assert erf(erfinv(-0.999999999995)).ae(-0.999999999995)
1116
+ mp.dps = 50
1117
+ assert erf(erfinv('0.99999999999999999999999999999995')).ae('0.99999999999999999999999999999995')
1118
+ assert erf(erfinv('0.999999999999999999999999999999995')).ae('0.999999999999999999999999999999995')
1119
+ assert erf(erfinv('-0.999999999999999999999999999999995')).ae('-0.999999999999999999999999999999995')
1120
+ mp.dps = 15
1121
+ # Complex asymptotic expansions
1122
+ v = erfc(50j)
1123
+ assert v.real == 1
1124
+ assert v.imag.ae('-6.1481820666053078736e+1083')
1125
+ assert erfc(-100+5j).ae(2)
1126
+ assert (erfc(100+5j)*10**4335).ae(2.3973567853824133572 - 3.9339259530609420597j)
1127
+ assert erfc(100+100j).ae(0.00065234366376857698698 - 0.0039357263629214118437j)
1128
+
1129
+ def test_pdf():
1130
+ mp.dps = 15
1131
+ assert npdf(-inf) == 0
1132
+ assert npdf(inf) == 0
1133
+ assert npdf(5,0,2).ae(npdf(5+4,4,2))
1134
+ assert quadts(lambda x: npdf(x,-0.5,0.8), [-inf, inf]) == 1
1135
+ assert ncdf(0) == 0.5
1136
+ assert ncdf(3,3) == 0.5
1137
+ assert ncdf(-inf) == 0
1138
+ assert ncdf(inf) == 1
1139
+ assert ncdf(10) == 1
1140
+ # Verify that this is computed accurately
1141
+ assert (ncdf(-10)*10**24).ae(7.619853024160526)
1142
+
1143
+ def test_lambertw():
1144
+ mp.dps = 15
1145
+ assert lambertw(0) == 0
1146
+ assert lambertw(0+0j) == 0
1147
+ assert lambertw(inf) == inf
1148
+ assert isnan(lambertw(nan))
1149
+ assert lambertw(inf,1).real == inf
1150
+ assert lambertw(inf,1).imag.ae(2*pi)
1151
+ assert lambertw(-inf,1).real == inf
1152
+ assert lambertw(-inf,1).imag.ae(3*pi)
1153
+ assert lambertw(0,-1) == -inf
1154
+ assert lambertw(0,1) == -inf
1155
+ assert lambertw(0,3) == -inf
1156
+ assert lambertw(e).ae(1)
1157
+ assert lambertw(1).ae(0.567143290409783873)
1158
+ assert lambertw(-pi/2).ae(j*pi/2)
1159
+ assert lambertw(-log(2)/2).ae(-log(2))
1160
+ assert lambertw(0.25).ae(0.203888354702240164)
1161
+ assert lambertw(-0.25).ae(-0.357402956181388903)
1162
+ assert lambertw(-1./10000,0).ae(-0.000100010001500266719)
1163
+ assert lambertw(-0.25,-1).ae(-2.15329236411034965)
1164
+ assert lambertw(0.25,-1).ae(-3.00899800997004620-4.07652978899159763j)
1165
+ assert lambertw(-0.25,-1).ae(-2.15329236411034965)
1166
+ assert lambertw(0.25,1).ae(-3.00899800997004620+4.07652978899159763j)
1167
+ assert lambertw(-0.25,1).ae(-3.48973228422959210+7.41405453009603664j)
1168
+ assert lambertw(-4).ae(0.67881197132094523+1.91195078174339937j)
1169
+ assert lambertw(-4,1).ae(-0.66743107129800988+7.76827456802783084j)
1170
+ assert lambertw(-4,-1).ae(0.67881197132094523-1.91195078174339937j)
1171
+ assert lambertw(1000).ae(5.24960285240159623)
1172
+ assert lambertw(1000,1).ae(4.91492239981054535+5.44652615979447070j)
1173
+ assert lambertw(1000,-1).ae(4.91492239981054535-5.44652615979447070j)
1174
+ assert lambertw(1000,5).ae(3.5010625305312892+29.9614548941181328j)
1175
+ assert lambertw(3+4j).ae(1.281561806123775878+0.533095222020971071j)
1176
+ assert lambertw(-0.4+0.4j).ae(-0.10396515323290657+0.61899273315171632j)
1177
+ assert lambertw(3+4j,1).ae(-0.11691092896595324+5.61888039871282334j)
1178
+ assert lambertw(3+4j,-1).ae(0.25856740686699742-3.85211668616143559j)
1179
+ assert lambertw(-0.5,-1).ae(-0.794023632344689368-0.770111750510379110j)
1180
+ assert lambertw(-1./10000,1).ae(-11.82350837248724344+6.80546081842002101j)
1181
+ assert lambertw(-1./10000,-1).ae(-11.6671145325663544)
1182
+ assert lambertw(-1./10000,-2).ae(-11.82350837248724344-6.80546081842002101j)
1183
+ assert lambertw(-1./100000,4).ae(-14.9186890769540539+26.1856750178782046j)
1184
+ assert lambertw(-1./100000,5).ae(-15.0931437726379218666+32.5525721210262290086j)
1185
+ assert lambertw((2+j)/10).ae(0.173704503762911669+0.071781336752835511j)
1186
+ assert lambertw((2+j)/10,1).ae(-3.21746028349820063+4.56175438896292539j)
1187
+ assert lambertw((2+j)/10,-1).ae(-3.03781405002993088-3.53946629633505737j)
1188
+ assert lambertw((2+j)/10,4).ae(-4.6878509692773249+23.8313630697683291j)
1189
+ assert lambertw(-(2+j)/10).ae(-0.226933772515757933-0.164986470020154580j)
1190
+ assert lambertw(-(2+j)/10,1).ae(-2.43569517046110001+0.76974067544756289j)
1191
+ assert lambertw(-(2+j)/10,-1).ae(-3.54858738151989450-6.91627921869943589j)
1192
+ assert lambertw(-(2+j)/10,4).ae(-4.5500846928118151+20.6672982215434637j)
1193
+ mp.dps = 50
1194
+ assert lambertw(pi).ae('1.073658194796149172092178407024821347547745350410314531')
1195
+ mp.dps = 15
1196
+ # Former bug in generated branch
1197
+ assert lambertw(-0.5+0.002j).ae(-0.78917138132659918344 + 0.76743539379990327749j)
1198
+ assert lambertw(-0.5-0.002j).ae(-0.78917138132659918344 - 0.76743539379990327749j)
1199
+ assert lambertw(-0.448+0.4j).ae(-0.11855133765652382241 + 0.66570534313583423116j)
1200
+ assert lambertw(-0.448-0.4j).ae(-0.11855133765652382241 - 0.66570534313583423116j)
1201
+ assert lambertw(-0.65475+0.0001j).ae(-0.61053421111385310898+1.0396534993944097723803j)
1202
+ # Huge branch index
1203
+ w = lambertw(1,10**20)
1204
+ assert w.real.ae(-47.889578926290259164)
1205
+ assert w.imag.ae(6.2831853071795864769e+20)
1206
+
1207
+ def test_lambertw_hard():
1208
+ def check(x,y):
1209
+ y = convert(y)
1210
+ type_ok = True
1211
+ if isinstance(y, mpf):
1212
+ type_ok = isinstance(x, mpf)
1213
+ real_ok = abs(x.real-y.real) <= abs(y.real)*8*eps
1214
+ imag_ok = abs(x.imag-y.imag) <= abs(y.imag)*8*eps
1215
+ #print x, y, abs(x.real-y.real), abs(x.imag-y.imag)
1216
+ return real_ok and imag_ok
1217
+ # Evaluation near 0
1218
+ mp.dps = 15
1219
+ assert check(lambertw(1e-10), 9.999999999000000000e-11)
1220
+ assert check(lambertw(-1e-10), -1.000000000100000000e-10)
1221
+ assert check(lambertw(1e-10j), 9.999999999999999999733e-21 + 9.99999999999999999985e-11j)
1222
+ assert check(lambertw(-1e-10j), 9.999999999999999999733e-21 - 9.99999999999999999985e-11j)
1223
+ assert check(lambertw(1e-10,1), -26.303186778379041559 + 3.265093911703828397j)
1224
+ assert check(lambertw(-1e-10,1), -26.326236166739163892 + 6.526183280686333315j)
1225
+ assert check(lambertw(1e-10j,1), -26.312931726911421551 + 4.896366881798013421j)
1226
+ assert check(lambertw(-1e-10j,1), -26.297238779529035066 + 1.632807161345576513j)
1227
+ assert check(lambertw(1e-10,-1), -26.303186778379041559 - 3.265093911703828397j)
1228
+ assert check(lambertw(-1e-10,-1), -26.295238819246925694)
1229
+ assert check(lambertw(1e-10j,-1), -26.297238779529035028 - 1.6328071613455765135j)
1230
+ assert check(lambertw(-1e-10j,-1), -26.312931726911421551 - 4.896366881798013421j)
1231
+ # Test evaluation very close to the branch point -1/e
1232
+ # on the -1, 0, and 1 branches
1233
+ add = lambda x, y: fadd(x,y,exact=True)
1234
+ sub = lambda x, y: fsub(x,y,exact=True)
1235
+ addj = lambda x, y: fadd(x,fmul(y,1j,exact=True),exact=True)
1236
+ subj = lambda x, y: fadd(x,fmul(y,-1j,exact=True),exact=True)
1237
+ mp.dps = 1500
1238
+ a = -1/e + 10*eps
1239
+ d3 = mpf('1e-3')
1240
+ d10 = mpf('1e-10')
1241
+ d20 = mpf('1e-20')
1242
+ d40 = mpf('1e-40')
1243
+ d80 = mpf('1e-80')
1244
+ d300 = mpf('1e-300')
1245
+ d1000 = mpf('1e-1000')
1246
+ mp.dps = 15
1247
+ # ---- Branch 0 ----
1248
+ # -1/e + eps
1249
+ assert check(lambertw(add(a,d3)), -0.92802015005456704876)
1250
+ assert check(lambertw(add(a,d10)), -0.99997668374140088071)
1251
+ assert check(lambertw(add(a,d20)), -0.99999999976683560186)
1252
+ assert lambertw(add(a,d40)) == -1
1253
+ assert lambertw(add(a,d80)) == -1
1254
+ assert lambertw(add(a,d300)) == -1
1255
+ assert lambertw(add(a,d1000)) == -1
1256
+ # -1/e - eps
1257
+ assert check(lambertw(sub(a,d3)), -0.99819016149860989001+0.07367191188934638577j)
1258
+ assert check(lambertw(sub(a,d10)), -0.9999999998187812114595992+0.0000233164398140346109194j)
1259
+ assert check(lambertw(sub(a,d20)), -0.99999999999999999998187+2.331643981597124203344e-10j)
1260
+ assert check(lambertw(sub(a,d40)), -1.0+2.33164398159712420336e-20j)
1261
+ assert check(lambertw(sub(a,d80)), -1.0+2.33164398159712420336e-40j)
1262
+ assert check(lambertw(sub(a,d300)), -1.0+2.33164398159712420336e-150j)
1263
+ assert check(lambertw(sub(a,d1000)), mpc(-1,'2.33164398159712420336e-500'))
1264
+ # -1/e + eps*j
1265
+ assert check(lambertw(addj(a,d3)), -0.94790387486938526634+0.05036819639190132490j)
1266
+ assert check(lambertw(addj(a,d10)), -0.9999835127872943680999899+0.0000164870314895821225256j)
1267
+ assert check(lambertw(addj(a,d20)), -0.999999999835127872929987+1.64872127051890935830e-10j)
1268
+ assert check(lambertw(addj(a,d40)), -0.9999999999999999999835+1.6487212707001281468305e-20j)
1269
+ assert check(lambertw(addj(a,d80)), -1.0 + 1.64872127070012814684865e-40j)
1270
+ assert check(lambertw(addj(a,d300)), -1.0 + 1.64872127070012814684865e-150j)
1271
+ assert check(lambertw(addj(a,d1000)), mpc(-1.0,'1.64872127070012814684865e-500'))
1272
+ # -1/e - eps*j
1273
+ assert check(lambertw(subj(a,d3)), -0.94790387486938526634-0.05036819639190132490j)
1274
+ assert check(lambertw(subj(a,d10)), -0.9999835127872943680999899-0.0000164870314895821225256j)
1275
+ assert check(lambertw(subj(a,d20)), -0.999999999835127872929987-1.64872127051890935830e-10j)
1276
+ assert check(lambertw(subj(a,d40)), -0.9999999999999999999835-1.6487212707001281468305e-20j)
1277
+ assert check(lambertw(subj(a,d80)), -1.0 - 1.64872127070012814684865e-40j)
1278
+ assert check(lambertw(subj(a,d300)), -1.0 - 1.64872127070012814684865e-150j)
1279
+ assert check(lambertw(subj(a,d1000)), mpc(-1.0,'-1.64872127070012814684865e-500'))
1280
+ # ---- Branch 1 ----
1281
+ assert check(lambertw(addj(a,d3),1), -3.088501303219933378005990 + 7.458676867597474813950098j)
1282
+ assert check(lambertw(addj(a,d80),1), -3.088843015613043855957087 + 7.461489285654254556906117j)
1283
+ assert check(lambertw(addj(a,d300),1), -3.088843015613043855957087 + 7.461489285654254556906117j)
1284
+ assert check(lambertw(addj(a,d1000),1), -3.088843015613043855957087 + 7.461489285654254556906117j)
1285
+ assert check(lambertw(subj(a,d3),1), -1.0520914180450129534365906 + 0.0539925638125450525673175j)
1286
+ assert check(lambertw(subj(a,d10),1), -1.0000164872127056318529390 + 0.000016487393927159250398333077j)
1287
+ assert check(lambertw(subj(a,d20),1), -1.0000000001648721270700128 + 1.64872127088134693542628e-10j)
1288
+ assert check(lambertw(subj(a,d40),1), -1.000000000000000000016487 + 1.64872127070012814686677e-20j)
1289
+ assert check(lambertw(subj(a,d80),1), -1.0 + 1.64872127070012814684865e-40j)
1290
+ assert check(lambertw(subj(a,d300),1), -1.0 + 1.64872127070012814684865e-150j)
1291
+ assert check(lambertw(subj(a,d1000),1), mpc(-1.0, '1.64872127070012814684865e-500'))
1292
+ # ---- Branch -1 ----
1293
+ # -1/e + eps
1294
+ assert check(lambertw(add(a,d3),-1), -1.075608941186624989414945)
1295
+ assert check(lambertw(add(a,d10),-1), -1.000023316621036696460620)
1296
+ assert check(lambertw(add(a,d20),-1), -1.000000000233164398177834)
1297
+ assert lambertw(add(a,d40),-1) == -1
1298
+ assert lambertw(add(a,d80),-1) == -1
1299
+ assert lambertw(add(a,d300),-1) == -1
1300
+ assert lambertw(add(a,d1000),-1) == -1
1301
+ # -1/e - eps
1302
+ assert check(lambertw(sub(a,d3),-1), -0.99819016149860989001-0.07367191188934638577j)
1303
+ assert check(lambertw(sub(a,d10),-1), -0.9999999998187812114595992-0.0000233164398140346109194j)
1304
+ assert check(lambertw(sub(a,d20),-1), -0.99999999999999999998187-2.331643981597124203344e-10j)
1305
+ assert check(lambertw(sub(a,d40),-1), -1.0-2.33164398159712420336e-20j)
1306
+ assert check(lambertw(sub(a,d80),-1), -1.0-2.33164398159712420336e-40j)
1307
+ assert check(lambertw(sub(a,d300),-1), -1.0-2.33164398159712420336e-150j)
1308
+ assert check(lambertw(sub(a,d1000),-1), mpc(-1,'-2.33164398159712420336e-500'))
1309
+ # -1/e + eps*j
1310
+ assert check(lambertw(addj(a,d3),-1), -1.0520914180450129534365906 - 0.0539925638125450525673175j)
1311
+ assert check(lambertw(addj(a,d10),-1), -1.0000164872127056318529390 - 0.0000164873939271592503983j)
1312
+ assert check(lambertw(addj(a,d20),-1), -1.0000000001648721270700 - 1.64872127088134693542628e-10j)
1313
+ assert check(lambertw(addj(a,d40),-1), -1.00000000000000000001648 - 1.6487212707001281468667726e-20j)
1314
+ assert check(lambertw(addj(a,d80),-1), -1.0 - 1.64872127070012814684865e-40j)
1315
+ assert check(lambertw(addj(a,d300),-1), -1.0 - 1.64872127070012814684865e-150j)
1316
+ assert check(lambertw(addj(a,d1000),-1), mpc(-1.0,'-1.64872127070012814684865e-500'))
1317
+ # -1/e - eps*j
1318
+ assert check(lambertw(subj(a,d3),-1), -3.088501303219933378005990-7.458676867597474813950098j)
1319
+ assert check(lambertw(subj(a,d10),-1), -3.088843015579260686911033-7.461489285372968780020716j)
1320
+ assert check(lambertw(subj(a,d20),-1), -3.088843015613043855953708-7.461489285654254556877988j)
1321
+ assert check(lambertw(subj(a,d40),-1), -3.088843015613043855957087-7.461489285654254556906117j)
1322
+ assert check(lambertw(subj(a,d80),-1), -3.088843015613043855957087 - 7.461489285654254556906117j)
1323
+ assert check(lambertw(subj(a,d300),-1), -3.088843015613043855957087 - 7.461489285654254556906117j)
1324
+ assert check(lambertw(subj(a,d1000),-1), -3.088843015613043855957087 - 7.461489285654254556906117j)
1325
+ # One more case, testing higher precision
1326
+ mp.dps = 500
1327
+ x = -1/e + mpf('1e-13')
1328
+ ans = "-0.99999926266961377166355784455394913638782494543377383"\
1329
+ "744978844374498153493943725364881490261187530235150668593869563"\
1330
+ "168276697689459394902153960200361935311512317183678882"
1331
+ mp.dps = 15
1332
+ assert lambertw(x).ae(ans)
1333
+ mp.dps = 50
1334
+ assert lambertw(x).ae(ans)
1335
+ mp.dps = 150
1336
+ assert lambertw(x).ae(ans)
1337
+
1338
+ def test_meijerg():
1339
+ mp.dps = 15
1340
+ assert meijerg([[2,3],[1]],[[0.5,2],[3,4]], 2.5).ae(4.2181028074787439386)
1341
+ assert meijerg([[],[1+j]],[[1],[1]], 3+4j).ae(271.46290321152464592 - 703.03330399954820169j)
1342
+ assert meijerg([[0.25],[1]],[[0.5],[2]],0) == 0
1343
+ assert meijerg([[0],[]],[[0,0,'1/3','2/3'], []], '2/27').ae(2.2019391389653314120)
1344
+ # Verify 1/z series being used
1345
+ assert meijerg([[-3],[-0.5]], [[-1],[-2.5]], -0.5).ae(-1.338096165935754898687431)
1346
+ assert meijerg([[1-(-1)],[1-(-2.5)]], [[1-(-3)],[1-(-0.5)]], -2.0).ae(-1.338096165935754898687431)
1347
+ assert meijerg([[-3],[-0.5]], [[-1],[-2.5]], -1).ae(-(pi+4)/(4*pi))
1348
+ a = 2.5
1349
+ b = 1.25
1350
+ for z in [mpf(0.25), mpf(2)]:
1351
+ x1 = hyp1f1(a,b,z)
1352
+ x2 = gamma(b)/gamma(a)*meijerg([[1-a],[]],[[0],[1-b]],-z)
1353
+ x3 = gamma(b)/gamma(a)*meijerg([[1-0],[1-(1-b)]],[[1-(1-a)],[]],-1/z)
1354
+ assert x1.ae(x2)
1355
+ assert x1.ae(x3)
1356
+
1357
+ def test_appellf1():
1358
+ mp.dps = 15
1359
+ assert appellf1(2,-2,1,1,2,3).ae(-1.75)
1360
+ assert appellf1(2,1,-2,1,2,3).ae(-8)
1361
+ assert appellf1(2,1,-2,1,0.5,0.25).ae(1.5)
1362
+ assert appellf1(-2,1,3,2,3,3).ae(19)
1363
+ assert appellf1(1,2,3,4,0.5,0.125).ae( 1.53843285792549786518)
1364
+
1365
+ def test_coulomb():
1366
+ # Note: most tests are doctests
1367
+ # Test for a bug:
1368
+ mp.dps = 15
1369
+ assert coulombg(mpc(-5,0),2,3).ae(20.087729487721430394)
1370
+
1371
+ def test_hyper_param_accuracy():
1372
+ mp.dps = 15
1373
+ As = [n+1e-10 for n in range(-5,-1)]
1374
+ Bs = [n+1e-10 for n in range(-12,-5)]
1375
+ assert hyper(As,Bs,10).ae(-381757055858.652671927)
1376
+ assert legenp(0.5, 100, 0.25).ae(-2.4124576567211311755e+144)
1377
+ assert (hyp1f1(1000,1,-100)*10**24).ae(5.2589445437370169113)
1378
+ assert (hyp2f1(10, -900, 10.5, 0.99)*10**24).ae(1.9185370579660768203)
1379
+ assert (hyp2f1(1000,1.5,-3.5,-1.5)*10**385).ae(-2.7367529051334000764)
1380
+ assert hyp2f1(-5, 10, 3, 0.5, zeroprec=500) == 0
1381
+ assert (hyp1f1(-10000, 1000, 100)*10**424).ae(-3.1046080515824859974)
1382
+ assert (hyp2f1(1000,1.5,-3.5,-0.75,maxterms=100000)*10**231).ae(-4.0534790813913998643)
1383
+ assert legenp(2, 3, 0.25) == 0
1384
+ pytest.raises(ValueError, lambda: hypercomb(lambda a: [([],[],[],[],[a],[-a],0.5)], [3]))
1385
+ assert hypercomb(lambda a: [([],[],[],[],[a],[-a],0.5)], [3], infprec=200) == inf
1386
+ assert meijerg([[],[]],[[0,0,0,0],[]],0.1).ae(1.5680822343832351418)
1387
+ assert (besselk(400,400)*10**94).ae(1.4387057277018550583)
1388
+ mp.dps = 5
1389
+ (hyp1f1(-5000.5, 1500, 100)*10**185).ae(8.5185229673381935522)
1390
+ (hyp1f1(-5000, 1500, 100)*10**185).ae(9.1501213424563944311)
1391
+ mp.dps = 15
1392
+ (hyp1f1(-5000.5, 1500, 100)*10**185).ae(8.5185229673381935522)
1393
+ (hyp1f1(-5000, 1500, 100)*10**185).ae(9.1501213424563944311)
1394
+ assert hyp0f1(fadd(-20,'1e-100',exact=True), 0.25).ae(1.85014429040102783e+49)
1395
+ assert hyp0f1((-20*10**100+1, 10**100), 0.25).ae(1.85014429040102783e+49)
1396
+
1397
+ def test_hypercomb_zero_pow():
1398
+ # check that 0^0 = 1
1399
+ assert hypercomb(lambda a: (([0],[a],[],[],[],[],0),), [0]) == 1
1400
+ assert meijerg([[-1.5],[]],[[0],[-0.75]],0).ae(1.4464090846320771425)
1401
+
1402
+ def test_spherharm():
1403
+ mp.dps = 15
1404
+ t = 0.5; r = 0.25
1405
+ assert spherharm(0,0,t,r).ae(0.28209479177387814347)
1406
+ assert spherharm(1,-1,t,r).ae(0.16048941205971996369 - 0.04097967481096344271j)
1407
+ assert spherharm(1,0,t,r).ae(0.42878904414183579379)
1408
+ assert spherharm(1,1,t,r).ae(-0.16048941205971996369 - 0.04097967481096344271j)
1409
+ assert spherharm(2,-2,t,r).ae(0.077915886919031181734 - 0.042565643022253962264j)
1410
+ assert spherharm(2,-1,t,r).ae(0.31493387233497459884 - 0.08041582001959297689j)
1411
+ assert spherharm(2,0,t,r).ae(0.41330596756220761898)
1412
+ assert spherharm(2,1,t,r).ae(-0.31493387233497459884 - 0.08041582001959297689j)
1413
+ assert spherharm(2,2,t,r).ae(0.077915886919031181734 + 0.042565643022253962264j)
1414
+ assert spherharm(3,-3,t,r).ae(0.033640236589690881646 - 0.031339125318637082197j)
1415
+ assert spherharm(3,-2,t,r).ae(0.18091018743101461963 - 0.09883168583167010241j)
1416
+ assert spherharm(3,-1,t,r).ae(0.42796713930907320351 - 0.10927795157064962317j)
1417
+ assert spherharm(3,0,t,r).ae(0.27861659336351639787)
1418
+ assert spherharm(3,1,t,r).ae(-0.42796713930907320351 - 0.10927795157064962317j)
1419
+ assert spherharm(3,2,t,r).ae(0.18091018743101461963 + 0.09883168583167010241j)
1420
+ assert spherharm(3,3,t,r).ae(-0.033640236589690881646 - 0.031339125318637082197j)
1421
+ assert spherharm(0,-1,t,r) == 0
1422
+ assert spherharm(0,-2,t,r) == 0
1423
+ assert spherharm(0,1,t,r) == 0
1424
+ assert spherharm(0,2,t,r) == 0
1425
+ assert spherharm(1,2,t,r) == 0
1426
+ assert spherharm(1,3,t,r) == 0
1427
+ assert spherharm(1,-2,t,r) == 0
1428
+ assert spherharm(1,-3,t,r) == 0
1429
+ assert spherharm(2,3,t,r) == 0
1430
+ assert spherharm(2,4,t,r) == 0
1431
+ assert spherharm(2,-3,t,r) == 0
1432
+ assert spherharm(2,-4,t,r) == 0
1433
+ assert spherharm(3,4.5,0.5,0.25).ae(-22.831053442240790148 + 10.910526059510013757j)
1434
+ assert spherharm(2+3j, 1-j, 1+j, 3+4j).ae(-2.6582752037810116935 - 1.0909214905642160211j)
1435
+ assert spherharm(-6,2.5,t,r).ae(0.39383644983851448178 + 0.28414687085358299021j)
1436
+ assert spherharm(-3.5, 3, 0.5, 0.25).ae(0.014516852987544698924 - 0.015582769591477628495j)
1437
+ assert spherharm(-3, 3, 0.5, 0.25) == 0
1438
+ assert spherharm(-6, 3, 0.5, 0.25).ae(-0.16544349818782275459 - 0.15412657723253924562j)
1439
+ assert spherharm(-6, 1.5, 0.5, 0.25).ae(0.032208193499767402477 + 0.012678000924063664921j)
1440
+ assert spherharm(3,0,0,1).ae(0.74635266518023078283)
1441
+ assert spherharm(3,-2,0,1) == 0
1442
+ assert spherharm(3,-2,1,1).ae(-0.16270707338254028971 - 0.35552144137546777097j)
1443
+
1444
+ def test_qfunctions():
1445
+ mp.dps = 15
1446
+ assert qp(2,3,100).ae('2.7291482267247332183e2391')
1447
+
1448
+ def test_issue_239():
1449
+ mp.prec = 150
1450
+ x = ldexp(2476979795053773,-52)
1451
+ assert betainc(206, 385, 0, 0.55, 1).ae('0.99999999999999999999996570910644857895771110649954')
1452
+ mp.dps = 15
1453
+ pytest.raises(ValueError, lambda: hyp2f1(-5,5,0.5,0.5))
1454
+
1455
+ # Extra stress testing for Bessel functions
1456
+ # Reference zeros generated with the aid of scipy.special
1457
+ # jn_zero, jnp_zero, yn_zero, ynp_zero
1458
+
1459
+ V = 15
1460
+ M = 15
1461
+
1462
+ jn_small_zeros = \
1463
+ [[2.4048255576957728,
1464
+ 5.5200781102863106,
1465
+ 8.6537279129110122,
1466
+ 11.791534439014282,
1467
+ 14.930917708487786,
1468
+ 18.071063967910923,
1469
+ 21.211636629879259,
1470
+ 24.352471530749303,
1471
+ 27.493479132040255,
1472
+ 30.634606468431975,
1473
+ 33.775820213573569,
1474
+ 36.917098353664044,
1475
+ 40.058425764628239,
1476
+ 43.19979171317673,
1477
+ 46.341188371661814],
1478
+ [3.8317059702075123,
1479
+ 7.0155866698156188,
1480
+ 10.173468135062722,
1481
+ 13.323691936314223,
1482
+ 16.470630050877633,
1483
+ 19.615858510468242,
1484
+ 22.760084380592772,
1485
+ 25.903672087618383,
1486
+ 29.046828534916855,
1487
+ 32.189679910974404,
1488
+ 35.332307550083865,
1489
+ 38.474766234771615,
1490
+ 41.617094212814451,
1491
+ 44.759318997652822,
1492
+ 47.901460887185447],
1493
+ [5.1356223018406826,
1494
+ 8.4172441403998649,
1495
+ 11.619841172149059,
1496
+ 14.795951782351261,
1497
+ 17.959819494987826,
1498
+ 21.116997053021846,
1499
+ 24.270112313573103,
1500
+ 27.420573549984557,
1501
+ 30.569204495516397,
1502
+ 33.7165195092227,
1503
+ 36.86285651128381,
1504
+ 40.008446733478192,
1505
+ 43.153453778371463,
1506
+ 46.297996677236919,
1507
+ 49.442164110416873],
1508
+ [6.3801618959239835,
1509
+ 9.7610231299816697,
1510
+ 13.015200721698434,
1511
+ 16.223466160318768,
1512
+ 19.409415226435012,
1513
+ 22.582729593104442,
1514
+ 25.748166699294978,
1515
+ 28.908350780921758,
1516
+ 32.064852407097709,
1517
+ 35.218670738610115,
1518
+ 38.370472434756944,
1519
+ 41.520719670406776,
1520
+ 44.669743116617253,
1521
+ 47.817785691533302,
1522
+ 50.965029906205183],
1523
+ [7.5883424345038044,
1524
+ 11.064709488501185,
1525
+ 14.37253667161759,
1526
+ 17.615966049804833,
1527
+ 20.826932956962388,
1528
+ 24.01901952477111,
1529
+ 27.199087765981251,
1530
+ 30.371007667117247,
1531
+ 33.537137711819223,
1532
+ 36.699001128744649,
1533
+ 39.857627302180889,
1534
+ 43.01373772335443,
1535
+ 46.167853512924375,
1536
+ 49.320360686390272,
1537
+ 52.471551398458023],
1538
+ [8.771483815959954,
1539
+ 12.338604197466944,
1540
+ 15.700174079711671,
1541
+ 18.980133875179921,
1542
+ 22.217799896561268,
1543
+ 25.430341154222704,
1544
+ 28.626618307291138,
1545
+ 31.811716724047763,
1546
+ 34.988781294559295,
1547
+ 38.159868561967132,
1548
+ 41.326383254047406,
1549
+ 44.489319123219673,
1550
+ 47.649399806697054,
1551
+ 50.80716520300633,
1552
+ 53.963026558378149],
1553
+ [9.9361095242176849,
1554
+ 13.589290170541217,
1555
+ 17.003819667816014,
1556
+ 20.320789213566506,
1557
+ 23.58608443558139,
1558
+ 26.820151983411405,
1559
+ 30.033722386570469,
1560
+ 33.233041762847123,
1561
+ 36.422019668258457,
1562
+ 39.603239416075404,
1563
+ 42.778481613199507,
1564
+ 45.949015998042603,
1565
+ 49.11577372476426,
1566
+ 52.279453903601052,
1567
+ 55.440592068853149],
1568
+ [11.086370019245084,
1569
+ 14.821268727013171,
1570
+ 18.287582832481726,
1571
+ 21.641541019848401,
1572
+ 24.934927887673022,
1573
+ 28.191188459483199,
1574
+ 31.42279419226558,
1575
+ 34.637089352069324,
1576
+ 37.838717382853611,
1577
+ 41.030773691585537,
1578
+ 44.21540850526126,
1579
+ 47.394165755570512,
1580
+ 50.568184679795566,
1581
+ 53.738325371963291,
1582
+ 56.905249991978781],
1583
+ [12.225092264004655,
1584
+ 16.037774190887709,
1585
+ 19.554536430997055,
1586
+ 22.94517313187462,
1587
+ 26.266814641176644,
1588
+ 29.54565967099855,
1589
+ 32.795800037341462,
1590
+ 36.025615063869571,
1591
+ 39.240447995178135,
1592
+ 42.443887743273558,
1593
+ 45.638444182199141,
1594
+ 48.825930381553857,
1595
+ 52.007691456686903,
1596
+ 55.184747939289049,
1597
+ 58.357889025269694],
1598
+ [13.354300477435331,
1599
+ 17.241220382489128,
1600
+ 20.807047789264107,
1601
+ 24.233885257750552,
1602
+ 27.583748963573006,
1603
+ 30.885378967696675,
1604
+ 34.154377923855096,
1605
+ 37.400099977156589,
1606
+ 40.628553718964528,
1607
+ 43.843801420337347,
1608
+ 47.048700737654032,
1609
+ 50.245326955305383,
1610
+ 53.435227157042058,
1611
+ 56.619580266508436,
1612
+ 59.799301630960228],
1613
+ [14.475500686554541,
1614
+ 18.433463666966583,
1615
+ 22.046985364697802,
1616
+ 25.509450554182826,
1617
+ 28.887375063530457,
1618
+ 32.211856199712731,
1619
+ 35.499909205373851,
1620
+ 38.761807017881651,
1621
+ 42.004190236671805,
1622
+ 45.231574103535045,
1623
+ 48.447151387269394,
1624
+ 51.653251668165858,
1625
+ 54.851619075963349,
1626
+ 58.043587928232478,
1627
+ 61.230197977292681],
1628
+ [15.589847884455485,
1629
+ 19.61596690396692,
1630
+ 23.275853726263409,
1631
+ 26.773322545509539,
1632
+ 30.17906117878486,
1633
+ 33.526364075588624,
1634
+ 36.833571341894905,
1635
+ 40.111823270954241,
1636
+ 43.368360947521711,
1637
+ 46.608132676274944,
1638
+ 49.834653510396724,
1639
+ 53.050498959135054,
1640
+ 56.257604715114484,
1641
+ 59.457456908388002,
1642
+ 62.651217388202912],
1643
+ [16.698249933848246,
1644
+ 20.789906360078443,
1645
+ 24.494885043881354,
1646
+ 28.026709949973129,
1647
+ 31.45996003531804,
1648
+ 34.829986990290238,
1649
+ 38.156377504681354,
1650
+ 41.451092307939681,
1651
+ 44.721943543191147,
1652
+ 47.974293531269048,
1653
+ 51.211967004101068,
1654
+ 54.437776928325074,
1655
+ 57.653844811906946,
1656
+ 60.8618046824805,
1657
+ 64.062937824850136],
1658
+ [17.801435153282442,
1659
+ 21.95624406783631,
1660
+ 25.705103053924724,
1661
+ 29.270630441874802,
1662
+ 32.731053310978403,
1663
+ 36.123657666448762,
1664
+ 39.469206825243883,
1665
+ 42.780439265447158,
1666
+ 46.06571091157561,
1667
+ 49.330780096443524,
1668
+ 52.579769064383396,
1669
+ 55.815719876305778,
1670
+ 59.040934037249271,
1671
+ 62.257189393731728,
1672
+ 65.465883797232125],
1673
+ [18.899997953174024,
1674
+ 23.115778347252756,
1675
+ 26.907368976182104,
1676
+ 30.505950163896036,
1677
+ 33.993184984781542,
1678
+ 37.408185128639695,
1679
+ 40.772827853501868,
1680
+ 44.100590565798301,
1681
+ 47.400347780543231,
1682
+ 50.678236946479898,
1683
+ 53.93866620912693,
1684
+ 57.184898598119301,
1685
+ 60.419409852130297,
1686
+ 63.644117508962281,
1687
+ 66.860533012260103]]
1688
+
1689
+ jnp_small_zeros = \
1690
+ [[0.0,
1691
+ 3.8317059702075123,
1692
+ 7.0155866698156188,
1693
+ 10.173468135062722,
1694
+ 13.323691936314223,
1695
+ 16.470630050877633,
1696
+ 19.615858510468242,
1697
+ 22.760084380592772,
1698
+ 25.903672087618383,
1699
+ 29.046828534916855,
1700
+ 32.189679910974404,
1701
+ 35.332307550083865,
1702
+ 38.474766234771615,
1703
+ 41.617094212814451,
1704
+ 44.759318997652822],
1705
+ [1.8411837813406593,
1706
+ 5.3314427735250326,
1707
+ 8.5363163663462858,
1708
+ 11.706004902592064,
1709
+ 14.863588633909033,
1710
+ 18.015527862681804,
1711
+ 21.16436985918879,
1712
+ 24.311326857210776,
1713
+ 27.457050571059246,
1714
+ 30.601922972669094,
1715
+ 33.746182898667383,
1716
+ 36.889987409236811,
1717
+ 40.033444053350675,
1718
+ 43.176628965448822,
1719
+ 46.319597561173912],
1720
+ [3.0542369282271403,
1721
+ 6.7061331941584591,
1722
+ 9.9694678230875958,
1723
+ 13.170370856016123,
1724
+ 16.347522318321783,
1725
+ 19.512912782488205,
1726
+ 22.671581772477426,
1727
+ 25.826037141785263,
1728
+ 28.977672772993679,
1729
+ 32.127327020443474,
1730
+ 35.275535050674691,
1731
+ 38.422654817555906,
1732
+ 41.568934936074314,
1733
+ 44.714553532819734,
1734
+ 47.859641607992093],
1735
+ [4.2011889412105285,
1736
+ 8.0152365983759522,
1737
+ 11.345924310743006,
1738
+ 14.585848286167028,
1739
+ 17.78874786606647,
1740
+ 20.9724769365377,
1741
+ 24.144897432909265,
1742
+ 27.310057930204349,
1743
+ 30.470268806290424,
1744
+ 33.626949182796679,
1745
+ 36.781020675464386,
1746
+ 39.933108623659488,
1747
+ 43.083652662375079,
1748
+ 46.232971081836478,
1749
+ 49.381300092370349],
1750
+ [5.3175531260839944,
1751
+ 9.2823962852416123,
1752
+ 12.681908442638891,
1753
+ 15.964107037731551,
1754
+ 19.196028800048905,
1755
+ 22.401032267689004,
1756
+ 25.589759681386733,
1757
+ 28.767836217666503,
1758
+ 31.938539340972783,
1759
+ 35.103916677346764,
1760
+ 38.265316987088158,
1761
+ 41.423666498500732,
1762
+ 44.579623137359257,
1763
+ 47.733667523865744,
1764
+ 50.886159153182682],
1765
+ [6.4156163757002403,
1766
+ 10.519860873772308,
1767
+ 13.9871886301403,
1768
+ 17.312842487884625,
1769
+ 20.575514521386888,
1770
+ 23.803581476593863,
1771
+ 27.01030789777772,
1772
+ 30.20284907898166,
1773
+ 33.385443901010121,
1774
+ 36.560777686880356,
1775
+ 39.730640230067416,
1776
+ 42.896273163494417,
1777
+ 46.058566273567043,
1778
+ 49.218174614666636,
1779
+ 52.375591529563596],
1780
+ [7.501266144684147,
1781
+ 11.734935953042708,
1782
+ 15.268181461097873,
1783
+ 18.637443009666202,
1784
+ 21.931715017802236,
1785
+ 25.183925599499626,
1786
+ 28.409776362510085,
1787
+ 31.617875716105035,
1788
+ 34.81339298429743,
1789
+ 37.999640897715301,
1790
+ 41.178849474321413,
1791
+ 44.352579199070217,
1792
+ 47.521956905768113,
1793
+ 50.687817781723741,
1794
+ 53.85079463676896],
1795
+ [8.5778364897140741,
1796
+ 12.932386237089576,
1797
+ 16.529365884366944,
1798
+ 19.941853366527342,
1799
+ 23.268052926457571,
1800
+ 26.545032061823576,
1801
+ 29.790748583196614,
1802
+ 33.015178641375142,
1803
+ 36.224380548787162,
1804
+ 39.422274578939259,
1805
+ 42.611522172286684,
1806
+ 45.793999658055002,
1807
+ 48.971070951900596,
1808
+ 52.143752969301988,
1809
+ 55.312820330403446],
1810
+ [9.6474216519972168,
1811
+ 14.115518907894618,
1812
+ 17.774012366915256,
1813
+ 21.229062622853124,
1814
+ 24.587197486317681,
1815
+ 27.889269427955092,
1816
+ 31.155326556188325,
1817
+ 34.39662855427218,
1818
+ 37.620078044197086,
1819
+ 40.830178681822041,
1820
+ 44.030010337966153,
1821
+ 47.221758471887113,
1822
+ 50.407020967034367,
1823
+ 53.586995435398319,
1824
+ 56.762598475105272],
1825
+ [10.711433970699945,
1826
+ 15.28673766733295,
1827
+ 19.004593537946053,
1828
+ 22.501398726777283,
1829
+ 25.891277276839136,
1830
+ 29.218563499936081,
1831
+ 32.505247352375523,
1832
+ 35.763792928808799,
1833
+ 39.001902811514218,
1834
+ 42.224638430753279,
1835
+ 45.435483097475542,
1836
+ 48.636922645305525,
1837
+ 51.830783925834728,
1838
+ 55.01844255063594,
1839
+ 58.200955824859509],
1840
+ [11.770876674955582,
1841
+ 16.447852748486498,
1842
+ 20.223031412681701,
1843
+ 23.760715860327448,
1844
+ 27.182021527190532,
1845
+ 30.534504754007074,
1846
+ 33.841965775135715,
1847
+ 37.118000423665604,
1848
+ 40.371068905333891,
1849
+ 43.606764901379516,
1850
+ 46.828959446564562,
1851
+ 50.040428970943456,
1852
+ 53.243223214220535,
1853
+ 56.438892058982552,
1854
+ 59.628631306921512],
1855
+ [12.826491228033465,
1856
+ 17.600266557468326,
1857
+ 21.430854238060294,
1858
+ 25.008518704644261,
1859
+ 28.460857279654847,
1860
+ 31.838424458616998,
1861
+ 35.166714427392629,
1862
+ 38.460388720328256,
1863
+ 41.728625562624312,
1864
+ 44.977526250903469,
1865
+ 48.211333836373288,
1866
+ 51.433105171422278,
1867
+ 54.645106240447105,
1868
+ 57.849056857839799,
1869
+ 61.046288512821078],
1870
+ [13.878843069697276,
1871
+ 18.745090916814406,
1872
+ 22.629300302835503,
1873
+ 26.246047773946584,
1874
+ 29.72897816891134,
1875
+ 33.131449953571661,
1876
+ 36.480548302231658,
1877
+ 39.791940718940855,
1878
+ 43.075486800191012,
1879
+ 46.337772104541405,
1880
+ 49.583396417633095,
1881
+ 52.815686826850452,
1882
+ 56.037118687012179,
1883
+ 59.249577075517968,
1884
+ 62.454525995970462],
1885
+ [14.928374492964716,
1886
+ 19.88322436109951,
1887
+ 23.81938909003628,
1888
+ 27.474339750968247,
1889
+ 30.987394331665278,
1890
+ 34.414545662167183,
1891
+ 37.784378506209499,
1892
+ 41.113512376883377,
1893
+ 44.412454519229281,
1894
+ 47.688252845993366,
1895
+ 50.945849245830813,
1896
+ 54.188831071035124,
1897
+ 57.419876154678179,
1898
+ 60.641030026538746,
1899
+ 63.853885828967512],
1900
+ [15.975438807484321,
1901
+ 21.015404934568315,
1902
+ 25.001971500138194,
1903
+ 28.694271223110755,
1904
+ 32.236969407878118,
1905
+ 35.688544091185301,
1906
+ 39.078998185245057,
1907
+ 42.425854432866141,
1908
+ 45.740236776624833,
1909
+ 49.029635055514276,
1910
+ 52.299319390331728,
1911
+ 55.553127779547459,
1912
+ 58.793933759028134,
1913
+ 62.02393848337554,
1914
+ 65.244860767043859]]
1915
+
1916
+ yn_small_zeros = \
1917
+ [[0.89357696627916752,
1918
+ 3.9576784193148579,
1919
+ 7.0860510603017727,
1920
+ 10.222345043496417,
1921
+ 13.361097473872763,
1922
+ 16.500922441528091,
1923
+ 19.64130970088794,
1924
+ 22.782028047291559,
1925
+ 25.922957653180923,
1926
+ 29.064030252728398,
1927
+ 32.205204116493281,
1928
+ 35.346452305214321,
1929
+ 38.487756653081537,
1930
+ 41.629104466213808,
1931
+ 44.770486607221993],
1932
+ [2.197141326031017,
1933
+ 5.4296810407941351,
1934
+ 8.5960058683311689,
1935
+ 11.749154830839881,
1936
+ 14.897442128336725,
1937
+ 18.043402276727856,
1938
+ 21.188068934142213,
1939
+ 24.331942571356912,
1940
+ 27.475294980449224,
1941
+ 30.618286491641115,
1942
+ 33.761017796109326,
1943
+ 36.90355531614295,
1944
+ 40.045944640266876,
1945
+ 43.188218097393211,
1946
+ 46.330399250701687],
1947
+ [3.3842417671495935,
1948
+ 6.7938075132682675,
1949
+ 10.023477979360038,
1950
+ 13.209986710206416,
1951
+ 16.378966558947457,
1952
+ 19.539039990286384,
1953
+ 22.69395593890929,
1954
+ 25.845613720902269,
1955
+ 28.995080395650151,
1956
+ 32.143002257627551,
1957
+ 35.289793869635804,
1958
+ 38.435733485446343,
1959
+ 41.581014867297885,
1960
+ 44.725777117640461,
1961
+ 47.870122696676504],
1962
+ [4.5270246611496439,
1963
+ 8.0975537628604907,
1964
+ 11.396466739595867,
1965
+ 14.623077742393873,
1966
+ 17.81845523294552,
1967
+ 20.997284754187761,
1968
+ 24.166235758581828,
1969
+ 27.328799850405162,
1970
+ 30.486989604098659,
1971
+ 33.642049384702463,
1972
+ 36.794791029185579,
1973
+ 39.945767226378749,
1974
+ 43.095367507846703,
1975
+ 46.2438744334407,
1976
+ 49.391498015725107],
1977
+ [5.6451478942208959,
1978
+ 9.3616206152445429,
1979
+ 12.730144474090465,
1980
+ 15.999627085382479,
1981
+ 19.22442895931681,
1982
+ 22.424810599698521,
1983
+ 25.610267054939328,
1984
+ 28.785893657666548,
1985
+ 31.954686680031668,
1986
+ 35.118529525584828,
1987
+ 38.278668089521758,
1988
+ 41.435960629910073,
1989
+ 44.591018225353424,
1990
+ 47.744288086361052,
1991
+ 50.896105199722123],
1992
+ [6.7471838248710219,
1993
+ 10.597176726782031,
1994
+ 14.033804104911233,
1995
+ 17.347086393228382,
1996
+ 20.602899017175335,
1997
+ 23.826536030287532,
1998
+ 27.030134937138834,
1999
+ 30.220335654231385,
2000
+ 33.401105611047908,
2001
+ 36.574972486670962,
2002
+ 39.743627733020277,
2003
+ 42.908248189569535,
2004
+ 46.069679073215439,
2005
+ 49.228543693445843,
2006
+ 52.385312123112282],
2007
+ [7.8377378223268716,
2008
+ 11.811037107609447,
2009
+ 15.313615118517857,
2010
+ 18.670704965906724,
2011
+ 21.958290897126571,
2012
+ 25.206207715021249,
2013
+ 28.429037095235496,
2014
+ 31.634879502950644,
2015
+ 34.828638524084437,
2016
+ 38.013473399691765,
2017
+ 41.19151880917741,
2018
+ 44.364272633271975,
2019
+ 47.53281875312084,
2020
+ 50.697961822183806,
2021
+ 53.860312300118388],
2022
+ [8.919605734873789,
2023
+ 13.007711435388313,
2024
+ 16.573915129085334,
2025
+ 19.974342312352426,
2026
+ 23.293972585596648,
2027
+ 26.5667563757203,
2028
+ 29.809531451608321,
2029
+ 33.031769327150685,
2030
+ 36.239265816598239,
2031
+ 39.435790312675323,
2032
+ 42.623910919472727,
2033
+ 45.805442883111651,
2034
+ 48.981708325514764,
2035
+ 52.153694518185572,
2036
+ 55.322154420959698],
2037
+ [9.9946283820824834,
2038
+ 14.190361295800141,
2039
+ 17.817887841179873,
2040
+ 21.26093227125945,
2041
+ 24.612576377421522,
2042
+ 27.910524883974868,
2043
+ 31.173701563441602,
2044
+ 34.412862242025045,
2045
+ 37.634648706110989,
2046
+ 40.843415321050884,
2047
+ 44.04214994542435,
2048
+ 47.232978012841169,
2049
+ 50.417456447370186,
2050
+ 53.596753874948731,
2051
+ 56.771765754432457],
2052
+ [11.064090256031013,
2053
+ 15.361301343575925,
2054
+ 19.047949646361388,
2055
+ 22.532765416313869,
2056
+ 25.91620496332662,
2057
+ 29.2394205079349,
2058
+ 32.523270869465881,
2059
+ 35.779715464475261,
2060
+ 39.016196664616095,
2061
+ 42.237627509803703,
2062
+ 45.4474001519274,
2063
+ 48.647941127433196,
2064
+ 51.841036928216499,
2065
+ 55.028034667184916,
2066
+ 58.209970905250097],
2067
+ [12.128927704415439,
2068
+ 16.522284394784426,
2069
+ 20.265984501212254,
2070
+ 23.791669719454272,
2071
+ 27.206568881574774,
2072
+ 30.555020011020762,
2073
+ 33.859683872746356,
2074
+ 37.133649760307504,
2075
+ 40.385117593813002,
2076
+ 43.619533085646856,
2077
+ 46.840676630553575,
2078
+ 50.051265851897857,
2079
+ 53.253310556711732,
2080
+ 56.448332488918971,
2081
+ 59.637507005589829],
2082
+ [13.189846995683845,
2083
+ 17.674674253171487,
2084
+ 21.473493977824902,
2085
+ 25.03913093040942,
2086
+ 28.485081336558058,
2087
+ 31.858644293774859,
2088
+ 35.184165245422787,
2089
+ 38.475796636190897,
2090
+ 41.742455848758449,
2091
+ 44.990096293791186,
2092
+ 48.222870660068338,
2093
+ 51.443777308699826,
2094
+ 54.655042589416311,
2095
+ 57.858358441436511,
2096
+ 61.055036135780528],
2097
+ [14.247395665073945,
2098
+ 18.819555894710682,
2099
+ 22.671697117872794,
2100
+ 26.276375544903892,
2101
+ 29.752925495549038,
2102
+ 33.151412708998983,
2103
+ 36.497763772987645,
2104
+ 39.807134090704376,
2105
+ 43.089121522203808,
2106
+ 46.350163579538652,
2107
+ 49.594769786270069,
2108
+ 52.82620892320143,
2109
+ 56.046916910756961,
2110
+ 59.258751140598783,
2111
+ 62.463155567737854],
2112
+ [15.30200785858925,
2113
+ 19.957808654258601,
2114
+ 23.861599172945054,
2115
+ 27.504429642227545,
2116
+ 31.011103429019229,
2117
+ 34.434283425782942,
2118
+ 37.801385632318459,
2119
+ 41.128514139788358,
2120
+ 44.425913324440663,
2121
+ 47.700482714581842,
2122
+ 50.957073905278458,
2123
+ 54.199216028087261,
2124
+ 57.429547607017405,
2125
+ 60.65008661807661,
2126
+ 63.862406280068586],
2127
+ [16.354034360047551,
2128
+ 21.090156519983806,
2129
+ 25.044040298785627,
2130
+ 28.724161640881914,
2131
+ 32.260472459522644,
2132
+ 35.708083982611664,
2133
+ 39.095820003878235,
2134
+ 42.440684315990936,
2135
+ 45.75353669045622,
2136
+ 49.041718113283529,
2137
+ 52.310408280968073,
2138
+ 55.56338698149062,
2139
+ 58.803488508906895,
2140
+ 62.032886550960831,
2141
+ 65.253280088312461]]
2142
+
2143
+ ynp_small_zeros = \
2144
+ [[2.197141326031017,
2145
+ 5.4296810407941351,
2146
+ 8.5960058683311689,
2147
+ 11.749154830839881,
2148
+ 14.897442128336725,
2149
+ 18.043402276727856,
2150
+ 21.188068934142213,
2151
+ 24.331942571356912,
2152
+ 27.475294980449224,
2153
+ 30.618286491641115,
2154
+ 33.761017796109326,
2155
+ 36.90355531614295,
2156
+ 40.045944640266876,
2157
+ 43.188218097393211,
2158
+ 46.330399250701687],
2159
+ [3.6830228565851777,
2160
+ 6.9414999536541757,
2161
+ 10.123404655436613,
2162
+ 13.285758156782854,
2163
+ 16.440058007293282,
2164
+ 19.590241756629495,
2165
+ 22.738034717396327,
2166
+ 25.884314618788867,
2167
+ 29.029575819372535,
2168
+ 32.174118233366201,
2169
+ 35.318134458192094,
2170
+ 38.461753870997549,
2171
+ 41.605066618873108,
2172
+ 44.74813744908079,
2173
+ 47.891014070791065],
2174
+ [5.0025829314460639,
2175
+ 8.3507247014130795,
2176
+ 11.574195465217647,
2177
+ 14.760909306207676,
2178
+ 17.931285939466855,
2179
+ 21.092894504412739,
2180
+ 24.249231678519058,
2181
+ 27.402145837145258,
2182
+ 30.552708880564553,
2183
+ 33.70158627151572,
2184
+ 36.849213419846257,
2185
+ 39.995887376143356,
2186
+ 43.141817835750686,
2187
+ 46.287157097544201,
2188
+ 49.432018469138281],
2189
+ [6.2536332084598136,
2190
+ 9.6987879841487711,
2191
+ 12.972409052292216,
2192
+ 16.19044719506921,
2193
+ 19.38238844973613,
2194
+ 22.559791857764261,
2195
+ 25.728213194724094,
2196
+ 28.890678419054777,
2197
+ 32.048984005266337,
2198
+ 35.204266606440635,
2199
+ 38.357281675961019,
2200
+ 41.508551443818436,
2201
+ 44.658448731963676,
2202
+ 47.807246956681162,
2203
+ 50.95515126455207],
2204
+ [7.4649217367571329,
2205
+ 11.005169149809189,
2206
+ 14.3317235192331,
2207
+ 17.58443601710272,
2208
+ 20.801062338411128,
2209
+ 23.997004122902644,
2210
+ 27.179886689853435,
2211
+ 30.353960608554323,
2212
+ 33.521797098666792,
2213
+ 36.685048382072301,
2214
+ 39.844826969405863,
2215
+ 43.001910515625288,
2216
+ 46.15685955107263,
2217
+ 49.310088614282257,
2218
+ 52.461911043685864],
2219
+ [8.6495562436971983,
2220
+ 12.280868725807848,
2221
+ 15.660799304540377,
2222
+ 18.949739756016503,
2223
+ 22.192841809428241,
2224
+ 25.409072788867674,
2225
+ 28.608039283077593,
2226
+ 31.795195353138159,
2227
+ 34.973890634255288,
2228
+ 38.14630522169358,
2229
+ 41.313923188794905,
2230
+ 44.477791768537617,
2231
+ 47.638672065035628,
2232
+ 50.797131066967842,
2233
+ 53.953600129601663],
2234
+ [9.8147970120105779,
2235
+ 13.532811875789828,
2236
+ 16.965526446046053,
2237
+ 20.291285512443867,
2238
+ 23.56186260680065,
2239
+ 26.799499736027237,
2240
+ 30.015665481543419,
2241
+ 33.216968050039509,
2242
+ 36.407516858984748,
2243
+ 39.590015243560459,
2244
+ 42.766320595957378,
2245
+ 45.937754257017323,
2246
+ 49.105283450953203,
2247
+ 52.269633324547373,
2248
+ 55.431358715604255],
2249
+ [10.965152105242974,
2250
+ 14.765687379508912,
2251
+ 18.250123150217555,
2252
+ 21.612750053384621,
2253
+ 24.911310600813573,
2254
+ 28.171051927637585,
2255
+ 31.40518108895689,
2256
+ 34.621401012564177,
2257
+ 37.824552065973114,
2258
+ 41.017847386464902,
2259
+ 44.203512240871601,
2260
+ 47.3831408366063,
2261
+ 50.557907466622796,
2262
+ 53.728697478957026,
2263
+ 56.896191727313342],
2264
+ [12.103641941939539,
2265
+ 15.982840905145284,
2266
+ 19.517731005559611,
2267
+ 22.916962141504605,
2268
+ 26.243700855690533,
2269
+ 29.525960140695407,
2270
+ 32.778568197561124,
2271
+ 36.010261572392516,
2272
+ 39.226578757802172,
2273
+ 42.43122493258747,
2274
+ 45.626783824134354,
2275
+ 48.815117837929515,
2276
+ 51.997606404328863,
2277
+ 55.175294723956816,
2278
+ 58.348990221754937],
2279
+ [13.232403808592215,
2280
+ 17.186756572616758,
2281
+ 20.770762917490496,
2282
+ 24.206152448722253,
2283
+ 27.561059462697153,
2284
+ 30.866053571250639,
2285
+ 34.137476603379774,
2286
+ 37.385039772270268,
2287
+ 40.614946085165892,
2288
+ 43.831373184731238,
2289
+ 47.037251786726299,
2290
+ 50.234705848765229,
2291
+ 53.425316228549359,
2292
+ 56.610286079882087,
2293
+ 59.790548623216652],
2294
+ [14.35301374369987,
2295
+ 18.379337301642568,
2296
+ 22.011118775283494,
2297
+ 25.482116178696707,
2298
+ 28.865046588695164,
2299
+ 32.192853922166294,
2300
+ 35.483296655830277,
2301
+ 38.747005493021857,
2302
+ 41.990815194320955,
2303
+ 45.219355876831731,
2304
+ 48.435892856078888,
2305
+ 51.642803925173029,
2306
+ 54.84186659475857,
2307
+ 58.034439083840155,
2308
+ 61.221578745109862],
2309
+ [15.466672066554263,
2310
+ 19.562077985759503,
2311
+ 23.240325531101082,
2312
+ 26.746322986645901,
2313
+ 30.157042415639891,
2314
+ 33.507642948240263,
2315
+ 36.817212798512775,
2316
+ 40.097251300178642,
2317
+ 43.355193847719752,
2318
+ 46.596103410173672,
2319
+ 49.823567279972794,
2320
+ 53.040208868780832,
2321
+ 56.247996968470062,
2322
+ 59.448441365714251,
2323
+ 62.642721301357187],
2324
+ [16.574317035530872,
2325
+ 20.73617763753932,
2326
+ 24.459631728238804,
2327
+ 27.999993668839644,
2328
+ 31.438208790267783,
2329
+ 34.811512070805535,
2330
+ 38.140243708611251,
2331
+ 41.436725143893739,
2332
+ 44.708963264433333,
2333
+ 47.962435051891027,
2334
+ 51.201037321915983,
2335
+ 54.427630745992975,
2336
+ 57.644369734615238,
2337
+ 60.852911791989989,
2338
+ 64.054555435720397],
2339
+ [17.676697936439624,
2340
+ 21.9026148697762,
2341
+ 25.670073356263225,
2342
+ 29.244155124266438,
2343
+ 32.709534477396028,
2344
+ 36.105399554497548,
2345
+ 39.453272918267025,
2346
+ 42.766255701958017,
2347
+ 46.052899215578358,
2348
+ 49.319076602061401,
2349
+ 52.568982147952547,
2350
+ 55.805705507386287,
2351
+ 59.031580956740466,
2352
+ 62.248409689597653,
2353
+ 65.457606670836759],
2354
+ [18.774423978290318,
2355
+ 23.06220035979272,
2356
+ 26.872520985976736,
2357
+ 30.479680663499762,
2358
+ 33.971869047372436,
2359
+ 37.390118854896324,
2360
+ 40.757072537673599,
2361
+ 44.086572292170345,
2362
+ 47.387688809191869,
2363
+ 50.66667461073936,
2364
+ 53.928009929563275,
2365
+ 57.175005343085052,
2366
+ 60.410169281219877,
2367
+ 63.635442539153021,
2368
+ 66.85235358587768]]
2369
+
2370
+ @pytest.mark.slow
2371
+ def test_bessel_zeros_extra():
2372
+ mp.dps = 15
2373
+ for v in range(V):
2374
+ for m in range(1,M+1):
2375
+ print(v, m, "of", V, M)
2376
+ # Twice to test cache (if used)
2377
+ assert besseljzero(v,m).ae(jn_small_zeros[v][m-1])
2378
+ assert besseljzero(v,m).ae(jn_small_zeros[v][m-1])
2379
+ assert besseljzero(v,m,1).ae(jnp_small_zeros[v][m-1])
2380
+ assert besseljzero(v,m,1).ae(jnp_small_zeros[v][m-1])
2381
+ assert besselyzero(v,m).ae(yn_small_zeros[v][m-1])
2382
+ assert besselyzero(v,m).ae(yn_small_zeros[v][m-1])
2383
+ assert besselyzero(v,m,1).ae(ynp_small_zeros[v][m-1])
2384
+ assert besselyzero(v,m,1).ae(ynp_small_zeros[v][m-1])
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/test_ode.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #from mpmath.calculus import ODE_step_euler, ODE_step_rk4, odeint, arange
2
+ from mpmath import odefun, cos, sin, mpf, sinc, mp
3
+
4
+ '''
5
+ solvers = [ODE_step_euler, ODE_step_rk4]
6
+
7
+ def test_ode1():
8
+ """
9
+ Let's solve:
10
+
11
+ x'' + w**2 * x = 0
12
+
13
+ i.e. x1 = x, x2 = x1':
14
+
15
+ x1' = x2
16
+ x2' = -x1
17
+ """
18
+ def derivs((x1, x2), t):
19
+ return x2, -x1
20
+
21
+ for solver in solvers:
22
+ t = arange(0, 3.1415926, 0.005)
23
+ sol = odeint(derivs, (0., 1.), t, solver)
24
+ x1 = [a[0] for a in sol]
25
+ x2 = [a[1] for a in sol]
26
+ # the result is x1 = sin(t), x2 = cos(t)
27
+ # let's just check the end points for t = pi
28
+ assert abs(x1[-1]) < 1e-2
29
+ assert abs(x2[-1] - (-1)) < 1e-2
30
+
31
+ def test_ode2():
32
+ """
33
+ Let's solve:
34
+
35
+ x' - x = 0
36
+
37
+ i.e. x = exp(x)
38
+
39
+ """
40
+ def derivs((x), t):
41
+ return x
42
+
43
+ for solver in solvers:
44
+ t = arange(0, 1, 1e-3)
45
+ sol = odeint(derivs, (1.,), t, solver)
46
+ x = [a[0] for a in sol]
47
+ # the result is x = exp(t)
48
+ # let's just check the end point for t = 1, i.e. x = e
49
+ assert abs(x[-1] - 2.718281828) < 1e-2
50
+ '''
51
+
52
+ def test_odefun_rational():
53
+ mp.dps = 15
54
+ # A rational function
55
+ f = lambda t: 1/(1+mpf(t)**2)
56
+ g = odefun(lambda x, y: [-2*x*y[0]**2], 0, [f(0)])
57
+ assert f(2).ae(g(2)[0])
58
+
59
+ def test_odefun_sinc_large():
60
+ mp.dps = 15
61
+ # Sinc function; test for large x
62
+ f = sinc
63
+ g = odefun(lambda x, y: [(cos(x)-y[0])/x], 1, [f(1)], tol=0.01, degree=5)
64
+ assert abs(f(100) - g(100)[0])/f(100) < 0.01
65
+
66
+ def test_odefun_harmonic():
67
+ mp.dps = 15
68
+ # Harmonic oscillator
69
+ f = odefun(lambda x, y: [-y[1], y[0]], 0, [1, 0])
70
+ for x in [0, 1, 2.5, 8, 3.7]: # we go back to 3.7 to check caching
71
+ c, s = f(x)
72
+ assert c.ae(cos(x))
73
+ assert s.ae(sin(x))
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/test_quad.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ from mpmath import *
3
+
4
+ def ae(a, b):
5
+ return abs(a-b) < 10**(-mp.dps+5)
6
+
7
+ def test_basic_integrals():
8
+ for prec in [15, 30, 100]:
9
+ mp.dps = prec
10
+ assert ae(quadts(lambda x: x**3 - 3*x**2, [-2, 4]), -12)
11
+ assert ae(quadgl(lambda x: x**3 - 3*x**2, [-2, 4]), -12)
12
+ assert ae(quadts(sin, [0, pi]), 2)
13
+ assert ae(quadts(sin, [0, 2*pi]), 0)
14
+ assert ae(quadts(exp, [-inf, -1]), 1/e)
15
+ assert ae(quadts(lambda x: exp(-x), [0, inf]), 1)
16
+ assert ae(quadts(lambda x: exp(-x*x), [-inf, inf]), sqrt(pi))
17
+ assert ae(quadts(lambda x: 1/(1+x*x), [-1, 1]), pi/2)
18
+ assert ae(quadts(lambda x: 1/(1+x*x), [-inf, inf]), pi)
19
+ assert ae(quadts(lambda x: 2*sqrt(1-x*x), [-1, 1]), pi)
20
+ mp.dps = 15
21
+
22
+ def test_multiple_intervals():
23
+ y,err = quad(lambda x: sign(x), [-0.5, 0.9, 1], maxdegree=2, error=True)
24
+ assert abs(y-0.5) < 2*err
25
+
26
+ def test_quad_symmetry():
27
+ assert quadts(sin, [-1, 1]) == 0
28
+ assert quadgl(sin, [-1, 1]) == 0
29
+
30
+ def test_quad_infinite_mirror():
31
+ # Check mirrored infinite interval
32
+ assert ae(quad(lambda x: exp(-x*x), [inf,-inf]), -sqrt(pi))
33
+ assert ae(quad(lambda x: exp(x), [0,-inf]), -1)
34
+
35
+ def test_quadgl_linear():
36
+ assert quadgl(lambda x: x, [0, 1], maxdegree=1).ae(0.5)
37
+
38
+ def test_complex_integration():
39
+ assert quadts(lambda x: x, [0, 1+j]).ae(j)
40
+
41
+ def test_quadosc():
42
+ mp.dps = 15
43
+ assert quadosc(lambda x: sin(x)/x, [0, inf], period=2*pi).ae(pi/2)
44
+
45
+ # Double integrals
46
+ def test_double_trivial():
47
+ assert ae(quadts(lambda x, y: x, [0, 1], [0, 1]), 0.5)
48
+ assert ae(quadts(lambda x, y: x, [-1, 1], [-1, 1]), 0.0)
49
+
50
+ def test_double_1():
51
+ assert ae(quadts(lambda x, y: cos(x+y/2), [-pi/2, pi/2], [0, pi]), 4)
52
+
53
+ def test_double_2():
54
+ assert ae(quadts(lambda x, y: (x-1)/((1-x*y)*log(x*y)), [0, 1], [0, 1]), euler)
55
+
56
+ def test_double_3():
57
+ assert ae(quadts(lambda x, y: 1/sqrt(1+x*x+y*y), [-1, 1], [-1, 1]), 4*log(2+sqrt(3))-2*pi/3)
58
+
59
+ def test_double_4():
60
+ assert ae(quadts(lambda x, y: 1/(1-x*x * y*y), [0, 1], [0, 1]), pi**2 / 8)
61
+
62
+ def test_double_5():
63
+ assert ae(quadts(lambda x, y: 1/(1-x*y), [0, 1], [0, 1]), pi**2 / 6)
64
+
65
+ def test_double_6():
66
+ assert ae(quadts(lambda x, y: exp(-(x+y)), [0, inf], [0, inf]), 1)
67
+
68
+ def test_double_7():
69
+ assert ae(quadts(lambda x, y: exp(-x*x-y*y), [-inf, inf], [-inf, inf]), pi)
70
+
71
+
72
+ # Test integrals from "Experimentation in Mathematics" by Borwein,
73
+ # Bailey & Girgensohn
74
+ def test_expmath_integrals():
75
+ for prec in [15, 30, 50]:
76
+ mp.dps = prec
77
+ assert ae(quadts(lambda x: x/sinh(x), [0, inf]), pi**2 / 4)
78
+ assert ae(quadts(lambda x: log(x)**2 / (1+x**2), [0, inf]), pi**3 / 8)
79
+ assert ae(quadts(lambda x: (1+x**2)/(1+x**4), [0, inf]), pi/sqrt(2))
80
+ assert ae(quadts(lambda x: log(x)/cosh(x)**2, [0, inf]), log(pi)-2*log(2)-euler)
81
+ assert ae(quadts(lambda x: log(1+x**3)/(1-x+x**2), [0, inf]), 2*pi*log(3)/sqrt(3))
82
+ assert ae(quadts(lambda x: log(x)**2 / (x**2+x+1), [0, 1]), 8*pi**3 / (81*sqrt(3)))
83
+ assert ae(quadts(lambda x: log(cos(x))**2, [0, pi/2]), pi/2 * (log(2)**2+pi**2/12))
84
+ assert ae(quadts(lambda x: x**2 / sin(x)**2, [0, pi/2]), pi*log(2))
85
+ assert ae(quadts(lambda x: x**2/sqrt(exp(x)-1), [0, inf]), 4*pi*(log(2)**2 + pi**2/12))
86
+ assert ae(quadts(lambda x: x*exp(-x)*sqrt(1-exp(-2*x)), [0, inf]), pi*(1+2*log(2))/8)
87
+ mp.dps = 15
88
+
89
+ # Do not reach full accuracy
90
+ @pytest.mark.xfail
91
+ def test_expmath_fail():
92
+ assert ae(quadts(lambda x: sqrt(tan(x)), [0, pi/2]), pi*sqrt(2)/2)
93
+ assert ae(quadts(lambda x: atan(x)/(x*sqrt(1-x**2)), [0, 1]), pi*log(1+sqrt(2))/2)
94
+ assert ae(quadts(lambda x: log(1+x**2)/x**2, [0, 1]), pi/2-log(2))
95
+ assert ae(quadts(lambda x: x**2/((1+x**4)*sqrt(1-x**4)), [0, 1]), pi/8)
tuning-competition-baseline/.venv/lib/python3.11/site-packages/mpmath/tests/test_rootfinding.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ from mpmath import *
3
+ from mpmath.calculus.optimization import Secant, Muller, Bisection, Illinois, \
4
+ Pegasus, Anderson, Ridder, ANewton, Newton, MNewton, MDNewton
5
+
6
+ def test_findroot():
7
+ # old tests, assuming secant
8
+ mp.dps = 15
9
+ assert findroot(lambda x: 4*x-3, mpf(5)).ae(0.75)
10
+ assert findroot(sin, mpf(3)).ae(pi)
11
+ assert findroot(sin, (mpf(3), mpf(3.14))).ae(pi)
12
+ assert findroot(lambda x: x*x+1, mpc(2+2j)).ae(1j)
13
+ # test all solvers with 1 starting point
14
+ f = lambda x: cos(x)
15
+ for solver in [Newton, Secant, MNewton, Muller, ANewton]:
16
+ x = findroot(f, 2., solver=solver)
17
+ assert abs(f(x)) < eps
18
+ # test all solvers with interval of 2 points
19
+ for solver in [Secant, Muller, Bisection, Illinois, Pegasus, Anderson,
20
+ Ridder]:
21
+ x = findroot(f, (1., 2.), solver=solver)
22
+ assert abs(f(x)) < eps
23
+ # test types
24
+ f = lambda x: (x - 2)**2
25
+
26
+ assert isinstance(findroot(f, 1, tol=1e-10), mpf)
27
+ assert isinstance(iv.findroot(f, 1., tol=1e-10), iv.mpf)
28
+ assert isinstance(fp.findroot(f, 1, tol=1e-10), float)
29
+ assert isinstance(fp.findroot(f, 1+0j, tol=1e-10), complex)
30
+
31
+ # issue 401
32
+ with pytest.raises(ValueError):
33
+ with workprec(2):
34
+ findroot(lambda x: x**2 - 4456178*x + 60372201703370,
35
+ mpc(real='5.278e+13', imag='-5.278e+13'))
36
+
37
+ # issue 192
38
+ with pytest.raises(ValueError):
39
+ findroot(lambda x: -1, 0)
40
+
41
+ # issue 387
42
+ with pytest.raises(ValueError):
43
+ findroot(lambda p: (1 - p)**30 - 1, 0.9)
44
+
45
+ def test_bisection():
46
+ # issue 273
47
+ assert findroot(lambda x: x**2-1,(0,2),solver='bisect') == 1
48
+
49
+ def test_mnewton():
50
+ f = lambda x: polyval([1,3,3,1],x)
51
+ x = findroot(f, -0.9, solver='mnewton')
52
+ assert abs(f(x)) < eps
53
+
54
+ def test_anewton():
55
+ f = lambda x: (x - 2)**100
56
+ x = findroot(f, 1., solver=ANewton)
57
+ assert abs(f(x)) < eps
58
+
59
+ def test_muller():
60
+ f = lambda x: (2 + x)**3 + 2
61
+ x = findroot(f, 1., solver=Muller)
62
+ assert abs(f(x)) < eps
63
+
64
+ def test_multiplicity():
65
+ for i in range(1, 5):
66
+ assert multiplicity(lambda x: (x - 1)**i, 1) == i
67
+ assert multiplicity(lambda x: x**2, 1) == 0
68
+
69
+ def test_multidimensional():
70
+ def f(*x):
71
+ return [3*x[0]**2-2*x[1]**2-1, x[0]**2-2*x[0]+x[1]**2+2*x[1]-8]
72
+ assert mnorm(jacobian(f, (1,-2)) - matrix([[6,8],[0,-2]]),1) < 1.e-7
73
+ for x, error in MDNewton(mp, f, (1,-2), verbose=0,
74
+ norm=lambda x: norm(x, inf)):
75
+ pass
76
+ assert norm(f(*x), 2) < 1e-14
77
+ # The Chinese mathematician Zhu Shijie was the very first to solve this
78
+ # nonlinear system 700 years ago
79
+ f1 = lambda x, y: -x + 2*y
80
+ f2 = lambda x, y: (x**2 + x*(y**2 - 2) - 4*y) / (x + 4)
81
+ f3 = lambda x, y: sqrt(x**2 + y**2)
82
+ def f(x, y):
83
+ f1x = f1(x, y)
84
+ return (f2(x, y) - f1x, f3(x, y) - f1x)
85
+ x = findroot(f, (10, 10))
86
+ assert [int(round(i)) for i in x] == [3, 4]
87
+
88
+ def test_trivial():
89
+ assert findroot(lambda x: 0, 1) == 1
90
+ assert findroot(lambda x: x, 0) == 0
91
+ #assert findroot(lambda x, y: x + y, (1, -1)) == (1, -1)
tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cuda_nvrtc/lib/__init__.py ADDED
File without changes
tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cudnn/__init__.py ADDED
File without changes
tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusolver/include/cusolverDn.h ADDED
The diff for this file is too large to render. See raw diff
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusolver/include/cusolver_common.h ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2014 NVIDIA Corporation. All rights reserved.
3
+ *
4
+ * NOTICE TO LICENSEE:
5
+ *
6
+ * This source code and/or documentation ("Licensed Deliverables") are
7
+ * subject to NVIDIA intellectual property rights under U.S. and
8
+ * international Copyright laws.
9
+ *
10
+ * These Licensed Deliverables contained herein is PROPRIETARY and
11
+ * CONFIDENTIAL to NVIDIA and is being provided under the terms and
12
+ * conditions of a form of NVIDIA software license agreement by and
13
+ * between NVIDIA and Licensee ("License Agreement") or electronically
14
+ * accepted by Licensee. Notwithstanding any terms or conditions to
15
+ * the contrary in the License Agreement, reproduction or disclosure
16
+ * of the Licensed Deliverables to any third party without the express
17
+ * written consent of NVIDIA is prohibited.
18
+ *
19
+ * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
20
+ * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE
21
+ * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS
22
+ * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.
23
+ * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED
24
+ * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY,
25
+ * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
26
+ * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
27
+ * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY
28
+ * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
29
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
30
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
31
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
32
+ * OF THESE LICENSED DELIVERABLES.
33
+ *
34
+ * U.S. Government End Users. These Licensed Deliverables are a
35
+ * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT
36
+ * 1995), consisting of "commercial computer software" and "commercial
37
+ * computer software documentation" as such terms are used in 48
38
+ * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government
39
+ * only as a commercial end item. Consistent with 48 C.F.R.12.212 and
40
+ * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all
41
+ * U.S. Government End Users acquire the Licensed Deliverables with
42
+ * only those rights set forth herein.
43
+ *
44
+ * Any use of the Licensed Deliverables in individual and commercial
45
+ * software must include, in the user documentation and internal
46
+ * comments to the code, the above Disclaimer and U.S. Government End
47
+ * Users Notice.
48
+ */
49
+
50
+ #if !defined(CUSOLVER_COMMON_H_)
51
+ #define CUSOLVER_COMMON_H_
52
+
53
+ #include "library_types.h"
54
+
55
+ #ifndef CUSOLVERAPI
56
+ #ifdef _WIN32
57
+ #define CUSOLVERAPI __stdcall
58
+ #else
59
+ #define CUSOLVERAPI
60
+ #endif
61
+ #endif
62
+
63
+ #if defined(_MSC_VER)
64
+ typedef __int64 int64_t;
65
+ #else
66
+ #include <inttypes.h>
67
+ #endif
68
+
69
+ typedef int cusolver_int_t;
70
+
71
+ #define CUSOLVER_VER_MAJOR 11
72
+ #define CUSOLVER_VER_MINOR 4
73
+ #define CUSOLVER_VER_PATCH 1
74
+ #define CUSOLVER_VER_BUILD 48
75
+ #define CUSOLVER_VERSION \
76
+ (CUSOLVER_VER_MAJOR * 1000 + CUSOLVER_VER_MINOR * 100 + CUSOLVER_VER_PATCH)
77
+
78
+ /*
79
+ * disable this macro to proceed old API
80
+ */
81
+ #define DISABLE_CUSOLVER_DEPRECATED
82
+
83
+ //------------------------------------------------------------------------------
84
+
85
+ #if !defined(_MSC_VER)
86
+ #define CUSOLVER_CPP_VERSION __cplusplus
87
+ #elif _MSC_FULL_VER >= 190024210 // Visual Studio 2015 Update 3
88
+ #define CUSOLVER_CPP_VERSION _MSVC_LANG
89
+ #else
90
+ #define CUSOLVER_CPP_VERSION 0
91
+ #endif
92
+
93
+ //------------------------------------------------------------------------------
94
+
95
+ #if !defined(DISABLE_CUSOLVER_DEPRECATED)
96
+
97
+ #if CUSOLVER_CPP_VERSION >= 201402L
98
+
99
+ #define CUSOLVER_DEPRECATED(new_func) \
100
+ [[deprecated("please use " #new_func " instead")]]
101
+
102
+ #elif defined(_MSC_VER)
103
+
104
+ #define CUSOLVER_DEPRECATED(new_func) \
105
+ __declspec(deprecated("please use " #new_func " instead"))
106
+
107
+ #elif defined(__INTEL_COMPILER) || defined(__clang__) || \
108
+ (defined(__GNUC__) && \
109
+ (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)))
110
+
111
+ #define CUSOLVER_DEPRECATED(new_func) \
112
+ __attribute__((deprecated("please use " #new_func " instead")))
113
+
114
+ #elif defined(__GNUC__) || defined(__xlc__)
115
+
116
+ #define CUSOLVER_DEPRECATED(new_func) __attribute__((deprecated))
117
+
118
+ #else
119
+
120
+ #define CUSOLVER_DEPRECATED(new_func)
121
+
122
+ #endif // defined(__cplusplus) && __cplusplus >= 201402L
123
+ //------------------------------------------------------------------------------
124
+
125
+ #if CUSOLVER_CPP_VERSION >= 201703L
126
+
127
+ #define CUSOLVER_DEPRECATED_ENUM(new_enum) \
128
+ [[deprecated("please use " #new_enum " instead")]]
129
+
130
+ #elif defined(__clang__) || \
131
+ (defined(__GNUC__) && __GNUC__ >= 6 && !defined(__PGI))
132
+
133
+ #define CUSOLVER_DEPRECATED_ENUM(new_enum) \
134
+ __attribute__((deprecated("please use " #new_enum " instead")))
135
+
136
+ #else
137
+
138
+ #define CUSOLVER_DEPRECATED_ENUM(new_enum)
139
+
140
+ #endif // defined(__cplusplus) && __cplusplus >= 201402L
141
+
142
+ #else // defined(DISABLE_CUSOLVER_DEPRECATED)
143
+
144
+ #define CUSOLVER_DEPRECATED(new_func)
145
+ #define CUSOLVER_DEPRECATED_ENUM(new_enum)
146
+
147
+ #endif // !defined(DISABLE_CUSOLVER_DEPRECATED)
148
+
149
+ #undef CUSOLVER_CPP_VERSION
150
+
151
+ #if defined(__cplusplus)
152
+ extern "C" {
153
+ #endif /* __cplusplus */
154
+
155
+ typedef enum {
156
+ CUSOLVER_STATUS_SUCCESS = 0,
157
+ CUSOLVER_STATUS_NOT_INITIALIZED = 1,
158
+ CUSOLVER_STATUS_ALLOC_FAILED = 2,
159
+ CUSOLVER_STATUS_INVALID_VALUE = 3,
160
+ CUSOLVER_STATUS_ARCH_MISMATCH = 4,
161
+ CUSOLVER_STATUS_MAPPING_ERROR = 5,
162
+ CUSOLVER_STATUS_EXECUTION_FAILED = 6,
163
+ CUSOLVER_STATUS_INTERNAL_ERROR = 7,
164
+ CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED = 8,
165
+ CUSOLVER_STATUS_NOT_SUPPORTED = 9,
166
+ CUSOLVER_STATUS_ZERO_PIVOT = 10,
167
+ CUSOLVER_STATUS_INVALID_LICENSE = 11,
168
+ CUSOLVER_STATUS_IRS_PARAMS_NOT_INITIALIZED = 12,
169
+ CUSOLVER_STATUS_IRS_PARAMS_INVALID = 13,
170
+ CUSOLVER_STATUS_IRS_PARAMS_INVALID_PREC = 14,
171
+ CUSOLVER_STATUS_IRS_PARAMS_INVALID_REFINE = 15,
172
+ CUSOLVER_STATUS_IRS_PARAMS_INVALID_MAXITER = 16,
173
+ CUSOLVER_STATUS_IRS_INTERNAL_ERROR = 20,
174
+ CUSOLVER_STATUS_IRS_NOT_SUPPORTED = 21,
175
+ CUSOLVER_STATUS_IRS_OUT_OF_RANGE = 22,
176
+ CUSOLVER_STATUS_IRS_NRHS_NOT_SUPPORTED_FOR_REFINE_GMRES = 23,
177
+ CUSOLVER_STATUS_IRS_INFOS_NOT_INITIALIZED = 25,
178
+ CUSOLVER_STATUS_IRS_INFOS_NOT_DESTROYED = 26,
179
+ CUSOLVER_STATUS_IRS_MATRIX_SINGULAR = 30,
180
+ CUSOLVER_STATUS_INVALID_WORKSPACE = 31
181
+ } cusolverStatus_t;
182
+
183
+ typedef enum {
184
+ CUSOLVER_EIG_TYPE_1 = 1,
185
+ CUSOLVER_EIG_TYPE_2 = 2,
186
+ CUSOLVER_EIG_TYPE_3 = 3
187
+ } cusolverEigType_t;
188
+
189
+ typedef enum {
190
+ CUSOLVER_EIG_MODE_NOVECTOR = 0,
191
+ CUSOLVER_EIG_MODE_VECTOR = 1
192
+ } cusolverEigMode_t;
193
+
194
+ typedef enum {
195
+ CUSOLVER_EIG_RANGE_ALL = 1001,
196
+ CUSOLVER_EIG_RANGE_I = 1002,
197
+ CUSOLVER_EIG_RANGE_V = 1003,
198
+ } cusolverEigRange_t;
199
+
200
+ typedef enum {
201
+ CUSOLVER_INF_NORM = 104,
202
+ CUSOLVER_MAX_NORM = 105,
203
+ CUSOLVER_ONE_NORM = 106,
204
+ CUSOLVER_FRO_NORM = 107,
205
+ } cusolverNorm_t;
206
+
207
+ typedef enum {
208
+ CUSOLVER_IRS_REFINE_NOT_SET = 1100,
209
+ CUSOLVER_IRS_REFINE_NONE = 1101,
210
+ CUSOLVER_IRS_REFINE_CLASSICAL = 1102,
211
+ CUSOLVER_IRS_REFINE_CLASSICAL_GMRES = 1103,
212
+ CUSOLVER_IRS_REFINE_GMRES = 1104,
213
+ CUSOLVER_IRS_REFINE_GMRES_GMRES = 1105,
214
+ CUSOLVER_IRS_REFINE_GMRES_NOPCOND = 1106,
215
+
216
+ CUSOLVER_PREC_DD = 1150,
217
+ CUSOLVER_PREC_SS = 1151,
218
+ CUSOLVER_PREC_SHT = 1152,
219
+
220
+ } cusolverIRSRefinement_t;
221
+
222
+ typedef enum {
223
+ CUSOLVER_R_8I = 1201,
224
+ CUSOLVER_R_8U = 1202,
225
+ CUSOLVER_R_64F = 1203,
226
+ CUSOLVER_R_32F = 1204,
227
+ CUSOLVER_R_16F = 1205,
228
+ CUSOLVER_R_16BF = 1206,
229
+ CUSOLVER_R_TF32 = 1207,
230
+ CUSOLVER_R_AP = 1208,
231
+ CUSOLVER_C_8I = 1211,
232
+ CUSOLVER_C_8U = 1212,
233
+ CUSOLVER_C_64F = 1213,
234
+ CUSOLVER_C_32F = 1214,
235
+ CUSOLVER_C_16F = 1215,
236
+ CUSOLVER_C_16BF = 1216,
237
+ CUSOLVER_C_TF32 = 1217,
238
+ CUSOLVER_C_AP = 1218,
239
+ } cusolverPrecType_t;
240
+
241
+ typedef enum {
242
+ CUSOLVER_ALG_0 = 0, /* default algorithm */
243
+ CUSOLVER_ALG_1 = 1,
244
+ CUSOLVER_ALG_2 = 2
245
+ } cusolverAlgMode_t;
246
+
247
+ typedef enum {
248
+ CUBLAS_STOREV_COLUMNWISE = 0,
249
+ CUBLAS_STOREV_ROWWISE = 1
250
+ } cusolverStorevMode_t;
251
+
252
+ typedef enum {
253
+ CUBLAS_DIRECT_FORWARD = 0,
254
+ CUBLAS_DIRECT_BACKWARD = 1
255
+ } cusolverDirectMode_t;
256
+
257
+ cusolverStatus_t CUSOLVERAPI
258
+ cusolverGetProperty(libraryPropertyType type, int *value);
259
+
260
+ cusolverStatus_t CUSOLVERAPI cusolverGetVersion(int *version);
261
+
262
+ #if defined(__cplusplus)
263
+ }
264
+ #endif /* __cplusplus */
265
+
266
+ #endif // CUSOLVER_COMMON_H_
tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusolver/lib/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (220 Bytes). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusparse/__init__.py ADDED
File without changes
tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusparse/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (216 Bytes). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusparse/include/__init__.py ADDED
File without changes
tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusparse/include/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (224 Bytes). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusparse/include/cusparse_v2.h ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 1993-2019 NVIDIA Corporation. All rights reserved.
3
+ *
4
+ * NOTICE TO LICENSEE:
5
+ *
6
+ * This source code and/or documentation ("Licensed Deliverables") are
7
+ * subject to NVIDIA intellectual property rights under U.S. and
8
+ * international Copyright laws.
9
+ *
10
+ * These Licensed Deliverables contained herein is PROPRIETARY and
11
+ * CONFIDENTIAL to NVIDIA and is being provided under the terms and
12
+ * conditions of a form of NVIDIA software license agreement by and
13
+ * between NVIDIA and Licensee ("License Agreement") or electronically
14
+ * accepted by Licensee. Notwithstanding any terms or conditions to
15
+ * the contrary in the License Agreement, reproduction or disclosure
16
+ * of the Licensed Deliverables to any third party without the express
17
+ * written consent of NVIDIA is prohibited.
18
+ *
19
+ * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
20
+ * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE
21
+ * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS
22
+ * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.
23
+ * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED
24
+ * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY,
25
+ * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
26
+ * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
27
+ * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY
28
+ * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
29
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
30
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
31
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
32
+ * OF THESE LICENSED DELIVERABLES.
33
+ *
34
+ * U.S. Government End Users. These Licensed Deliverables are a
35
+ * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT
36
+ * 1995), consisting of "commercial computer software" and "commercial
37
+ * computer software documentation" as such terms are used in 48
38
+ * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government
39
+ * only as a commercial end item. Consistent with 48 C.F.R.12.212 and
40
+ * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all
41
+ * U.S. Government End Users acquire the Licensed Deliverables with
42
+ * only those rights set forth herein.
43
+ *
44
+ * Any use of the Licensed Deliverables in individual and commercial
45
+ * software must include, in the user documentation and internal
46
+ * comments to the code, the above Disclaimer and U.S. Government End
47
+ * Users Notice.
48
+ */
49
+ #if !defined(CUSPARSE_V2_H_)
50
+ #define CUSPARSE_V2_H_
51
+
52
+ #include "cusparse.h"
53
+
54
+ #endif
tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cusparse/lib/__init__.py ADDED
File without changes
tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/nccl/lib/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (216 Bytes). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/__init__.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import contextlib
2
+ import functools
3
+ import os
4
+ import sys
5
+ from typing import TYPE_CHECKING, List, Optional, Type, cast
6
+
7
+ from pip._internal.utils.misc import strtobool
8
+
9
+ from .base import BaseDistribution, BaseEnvironment, FilesystemWheel, MemoryWheel, Wheel
10
+
11
+ if TYPE_CHECKING:
12
+ from typing import Literal, Protocol
13
+ else:
14
+ Protocol = object
15
+
16
+ __all__ = [
17
+ "BaseDistribution",
18
+ "BaseEnvironment",
19
+ "FilesystemWheel",
20
+ "MemoryWheel",
21
+ "Wheel",
22
+ "get_default_environment",
23
+ "get_environment",
24
+ "get_wheel_distribution",
25
+ "select_backend",
26
+ ]
27
+
28
+
29
+ def _should_use_importlib_metadata() -> bool:
30
+ """Whether to use the ``importlib.metadata`` or ``pkg_resources`` backend.
31
+
32
+ By default, pip uses ``importlib.metadata`` on Python 3.11+, and
33
+ ``pkg_resourcess`` otherwise. This can be overridden by a couple of ways:
34
+
35
+ * If environment variable ``_PIP_USE_IMPORTLIB_METADATA`` is set, it
36
+ dictates whether ``importlib.metadata`` is used, regardless of Python
37
+ version.
38
+ * On Python 3.11+, Python distributors can patch ``importlib.metadata``
39
+ to add a global constant ``_PIP_USE_IMPORTLIB_METADATA = False``. This
40
+ makes pip use ``pkg_resources`` (unless the user set the aforementioned
41
+ environment variable to *True*).
42
+ """
43
+ with contextlib.suppress(KeyError, ValueError):
44
+ return bool(strtobool(os.environ["_PIP_USE_IMPORTLIB_METADATA"]))
45
+ if sys.version_info < (3, 11):
46
+ return False
47
+ import importlib.metadata
48
+
49
+ return bool(getattr(importlib.metadata, "_PIP_USE_IMPORTLIB_METADATA", True))
50
+
51
+
52
+ class Backend(Protocol):
53
+ NAME: 'Literal["importlib", "pkg_resources"]'
54
+ Distribution: Type[BaseDistribution]
55
+ Environment: Type[BaseEnvironment]
56
+
57
+
58
+ @functools.lru_cache(maxsize=None)
59
+ def select_backend() -> Backend:
60
+ if _should_use_importlib_metadata():
61
+ from . import importlib
62
+
63
+ return cast(Backend, importlib)
64
+ from . import pkg_resources
65
+
66
+ return cast(Backend, pkg_resources)
67
+
68
+
69
+ def get_default_environment() -> BaseEnvironment:
70
+ """Get the default representation for the current environment.
71
+
72
+ This returns an Environment instance from the chosen backend. The default
73
+ Environment instance should be built from ``sys.path`` and may use caching
74
+ to share instance state accorss calls.
75
+ """
76
+ return select_backend().Environment.default()
77
+
78
+
79
+ def get_environment(paths: Optional[List[str]]) -> BaseEnvironment:
80
+ """Get a representation of the environment specified by ``paths``.
81
+
82
+ This returns an Environment instance from the chosen backend based on the
83
+ given import paths. The backend must build a fresh instance representing
84
+ the state of installed distributions when this function is called.
85
+ """
86
+ return select_backend().Environment.from_paths(paths)
87
+
88
+
89
+ def get_directory_distribution(directory: str) -> BaseDistribution:
90
+ """Get the distribution metadata representation in the specified directory.
91
+
92
+ This returns a Distribution instance from the chosen backend based on
93
+ the given on-disk ``.dist-info`` directory.
94
+ """
95
+ return select_backend().Distribution.from_directory(directory)
96
+
97
+
98
+ def get_wheel_distribution(wheel: Wheel, canonical_name: str) -> BaseDistribution:
99
+ """Get the representation of the specified wheel's distribution metadata.
100
+
101
+ This returns a Distribution instance from the chosen backend based on
102
+ the given wheel's ``.dist-info`` directory.
103
+
104
+ :param canonical_name: Normalized project name of the given wheel.
105
+ """
106
+ return select_backend().Distribution.from_wheel(wheel, canonical_name)
107
+
108
+
109
+ def get_metadata_distribution(
110
+ metadata_contents: bytes,
111
+ filename: str,
112
+ canonical_name: str,
113
+ ) -> BaseDistribution:
114
+ """Get the dist representation of the specified METADATA file contents.
115
+
116
+ This returns a Distribution instance from the chosen backend sourced from the data
117
+ in `metadata_contents`.
118
+
119
+ :param metadata_contents: Contents of a METADATA file within a dist, or one served
120
+ via PEP 658.
121
+ :param filename: Filename for the dist this metadata represents.
122
+ :param canonical_name: Normalized project name of the given dist.
123
+ """
124
+ return select_backend().Distribution.from_metadata_file_contents(
125
+ metadata_contents,
126
+ filename,
127
+ canonical_name,
128
+ )
tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (6.53 kB). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/_json.cpython-311.pyc ADDED
Binary file (3.66 kB). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/__pycache__/base.cpython-311.pyc ADDED
Binary file (38.2 kB). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/_json.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Extracted from https://github.com/pfmoore/pkg_metadata
2
+
3
+ from email.header import Header, decode_header, make_header
4
+ from email.message import Message
5
+ from typing import Any, Dict, List, Union, cast
6
+
7
+ METADATA_FIELDS = [
8
+ # Name, Multiple-Use
9
+ ("Metadata-Version", False),
10
+ ("Name", False),
11
+ ("Version", False),
12
+ ("Dynamic", True),
13
+ ("Platform", True),
14
+ ("Supported-Platform", True),
15
+ ("Summary", False),
16
+ ("Description", False),
17
+ ("Description-Content-Type", False),
18
+ ("Keywords", False),
19
+ ("Home-page", False),
20
+ ("Download-URL", False),
21
+ ("Author", False),
22
+ ("Author-email", False),
23
+ ("Maintainer", False),
24
+ ("Maintainer-email", False),
25
+ ("License", False),
26
+ ("Classifier", True),
27
+ ("Requires-Dist", True),
28
+ ("Requires-Python", False),
29
+ ("Requires-External", True),
30
+ ("Project-URL", True),
31
+ ("Provides-Extra", True),
32
+ ("Provides-Dist", True),
33
+ ("Obsoletes-Dist", True),
34
+ ]
35
+
36
+
37
+ def json_name(field: str) -> str:
38
+ return field.lower().replace("-", "_")
39
+
40
+
41
+ def msg_to_json(msg: Message) -> Dict[str, Any]:
42
+ """Convert a Message object into a JSON-compatible dictionary."""
43
+
44
+ def sanitise_header(h: Union[Header, str]) -> str:
45
+ if isinstance(h, Header):
46
+ chunks = []
47
+ for bytes, encoding in decode_header(h):
48
+ if encoding == "unknown-8bit":
49
+ try:
50
+ # See if UTF-8 works
51
+ bytes.decode("utf-8")
52
+ encoding = "utf-8"
53
+ except UnicodeDecodeError:
54
+ # If not, latin1 at least won't fail
55
+ encoding = "latin1"
56
+ chunks.append((bytes, encoding))
57
+ return str(make_header(chunks))
58
+ return str(h)
59
+
60
+ result = {}
61
+ for field, multi in METADATA_FIELDS:
62
+ if field not in msg:
63
+ continue
64
+ key = json_name(field)
65
+ if multi:
66
+ value: Union[str, List[str]] = [
67
+ sanitise_header(v) for v in msg.get_all(field) # type: ignore
68
+ ]
69
+ else:
70
+ value = sanitise_header(msg.get(field)) # type: ignore
71
+ if key == "keywords":
72
+ # Accept both comma-separated and space-separated
73
+ # forms, for better compatibility with old data.
74
+ if "," in value:
75
+ value = [v.strip() for v in value.split(",")]
76
+ else:
77
+ value = value.split()
78
+ result[key] = value
79
+
80
+ payload = cast(str, msg.get_payload())
81
+ if payload:
82
+ result["description"] = payload
83
+
84
+ return result
tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/importlib/_dists.py ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import email.message
2
+ import importlib.metadata
3
+ import pathlib
4
+ import zipfile
5
+ from typing import (
6
+ Collection,
7
+ Dict,
8
+ Iterable,
9
+ Iterator,
10
+ Mapping,
11
+ Optional,
12
+ Sequence,
13
+ cast,
14
+ )
15
+
16
+ from pip._vendor.packaging.requirements import Requirement
17
+ from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
18
+ from pip._vendor.packaging.version import Version
19
+ from pip._vendor.packaging.version import parse as parse_version
20
+
21
+ from pip._internal.exceptions import InvalidWheel, UnsupportedWheel
22
+ from pip._internal.metadata.base import (
23
+ BaseDistribution,
24
+ BaseEntryPoint,
25
+ InfoPath,
26
+ Wheel,
27
+ )
28
+ from pip._internal.utils.misc import normalize_path
29
+ from pip._internal.utils.packaging import get_requirement
30
+ from pip._internal.utils.temp_dir import TempDirectory
31
+ from pip._internal.utils.wheel import parse_wheel, read_wheel_metadata_file
32
+
33
+ from ._compat import (
34
+ BasePath,
35
+ get_dist_canonical_name,
36
+ parse_name_and_version_from_info_directory,
37
+ )
38
+
39
+
40
+ class WheelDistribution(importlib.metadata.Distribution):
41
+ """An ``importlib.metadata.Distribution`` read from a wheel.
42
+
43
+ Although ``importlib.metadata.PathDistribution`` accepts ``zipfile.Path``,
44
+ its implementation is too "lazy" for pip's needs (we can't keep the ZipFile
45
+ handle open for the entire lifetime of the distribution object).
46
+
47
+ This implementation eagerly reads the entire metadata directory into the
48
+ memory instead, and operates from that.
49
+ """
50
+
51
+ def __init__(
52
+ self,
53
+ files: Mapping[pathlib.PurePosixPath, bytes],
54
+ info_location: pathlib.PurePosixPath,
55
+ ) -> None:
56
+ self._files = files
57
+ self.info_location = info_location
58
+
59
+ @classmethod
60
+ def from_zipfile(
61
+ cls,
62
+ zf: zipfile.ZipFile,
63
+ name: str,
64
+ location: str,
65
+ ) -> "WheelDistribution":
66
+ info_dir, _ = parse_wheel(zf, name)
67
+ paths = (
68
+ (name, pathlib.PurePosixPath(name.split("/", 1)[-1]))
69
+ for name in zf.namelist()
70
+ if name.startswith(f"{info_dir}/")
71
+ )
72
+ files = {
73
+ relpath: read_wheel_metadata_file(zf, fullpath)
74
+ for fullpath, relpath in paths
75
+ }
76
+ info_location = pathlib.PurePosixPath(location, info_dir)
77
+ return cls(files, info_location)
78
+
79
+ def iterdir(self, path: InfoPath) -> Iterator[pathlib.PurePosixPath]:
80
+ # Only allow iterating through the metadata directory.
81
+ if pathlib.PurePosixPath(str(path)) in self._files:
82
+ return iter(self._files)
83
+ raise FileNotFoundError(path)
84
+
85
+ def read_text(self, filename: str) -> Optional[str]:
86
+ try:
87
+ data = self._files[pathlib.PurePosixPath(filename)]
88
+ except KeyError:
89
+ return None
90
+ try:
91
+ text = data.decode("utf-8")
92
+ except UnicodeDecodeError as e:
93
+ wheel = self.info_location.parent
94
+ error = f"Error decoding metadata for {wheel}: {e} in {filename} file"
95
+ raise UnsupportedWheel(error)
96
+ return text
97
+
98
+
99
+ class Distribution(BaseDistribution):
100
+ def __init__(
101
+ self,
102
+ dist: importlib.metadata.Distribution,
103
+ info_location: Optional[BasePath],
104
+ installed_location: Optional[BasePath],
105
+ ) -> None:
106
+ self._dist = dist
107
+ self._info_location = info_location
108
+ self._installed_location = installed_location
109
+
110
+ @classmethod
111
+ def from_directory(cls, directory: str) -> BaseDistribution:
112
+ info_location = pathlib.Path(directory)
113
+ dist = importlib.metadata.Distribution.at(info_location)
114
+ return cls(dist, info_location, info_location.parent)
115
+
116
+ @classmethod
117
+ def from_metadata_file_contents(
118
+ cls,
119
+ metadata_contents: bytes,
120
+ filename: str,
121
+ project_name: str,
122
+ ) -> BaseDistribution:
123
+ # Generate temp dir to contain the metadata file, and write the file contents.
124
+ temp_dir = pathlib.Path(
125
+ TempDirectory(kind="metadata", globally_managed=True).path
126
+ )
127
+ metadata_path = temp_dir / "METADATA"
128
+ metadata_path.write_bytes(metadata_contents)
129
+ # Construct dist pointing to the newly created directory.
130
+ dist = importlib.metadata.Distribution.at(metadata_path.parent)
131
+ return cls(dist, metadata_path.parent, None)
132
+
133
+ @classmethod
134
+ def from_wheel(cls, wheel: Wheel, name: str) -> BaseDistribution:
135
+ try:
136
+ with wheel.as_zipfile() as zf:
137
+ dist = WheelDistribution.from_zipfile(zf, name, wheel.location)
138
+ except zipfile.BadZipFile as e:
139
+ raise InvalidWheel(wheel.location, name) from e
140
+ return cls(dist, dist.info_location, pathlib.PurePosixPath(wheel.location))
141
+
142
+ @property
143
+ def location(self) -> Optional[str]:
144
+ if self._info_location is None:
145
+ return None
146
+ return str(self._info_location.parent)
147
+
148
+ @property
149
+ def info_location(self) -> Optional[str]:
150
+ if self._info_location is None:
151
+ return None
152
+ return str(self._info_location)
153
+
154
+ @property
155
+ def installed_location(self) -> Optional[str]:
156
+ if self._installed_location is None:
157
+ return None
158
+ return normalize_path(str(self._installed_location))
159
+
160
+ @property
161
+ def canonical_name(self) -> NormalizedName:
162
+ return get_dist_canonical_name(self._dist)
163
+
164
+ @property
165
+ def version(self) -> Version:
166
+ if version := parse_name_and_version_from_info_directory(self._dist)[1]:
167
+ return parse_version(version)
168
+ return parse_version(self._dist.version)
169
+
170
+ @property
171
+ def raw_version(self) -> str:
172
+ return self._dist.version
173
+
174
+ def is_file(self, path: InfoPath) -> bool:
175
+ return self._dist.read_text(str(path)) is not None
176
+
177
+ def iter_distutils_script_names(self) -> Iterator[str]:
178
+ # A distutils installation is always "flat" (not in e.g. egg form), so
179
+ # if this distribution's info location is NOT a pathlib.Path (but e.g.
180
+ # zipfile.Path), it can never contain any distutils scripts.
181
+ if not isinstance(self._info_location, pathlib.Path):
182
+ return
183
+ for child in self._info_location.joinpath("scripts").iterdir():
184
+ yield child.name
185
+
186
+ def read_text(self, path: InfoPath) -> str:
187
+ content = self._dist.read_text(str(path))
188
+ if content is None:
189
+ raise FileNotFoundError(path)
190
+ return content
191
+
192
+ def iter_entry_points(self) -> Iterable[BaseEntryPoint]:
193
+ # importlib.metadata's EntryPoint structure sasitfies BaseEntryPoint.
194
+ return self._dist.entry_points
195
+
196
+ def _metadata_impl(self) -> email.message.Message:
197
+ # From Python 3.10+, importlib.metadata declares PackageMetadata as the
198
+ # return type. This protocol is unfortunately a disaster now and misses
199
+ # a ton of fields that we need, including get() and get_payload(). We
200
+ # rely on the implementation that the object is actually a Message now,
201
+ # until upstream can improve the protocol. (python/cpython#94952)
202
+ return cast(email.message.Message, self._dist.metadata)
203
+
204
+ def iter_provided_extras(self) -> Iterable[NormalizedName]:
205
+ return [
206
+ canonicalize_name(extra)
207
+ for extra in self.metadata.get_all("Provides-Extra", [])
208
+ ]
209
+
210
+ def iter_dependencies(self, extras: Collection[str] = ()) -> Iterable[Requirement]:
211
+ contexts: Sequence[Dict[str, str]] = [{"extra": e} for e in extras]
212
+ for req_string in self.metadata.get_all("Requires-Dist", []):
213
+ # strip() because email.message.Message.get_all() may return a leading \n
214
+ # in case a long header was wrapped.
215
+ req = get_requirement(req_string.strip())
216
+ if not req.marker:
217
+ yield req
218
+ elif not extras and req.marker.evaluate({"extra": ""}):
219
+ yield req
220
+ elif any(req.marker.evaluate(context) for context in contexts):
221
+ yield req
tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/metadata/pkg_resources.py ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import email.message
2
+ import email.parser
3
+ import logging
4
+ import os
5
+ import zipfile
6
+ from typing import (
7
+ Collection,
8
+ Iterable,
9
+ Iterator,
10
+ List,
11
+ Mapping,
12
+ NamedTuple,
13
+ Optional,
14
+ )
15
+
16
+ from pip._vendor import pkg_resources
17
+ from pip._vendor.packaging.requirements import Requirement
18
+ from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
19
+ from pip._vendor.packaging.version import Version
20
+ from pip._vendor.packaging.version import parse as parse_version
21
+
22
+ from pip._internal.exceptions import InvalidWheel, NoneMetadataError, UnsupportedWheel
23
+ from pip._internal.utils.egg_link import egg_link_path_from_location
24
+ from pip._internal.utils.misc import display_path, normalize_path
25
+ from pip._internal.utils.wheel import parse_wheel, read_wheel_metadata_file
26
+
27
+ from .base import (
28
+ BaseDistribution,
29
+ BaseEntryPoint,
30
+ BaseEnvironment,
31
+ InfoPath,
32
+ Wheel,
33
+ )
34
+
35
+ __all__ = ["NAME", "Distribution", "Environment"]
36
+
37
+ logger = logging.getLogger(__name__)
38
+
39
+ NAME = "pkg_resources"
40
+
41
+
42
+ class EntryPoint(NamedTuple):
43
+ name: str
44
+ value: str
45
+ group: str
46
+
47
+
48
+ class InMemoryMetadata:
49
+ """IMetadataProvider that reads metadata files from a dictionary.
50
+
51
+ This also maps metadata decoding exceptions to our internal exception type.
52
+ """
53
+
54
+ def __init__(self, metadata: Mapping[str, bytes], wheel_name: str) -> None:
55
+ self._metadata = metadata
56
+ self._wheel_name = wheel_name
57
+
58
+ def has_metadata(self, name: str) -> bool:
59
+ return name in self._metadata
60
+
61
+ def get_metadata(self, name: str) -> str:
62
+ try:
63
+ return self._metadata[name].decode()
64
+ except UnicodeDecodeError as e:
65
+ # Augment the default error with the origin of the file.
66
+ raise UnsupportedWheel(
67
+ f"Error decoding metadata for {self._wheel_name}: {e} in {name} file"
68
+ )
69
+
70
+ def get_metadata_lines(self, name: str) -> Iterable[str]:
71
+ return pkg_resources.yield_lines(self.get_metadata(name))
72
+
73
+ def metadata_isdir(self, name: str) -> bool:
74
+ return False
75
+
76
+ def metadata_listdir(self, name: str) -> List[str]:
77
+ return []
78
+
79
+ def run_script(self, script_name: str, namespace: str) -> None:
80
+ pass
81
+
82
+
83
+ class Distribution(BaseDistribution):
84
+ def __init__(self, dist: pkg_resources.Distribution) -> None:
85
+ self._dist = dist
86
+ # This is populated lazily, to avoid loading metadata for all possible
87
+ # distributions eagerly.
88
+ self.__extra_mapping: Optional[Mapping[NormalizedName, str]] = None
89
+
90
+ @property
91
+ def _extra_mapping(self) -> Mapping[NormalizedName, str]:
92
+ if self.__extra_mapping is None:
93
+ self.__extra_mapping = {
94
+ canonicalize_name(extra): extra for extra in self._dist.extras
95
+ }
96
+
97
+ return self.__extra_mapping
98
+
99
+ @classmethod
100
+ def from_directory(cls, directory: str) -> BaseDistribution:
101
+ dist_dir = directory.rstrip(os.sep)
102
+
103
+ # Build a PathMetadata object, from path to metadata. :wink:
104
+ base_dir, dist_dir_name = os.path.split(dist_dir)
105
+ metadata = pkg_resources.PathMetadata(base_dir, dist_dir)
106
+
107
+ # Determine the correct Distribution object type.
108
+ if dist_dir.endswith(".egg-info"):
109
+ dist_cls = pkg_resources.Distribution
110
+ dist_name = os.path.splitext(dist_dir_name)[0]
111
+ else:
112
+ assert dist_dir.endswith(".dist-info")
113
+ dist_cls = pkg_resources.DistInfoDistribution
114
+ dist_name = os.path.splitext(dist_dir_name)[0].split("-")[0]
115
+
116
+ dist = dist_cls(base_dir, project_name=dist_name, metadata=metadata)
117
+ return cls(dist)
118
+
119
+ @classmethod
120
+ def from_metadata_file_contents(
121
+ cls,
122
+ metadata_contents: bytes,
123
+ filename: str,
124
+ project_name: str,
125
+ ) -> BaseDistribution:
126
+ metadata_dict = {
127
+ "METADATA": metadata_contents,
128
+ }
129
+ dist = pkg_resources.DistInfoDistribution(
130
+ location=filename,
131
+ metadata=InMemoryMetadata(metadata_dict, filename),
132
+ project_name=project_name,
133
+ )
134
+ return cls(dist)
135
+
136
+ @classmethod
137
+ def from_wheel(cls, wheel: Wheel, name: str) -> BaseDistribution:
138
+ try:
139
+ with wheel.as_zipfile() as zf:
140
+ info_dir, _ = parse_wheel(zf, name)
141
+ metadata_dict = {
142
+ path.split("/", 1)[-1]: read_wheel_metadata_file(zf, path)
143
+ for path in zf.namelist()
144
+ if path.startswith(f"{info_dir}/")
145
+ }
146
+ except zipfile.BadZipFile as e:
147
+ raise InvalidWheel(wheel.location, name) from e
148
+ except UnsupportedWheel as e:
149
+ raise UnsupportedWheel(f"{name} has an invalid wheel, {e}")
150
+ dist = pkg_resources.DistInfoDistribution(
151
+ location=wheel.location,
152
+ metadata=InMemoryMetadata(metadata_dict, wheel.location),
153
+ project_name=name,
154
+ )
155
+ return cls(dist)
156
+
157
+ @property
158
+ def location(self) -> Optional[str]:
159
+ return self._dist.location
160
+
161
+ @property
162
+ def installed_location(self) -> Optional[str]:
163
+ egg_link = egg_link_path_from_location(self.raw_name)
164
+ if egg_link:
165
+ location = egg_link
166
+ elif self.location:
167
+ location = self.location
168
+ else:
169
+ return None
170
+ return normalize_path(location)
171
+
172
+ @property
173
+ def info_location(self) -> Optional[str]:
174
+ return self._dist.egg_info
175
+
176
+ @property
177
+ def installed_by_distutils(self) -> bool:
178
+ # A distutils-installed distribution is provided by FileMetadata. This
179
+ # provider has a "path" attribute not present anywhere else. Not the
180
+ # best introspection logic, but pip has been doing this for a long time.
181
+ try:
182
+ return bool(self._dist._provider.path)
183
+ except AttributeError:
184
+ return False
185
+
186
+ @property
187
+ def canonical_name(self) -> NormalizedName:
188
+ return canonicalize_name(self._dist.project_name)
189
+
190
+ @property
191
+ def version(self) -> Version:
192
+ return parse_version(self._dist.version)
193
+
194
+ @property
195
+ def raw_version(self) -> str:
196
+ return self._dist.version
197
+
198
+ def is_file(self, path: InfoPath) -> bool:
199
+ return self._dist.has_metadata(str(path))
200
+
201
+ def iter_distutils_script_names(self) -> Iterator[str]:
202
+ yield from self._dist.metadata_listdir("scripts")
203
+
204
+ def read_text(self, path: InfoPath) -> str:
205
+ name = str(path)
206
+ if not self._dist.has_metadata(name):
207
+ raise FileNotFoundError(name)
208
+ content = self._dist.get_metadata(name)
209
+ if content is None:
210
+ raise NoneMetadataError(self, name)
211
+ return content
212
+
213
+ def iter_entry_points(self) -> Iterable[BaseEntryPoint]:
214
+ for group, entries in self._dist.get_entry_map().items():
215
+ for name, entry_point in entries.items():
216
+ name, _, value = str(entry_point).partition("=")
217
+ yield EntryPoint(name=name.strip(), value=value.strip(), group=group)
218
+
219
+ def _metadata_impl(self) -> email.message.Message:
220
+ """
221
+ :raises NoneMetadataError: if the distribution reports `has_metadata()`
222
+ True but `get_metadata()` returns None.
223
+ """
224
+ if isinstance(self._dist, pkg_resources.DistInfoDistribution):
225
+ metadata_name = "METADATA"
226
+ else:
227
+ metadata_name = "PKG-INFO"
228
+ try:
229
+ metadata = self.read_text(metadata_name)
230
+ except FileNotFoundError:
231
+ if self.location:
232
+ displaying_path = display_path(self.location)
233
+ else:
234
+ displaying_path = repr(self.location)
235
+ logger.warning("No metadata found in %s", displaying_path)
236
+ metadata = ""
237
+ feed_parser = email.parser.FeedParser()
238
+ feed_parser.feed(metadata)
239
+ return feed_parser.close()
240
+
241
+ def iter_dependencies(self, extras: Collection[str] = ()) -> Iterable[Requirement]:
242
+ if extras:
243
+ relevant_extras = set(self._extra_mapping) & set(
244
+ map(canonicalize_name, extras)
245
+ )
246
+ extras = [self._extra_mapping[extra] for extra in relevant_extras]
247
+ return self._dist.requires(extras)
248
+
249
+ def iter_provided_extras(self) -> Iterable[NormalizedName]:
250
+ return self._extra_mapping.keys()
251
+
252
+
253
+ class Environment(BaseEnvironment):
254
+ def __init__(self, ws: pkg_resources.WorkingSet) -> None:
255
+ self._ws = ws
256
+
257
+ @classmethod
258
+ def default(cls) -> BaseEnvironment:
259
+ return cls(pkg_resources.working_set)
260
+
261
+ @classmethod
262
+ def from_paths(cls, paths: Optional[List[str]]) -> BaseEnvironment:
263
+ return cls(pkg_resources.WorkingSet(paths))
264
+
265
+ def _iter_distributions(self) -> Iterator[BaseDistribution]:
266
+ for dist in self._ws:
267
+ yield Distribution(dist)
268
+
269
+ def _search_distribution(self, name: str) -> Optional[BaseDistribution]:
270
+ """Find a distribution matching the ``name`` in the environment.
271
+
272
+ This searches from *all* distributions available in the environment, to
273
+ match the behavior of ``pkg_resources.get_distribution()``.
274
+ """
275
+ canonical_name = canonicalize_name(name)
276
+ for dist in self.iter_all_distributions():
277
+ if dist.canonical_name == canonical_name:
278
+ return dist
279
+ return None
280
+
281
+ def get_distribution(self, name: str) -> Optional[BaseDistribution]:
282
+ # Search the distribution by looking through the working set.
283
+ dist = self._search_distribution(name)
284
+ if dist:
285
+ return dist
286
+
287
+ # If distribution could not be found, call working_set.require to
288
+ # update the working set, and try to find the distribution again.
289
+ # This might happen for e.g. when you install a package twice, once
290
+ # using setup.py develop and again using setup.py install. Now when
291
+ # running pip uninstall twice, the package gets removed from the
292
+ # working set in the first uninstall, so we have to populate the
293
+ # working set again so that pip knows about it and the packages gets
294
+ # picked up and is successfully uninstalled the second time too.
295
+ try:
296
+ # We didn't pass in any version specifiers, so this can never
297
+ # raise pkg_resources.VersionConflict.
298
+ self._ws.require(name)
299
+ except pkg_resources.DistributionNotFound:
300
+ return None
301
+ return self._search_distribution(name)
tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/network/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (287 Bytes). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/network/__pycache__/download.cpython-311.pyc ADDED
Binary file (9.51 kB). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/network/__pycache__/session.cpython-311.pyc ADDED
Binary file (21.6 kB). View file
 
tuning-competition-baseline/.venv/lib/python3.11/site-packages/pip/_internal/network/__pycache__/utils.cpython-311.pyc ADDED
Binary file (2.44 kB). View file