Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +3 -0
- openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/__init__.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/_bsplines.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/_fitpack_impl.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/_pade.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/_rbf.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/_rbfinterp.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/fitpack.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/fitpack2.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/rbf.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/io/matlab/_mio5_utils.cpython-310-x86_64-linux-gnu.so +3 -0
- openflamingo/lib/python3.10/site-packages/scipy/io/matlab/_streams.cpython-310-x86_64-linux-gnu.so +3 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/_ckdtree.pyi +214 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/_kdtree.py +920 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/_procrustes.py +132 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/_qhull.pyi +213 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/_voronoi.pyi +4 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/distance.pyi +211 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/qhull.py +25 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/__pycache__/test__plotutils.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/__pycache__/test_distance.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/__pycache__/test_qhull.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/__pycache__/test_slerp.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/__pycache__/test_spherical_voronoi.cpython-310.pyc +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/data/cdist-X2.txt +20 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/data/iris.txt +150 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/data/pdist-chebyshev-ml.txt +1 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/data/pdist-double-inp.txt +20 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/data/pdist-hamming-ml.txt +1 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/data/pdist-jensenshannon-ml-iris.txt +0 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/test__plotutils.py +91 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/test__procrustes.py +116 -0
- openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/test_spherical_voronoi.py +358 -0
- phi4/lib/python3.10/site-packages/numpy/_core/__pycache__/fromnumeric.cpython-310.pyc +3 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/_array_api.py +595 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/_bunch.py +225 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/_ccallback.py +251 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/_disjoint_set.py +254 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/_gcutils.py +105 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/_pep440.py +487 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/_test_deprecation_call.cpython-310-x86_64-linux-gnu.so +0 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/_test_deprecation_def.cpython-310-x86_64-linux-gnu.so +0 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/_testutils.py +369 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/_tmpdirs.py +86 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/_util.py +1179 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/array_api_compat/__init__.py +22 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/array_api_compat/_internal.py +46 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/array_api_compat/cupy/__init__.py +16 -0
- phi4/lib/python3.10/site-packages/scipy/_lib/array_api_compat/cupy/__pycache__/__init__.cpython-310.pyc +0 -0
.gitattributes
CHANGED
|
@@ -783,3 +783,6 @@ openflamingo/lib/python3.10/site-packages/scipy/stats/__pycache__/_multivariate.
|
|
| 783 |
openflamingo/lib/python3.10/site-packages/scipy/stats/_rcont/rcont.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 784 |
openflamingo/lib/python3.10/site-packages/scipy/stats/__pycache__/_morestats.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 785 |
phi4/lib/python3.10/site-packages/numpy/_core/lib/libnpymath.a filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 783 |
openflamingo/lib/python3.10/site-packages/scipy/stats/_rcont/rcont.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 784 |
openflamingo/lib/python3.10/site-packages/scipy/stats/__pycache__/_morestats.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 785 |
phi4/lib/python3.10/site-packages/numpy/_core/lib/libnpymath.a filter=lfs diff=lfs merge=lfs -text
|
| 786 |
+
phi4/lib/python3.10/site-packages/numpy/_core/__pycache__/fromnumeric.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 787 |
+
openflamingo/lib/python3.10/site-packages/scipy/io/matlab/_streams.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 788 |
+
openflamingo/lib/python3.10/site-packages/scipy/io/matlab/_mio5_utils.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (3.75 kB). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/_bsplines.cpython-310.pyc
ADDED
|
Binary file (63.9 kB). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/_fitpack_impl.cpython-310.pyc
ADDED
|
Binary file (22.6 kB). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/_pade.cpython-310.pyc
ADDED
|
Binary file (2.08 kB). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/_rbf.cpython-310.pyc
ADDED
|
Binary file (11.1 kB). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/_rbfinterp.cpython-310.pyc
ADDED
|
Binary file (14.6 kB). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/fitpack.cpython-310.pyc
ADDED
|
Binary file (710 Bytes). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/fitpack2.cpython-310.pyc
ADDED
|
Binary file (923 Bytes). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/interpolate/__pycache__/rbf.cpython-310.pyc
ADDED
|
Binary file (629 Bytes). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/io/matlab/_mio5_utils.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f6db2c15f3aab0d2b55bbb7cd6fdcd0dfe4e8ebab20ad5f48f2e715493c6f684
|
| 3 |
+
size 264600
|
openflamingo/lib/python3.10/site-packages/scipy/io/matlab/_streams.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:82c90081d32a4102eeda9b5d02babb6a96631bb43e462cf4c56776bfcd44617f
|
| 3 |
+
size 147488
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/_ckdtree.pyi
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
from typing import (
|
| 3 |
+
Any,
|
| 4 |
+
Generic,
|
| 5 |
+
overload,
|
| 6 |
+
TypeVar,
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
import numpy.typing as npt
|
| 11 |
+
from scipy.sparse import coo_matrix, dok_matrix
|
| 12 |
+
|
| 13 |
+
from typing import Literal
|
| 14 |
+
|
| 15 |
+
# TODO: Replace `ndarray` with a 1D float64 array when possible
|
| 16 |
+
_BoxType = TypeVar("_BoxType", None, npt.NDArray[np.float64])
|
| 17 |
+
|
| 18 |
+
# Copied from `numpy.typing._scalar_like._ScalarLike`
|
| 19 |
+
# TODO: Expand with 0D arrays once we have shape support
|
| 20 |
+
_ArrayLike0D = bool | int | float | complex | str | bytes | np.generic
|
| 21 |
+
|
| 22 |
+
_WeightType = npt.ArrayLike | tuple[npt.ArrayLike | None, npt.ArrayLike | None]
|
| 23 |
+
|
| 24 |
+
class cKDTreeNode:
|
| 25 |
+
@property
|
| 26 |
+
def data_points(self) -> npt.NDArray[np.float64]: ...
|
| 27 |
+
@property
|
| 28 |
+
def indices(self) -> npt.NDArray[np.intp]: ...
|
| 29 |
+
|
| 30 |
+
# These are read-only attributes in cython, which behave like properties
|
| 31 |
+
@property
|
| 32 |
+
def level(self) -> int: ...
|
| 33 |
+
@property
|
| 34 |
+
def split_dim(self) -> int: ...
|
| 35 |
+
@property
|
| 36 |
+
def children(self) -> int: ...
|
| 37 |
+
@property
|
| 38 |
+
def start_idx(self) -> int: ...
|
| 39 |
+
@property
|
| 40 |
+
def end_idx(self) -> int: ...
|
| 41 |
+
@property
|
| 42 |
+
def split(self) -> float: ...
|
| 43 |
+
@property
|
| 44 |
+
def lesser(self) -> cKDTreeNode | None: ...
|
| 45 |
+
@property
|
| 46 |
+
def greater(self) -> cKDTreeNode | None: ...
|
| 47 |
+
|
| 48 |
+
class cKDTree(Generic[_BoxType]):
|
| 49 |
+
@property
|
| 50 |
+
def n(self) -> int: ...
|
| 51 |
+
@property
|
| 52 |
+
def m(self) -> int: ...
|
| 53 |
+
@property
|
| 54 |
+
def leafsize(self) -> int: ...
|
| 55 |
+
@property
|
| 56 |
+
def size(self) -> int: ...
|
| 57 |
+
@property
|
| 58 |
+
def tree(self) -> cKDTreeNode: ...
|
| 59 |
+
|
| 60 |
+
# These are read-only attributes in cython, which behave like properties
|
| 61 |
+
@property
|
| 62 |
+
def data(self) -> npt.NDArray[np.float64]: ...
|
| 63 |
+
@property
|
| 64 |
+
def maxes(self) -> npt.NDArray[np.float64]: ...
|
| 65 |
+
@property
|
| 66 |
+
def mins(self) -> npt.NDArray[np.float64]: ...
|
| 67 |
+
@property
|
| 68 |
+
def indices(self) -> npt.NDArray[np.float64]: ...
|
| 69 |
+
@property
|
| 70 |
+
def boxsize(self) -> _BoxType: ...
|
| 71 |
+
|
| 72 |
+
# NOTE: In practice `__init__` is used as constructor, not `__new__`.
|
| 73 |
+
# The latter gives us more flexibility in setting the generic parameter
|
| 74 |
+
# though.
|
| 75 |
+
@overload
|
| 76 |
+
def __new__( # type: ignore[misc]
|
| 77 |
+
cls,
|
| 78 |
+
data: npt.ArrayLike,
|
| 79 |
+
leafsize: int = ...,
|
| 80 |
+
compact_nodes: bool = ...,
|
| 81 |
+
copy_data: bool = ...,
|
| 82 |
+
balanced_tree: bool = ...,
|
| 83 |
+
boxsize: None = ...,
|
| 84 |
+
) -> cKDTree[None]: ...
|
| 85 |
+
@overload
|
| 86 |
+
def __new__(
|
| 87 |
+
cls,
|
| 88 |
+
data: npt.ArrayLike,
|
| 89 |
+
leafsize: int = ...,
|
| 90 |
+
compact_nodes: bool = ...,
|
| 91 |
+
copy_data: bool = ...,
|
| 92 |
+
balanced_tree: bool = ...,
|
| 93 |
+
boxsize: npt.ArrayLike = ...,
|
| 94 |
+
) -> cKDTree[npt.NDArray[np.float64]]: ...
|
| 95 |
+
|
| 96 |
+
# TODO: returns a 2-tuple of scalars if `x.ndim == 1` and `k == 1`,
|
| 97 |
+
# returns a 2-tuple of arrays otherwise
|
| 98 |
+
def query(
|
| 99 |
+
self,
|
| 100 |
+
x: npt.ArrayLike,
|
| 101 |
+
k: npt.ArrayLike = ...,
|
| 102 |
+
eps: float = ...,
|
| 103 |
+
p: float = ...,
|
| 104 |
+
distance_upper_bound: float = ...,
|
| 105 |
+
workers: int | None = ...,
|
| 106 |
+
) -> tuple[Any, Any]: ...
|
| 107 |
+
|
| 108 |
+
# TODO: returns a list scalars if `x.ndim <= 1`,
|
| 109 |
+
# returns an object array of lists otherwise
|
| 110 |
+
def query_ball_point(
|
| 111 |
+
self,
|
| 112 |
+
x: npt.ArrayLike,
|
| 113 |
+
r: npt.ArrayLike,
|
| 114 |
+
p: float,
|
| 115 |
+
eps: float = ...,
|
| 116 |
+
workers: int | None = ...,
|
| 117 |
+
return_sorted: bool | None = ...,
|
| 118 |
+
return_length: bool = ...
|
| 119 |
+
) -> Any: ...
|
| 120 |
+
|
| 121 |
+
def query_ball_tree(
|
| 122 |
+
self,
|
| 123 |
+
other: cKDTree,
|
| 124 |
+
r: float,
|
| 125 |
+
p: float,
|
| 126 |
+
eps: float = ...,
|
| 127 |
+
) -> list[list[int]]: ...
|
| 128 |
+
|
| 129 |
+
@overload
|
| 130 |
+
def query_pairs( # type: ignore[misc]
|
| 131 |
+
self,
|
| 132 |
+
r: float,
|
| 133 |
+
p: float = ...,
|
| 134 |
+
eps: float = ...,
|
| 135 |
+
output_type: Literal["set"] = ...,
|
| 136 |
+
) -> set[tuple[int, int]]: ...
|
| 137 |
+
@overload
|
| 138 |
+
def query_pairs(
|
| 139 |
+
self,
|
| 140 |
+
r: float,
|
| 141 |
+
p: float = ...,
|
| 142 |
+
eps: float = ...,
|
| 143 |
+
output_type: Literal["ndarray"] = ...,
|
| 144 |
+
) -> npt.NDArray[np.intp]: ...
|
| 145 |
+
|
| 146 |
+
@overload
|
| 147 |
+
def count_neighbors( # type: ignore[misc]
|
| 148 |
+
self,
|
| 149 |
+
other: cKDTree,
|
| 150 |
+
r: _ArrayLike0D,
|
| 151 |
+
p: float = ...,
|
| 152 |
+
weights: None | tuple[None, None] = ...,
|
| 153 |
+
cumulative: bool = ...,
|
| 154 |
+
) -> int: ...
|
| 155 |
+
@overload
|
| 156 |
+
def count_neighbors( # type: ignore[misc]
|
| 157 |
+
self,
|
| 158 |
+
other: cKDTree,
|
| 159 |
+
r: _ArrayLike0D,
|
| 160 |
+
p: float = ...,
|
| 161 |
+
weights: _WeightType = ...,
|
| 162 |
+
cumulative: bool = ...,
|
| 163 |
+
) -> np.float64: ...
|
| 164 |
+
@overload
|
| 165 |
+
def count_neighbors( # type: ignore[misc]
|
| 166 |
+
self,
|
| 167 |
+
other: cKDTree,
|
| 168 |
+
r: npt.ArrayLike,
|
| 169 |
+
p: float = ...,
|
| 170 |
+
weights: None | tuple[None, None] = ...,
|
| 171 |
+
cumulative: bool = ...,
|
| 172 |
+
) -> npt.NDArray[np.intp]: ...
|
| 173 |
+
@overload
|
| 174 |
+
def count_neighbors(
|
| 175 |
+
self,
|
| 176 |
+
other: cKDTree,
|
| 177 |
+
r: npt.ArrayLike,
|
| 178 |
+
p: float = ...,
|
| 179 |
+
weights: _WeightType = ...,
|
| 180 |
+
cumulative: bool = ...,
|
| 181 |
+
) -> npt.NDArray[np.float64]: ...
|
| 182 |
+
|
| 183 |
+
@overload
|
| 184 |
+
def sparse_distance_matrix( # type: ignore[misc]
|
| 185 |
+
self,
|
| 186 |
+
other: cKDTree,
|
| 187 |
+
max_distance: float,
|
| 188 |
+
p: float = ...,
|
| 189 |
+
output_type: Literal["dok_matrix"] = ...,
|
| 190 |
+
) -> dok_matrix: ...
|
| 191 |
+
@overload
|
| 192 |
+
def sparse_distance_matrix( # type: ignore[misc]
|
| 193 |
+
self,
|
| 194 |
+
other: cKDTree,
|
| 195 |
+
max_distance: float,
|
| 196 |
+
p: float = ...,
|
| 197 |
+
output_type: Literal["coo_matrix"] = ...,
|
| 198 |
+
) -> coo_matrix: ...
|
| 199 |
+
@overload
|
| 200 |
+
def sparse_distance_matrix( # type: ignore[misc]
|
| 201 |
+
self,
|
| 202 |
+
other: cKDTree,
|
| 203 |
+
max_distance: float,
|
| 204 |
+
p: float = ...,
|
| 205 |
+
output_type: Literal["dict"] = ...,
|
| 206 |
+
) -> dict[tuple[int, int], float]: ...
|
| 207 |
+
@overload
|
| 208 |
+
def sparse_distance_matrix(
|
| 209 |
+
self,
|
| 210 |
+
other: cKDTree,
|
| 211 |
+
max_distance: float,
|
| 212 |
+
p: float = ...,
|
| 213 |
+
output_type: Literal["ndarray"] = ...,
|
| 214 |
+
) -> npt.NDArray[np.void]: ...
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/_kdtree.py
ADDED
|
@@ -0,0 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright Anne M. Archibald 2008
|
| 2 |
+
# Released under the scipy license
|
| 3 |
+
import numpy as np
|
| 4 |
+
from ._ckdtree import cKDTree, cKDTreeNode
|
| 5 |
+
|
| 6 |
+
__all__ = ['minkowski_distance_p', 'minkowski_distance',
|
| 7 |
+
'distance_matrix',
|
| 8 |
+
'Rectangle', 'KDTree']
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def minkowski_distance_p(x, y, p=2):
|
| 12 |
+
"""Compute the pth power of the L**p distance between two arrays.
|
| 13 |
+
|
| 14 |
+
For efficiency, this function computes the L**p distance but does
|
| 15 |
+
not extract the pth root. If `p` is 1 or infinity, this is equal to
|
| 16 |
+
the actual L**p distance.
|
| 17 |
+
|
| 18 |
+
The last dimensions of `x` and `y` must be the same length. Any
|
| 19 |
+
other dimensions must be compatible for broadcasting.
|
| 20 |
+
|
| 21 |
+
Parameters
|
| 22 |
+
----------
|
| 23 |
+
x : (..., K) array_like
|
| 24 |
+
Input array.
|
| 25 |
+
y : (..., K) array_like
|
| 26 |
+
Input array.
|
| 27 |
+
p : float, 1 <= p <= infinity
|
| 28 |
+
Which Minkowski p-norm to use.
|
| 29 |
+
|
| 30 |
+
Returns
|
| 31 |
+
-------
|
| 32 |
+
dist : ndarray
|
| 33 |
+
pth power of the distance between the input arrays.
|
| 34 |
+
|
| 35 |
+
Examples
|
| 36 |
+
--------
|
| 37 |
+
>>> from scipy.spatial import minkowski_distance_p
|
| 38 |
+
>>> minkowski_distance_p([[0, 0], [0, 0]], [[1, 1], [0, 1]])
|
| 39 |
+
array([2, 1])
|
| 40 |
+
|
| 41 |
+
"""
|
| 42 |
+
x = np.asarray(x)
|
| 43 |
+
y = np.asarray(y)
|
| 44 |
+
|
| 45 |
+
# Find smallest common datatype with float64 (return type of this
|
| 46 |
+
# function) - addresses #10262.
|
| 47 |
+
# Don't just cast to float64 for complex input case.
|
| 48 |
+
common_datatype = np.promote_types(np.promote_types(x.dtype, y.dtype),
|
| 49 |
+
'float64')
|
| 50 |
+
|
| 51 |
+
# Make sure x and y are NumPy arrays of correct datatype.
|
| 52 |
+
x = x.astype(common_datatype)
|
| 53 |
+
y = y.astype(common_datatype)
|
| 54 |
+
|
| 55 |
+
if p == np.inf:
|
| 56 |
+
return np.amax(np.abs(y-x), axis=-1)
|
| 57 |
+
elif p == 1:
|
| 58 |
+
return np.sum(np.abs(y-x), axis=-1)
|
| 59 |
+
else:
|
| 60 |
+
return np.sum(np.abs(y-x)**p, axis=-1)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def minkowski_distance(x, y, p=2):
|
| 64 |
+
"""Compute the L**p distance between two arrays.
|
| 65 |
+
|
| 66 |
+
The last dimensions of `x` and `y` must be the same length. Any
|
| 67 |
+
other dimensions must be compatible for broadcasting.
|
| 68 |
+
|
| 69 |
+
Parameters
|
| 70 |
+
----------
|
| 71 |
+
x : (..., K) array_like
|
| 72 |
+
Input array.
|
| 73 |
+
y : (..., K) array_like
|
| 74 |
+
Input array.
|
| 75 |
+
p : float, 1 <= p <= infinity
|
| 76 |
+
Which Minkowski p-norm to use.
|
| 77 |
+
|
| 78 |
+
Returns
|
| 79 |
+
-------
|
| 80 |
+
dist : ndarray
|
| 81 |
+
Distance between the input arrays.
|
| 82 |
+
|
| 83 |
+
Examples
|
| 84 |
+
--------
|
| 85 |
+
>>> from scipy.spatial import minkowski_distance
|
| 86 |
+
>>> minkowski_distance([[0, 0], [0, 0]], [[1, 1], [0, 1]])
|
| 87 |
+
array([ 1.41421356, 1. ])
|
| 88 |
+
|
| 89 |
+
"""
|
| 90 |
+
x = np.asarray(x)
|
| 91 |
+
y = np.asarray(y)
|
| 92 |
+
if p == np.inf or p == 1:
|
| 93 |
+
return minkowski_distance_p(x, y, p)
|
| 94 |
+
else:
|
| 95 |
+
return minkowski_distance_p(x, y, p)**(1./p)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
class Rectangle:
|
| 99 |
+
"""Hyperrectangle class.
|
| 100 |
+
|
| 101 |
+
Represents a Cartesian product of intervals.
|
| 102 |
+
"""
|
| 103 |
+
def __init__(self, maxes, mins):
|
| 104 |
+
"""Construct a hyperrectangle."""
|
| 105 |
+
self.maxes = np.maximum(maxes,mins).astype(float)
|
| 106 |
+
self.mins = np.minimum(maxes,mins).astype(float)
|
| 107 |
+
self.m, = self.maxes.shape
|
| 108 |
+
|
| 109 |
+
def __repr__(self):
|
| 110 |
+
return "<Rectangle %s>" % list(zip(self.mins, self.maxes))
|
| 111 |
+
|
| 112 |
+
def volume(self):
|
| 113 |
+
"""Total volume."""
|
| 114 |
+
return np.prod(self.maxes-self.mins)
|
| 115 |
+
|
| 116 |
+
def split(self, d, split):
|
| 117 |
+
"""Produce two hyperrectangles by splitting.
|
| 118 |
+
|
| 119 |
+
In general, if you need to compute maximum and minimum
|
| 120 |
+
distances to the children, it can be done more efficiently
|
| 121 |
+
by updating the maximum and minimum distances to the parent.
|
| 122 |
+
|
| 123 |
+
Parameters
|
| 124 |
+
----------
|
| 125 |
+
d : int
|
| 126 |
+
Axis to split hyperrectangle along.
|
| 127 |
+
split : float
|
| 128 |
+
Position along axis `d` to split at.
|
| 129 |
+
|
| 130 |
+
"""
|
| 131 |
+
mid = np.copy(self.maxes)
|
| 132 |
+
mid[d] = split
|
| 133 |
+
less = Rectangle(self.mins, mid)
|
| 134 |
+
mid = np.copy(self.mins)
|
| 135 |
+
mid[d] = split
|
| 136 |
+
greater = Rectangle(mid, self.maxes)
|
| 137 |
+
return less, greater
|
| 138 |
+
|
| 139 |
+
def min_distance_point(self, x, p=2.):
|
| 140 |
+
"""
|
| 141 |
+
Return the minimum distance between input and points in the
|
| 142 |
+
hyperrectangle.
|
| 143 |
+
|
| 144 |
+
Parameters
|
| 145 |
+
----------
|
| 146 |
+
x : array_like
|
| 147 |
+
Input.
|
| 148 |
+
p : float, optional
|
| 149 |
+
Input.
|
| 150 |
+
|
| 151 |
+
"""
|
| 152 |
+
return minkowski_distance(
|
| 153 |
+
0, np.maximum(0, np.maximum(self.mins-x, x-self.maxes)),
|
| 154 |
+
p
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
def max_distance_point(self, x, p=2.):
|
| 158 |
+
"""
|
| 159 |
+
Return the maximum distance between input and points in the hyperrectangle.
|
| 160 |
+
|
| 161 |
+
Parameters
|
| 162 |
+
----------
|
| 163 |
+
x : array_like
|
| 164 |
+
Input array.
|
| 165 |
+
p : float, optional
|
| 166 |
+
Input.
|
| 167 |
+
|
| 168 |
+
"""
|
| 169 |
+
return minkowski_distance(0, np.maximum(self.maxes-x, x-self.mins), p)
|
| 170 |
+
|
| 171 |
+
def min_distance_rectangle(self, other, p=2.):
|
| 172 |
+
"""
|
| 173 |
+
Compute the minimum distance between points in the two hyperrectangles.
|
| 174 |
+
|
| 175 |
+
Parameters
|
| 176 |
+
----------
|
| 177 |
+
other : hyperrectangle
|
| 178 |
+
Input.
|
| 179 |
+
p : float
|
| 180 |
+
Input.
|
| 181 |
+
|
| 182 |
+
"""
|
| 183 |
+
return minkowski_distance(
|
| 184 |
+
0,
|
| 185 |
+
np.maximum(0, np.maximum(self.mins-other.maxes,
|
| 186 |
+
other.mins-self.maxes)),
|
| 187 |
+
p
|
| 188 |
+
)
|
| 189 |
+
|
| 190 |
+
def max_distance_rectangle(self, other, p=2.):
|
| 191 |
+
"""
|
| 192 |
+
Compute the maximum distance between points in the two hyperrectangles.
|
| 193 |
+
|
| 194 |
+
Parameters
|
| 195 |
+
----------
|
| 196 |
+
other : hyperrectangle
|
| 197 |
+
Input.
|
| 198 |
+
p : float, optional
|
| 199 |
+
Input.
|
| 200 |
+
|
| 201 |
+
"""
|
| 202 |
+
return minkowski_distance(
|
| 203 |
+
0, np.maximum(self.maxes-other.mins, other.maxes-self.mins), p)
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
class KDTree(cKDTree):
|
| 207 |
+
"""kd-tree for quick nearest-neighbor lookup.
|
| 208 |
+
|
| 209 |
+
This class provides an index into a set of k-dimensional points
|
| 210 |
+
which can be used to rapidly look up the nearest neighbors of any
|
| 211 |
+
point.
|
| 212 |
+
|
| 213 |
+
Parameters
|
| 214 |
+
----------
|
| 215 |
+
data : array_like, shape (n,m)
|
| 216 |
+
The n data points of dimension m to be indexed. This array is
|
| 217 |
+
not copied unless this is necessary to produce a contiguous
|
| 218 |
+
array of doubles, and so modifying this data will result in
|
| 219 |
+
bogus results. The data are also copied if the kd-tree is built
|
| 220 |
+
with copy_data=True.
|
| 221 |
+
leafsize : positive int, optional
|
| 222 |
+
The number of points at which the algorithm switches over to
|
| 223 |
+
brute-force. Default: 10.
|
| 224 |
+
compact_nodes : bool, optional
|
| 225 |
+
If True, the kd-tree is built to shrink the hyperrectangles to
|
| 226 |
+
the actual data range. This usually gives a more compact tree that
|
| 227 |
+
is robust against degenerated input data and gives faster queries
|
| 228 |
+
at the expense of longer build time. Default: True.
|
| 229 |
+
copy_data : bool, optional
|
| 230 |
+
If True the data is always copied to protect the kd-tree against
|
| 231 |
+
data corruption. Default: False.
|
| 232 |
+
balanced_tree : bool, optional
|
| 233 |
+
If True, the median is used to split the hyperrectangles instead of
|
| 234 |
+
the midpoint. This usually gives a more compact tree and
|
| 235 |
+
faster queries at the expense of longer build time. Default: True.
|
| 236 |
+
boxsize : array_like or scalar, optional
|
| 237 |
+
Apply a m-d toroidal topology to the KDTree.. The topology is generated
|
| 238 |
+
by :math:`x_i + n_i L_i` where :math:`n_i` are integers and :math:`L_i`
|
| 239 |
+
is the boxsize along i-th dimension. The input data shall be wrapped
|
| 240 |
+
into :math:`[0, L_i)`. A ValueError is raised if any of the data is
|
| 241 |
+
outside of this bound.
|
| 242 |
+
|
| 243 |
+
Notes
|
| 244 |
+
-----
|
| 245 |
+
The algorithm used is described in Maneewongvatana and Mount 1999.
|
| 246 |
+
The general idea is that the kd-tree is a binary tree, each of whose
|
| 247 |
+
nodes represents an axis-aligned hyperrectangle. Each node specifies
|
| 248 |
+
an axis and splits the set of points based on whether their coordinate
|
| 249 |
+
along that axis is greater than or less than a particular value.
|
| 250 |
+
|
| 251 |
+
During construction, the axis and splitting point are chosen by the
|
| 252 |
+
"sliding midpoint" rule, which ensures that the cells do not all
|
| 253 |
+
become long and thin.
|
| 254 |
+
|
| 255 |
+
The tree can be queried for the r closest neighbors of any given point
|
| 256 |
+
(optionally returning only those within some maximum distance of the
|
| 257 |
+
point). It can also be queried, with a substantial gain in efficiency,
|
| 258 |
+
for the r approximate closest neighbors.
|
| 259 |
+
|
| 260 |
+
For large dimensions (20 is already large) do not expect this to run
|
| 261 |
+
significantly faster than brute force. High-dimensional nearest-neighbor
|
| 262 |
+
queries are a substantial open problem in computer science.
|
| 263 |
+
|
| 264 |
+
Attributes
|
| 265 |
+
----------
|
| 266 |
+
data : ndarray, shape (n,m)
|
| 267 |
+
The n data points of dimension m to be indexed. This array is
|
| 268 |
+
not copied unless this is necessary to produce a contiguous
|
| 269 |
+
array of doubles. The data are also copied if the kd-tree is built
|
| 270 |
+
with `copy_data=True`.
|
| 271 |
+
leafsize : positive int
|
| 272 |
+
The number of points at which the algorithm switches over to
|
| 273 |
+
brute-force.
|
| 274 |
+
m : int
|
| 275 |
+
The dimension of a single data-point.
|
| 276 |
+
n : int
|
| 277 |
+
The number of data points.
|
| 278 |
+
maxes : ndarray, shape (m,)
|
| 279 |
+
The maximum value in each dimension of the n data points.
|
| 280 |
+
mins : ndarray, shape (m,)
|
| 281 |
+
The minimum value in each dimension of the n data points.
|
| 282 |
+
size : int
|
| 283 |
+
The number of nodes in the tree.
|
| 284 |
+
|
| 285 |
+
"""
|
| 286 |
+
|
| 287 |
+
class node:
|
| 288 |
+
@staticmethod
|
| 289 |
+
def _create(ckdtree_node=None):
|
| 290 |
+
"""Create either an inner or leaf node, wrapping a cKDTreeNode instance"""
|
| 291 |
+
if ckdtree_node is None:
|
| 292 |
+
return KDTree.node(ckdtree_node)
|
| 293 |
+
elif ckdtree_node.split_dim == -1:
|
| 294 |
+
return KDTree.leafnode(ckdtree_node)
|
| 295 |
+
else:
|
| 296 |
+
return KDTree.innernode(ckdtree_node)
|
| 297 |
+
|
| 298 |
+
def __init__(self, ckdtree_node=None):
|
| 299 |
+
if ckdtree_node is None:
|
| 300 |
+
ckdtree_node = cKDTreeNode()
|
| 301 |
+
self._node = ckdtree_node
|
| 302 |
+
|
| 303 |
+
def __lt__(self, other):
|
| 304 |
+
return id(self) < id(other)
|
| 305 |
+
|
| 306 |
+
def __gt__(self, other):
|
| 307 |
+
return id(self) > id(other)
|
| 308 |
+
|
| 309 |
+
def __le__(self, other):
|
| 310 |
+
return id(self) <= id(other)
|
| 311 |
+
|
| 312 |
+
def __ge__(self, other):
|
| 313 |
+
return id(self) >= id(other)
|
| 314 |
+
|
| 315 |
+
def __eq__(self, other):
|
| 316 |
+
return id(self) == id(other)
|
| 317 |
+
|
| 318 |
+
class leafnode(node):
|
| 319 |
+
@property
|
| 320 |
+
def idx(self):
|
| 321 |
+
return self._node.indices
|
| 322 |
+
|
| 323 |
+
@property
|
| 324 |
+
def children(self):
|
| 325 |
+
return self._node.children
|
| 326 |
+
|
| 327 |
+
class innernode(node):
|
| 328 |
+
def __init__(self, ckdtreenode):
|
| 329 |
+
assert isinstance(ckdtreenode, cKDTreeNode)
|
| 330 |
+
super().__init__(ckdtreenode)
|
| 331 |
+
self.less = KDTree.node._create(ckdtreenode.lesser)
|
| 332 |
+
self.greater = KDTree.node._create(ckdtreenode.greater)
|
| 333 |
+
|
| 334 |
+
@property
|
| 335 |
+
def split_dim(self):
|
| 336 |
+
return self._node.split_dim
|
| 337 |
+
|
| 338 |
+
@property
|
| 339 |
+
def split(self):
|
| 340 |
+
return self._node.split
|
| 341 |
+
|
| 342 |
+
@property
|
| 343 |
+
def children(self):
|
| 344 |
+
return self._node.children
|
| 345 |
+
|
| 346 |
+
@property
|
| 347 |
+
def tree(self):
|
| 348 |
+
if not hasattr(self, "_tree"):
|
| 349 |
+
self._tree = KDTree.node._create(super().tree)
|
| 350 |
+
|
| 351 |
+
return self._tree
|
| 352 |
+
|
| 353 |
+
def __init__(self, data, leafsize=10, compact_nodes=True, copy_data=False,
|
| 354 |
+
balanced_tree=True, boxsize=None):
|
| 355 |
+
data = np.asarray(data)
|
| 356 |
+
if data.dtype.kind == 'c':
|
| 357 |
+
raise TypeError("KDTree does not work with complex data")
|
| 358 |
+
|
| 359 |
+
# Note KDTree has different default leafsize from cKDTree
|
| 360 |
+
super().__init__(data, leafsize, compact_nodes, copy_data,
|
| 361 |
+
balanced_tree, boxsize)
|
| 362 |
+
|
| 363 |
+
def query(
|
| 364 |
+
self, x, k=1, eps=0, p=2, distance_upper_bound=np.inf, workers=1):
|
| 365 |
+
r"""Query the kd-tree for nearest neighbors.
|
| 366 |
+
|
| 367 |
+
Parameters
|
| 368 |
+
----------
|
| 369 |
+
x : array_like, last dimension self.m
|
| 370 |
+
An array of points to query.
|
| 371 |
+
k : int or Sequence[int], optional
|
| 372 |
+
Either the number of nearest neighbors to return, or a list of the
|
| 373 |
+
k-th nearest neighbors to return, starting from 1.
|
| 374 |
+
eps : nonnegative float, optional
|
| 375 |
+
Return approximate nearest neighbors; the kth returned value
|
| 376 |
+
is guaranteed to be no further than (1+eps) times the
|
| 377 |
+
distance to the real kth nearest neighbor.
|
| 378 |
+
p : float, 1<=p<=infinity, optional
|
| 379 |
+
Which Minkowski p-norm to use.
|
| 380 |
+
1 is the sum-of-absolute-values distance ("Manhattan" distance).
|
| 381 |
+
2 is the usual Euclidean distance.
|
| 382 |
+
infinity is the maximum-coordinate-difference distance.
|
| 383 |
+
A large, finite p may cause a ValueError if overflow can occur.
|
| 384 |
+
distance_upper_bound : nonnegative float, optional
|
| 385 |
+
Return only neighbors within this distance. This is used to prune
|
| 386 |
+
tree searches, so if you are doing a series of nearest-neighbor
|
| 387 |
+
queries, it may help to supply the distance to the nearest neighbor
|
| 388 |
+
of the most recent point.
|
| 389 |
+
workers : int, optional
|
| 390 |
+
Number of workers to use for parallel processing. If -1 is given
|
| 391 |
+
all CPU threads are used. Default: 1.
|
| 392 |
+
|
| 393 |
+
.. versionadded:: 1.6.0
|
| 394 |
+
|
| 395 |
+
Returns
|
| 396 |
+
-------
|
| 397 |
+
d : float or array of floats
|
| 398 |
+
The distances to the nearest neighbors.
|
| 399 |
+
If ``x`` has shape ``tuple+(self.m,)``, then ``d`` has shape
|
| 400 |
+
``tuple+(k,)``.
|
| 401 |
+
When k == 1, the last dimension of the output is squeezed.
|
| 402 |
+
Missing neighbors are indicated with infinite distances.
|
| 403 |
+
Hits are sorted by distance (nearest first).
|
| 404 |
+
|
| 405 |
+
.. versionchanged:: 1.9.0
|
| 406 |
+
Previously if ``k=None``, then `d` was an object array of
|
| 407 |
+
shape ``tuple``, containing lists of distances. This behavior
|
| 408 |
+
has been removed, use `query_ball_point` instead.
|
| 409 |
+
|
| 410 |
+
i : integer or array of integers
|
| 411 |
+
The index of each neighbor in ``self.data``.
|
| 412 |
+
``i`` is the same shape as d.
|
| 413 |
+
Missing neighbors are indicated with ``self.n``.
|
| 414 |
+
|
| 415 |
+
Examples
|
| 416 |
+
--------
|
| 417 |
+
|
| 418 |
+
>>> import numpy as np
|
| 419 |
+
>>> from scipy.spatial import KDTree
|
| 420 |
+
>>> x, y = np.mgrid[0:5, 2:8]
|
| 421 |
+
>>> tree = KDTree(np.c_[x.ravel(), y.ravel()])
|
| 422 |
+
|
| 423 |
+
To query the nearest neighbours and return squeezed result, use
|
| 424 |
+
|
| 425 |
+
>>> dd, ii = tree.query([[0, 0], [2.2, 2.9]], k=1)
|
| 426 |
+
>>> print(dd, ii, sep='\n')
|
| 427 |
+
[2. 0.2236068]
|
| 428 |
+
[ 0 13]
|
| 429 |
+
|
| 430 |
+
To query the nearest neighbours and return unsqueezed result, use
|
| 431 |
+
|
| 432 |
+
>>> dd, ii = tree.query([[0, 0], [2.2, 2.9]], k=[1])
|
| 433 |
+
>>> print(dd, ii, sep='\n')
|
| 434 |
+
[[2. ]
|
| 435 |
+
[0.2236068]]
|
| 436 |
+
[[ 0]
|
| 437 |
+
[13]]
|
| 438 |
+
|
| 439 |
+
To query the second nearest neighbours and return unsqueezed result,
|
| 440 |
+
use
|
| 441 |
+
|
| 442 |
+
>>> dd, ii = tree.query([[0, 0], [2.2, 2.9]], k=[2])
|
| 443 |
+
>>> print(dd, ii, sep='\n')
|
| 444 |
+
[[2.23606798]
|
| 445 |
+
[0.80622577]]
|
| 446 |
+
[[ 6]
|
| 447 |
+
[19]]
|
| 448 |
+
|
| 449 |
+
To query the first and second nearest neighbours, use
|
| 450 |
+
|
| 451 |
+
>>> dd, ii = tree.query([[0, 0], [2.2, 2.9]], k=2)
|
| 452 |
+
>>> print(dd, ii, sep='\n')
|
| 453 |
+
[[2. 2.23606798]
|
| 454 |
+
[0.2236068 0.80622577]]
|
| 455 |
+
[[ 0 6]
|
| 456 |
+
[13 19]]
|
| 457 |
+
|
| 458 |
+
or, be more specific
|
| 459 |
+
|
| 460 |
+
>>> dd, ii = tree.query([[0, 0], [2.2, 2.9]], k=[1, 2])
|
| 461 |
+
>>> print(dd, ii, sep='\n')
|
| 462 |
+
[[2. 2.23606798]
|
| 463 |
+
[0.2236068 0.80622577]]
|
| 464 |
+
[[ 0 6]
|
| 465 |
+
[13 19]]
|
| 466 |
+
|
| 467 |
+
"""
|
| 468 |
+
x = np.asarray(x)
|
| 469 |
+
if x.dtype.kind == 'c':
|
| 470 |
+
raise TypeError("KDTree does not work with complex data")
|
| 471 |
+
|
| 472 |
+
if k is None:
|
| 473 |
+
raise ValueError("k must be an integer or a sequence of integers")
|
| 474 |
+
|
| 475 |
+
d, i = super().query(x, k, eps, p, distance_upper_bound, workers)
|
| 476 |
+
if isinstance(i, int):
|
| 477 |
+
i = np.intp(i)
|
| 478 |
+
return d, i
|
| 479 |
+
|
| 480 |
+
def query_ball_point(self, x, r, p=2., eps=0, workers=1,
|
| 481 |
+
return_sorted=None, return_length=False):
|
| 482 |
+
"""Find all points within distance r of point(s) x.
|
| 483 |
+
|
| 484 |
+
Parameters
|
| 485 |
+
----------
|
| 486 |
+
x : array_like, shape tuple + (self.m,)
|
| 487 |
+
The point or points to search for neighbors of.
|
| 488 |
+
r : array_like, float
|
| 489 |
+
The radius of points to return, must broadcast to the length of x.
|
| 490 |
+
p : float, optional
|
| 491 |
+
Which Minkowski p-norm to use. Should be in the range [1, inf].
|
| 492 |
+
A finite large p may cause a ValueError if overflow can occur.
|
| 493 |
+
eps : nonnegative float, optional
|
| 494 |
+
Approximate search. Branches of the tree are not explored if their
|
| 495 |
+
nearest points are further than ``r / (1 + eps)``, and branches are
|
| 496 |
+
added in bulk if their furthest points are nearer than
|
| 497 |
+
``r * (1 + eps)``.
|
| 498 |
+
workers : int, optional
|
| 499 |
+
Number of jobs to schedule for parallel processing. If -1 is given
|
| 500 |
+
all processors are used. Default: 1.
|
| 501 |
+
|
| 502 |
+
.. versionadded:: 1.6.0
|
| 503 |
+
return_sorted : bool, optional
|
| 504 |
+
Sorts returned indices if True and does not sort them if False. If
|
| 505 |
+
None, does not sort single point queries, but does sort
|
| 506 |
+
multi-point queries which was the behavior before this option
|
| 507 |
+
was added.
|
| 508 |
+
|
| 509 |
+
.. versionadded:: 1.6.0
|
| 510 |
+
return_length : bool, optional
|
| 511 |
+
Return the number of points inside the radius instead of a list
|
| 512 |
+
of the indices.
|
| 513 |
+
|
| 514 |
+
.. versionadded:: 1.6.0
|
| 515 |
+
|
| 516 |
+
Returns
|
| 517 |
+
-------
|
| 518 |
+
results : list or array of lists
|
| 519 |
+
If `x` is a single point, returns a list of the indices of the
|
| 520 |
+
neighbors of `x`. If `x` is an array of points, returns an object
|
| 521 |
+
array of shape tuple containing lists of neighbors.
|
| 522 |
+
|
| 523 |
+
Notes
|
| 524 |
+
-----
|
| 525 |
+
If you have many points whose neighbors you want to find, you may save
|
| 526 |
+
substantial amounts of time by putting them in a KDTree and using
|
| 527 |
+
query_ball_tree.
|
| 528 |
+
|
| 529 |
+
Examples
|
| 530 |
+
--------
|
| 531 |
+
>>> import numpy as np
|
| 532 |
+
>>> from scipy import spatial
|
| 533 |
+
>>> x, y = np.mgrid[0:5, 0:5]
|
| 534 |
+
>>> points = np.c_[x.ravel(), y.ravel()]
|
| 535 |
+
>>> tree = spatial.KDTree(points)
|
| 536 |
+
>>> sorted(tree.query_ball_point([2, 0], 1))
|
| 537 |
+
[5, 10, 11, 15]
|
| 538 |
+
|
| 539 |
+
Query multiple points and plot the results:
|
| 540 |
+
|
| 541 |
+
>>> import matplotlib.pyplot as plt
|
| 542 |
+
>>> points = np.asarray(points)
|
| 543 |
+
>>> plt.plot(points[:,0], points[:,1], '.')
|
| 544 |
+
>>> for results in tree.query_ball_point(([2, 0], [3, 3]), 1):
|
| 545 |
+
... nearby_points = points[results]
|
| 546 |
+
... plt.plot(nearby_points[:,0], nearby_points[:,1], 'o')
|
| 547 |
+
>>> plt.margins(0.1, 0.1)
|
| 548 |
+
>>> plt.show()
|
| 549 |
+
|
| 550 |
+
"""
|
| 551 |
+
x = np.asarray(x)
|
| 552 |
+
if x.dtype.kind == 'c':
|
| 553 |
+
raise TypeError("KDTree does not work with complex data")
|
| 554 |
+
return super().query_ball_point(
|
| 555 |
+
x, r, p, eps, workers, return_sorted, return_length)
|
| 556 |
+
|
| 557 |
+
def query_ball_tree(self, other, r, p=2., eps=0):
|
| 558 |
+
"""
|
| 559 |
+
Find all pairs of points between `self` and `other` whose distance is
|
| 560 |
+
at most r.
|
| 561 |
+
|
| 562 |
+
Parameters
|
| 563 |
+
----------
|
| 564 |
+
other : KDTree instance
|
| 565 |
+
The tree containing points to search against.
|
| 566 |
+
r : float
|
| 567 |
+
The maximum distance, has to be positive.
|
| 568 |
+
p : float, optional
|
| 569 |
+
Which Minkowski norm to use. `p` has to meet the condition
|
| 570 |
+
``1 <= p <= infinity``.
|
| 571 |
+
eps : float, optional
|
| 572 |
+
Approximate search. Branches of the tree are not explored
|
| 573 |
+
if their nearest points are further than ``r/(1+eps)``, and
|
| 574 |
+
branches are added in bulk if their furthest points are nearer
|
| 575 |
+
than ``r * (1+eps)``. `eps` has to be non-negative.
|
| 576 |
+
|
| 577 |
+
Returns
|
| 578 |
+
-------
|
| 579 |
+
results : list of lists
|
| 580 |
+
For each element ``self.data[i]`` of this tree, ``results[i]`` is a
|
| 581 |
+
list of the indices of its neighbors in ``other.data``.
|
| 582 |
+
|
| 583 |
+
Examples
|
| 584 |
+
--------
|
| 585 |
+
You can search all pairs of points between two kd-trees within a distance:
|
| 586 |
+
|
| 587 |
+
>>> import matplotlib.pyplot as plt
|
| 588 |
+
>>> import numpy as np
|
| 589 |
+
>>> from scipy.spatial import KDTree
|
| 590 |
+
>>> rng = np.random.default_rng()
|
| 591 |
+
>>> points1 = rng.random((15, 2))
|
| 592 |
+
>>> points2 = rng.random((15, 2))
|
| 593 |
+
>>> plt.figure(figsize=(6, 6))
|
| 594 |
+
>>> plt.plot(points1[:, 0], points1[:, 1], "xk", markersize=14)
|
| 595 |
+
>>> plt.plot(points2[:, 0], points2[:, 1], "og", markersize=14)
|
| 596 |
+
>>> kd_tree1 = KDTree(points1)
|
| 597 |
+
>>> kd_tree2 = KDTree(points2)
|
| 598 |
+
>>> indexes = kd_tree1.query_ball_tree(kd_tree2, r=0.2)
|
| 599 |
+
>>> for i in range(len(indexes)):
|
| 600 |
+
... for j in indexes[i]:
|
| 601 |
+
... plt.plot([points1[i, 0], points2[j, 0]],
|
| 602 |
+
... [points1[i, 1], points2[j, 1]], "-r")
|
| 603 |
+
>>> plt.show()
|
| 604 |
+
|
| 605 |
+
"""
|
| 606 |
+
return super().query_ball_tree(other, r, p, eps)
|
| 607 |
+
|
| 608 |
+
def query_pairs(self, r, p=2., eps=0, output_type='set'):
|
| 609 |
+
"""Find all pairs of points in `self` whose distance is at most r.
|
| 610 |
+
|
| 611 |
+
Parameters
|
| 612 |
+
----------
|
| 613 |
+
r : positive float
|
| 614 |
+
The maximum distance.
|
| 615 |
+
p : float, optional
|
| 616 |
+
Which Minkowski norm to use. `p` has to meet the condition
|
| 617 |
+
``1 <= p <= infinity``.
|
| 618 |
+
eps : float, optional
|
| 619 |
+
Approximate search. Branches of the tree are not explored
|
| 620 |
+
if their nearest points are further than ``r/(1+eps)``, and
|
| 621 |
+
branches are added in bulk if their furthest points are nearer
|
| 622 |
+
than ``r * (1+eps)``. `eps` has to be non-negative.
|
| 623 |
+
output_type : string, optional
|
| 624 |
+
Choose the output container, 'set' or 'ndarray'. Default: 'set'
|
| 625 |
+
|
| 626 |
+
.. versionadded:: 1.6.0
|
| 627 |
+
|
| 628 |
+
Returns
|
| 629 |
+
-------
|
| 630 |
+
results : set or ndarray
|
| 631 |
+
Set of pairs ``(i,j)``, with ``i < j``, for which the corresponding
|
| 632 |
+
positions are close. If output_type is 'ndarray', an ndarry is
|
| 633 |
+
returned instead of a set.
|
| 634 |
+
|
| 635 |
+
Examples
|
| 636 |
+
--------
|
| 637 |
+
You can search all pairs of points in a kd-tree within a distance:
|
| 638 |
+
|
| 639 |
+
>>> import matplotlib.pyplot as plt
|
| 640 |
+
>>> import numpy as np
|
| 641 |
+
>>> from scipy.spatial import KDTree
|
| 642 |
+
>>> rng = np.random.default_rng()
|
| 643 |
+
>>> points = rng.random((20, 2))
|
| 644 |
+
>>> plt.figure(figsize=(6, 6))
|
| 645 |
+
>>> plt.plot(points[:, 0], points[:, 1], "xk", markersize=14)
|
| 646 |
+
>>> kd_tree = KDTree(points)
|
| 647 |
+
>>> pairs = kd_tree.query_pairs(r=0.2)
|
| 648 |
+
>>> for (i, j) in pairs:
|
| 649 |
+
... plt.plot([points[i, 0], points[j, 0]],
|
| 650 |
+
... [points[i, 1], points[j, 1]], "-r")
|
| 651 |
+
>>> plt.show()
|
| 652 |
+
|
| 653 |
+
"""
|
| 654 |
+
return super().query_pairs(r, p, eps, output_type)
|
| 655 |
+
|
| 656 |
+
def count_neighbors(self, other, r, p=2., weights=None, cumulative=True):
|
| 657 |
+
"""Count how many nearby pairs can be formed.
|
| 658 |
+
|
| 659 |
+
Count the number of pairs ``(x1,x2)`` can be formed, with ``x1`` drawn
|
| 660 |
+
from ``self`` and ``x2`` drawn from ``other``, and where
|
| 661 |
+
``distance(x1, x2, p) <= r``.
|
| 662 |
+
|
| 663 |
+
Data points on ``self`` and ``other`` are optionally weighted by the
|
| 664 |
+
``weights`` argument. (See below)
|
| 665 |
+
|
| 666 |
+
This is adapted from the "two-point correlation" algorithm described by
|
| 667 |
+
Gray and Moore [1]_. See notes for further discussion.
|
| 668 |
+
|
| 669 |
+
Parameters
|
| 670 |
+
----------
|
| 671 |
+
other : KDTree
|
| 672 |
+
The other tree to draw points from, can be the same tree as self.
|
| 673 |
+
r : float or one-dimensional array of floats
|
| 674 |
+
The radius to produce a count for. Multiple radii are searched with
|
| 675 |
+
a single tree traversal.
|
| 676 |
+
If the count is non-cumulative(``cumulative=False``), ``r`` defines
|
| 677 |
+
the edges of the bins, and must be non-decreasing.
|
| 678 |
+
p : float, optional
|
| 679 |
+
1<=p<=infinity.
|
| 680 |
+
Which Minkowski p-norm to use.
|
| 681 |
+
Default 2.0.
|
| 682 |
+
A finite large p may cause a ValueError if overflow can occur.
|
| 683 |
+
weights : tuple, array_like, or None, optional
|
| 684 |
+
If None, the pair-counting is unweighted.
|
| 685 |
+
If given as a tuple, weights[0] is the weights of points in
|
| 686 |
+
``self``, and weights[1] is the weights of points in ``other``;
|
| 687 |
+
either can be None to indicate the points are unweighted.
|
| 688 |
+
If given as an array_like, weights is the weights of points in
|
| 689 |
+
``self`` and ``other``. For this to make sense, ``self`` and
|
| 690 |
+
``other`` must be the same tree. If ``self`` and ``other`` are two
|
| 691 |
+
different trees, a ``ValueError`` is raised.
|
| 692 |
+
Default: None
|
| 693 |
+
|
| 694 |
+
.. versionadded:: 1.6.0
|
| 695 |
+
cumulative : bool, optional
|
| 696 |
+
Whether the returned counts are cumulative. When cumulative is set
|
| 697 |
+
to ``False`` the algorithm is optimized to work with a large number
|
| 698 |
+
of bins (>10) specified by ``r``. When ``cumulative`` is set to
|
| 699 |
+
True, the algorithm is optimized to work with a small number of
|
| 700 |
+
``r``. Default: True
|
| 701 |
+
|
| 702 |
+
.. versionadded:: 1.6.0
|
| 703 |
+
|
| 704 |
+
Returns
|
| 705 |
+
-------
|
| 706 |
+
result : scalar or 1-D array
|
| 707 |
+
The number of pairs. For unweighted counts, the result is integer.
|
| 708 |
+
For weighted counts, the result is float.
|
| 709 |
+
If cumulative is False, ``result[i]`` contains the counts with
|
| 710 |
+
``(-inf if i == 0 else r[i-1]) < R <= r[i]``
|
| 711 |
+
|
| 712 |
+
Notes
|
| 713 |
+
-----
|
| 714 |
+
Pair-counting is the basic operation used to calculate the two point
|
| 715 |
+
correlation functions from a data set composed of position of objects.
|
| 716 |
+
|
| 717 |
+
Two point correlation function measures the clustering of objects and
|
| 718 |
+
is widely used in cosmology to quantify the large scale structure
|
| 719 |
+
in our Universe, but it may be useful for data analysis in other fields
|
| 720 |
+
where self-similar assembly of objects also occur.
|
| 721 |
+
|
| 722 |
+
The Landy-Szalay estimator for the two point correlation function of
|
| 723 |
+
``D`` measures the clustering signal in ``D``. [2]_
|
| 724 |
+
|
| 725 |
+
For example, given the position of two sets of objects,
|
| 726 |
+
|
| 727 |
+
- objects ``D`` (data) contains the clustering signal, and
|
| 728 |
+
|
| 729 |
+
- objects ``R`` (random) that contains no signal,
|
| 730 |
+
|
| 731 |
+
.. math::
|
| 732 |
+
|
| 733 |
+
\\xi(r) = \\frac{<D, D> - 2 f <D, R> + f^2<R, R>}{f^2<R, R>},
|
| 734 |
+
|
| 735 |
+
where the brackets represents counting pairs between two data sets
|
| 736 |
+
in a finite bin around ``r`` (distance), corresponding to setting
|
| 737 |
+
`cumulative=False`, and ``f = float(len(D)) / float(len(R))`` is the
|
| 738 |
+
ratio between number of objects from data and random.
|
| 739 |
+
|
| 740 |
+
The algorithm implemented here is loosely based on the dual-tree
|
| 741 |
+
algorithm described in [1]_. We switch between two different
|
| 742 |
+
pair-cumulation scheme depending on the setting of ``cumulative``.
|
| 743 |
+
The computing time of the method we use when for
|
| 744 |
+
``cumulative == False`` does not scale with the total number of bins.
|
| 745 |
+
The algorithm for ``cumulative == True`` scales linearly with the
|
| 746 |
+
number of bins, though it is slightly faster when only
|
| 747 |
+
1 or 2 bins are used. [5]_.
|
| 748 |
+
|
| 749 |
+
As an extension to the naive pair-counting,
|
| 750 |
+
weighted pair-counting counts the product of weights instead
|
| 751 |
+
of number of pairs.
|
| 752 |
+
Weighted pair-counting is used to estimate marked correlation functions
|
| 753 |
+
([3]_, section 2.2),
|
| 754 |
+
or to properly calculate the average of data per distance bin
|
| 755 |
+
(e.g. [4]_, section 2.1 on redshift).
|
| 756 |
+
|
| 757 |
+
.. [1] Gray and Moore,
|
| 758 |
+
"N-body problems in statistical learning",
|
| 759 |
+
Mining the sky, 2000,
|
| 760 |
+
https://arxiv.org/abs/astro-ph/0012333
|
| 761 |
+
|
| 762 |
+
.. [2] Landy and Szalay,
|
| 763 |
+
"Bias and variance of angular correlation functions",
|
| 764 |
+
The Astrophysical Journal, 1993,
|
| 765 |
+
http://adsabs.harvard.edu/abs/1993ApJ...412...64L
|
| 766 |
+
|
| 767 |
+
.. [3] Sheth, Connolly and Skibba,
|
| 768 |
+
"Marked correlations in galaxy formation models",
|
| 769 |
+
Arxiv e-print, 2005,
|
| 770 |
+
https://arxiv.org/abs/astro-ph/0511773
|
| 771 |
+
|
| 772 |
+
.. [4] Hawkins, et al.,
|
| 773 |
+
"The 2dF Galaxy Redshift Survey: correlation functions,
|
| 774 |
+
peculiar velocities and the matter density of the Universe",
|
| 775 |
+
Monthly Notices of the Royal Astronomical Society, 2002,
|
| 776 |
+
http://adsabs.harvard.edu/abs/2003MNRAS.346...78H
|
| 777 |
+
|
| 778 |
+
.. [5] https://github.com/scipy/scipy/pull/5647#issuecomment-168474926
|
| 779 |
+
|
| 780 |
+
Examples
|
| 781 |
+
--------
|
| 782 |
+
You can count neighbors number between two kd-trees within a distance:
|
| 783 |
+
|
| 784 |
+
>>> import numpy as np
|
| 785 |
+
>>> from scipy.spatial import KDTree
|
| 786 |
+
>>> rng = np.random.default_rng()
|
| 787 |
+
>>> points1 = rng.random((5, 2))
|
| 788 |
+
>>> points2 = rng.random((5, 2))
|
| 789 |
+
>>> kd_tree1 = KDTree(points1)
|
| 790 |
+
>>> kd_tree2 = KDTree(points2)
|
| 791 |
+
>>> kd_tree1.count_neighbors(kd_tree2, 0.2)
|
| 792 |
+
1
|
| 793 |
+
|
| 794 |
+
This number is same as the total pair number calculated by
|
| 795 |
+
`query_ball_tree`:
|
| 796 |
+
|
| 797 |
+
>>> indexes = kd_tree1.query_ball_tree(kd_tree2, r=0.2)
|
| 798 |
+
>>> sum([len(i) for i in indexes])
|
| 799 |
+
1
|
| 800 |
+
|
| 801 |
+
"""
|
| 802 |
+
return super().count_neighbors(other, r, p, weights, cumulative)
|
| 803 |
+
|
| 804 |
+
def sparse_distance_matrix(
|
| 805 |
+
self, other, max_distance, p=2., output_type='dok_matrix'):
|
| 806 |
+
"""Compute a sparse distance matrix.
|
| 807 |
+
|
| 808 |
+
Computes a distance matrix between two KDTrees, leaving as zero
|
| 809 |
+
any distance greater than max_distance.
|
| 810 |
+
|
| 811 |
+
Parameters
|
| 812 |
+
----------
|
| 813 |
+
other : KDTree
|
| 814 |
+
|
| 815 |
+
max_distance : positive float
|
| 816 |
+
|
| 817 |
+
p : float, 1<=p<=infinity
|
| 818 |
+
Which Minkowski p-norm to use.
|
| 819 |
+
A finite large p may cause a ValueError if overflow can occur.
|
| 820 |
+
|
| 821 |
+
output_type : string, optional
|
| 822 |
+
Which container to use for output data. Options: 'dok_matrix',
|
| 823 |
+
'coo_matrix', 'dict', or 'ndarray'. Default: 'dok_matrix'.
|
| 824 |
+
|
| 825 |
+
.. versionadded:: 1.6.0
|
| 826 |
+
|
| 827 |
+
Returns
|
| 828 |
+
-------
|
| 829 |
+
result : dok_matrix, coo_matrix, dict or ndarray
|
| 830 |
+
Sparse matrix representing the results in "dictionary of keys"
|
| 831 |
+
format. If a dict is returned the keys are (i,j) tuples of indices.
|
| 832 |
+
If output_type is 'ndarray' a record array with fields 'i', 'j',
|
| 833 |
+
and 'v' is returned,
|
| 834 |
+
|
| 835 |
+
Examples
|
| 836 |
+
--------
|
| 837 |
+
You can compute a sparse distance matrix between two kd-trees:
|
| 838 |
+
|
| 839 |
+
>>> import numpy as np
|
| 840 |
+
>>> from scipy.spatial import KDTree
|
| 841 |
+
>>> rng = np.random.default_rng()
|
| 842 |
+
>>> points1 = rng.random((5, 2))
|
| 843 |
+
>>> points2 = rng.random((5, 2))
|
| 844 |
+
>>> kd_tree1 = KDTree(points1)
|
| 845 |
+
>>> kd_tree2 = KDTree(points2)
|
| 846 |
+
>>> sdm = kd_tree1.sparse_distance_matrix(kd_tree2, 0.3)
|
| 847 |
+
>>> sdm.toarray()
|
| 848 |
+
array([[0. , 0. , 0.12295571, 0. , 0. ],
|
| 849 |
+
[0. , 0. , 0. , 0. , 0. ],
|
| 850 |
+
[0.28942611, 0. , 0. , 0.2333084 , 0. ],
|
| 851 |
+
[0. , 0. , 0. , 0. , 0. ],
|
| 852 |
+
[0.24617575, 0.29571802, 0.26836782, 0. , 0. ]])
|
| 853 |
+
|
| 854 |
+
You can check distances above the `max_distance` are zeros:
|
| 855 |
+
|
| 856 |
+
>>> from scipy.spatial import distance_matrix
|
| 857 |
+
>>> distance_matrix(points1, points2)
|
| 858 |
+
array([[0.56906522, 0.39923701, 0.12295571, 0.8658745 , 0.79428925],
|
| 859 |
+
[0.37327919, 0.7225693 , 0.87665969, 0.32580855, 0.75679479],
|
| 860 |
+
[0.28942611, 0.30088013, 0.6395831 , 0.2333084 , 0.33630734],
|
| 861 |
+
[0.31994999, 0.72658602, 0.71124834, 0.55396483, 0.90785663],
|
| 862 |
+
[0.24617575, 0.29571802, 0.26836782, 0.57714465, 0.6473269 ]])
|
| 863 |
+
|
| 864 |
+
"""
|
| 865 |
+
return super().sparse_distance_matrix(
|
| 866 |
+
other, max_distance, p, output_type)
|
| 867 |
+
|
| 868 |
+
|
| 869 |
+
def distance_matrix(x, y, p=2, threshold=1000000):
|
| 870 |
+
"""Compute the distance matrix.
|
| 871 |
+
|
| 872 |
+
Returns the matrix of all pair-wise distances.
|
| 873 |
+
|
| 874 |
+
Parameters
|
| 875 |
+
----------
|
| 876 |
+
x : (M, K) array_like
|
| 877 |
+
Matrix of M vectors in K dimensions.
|
| 878 |
+
y : (N, K) array_like
|
| 879 |
+
Matrix of N vectors in K dimensions.
|
| 880 |
+
p : float, 1 <= p <= infinity
|
| 881 |
+
Which Minkowski p-norm to use.
|
| 882 |
+
threshold : positive int
|
| 883 |
+
If ``M * N * K`` > `threshold`, algorithm uses a Python loop instead
|
| 884 |
+
of large temporary arrays.
|
| 885 |
+
|
| 886 |
+
Returns
|
| 887 |
+
-------
|
| 888 |
+
result : (M, N) ndarray
|
| 889 |
+
Matrix containing the distance from every vector in `x` to every vector
|
| 890 |
+
in `y`.
|
| 891 |
+
|
| 892 |
+
Examples
|
| 893 |
+
--------
|
| 894 |
+
>>> from scipy.spatial import distance_matrix
|
| 895 |
+
>>> distance_matrix([[0,0],[0,1]], [[1,0],[1,1]])
|
| 896 |
+
array([[ 1. , 1.41421356],
|
| 897 |
+
[ 1.41421356, 1. ]])
|
| 898 |
+
|
| 899 |
+
"""
|
| 900 |
+
|
| 901 |
+
x = np.asarray(x)
|
| 902 |
+
m, k = x.shape
|
| 903 |
+
y = np.asarray(y)
|
| 904 |
+
n, kk = y.shape
|
| 905 |
+
|
| 906 |
+
if k != kk:
|
| 907 |
+
raise ValueError(f"x contains {k}-dimensional vectors but y contains "
|
| 908 |
+
f"{kk}-dimensional vectors")
|
| 909 |
+
|
| 910 |
+
if m*n*k <= threshold:
|
| 911 |
+
return minkowski_distance(x[:,np.newaxis,:],y[np.newaxis,:,:],p)
|
| 912 |
+
else:
|
| 913 |
+
result = np.empty((m,n),dtype=float) # FIXME: figure out the best dtype
|
| 914 |
+
if m < n:
|
| 915 |
+
for i in range(m):
|
| 916 |
+
result[i,:] = minkowski_distance(x[i],y,p)
|
| 917 |
+
else:
|
| 918 |
+
for j in range(n):
|
| 919 |
+
result[:,j] = minkowski_distance(x,y[j],p)
|
| 920 |
+
return result
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/_procrustes.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This module provides functions to perform full Procrustes analysis.
|
| 3 |
+
|
| 4 |
+
This code was originally written by Justin Kucynski and ported over from
|
| 5 |
+
scikit-bio by Yoshiki Vazquez-Baeza.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import numpy as np
|
| 9 |
+
from scipy.linalg import orthogonal_procrustes
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
__all__ = ['procrustes']
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def procrustes(data1, data2):
|
| 16 |
+
r"""Procrustes analysis, a similarity test for two data sets.
|
| 17 |
+
|
| 18 |
+
Each input matrix is a set of points or vectors (the rows of the matrix).
|
| 19 |
+
The dimension of the space is the number of columns of each matrix. Given
|
| 20 |
+
two identically sized matrices, procrustes standardizes both such that:
|
| 21 |
+
|
| 22 |
+
- :math:`tr(AA^{T}) = 1`.
|
| 23 |
+
|
| 24 |
+
- Both sets of points are centered around the origin.
|
| 25 |
+
|
| 26 |
+
Procrustes ([1]_, [2]_) then applies the optimal transform to the second
|
| 27 |
+
matrix (including scaling/dilation, rotations, and reflections) to minimize
|
| 28 |
+
:math:`M^{2}=\sum(data1-data2)^{2}`, or the sum of the squares of the
|
| 29 |
+
pointwise differences between the two input datasets.
|
| 30 |
+
|
| 31 |
+
This function was not designed to handle datasets with different numbers of
|
| 32 |
+
datapoints (rows). If two data sets have different dimensionality
|
| 33 |
+
(different number of columns), simply add columns of zeros to the smaller
|
| 34 |
+
of the two.
|
| 35 |
+
|
| 36 |
+
Parameters
|
| 37 |
+
----------
|
| 38 |
+
data1 : array_like
|
| 39 |
+
Matrix, n rows represent points in k (columns) space `data1` is the
|
| 40 |
+
reference data, after it is standardised, the data from `data2` will be
|
| 41 |
+
transformed to fit the pattern in `data1` (must have >1 unique points).
|
| 42 |
+
data2 : array_like
|
| 43 |
+
n rows of data in k space to be fit to `data1`. Must be the same
|
| 44 |
+
shape ``(numrows, numcols)`` as data1 (must have >1 unique points).
|
| 45 |
+
|
| 46 |
+
Returns
|
| 47 |
+
-------
|
| 48 |
+
mtx1 : array_like
|
| 49 |
+
A standardized version of `data1`.
|
| 50 |
+
mtx2 : array_like
|
| 51 |
+
The orientation of `data2` that best fits `data1`. Centered, but not
|
| 52 |
+
necessarily :math:`tr(AA^{T}) = 1`.
|
| 53 |
+
disparity : float
|
| 54 |
+
:math:`M^{2}` as defined above.
|
| 55 |
+
|
| 56 |
+
Raises
|
| 57 |
+
------
|
| 58 |
+
ValueError
|
| 59 |
+
If the input arrays are not two-dimensional.
|
| 60 |
+
If the shape of the input arrays is different.
|
| 61 |
+
If the input arrays have zero columns or zero rows.
|
| 62 |
+
|
| 63 |
+
See Also
|
| 64 |
+
--------
|
| 65 |
+
scipy.linalg.orthogonal_procrustes
|
| 66 |
+
scipy.spatial.distance.directed_hausdorff : Another similarity test
|
| 67 |
+
for two data sets
|
| 68 |
+
|
| 69 |
+
Notes
|
| 70 |
+
-----
|
| 71 |
+
- The disparity should not depend on the order of the input matrices, but
|
| 72 |
+
the output matrices will, as only the first output matrix is guaranteed
|
| 73 |
+
to be scaled such that :math:`tr(AA^{T}) = 1`.
|
| 74 |
+
|
| 75 |
+
- Duplicate data points are generally ok, duplicating a data point will
|
| 76 |
+
increase its effect on the procrustes fit.
|
| 77 |
+
|
| 78 |
+
- The disparity scales as the number of points per input matrix.
|
| 79 |
+
|
| 80 |
+
References
|
| 81 |
+
----------
|
| 82 |
+
.. [1] Krzanowski, W. J. (2000). "Principles of Multivariate analysis".
|
| 83 |
+
.. [2] Gower, J. C. (1975). "Generalized procrustes analysis".
|
| 84 |
+
|
| 85 |
+
Examples
|
| 86 |
+
--------
|
| 87 |
+
>>> import numpy as np
|
| 88 |
+
>>> from scipy.spatial import procrustes
|
| 89 |
+
|
| 90 |
+
The matrix ``b`` is a rotated, shifted, scaled and mirrored version of
|
| 91 |
+
``a`` here:
|
| 92 |
+
|
| 93 |
+
>>> a = np.array([[1, 3], [1, 2], [1, 1], [2, 1]], 'd')
|
| 94 |
+
>>> b = np.array([[4, -2], [4, -4], [4, -6], [2, -6]], 'd')
|
| 95 |
+
>>> mtx1, mtx2, disparity = procrustes(a, b)
|
| 96 |
+
>>> round(disparity)
|
| 97 |
+
0.0
|
| 98 |
+
|
| 99 |
+
"""
|
| 100 |
+
mtx1 = np.array(data1, dtype=np.float64, copy=True)
|
| 101 |
+
mtx2 = np.array(data2, dtype=np.float64, copy=True)
|
| 102 |
+
|
| 103 |
+
if mtx1.ndim != 2 or mtx2.ndim != 2:
|
| 104 |
+
raise ValueError("Input matrices must be two-dimensional")
|
| 105 |
+
if mtx1.shape != mtx2.shape:
|
| 106 |
+
raise ValueError("Input matrices must be of same shape")
|
| 107 |
+
if mtx1.size == 0:
|
| 108 |
+
raise ValueError("Input matrices must be >0 rows and >0 cols")
|
| 109 |
+
|
| 110 |
+
# translate all the data to the origin
|
| 111 |
+
mtx1 -= np.mean(mtx1, 0)
|
| 112 |
+
mtx2 -= np.mean(mtx2, 0)
|
| 113 |
+
|
| 114 |
+
norm1 = np.linalg.norm(mtx1)
|
| 115 |
+
norm2 = np.linalg.norm(mtx2)
|
| 116 |
+
|
| 117 |
+
if norm1 == 0 or norm2 == 0:
|
| 118 |
+
raise ValueError("Input matrices must contain >1 unique points")
|
| 119 |
+
|
| 120 |
+
# change scaling of data (in rows) such that trace(mtx*mtx') = 1
|
| 121 |
+
mtx1 /= norm1
|
| 122 |
+
mtx2 /= norm2
|
| 123 |
+
|
| 124 |
+
# transform mtx2 to minimize disparity
|
| 125 |
+
R, s = orthogonal_procrustes(mtx1, mtx2)
|
| 126 |
+
mtx2 = np.dot(mtx2, R.T) * s
|
| 127 |
+
|
| 128 |
+
# measure the dissimilarity between the two datasets
|
| 129 |
+
disparity = np.sum(np.square(mtx1 - mtx2))
|
| 130 |
+
|
| 131 |
+
return mtx1, mtx2, disparity
|
| 132 |
+
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/_qhull.pyi
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
Static type checking stub file for scipy/spatial/qhull.pyx
|
| 3 |
+
'''
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
from numpy.typing import ArrayLike, NDArray
|
| 8 |
+
from typing_extensions import final
|
| 9 |
+
|
| 10 |
+
class QhullError(RuntimeError):
|
| 11 |
+
...
|
| 12 |
+
|
| 13 |
+
@final
|
| 14 |
+
class _Qhull:
|
| 15 |
+
# Read-only cython attribute that behaves, more or less, like a property
|
| 16 |
+
@property
|
| 17 |
+
def ndim(self) -> int: ...
|
| 18 |
+
mode_option: bytes
|
| 19 |
+
options: bytes
|
| 20 |
+
furthest_site: bool
|
| 21 |
+
|
| 22 |
+
def __init__(
|
| 23 |
+
self,
|
| 24 |
+
mode_option: bytes,
|
| 25 |
+
points: NDArray[np.float64],
|
| 26 |
+
options: None | bytes = ...,
|
| 27 |
+
required_options: None | bytes = ...,
|
| 28 |
+
furthest_site: bool = ...,
|
| 29 |
+
incremental: bool = ...,
|
| 30 |
+
interior_point: None | NDArray[np.float64] = ...,
|
| 31 |
+
) -> None: ...
|
| 32 |
+
def check_active(self) -> None: ...
|
| 33 |
+
def close(self) -> None: ...
|
| 34 |
+
def get_points(self) -> NDArray[np.float64]: ...
|
| 35 |
+
def add_points(
|
| 36 |
+
self,
|
| 37 |
+
points: ArrayLike,
|
| 38 |
+
interior_point: ArrayLike = ...
|
| 39 |
+
) -> None: ...
|
| 40 |
+
def get_paraboloid_shift_scale(self) -> tuple[float, float]: ...
|
| 41 |
+
def volume_area(self) -> tuple[float, float]: ...
|
| 42 |
+
def triangulate(self) -> None: ...
|
| 43 |
+
def get_simplex_facet_array(self) -> tuple[
|
| 44 |
+
NDArray[np.intc],
|
| 45 |
+
NDArray[np.intc],
|
| 46 |
+
NDArray[np.float64],
|
| 47 |
+
NDArray[np.intc],
|
| 48 |
+
NDArray[np.intc],
|
| 49 |
+
]: ...
|
| 50 |
+
def get_hull_points(self) -> NDArray[np.float64]: ...
|
| 51 |
+
def get_hull_facets(self) -> tuple[
|
| 52 |
+
list[list[int]],
|
| 53 |
+
NDArray[np.float64],
|
| 54 |
+
]: ...
|
| 55 |
+
def get_voronoi_diagram(self) -> tuple[
|
| 56 |
+
NDArray[np.float64],
|
| 57 |
+
NDArray[np.intc],
|
| 58 |
+
list[list[int]],
|
| 59 |
+
list[list[int]],
|
| 60 |
+
NDArray[np.intp],
|
| 61 |
+
]: ...
|
| 62 |
+
def get_extremes_2d(self) -> NDArray[np.intc]: ...
|
| 63 |
+
|
| 64 |
+
def _get_barycentric_transforms(
|
| 65 |
+
points: NDArray[np.float64],
|
| 66 |
+
simplices: NDArray[np.intc],
|
| 67 |
+
eps: float
|
| 68 |
+
) -> NDArray[np.float64]: ...
|
| 69 |
+
|
| 70 |
+
class _QhullUser:
|
| 71 |
+
ndim: int
|
| 72 |
+
npoints: int
|
| 73 |
+
min_bound: NDArray[np.float64]
|
| 74 |
+
max_bound: NDArray[np.float64]
|
| 75 |
+
|
| 76 |
+
def __init__(self, qhull: _Qhull, incremental: bool = ...) -> None: ...
|
| 77 |
+
def close(self) -> None: ...
|
| 78 |
+
def _update(self, qhull: _Qhull) -> None: ...
|
| 79 |
+
def _add_points(
|
| 80 |
+
self,
|
| 81 |
+
points: ArrayLike,
|
| 82 |
+
restart: bool = ...,
|
| 83 |
+
interior_point: ArrayLike = ...
|
| 84 |
+
) -> None: ...
|
| 85 |
+
|
| 86 |
+
class Delaunay(_QhullUser):
|
| 87 |
+
furthest_site: bool
|
| 88 |
+
paraboloid_scale: float
|
| 89 |
+
paraboloid_shift: float
|
| 90 |
+
simplices: NDArray[np.intc]
|
| 91 |
+
neighbors: NDArray[np.intc]
|
| 92 |
+
equations: NDArray[np.float64]
|
| 93 |
+
coplanar: NDArray[np.intc]
|
| 94 |
+
good: NDArray[np.intc]
|
| 95 |
+
nsimplex: int
|
| 96 |
+
vertices: NDArray[np.intc]
|
| 97 |
+
|
| 98 |
+
def __init__(
|
| 99 |
+
self,
|
| 100 |
+
points: ArrayLike,
|
| 101 |
+
furthest_site: bool = ...,
|
| 102 |
+
incremental: bool = ...,
|
| 103 |
+
qhull_options: None | str = ...
|
| 104 |
+
) -> None: ...
|
| 105 |
+
def _update(self, qhull: _Qhull) -> None: ...
|
| 106 |
+
def add_points(
|
| 107 |
+
self,
|
| 108 |
+
points: ArrayLike,
|
| 109 |
+
restart: bool = ...
|
| 110 |
+
) -> None: ...
|
| 111 |
+
@property
|
| 112 |
+
def points(self) -> NDArray[np.float64]: ...
|
| 113 |
+
@property
|
| 114 |
+
def transform(self) -> NDArray[np.float64]: ...
|
| 115 |
+
@property
|
| 116 |
+
def vertex_to_simplex(self) -> NDArray[np.intc]: ...
|
| 117 |
+
@property
|
| 118 |
+
def vertex_neighbor_vertices(self) -> tuple[
|
| 119 |
+
NDArray[np.intc],
|
| 120 |
+
NDArray[np.intc],
|
| 121 |
+
]: ...
|
| 122 |
+
@property
|
| 123 |
+
def convex_hull(self) -> NDArray[np.intc]: ...
|
| 124 |
+
def find_simplex(
|
| 125 |
+
self,
|
| 126 |
+
xi: ArrayLike,
|
| 127 |
+
bruteforce: bool = ...,
|
| 128 |
+
tol: float = ...
|
| 129 |
+
) -> NDArray[np.intc]: ...
|
| 130 |
+
def plane_distance(self, xi: ArrayLike) -> NDArray[np.float64]: ...
|
| 131 |
+
def lift_points(self, x: ArrayLike) -> NDArray[np.float64]: ...
|
| 132 |
+
|
| 133 |
+
def tsearch(tri: Delaunay, xi: ArrayLike) -> NDArray[np.intc]: ...
|
| 134 |
+
def _copy_docstr(dst: object, src: object) -> None: ...
|
| 135 |
+
|
| 136 |
+
class ConvexHull(_QhullUser):
|
| 137 |
+
simplices: NDArray[np.intc]
|
| 138 |
+
neighbors: NDArray[np.intc]
|
| 139 |
+
equations: NDArray[np.float64]
|
| 140 |
+
coplanar: NDArray[np.intc]
|
| 141 |
+
good: None | NDArray[np.bool_]
|
| 142 |
+
volume: float
|
| 143 |
+
area: float
|
| 144 |
+
nsimplex: int
|
| 145 |
+
|
| 146 |
+
def __init__(
|
| 147 |
+
self,
|
| 148 |
+
points: ArrayLike,
|
| 149 |
+
incremental: bool = ...,
|
| 150 |
+
qhull_options: None | str = ...
|
| 151 |
+
) -> None: ...
|
| 152 |
+
def _update(self, qhull: _Qhull) -> None: ...
|
| 153 |
+
def add_points(self, points: ArrayLike,
|
| 154 |
+
restart: bool = ...) -> None: ...
|
| 155 |
+
@property
|
| 156 |
+
def points(self) -> NDArray[np.float64]: ...
|
| 157 |
+
@property
|
| 158 |
+
def vertices(self) -> NDArray[np.intc]: ...
|
| 159 |
+
|
| 160 |
+
class Voronoi(_QhullUser):
|
| 161 |
+
vertices: NDArray[np.float64]
|
| 162 |
+
ridge_points: NDArray[np.intc]
|
| 163 |
+
ridge_vertices: list[list[int]]
|
| 164 |
+
regions: list[list[int]]
|
| 165 |
+
point_region: NDArray[np.intp]
|
| 166 |
+
furthest_site: bool
|
| 167 |
+
|
| 168 |
+
def __init__(
|
| 169 |
+
self,
|
| 170 |
+
points: ArrayLike,
|
| 171 |
+
furthest_site: bool = ...,
|
| 172 |
+
incremental: bool = ...,
|
| 173 |
+
qhull_options: None | str = ...
|
| 174 |
+
) -> None: ...
|
| 175 |
+
def _update(self, qhull: _Qhull) -> None: ...
|
| 176 |
+
def add_points(
|
| 177 |
+
self,
|
| 178 |
+
points: ArrayLike,
|
| 179 |
+
restart: bool = ...
|
| 180 |
+
) -> None: ...
|
| 181 |
+
@property
|
| 182 |
+
def points(self) -> NDArray[np.float64]: ...
|
| 183 |
+
@property
|
| 184 |
+
def ridge_dict(self) -> dict[tuple[int, int], list[int]]: ...
|
| 185 |
+
|
| 186 |
+
class HalfspaceIntersection(_QhullUser):
|
| 187 |
+
interior_point: NDArray[np.float64]
|
| 188 |
+
dual_facets: list[list[int]]
|
| 189 |
+
dual_equations: NDArray[np.float64]
|
| 190 |
+
dual_points: NDArray[np.float64]
|
| 191 |
+
dual_volume: float
|
| 192 |
+
dual_area: float
|
| 193 |
+
intersections: NDArray[np.float64]
|
| 194 |
+
ndim: int
|
| 195 |
+
nineq: int
|
| 196 |
+
|
| 197 |
+
def __init__(
|
| 198 |
+
self,
|
| 199 |
+
halfspaces: ArrayLike,
|
| 200 |
+
interior_point: ArrayLike,
|
| 201 |
+
incremental: bool = ...,
|
| 202 |
+
qhull_options: None | str = ...
|
| 203 |
+
) -> None: ...
|
| 204 |
+
def _update(self, qhull: _Qhull) -> None: ...
|
| 205 |
+
def add_halfspaces(
|
| 206 |
+
self,
|
| 207 |
+
halfspaces: ArrayLike,
|
| 208 |
+
restart: bool = ...
|
| 209 |
+
) -> None: ...
|
| 210 |
+
@property
|
| 211 |
+
def halfspaces(self) -> NDArray[np.float64]: ...
|
| 212 |
+
@property
|
| 213 |
+
def dual_vertices(self) -> NDArray[np.integer]: ...
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/_voronoi.pyi
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
def sort_vertices_of_regions(simplices: np.ndarray, regions: list[list[int]]) -> None: ... # noqa: E501
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/distance.pyi
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
from typing import (overload, Any, SupportsFloat, Literal, Protocol, SupportsIndex)
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
from numpy.typing import ArrayLike, NDArray
|
| 6 |
+
|
| 7 |
+
# Anything that can be parsed by `np.float64.__init__` and is thus
|
| 8 |
+
# compatible with `ndarray.__setitem__` (for a float64 array)
|
| 9 |
+
_FloatValue = None | str | bytes | SupportsFloat | SupportsIndex
|
| 10 |
+
|
| 11 |
+
class _MetricCallback1(Protocol):
|
| 12 |
+
def __call__(
|
| 13 |
+
self, __XA: NDArray[Any], __XB: NDArray[Any]
|
| 14 |
+
) -> _FloatValue: ...
|
| 15 |
+
|
| 16 |
+
class _MetricCallback2(Protocol):
|
| 17 |
+
def __call__(
|
| 18 |
+
self, __XA: NDArray[Any], __XB: NDArray[Any], **kwargs: Any
|
| 19 |
+
) -> _FloatValue: ...
|
| 20 |
+
|
| 21 |
+
# TODO: Use a single protocol with a parameter specification variable
|
| 22 |
+
# once available (PEP 612)
|
| 23 |
+
_MetricCallback = _MetricCallback1 | _MetricCallback2
|
| 24 |
+
|
| 25 |
+
_MetricKind = Literal[
|
| 26 |
+
'braycurtis',
|
| 27 |
+
'canberra',
|
| 28 |
+
'chebychev', 'chebyshev', 'cheby', 'cheb', 'ch',
|
| 29 |
+
'cityblock', 'cblock', 'cb', 'c',
|
| 30 |
+
'correlation', 'co',
|
| 31 |
+
'cosine', 'cos',
|
| 32 |
+
'dice',
|
| 33 |
+
'euclidean', 'euclid', 'eu', 'e',
|
| 34 |
+
'hamming', 'hamm', 'ha', 'h',
|
| 35 |
+
'minkowski', 'mi', 'm', 'pnorm',
|
| 36 |
+
'jaccard', 'jacc', 'ja', 'j',
|
| 37 |
+
'jensenshannon', 'js',
|
| 38 |
+
'kulczynski1',
|
| 39 |
+
'mahalanobis', 'mahal', 'mah',
|
| 40 |
+
'rogerstanimoto',
|
| 41 |
+
'russellrao',
|
| 42 |
+
'seuclidean', 'se', 's',
|
| 43 |
+
'sokalmichener',
|
| 44 |
+
'sokalsneath',
|
| 45 |
+
'sqeuclidean', 'sqe', 'sqeuclid',
|
| 46 |
+
'yule',
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
# Function annotations
|
| 50 |
+
|
| 51 |
+
def braycurtis(
|
| 52 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 53 |
+
) -> np.float64: ...
|
| 54 |
+
|
| 55 |
+
def canberra(
|
| 56 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 57 |
+
) -> np.float64: ...
|
| 58 |
+
|
| 59 |
+
# TODO: Add `metric`-specific overloads
|
| 60 |
+
# Returns a float64 or float128 array, depending on the input dtype
|
| 61 |
+
@overload
|
| 62 |
+
def cdist(
|
| 63 |
+
XA: ArrayLike,
|
| 64 |
+
XB: ArrayLike,
|
| 65 |
+
metric: _MetricKind = ...,
|
| 66 |
+
*,
|
| 67 |
+
out: None | NDArray[np.floating[Any]] = ...,
|
| 68 |
+
p: float = ...,
|
| 69 |
+
w: ArrayLike | None = ...,
|
| 70 |
+
V: ArrayLike | None = ...,
|
| 71 |
+
VI: ArrayLike | None = ...,
|
| 72 |
+
) -> NDArray[np.floating[Any]]: ...
|
| 73 |
+
@overload
|
| 74 |
+
def cdist(
|
| 75 |
+
XA: ArrayLike,
|
| 76 |
+
XB: ArrayLike,
|
| 77 |
+
metric: _MetricCallback,
|
| 78 |
+
*,
|
| 79 |
+
out: None | NDArray[np.floating[Any]] = ...,
|
| 80 |
+
**kwargs: Any,
|
| 81 |
+
) -> NDArray[np.floating[Any]]: ...
|
| 82 |
+
|
| 83 |
+
# TODO: Wait for dtype support; the return type is
|
| 84 |
+
# dependent on the input arrays dtype
|
| 85 |
+
def chebyshev(
|
| 86 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 87 |
+
) -> Any: ...
|
| 88 |
+
|
| 89 |
+
# TODO: Wait for dtype support; the return type is
|
| 90 |
+
# dependent on the input arrays dtype
|
| 91 |
+
def cityblock(
|
| 92 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 93 |
+
) -> Any: ...
|
| 94 |
+
|
| 95 |
+
def correlation(
|
| 96 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ..., centered: bool = ...
|
| 97 |
+
) -> np.float64: ...
|
| 98 |
+
|
| 99 |
+
def cosine(
|
| 100 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 101 |
+
) -> np.float64: ...
|
| 102 |
+
|
| 103 |
+
def dice(
|
| 104 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 105 |
+
) -> float: ...
|
| 106 |
+
|
| 107 |
+
def directed_hausdorff(
|
| 108 |
+
u: ArrayLike, v: ArrayLike, seed: int | None = ...
|
| 109 |
+
) -> tuple[float, int, int]: ...
|
| 110 |
+
|
| 111 |
+
def euclidean(
|
| 112 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 113 |
+
) -> float: ...
|
| 114 |
+
|
| 115 |
+
def hamming(
|
| 116 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 117 |
+
) -> np.float64: ...
|
| 118 |
+
|
| 119 |
+
def is_valid_dm(
|
| 120 |
+
D: ArrayLike,
|
| 121 |
+
tol: float = ...,
|
| 122 |
+
throw: bool = ...,
|
| 123 |
+
name: str | None = ...,
|
| 124 |
+
warning: bool = ...,
|
| 125 |
+
) -> bool: ...
|
| 126 |
+
|
| 127 |
+
def is_valid_y(
|
| 128 |
+
y: ArrayLike,
|
| 129 |
+
warning: bool = ...,
|
| 130 |
+
throw: bool = ...,
|
| 131 |
+
name: str | None = ...,
|
| 132 |
+
) -> bool: ...
|
| 133 |
+
|
| 134 |
+
def jaccard(
|
| 135 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 136 |
+
) -> np.float64: ...
|
| 137 |
+
|
| 138 |
+
def jensenshannon(
|
| 139 |
+
p: ArrayLike, q: ArrayLike, base: float | None = ...
|
| 140 |
+
) -> np.float64: ...
|
| 141 |
+
|
| 142 |
+
def kulczynski1(
|
| 143 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 144 |
+
) -> np.float64: ...
|
| 145 |
+
|
| 146 |
+
def mahalanobis(
|
| 147 |
+
u: ArrayLike, v: ArrayLike, VI: ArrayLike
|
| 148 |
+
) -> np.float64: ...
|
| 149 |
+
|
| 150 |
+
def minkowski(
|
| 151 |
+
u: ArrayLike, v: ArrayLike, p: float = ..., w: ArrayLike | None = ...
|
| 152 |
+
) -> float: ...
|
| 153 |
+
|
| 154 |
+
def num_obs_dm(d: ArrayLike) -> int: ...
|
| 155 |
+
|
| 156 |
+
def num_obs_y(Y: ArrayLike) -> int: ...
|
| 157 |
+
|
| 158 |
+
# TODO: Add `metric`-specific overloads
|
| 159 |
+
@overload
|
| 160 |
+
def pdist(
|
| 161 |
+
X: ArrayLike,
|
| 162 |
+
metric: _MetricKind = ...,
|
| 163 |
+
*,
|
| 164 |
+
out: None | NDArray[np.floating[Any]] = ...,
|
| 165 |
+
p: float = ...,
|
| 166 |
+
w: ArrayLike | None = ...,
|
| 167 |
+
V: ArrayLike | None = ...,
|
| 168 |
+
VI: ArrayLike | None = ...,
|
| 169 |
+
) -> NDArray[np.floating[Any]]: ...
|
| 170 |
+
@overload
|
| 171 |
+
def pdist(
|
| 172 |
+
X: ArrayLike,
|
| 173 |
+
metric: _MetricCallback,
|
| 174 |
+
*,
|
| 175 |
+
out: None | NDArray[np.floating[Any]] = ...,
|
| 176 |
+
**kwargs: Any,
|
| 177 |
+
) -> NDArray[np.floating[Any]]: ...
|
| 178 |
+
|
| 179 |
+
def seuclidean(
|
| 180 |
+
u: ArrayLike, v: ArrayLike, V: ArrayLike
|
| 181 |
+
) -> float: ...
|
| 182 |
+
|
| 183 |
+
def sokalmichener(
|
| 184 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 185 |
+
) -> float: ...
|
| 186 |
+
|
| 187 |
+
def sokalsneath(
|
| 188 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 189 |
+
) -> np.float64: ...
|
| 190 |
+
|
| 191 |
+
def sqeuclidean(
|
| 192 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 193 |
+
) -> np.float64: ...
|
| 194 |
+
|
| 195 |
+
def squareform(
|
| 196 |
+
X: ArrayLike,
|
| 197 |
+
force: Literal["no", "tomatrix", "tovector"] = ...,
|
| 198 |
+
checks: bool = ...,
|
| 199 |
+
) -> NDArray[Any]: ...
|
| 200 |
+
|
| 201 |
+
def rogerstanimoto(
|
| 202 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 203 |
+
) -> float: ...
|
| 204 |
+
|
| 205 |
+
def russellrao(
|
| 206 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 207 |
+
) -> float: ...
|
| 208 |
+
|
| 209 |
+
def yule(
|
| 210 |
+
u: ArrayLike, v: ArrayLike, w: ArrayLike | None = ...
|
| 211 |
+
) -> float: ...
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/qhull.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is not meant for public use and will be removed in SciPy v2.0.0.
|
| 2 |
+
# Use the `scipy.spatial` namespace for importing the functions
|
| 3 |
+
# included below.
|
| 4 |
+
|
| 5 |
+
from scipy._lib.deprecation import _sub_module_deprecation
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
__all__ = [ # noqa: F822
|
| 9 |
+
'ConvexHull',
|
| 10 |
+
'Delaunay',
|
| 11 |
+
'HalfspaceIntersection',
|
| 12 |
+
'QhullError',
|
| 13 |
+
'Voronoi',
|
| 14 |
+
'tsearch',
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def __dir__():
|
| 19 |
+
return __all__
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def __getattr__(name):
|
| 23 |
+
return _sub_module_deprecation(sub_package="spatial", module="qhull",
|
| 24 |
+
private_modules=["_qhull"], all=__all__,
|
| 25 |
+
attribute=name)
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (177 Bytes). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/__pycache__/test__plotutils.cpython-310.pyc
ADDED
|
Binary file (2.87 kB). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/__pycache__/test_distance.cpython-310.pyc
ADDED
|
Binary file (70.1 kB). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/__pycache__/test_qhull.cpython-310.pyc
ADDED
|
Binary file (33.2 kB). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/__pycache__/test_slerp.cpython-310.pyc
ADDED
|
Binary file (9.32 kB). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/__pycache__/test_spherical_voronoi.cpython-310.pyc
ADDED
|
Binary file (13.6 kB). View file
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/data/cdist-X2.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
7.680465556300619667e-02 4.675022344069014180e-01 8.955498989131543963e-01 3.816236071436276411e-01 1.109030077070989329e-01 2.318928815459808668e-02 7.477394240984251983e-01 1.202289789304434864e-01 8.007290497575981769e-01 6.795195698871731027e-01 6.568225762396605605e-01 2.231475263228478445e-01 7.064624077661341151e-02 1.081656666815267176e-02 1.592069359090128033e-01 1.363392203645097389e-01 9.277020735447568667e-01 8.103136564528209407e-01 5.229467676276455812e-02 7.708020259874025504e-01 6.527954747473352359e-02 5.516397414886525796e-01 3.653371861367954443e-01
|
| 2 |
+
8.144399106025798085e-01 7.731852525462976633e-01 6.909477620673205589e-01 9.696063817000286633e-01 4.297887511677249694e-01 6.989600553425188156e-01 7.310201335033380543e-01 3.135256147868910048e-01 5.715578037275241829e-01 3.935000744675094531e-01 2.057715781268398825e-01 5.892508589665171881e-01 8.512951599236765476e-01 9.569808799061578775e-01 6.164885878024699561e-01 4.714185430004367294e-01 6.128831737628155363e-01 6.641799309623502845e-01 6.001985185338730711e-01 4.231922889723856995e-01 7.605249308075449077e-01 1.064530958018087281e-01 6.306470691957204444e-01
|
| 3 |
+
4.265470127256254518e-01 5.933766716280767239e-01 3.698589270536845053e-02 2.173799740537294412e-01 3.032679325475639009e-01 4.271831790058847611e-01 1.828944535901013690e-01 4.772333422710156592e-01 2.564773455194128138e-01 7.120329875362141347e-01 8.952243430110462530e-01 1.808777012183288013e-01 3.612151871458374464e-01 3.960999167923041631e-01 1.821669970670747318e-02 8.835474857189200559e-01 1.353104648821573663e-01 3.457291739160937016e-01 1.126467375304566199e-01 4.107293162402323450e-01 4.051719311053743056e-01 4.007382985250427243e-01 1.286905671428811848e-01
|
| 4 |
+
2.910657003883979632e-01 9.616259180685315933e-03 2.033032441536681834e-01 1.096599110293863255e-01 4.191101704605176836e-01 5.462131536027151624e-01 8.393047907010142694e-01 9.046805198676335369e-01 7.009863472176891541e-01 2.508215985039629059e-01 6.754410796667598138e-01 6.740895474032024826e-01 1.358993708621679675e-01 8.219861775211464439e-01 6.322220445623235596e-01 2.766813559002430090e-01 6.575983861590951607e-01 9.515869708336625044e-01 8.654526462353933081e-01 3.450245117834797037e-01 5.649032890631299209e-01 4.717687914789682191e-01 3.296483580510030098e-01
|
| 5 |
+
9.172477457635394016e-01 3.057396583041891436e-01 7.335332344225760082e-01 8.370236206345178509e-01 3.765464253115927695e-01 5.089680319287778199e-01 1.202325719268168003e-01 9.717771065272349240e-01 5.907820104019682050e-01 9.809211614977710880e-01 9.064285003671219698e-01 8.848841466121748489e-01 2.043407730734815297e-01 9.157600394927275511e-01 4.532260315147775831e-01 4.241077335005828397e-01 1.751730149568804240e-01 4.090412146081819911e-01 3.632197861847064058e-02 5.832539334970230360e-01 4.041848151536805434e-01 3.603643989086504629e-01 1.838411383882069261e-01
|
| 6 |
+
2.508806403290032572e-01 4.381403985282813496e-01 4.694787405018008286e-02 6.353900562024634713e-01 1.200813444244532846e-01 6.072397042913001419e-01 9.937255904754030977e-01 4.916670237677555066e-01 3.473845913923001572e-01 3.526875922864345370e-01 5.448595548197197047e-01 2.245096010156972799e-01 9.003258279804994269e-01 3.534560469735994470e-01 2.989266066346342177e-01 4.621024982808636938e-01 9.626538866576676012e-01 9.791401720716153001e-01 7.138514287330390840e-01 9.832862333928654719e-01 3.233999591031431198e-01 5.406467224926423398e-01 9.581890295057201579e-01
|
| 7 |
+
5.210583601680578436e-01 4.598159993059653949e-01 2.111497132057748027e-01 5.949977700916546652e-01 6.342618461422359077e-01 9.888228769705599275e-01 6.096770711536318998e-01 7.548431368960863974e-01 7.490858664860100546e-01 3.186213496546415058e-01 7.895687083231245351e-01 4.178326793268141159e-01 8.095818334534051752e-01 7.886271673523481684e-01 4.038905626506847923e-01 3.652649247094948981e-01 8.267205959224892542e-01 6.433617243328785262e-01 3.117681563249452559e-01 9.675995575054980868e-01 3.675673836358472890e-01 5.863757289184046151e-01 9.099029857959717305e-02
|
| 8 |
+
4.024573981231733821e-01 3.578997554002771864e-01 3.519299868071553705e-01 7.417747693762357653e-01 2.963713903285800644e-01 9.602967989298948348e-01 3.811392331739601458e-01 5.493237898295448840e-01 6.835113342793640578e-01 2.304506220807415184e-01 3.727299857731285471e-01 5.450263991912108752e-01 6.951521210987908761e-01 6.474582745861203747e-01 6.316089475403589004e-01 5.672043967425510758e-02 9.034937506977609445e-01 2.332567550780038079e-01 1.096955741449157085e-02 8.870663813493575578e-01 4.384385452180562526e-01 7.100898998169548060e-01 3.245358176196319056e-01
|
| 9 |
+
9.162009194452818139e-01 5.572224742426723498e-02 3.445910686865658601e-01 9.683564008127462097e-01 9.375063149031520604e-01 9.128188852869822956e-02 9.613605414326487075e-01 5.298598697556915482e-01 6.724799695520149445e-01 1.269103938571825019e-02 1.008406153387807480e-01 8.951105272379104028e-01 1.585460318853607609e-01 6.739986455059543413e-01 5.345419321702655768e-01 6.248843899572337213e-01 3.050288488994817859e-01 1.423645553465189284e-01 1.802121190541096096e-01 9.474646822694763326e-01 2.345716438587298613e-01 9.688281784764296578e-01 1.845165243240991515e-01
|
| 10 |
+
2.548297646910531178e-01 2.580877375379494465e-01 1.355482532666937301e-01 6.478812986505504412e-01 9.971695982152032345e-01 2.606721082477282403e-01 5.483439686378906996e-01 4.409612606704470528e-01 4.396442074915688503e-01 7.414262832597111608e-01 7.308840725375539416e-01 8.072095530497225280e-02 6.829509968656330976e-01 5.700030854230387911e-01 3.801845336730320657e-01 2.481059916867158766e-01 3.977295094395927322e-03 5.749480512407895150e-01 4.112033136603401307e-01 8.676159710377848722e-01 9.062646588480167686e-01 3.326691167317923359e-01 8.498307982774666591e-01
|
| 11 |
+
4.464338109330643345e-01 8.546516760817471914e-01 7.384800352329814466e-01 3.692485164984804502e-02 2.915662689505471583e-02 9.010049994217171898e-01 8.622900253010918892e-01 9.786230638032608065e-01 6.546824077297251909e-01 6.342297560006789903e-01 2.230339826582647955e-01 7.658846744185553446e-01 4.603043831539479491e-01 2.017100469861691225e-01 4.891590639893540482e-01 1.937140918314912419e-01 8.161582138652878626e-01 5.597293607114051106e-02 8.423261093326828153e-02 5.105392204475533990e-02 8.234193902673621057e-01 1.784268309975372002e-01 9.118997881986501408e-02
|
| 12 |
+
8.588746913421980711e-01 1.479641118621310980e-02 1.375875301146138874e-01 7.533888774725254756e-01 5.782592791549248101e-01 9.128573037619659436e-01 1.831275762880391067e-01 3.471382864827737835e-01 4.859524740929310749e-02 8.955146541561730400e-01 4.787220791101074457e-01 4.222803577759057791e-01 8.469923964908064873e-01 6.300290047587608910e-02 1.020873237837905956e-01 3.585612487182909813e-02 6.320107119904569970e-01 5.891245970008752719e-01 1.104698053665007507e-01 4.233226558073774903e-01 4.432217054386708988e-01 2.864765416628194394e-01 2.489777211814803159e-02
|
| 13 |
+
5.343810659756068615e-01 4.829076396403546578e-01 8.364480888953172988e-01 8.931374995414760321e-01 6.034161442354715188e-01 3.578336000768178593e-03 4.100579775972763574e-01 3.968667908067096128e-01 5.897163653686778861e-01 3.003241263928478899e-01 2.520935203143799264e-01 3.112129371563532310e-02 9.052865295974613646e-01 1.172285124002711010e-01 4.840001666149388315e-01 3.424620676348436588e-01 5.526057133826853818e-01 6.346139530261846184e-01 5.747945930485597321e-01 1.389915612177697879e-01 2.413801217666421417e-01 7.829900796662081497e-01 7.213528084845653998e-01
|
| 14 |
+
9.384509283406079483e-01 6.303019601671526750e-01 1.787921522728125323e-01 1.556003868047917127e-02 5.662397078816850948e-01 3.437473614806091371e-01 8.615844972800188462e-01 7.624380237306396246e-01 1.096468347898514883e-01 1.276566836610887323e-01 8.479188493443535757e-01 3.634713454428405432e-01 7.478112314318967613e-01 9.856395696968375253e-01 6.250293654177319080e-02 1.919327272501809567e-01 1.415594476031050153e-01 7.224057351041784925e-01 8.452145259310355208e-01 5.434318833772002755e-01 5.177620959731277228e-02 3.358977598185840518e-01 2.542654881527960375e-01
|
| 15 |
+
4.800909104006243489e-01 3.651345393613150137e-01 3.657093052788148446e-01 8.579662326651369408e-01 5.787694361240260932e-01 6.491966196891312268e-01 3.252508517294879775e-01 8.639694334693422961e-01 3.028097078756678551e-01 6.295814666338699350e-01 7.305627351548695803e-01 6.975931849120264872e-03 8.321205159004851915e-01 2.681809305821257761e-01 3.628869474597150591e-01 9.598981434716586936e-01 5.947913523332928332e-01 7.794864238003402779e-01 2.819511239444029149e-01 5.134200958476284882e-01 7.284684743064278045e-01 3.099571109539331903e-01 1.502222882866774967e-01
|
| 16 |
+
2.463382654375219083e-01 4.465700737264240994e-01 7.180855317941433613e-01 5.056099420785193921e-01 6.182117344332578313e-01 2.370453793561340117e-01 9.831748018047525850e-01 6.397098184531551102e-01 8.260469782208745837e-02 7.474671691560941245e-01 9.963429983418570224e-02 5.450078811081275898e-01 5.370188678062637333e-02 2.774024442708808991e-01 2.082643088545442778e-01 2.704155352788065736e-01 7.225035580445194894e-01 4.866791976239246420e-01 1.357043111201584606e-01 7.911335827987711067e-01 7.278977102006007893e-01 6.880892094410231419e-01 1.029231496520791600e-01
|
| 17 |
+
6.901796117735281566e-01 1.558248977395644275e-01 4.241818789360329855e-01 5.055658246392458199e-01 1.756288758075611467e-01 4.215083703818177652e-01 7.809231602323289945e-01 1.170053878686481141e-01 6.497026323614403243e-01 5.733120641440232479e-01 4.407703406152092551e-01 5.608677124532297498e-01 7.471045703286000039e-01 3.334604336022076732e-01 8.927208811415126011e-01 9.794565286182396191e-01 9.621542824973521313e-01 3.945825239405253981e-01 8.338963875792834157e-01 9.310552325082104286e-01 7.688283033784242271e-01 3.798823731047119567e-01 1.459993613028365278e-02
|
| 18 |
+
7.848623555505630511e-01 2.681039365355797344e-03 7.833208051794043891e-01 8.184381915171493604e-01 4.682581645582317709e-01 2.391069309436419932e-01 1.765377537168698607e-01 9.863494676539893424e-01 4.378412300863872009e-01 7.494505491149090481e-01 1.942180356195394308e-01 9.981402467222395547e-01 7.992190944052800505e-01 1.350875702852057936e-01 4.950149186748543650e-01 7.243422481248201761e-01 3.544596746353472216e-01 8.320192561472177228e-01 9.776840296475269865e-01 7.733852731914863110e-01 2.305732998099923048e-01 9.746878189802981041e-01 7.747723331200035979e-01
|
| 19 |
+
6.521099013127149568e-01 5.452399443648201505e-01 8.146707517183656710e-01 3.827256063695345656e-01 7.954832091744263867e-01 7.834427643148527132e-01 9.661317930643520402e-02 9.215673965718058636e-01 4.914305728788055383e-01 4.105628408027649501e-01 9.844647830893304974e-02 3.974831165301851987e-01 3.857608898053827007e-01 5.520210781401946321e-01 3.445787541654143915e-03 4.552922057017416702e-01 7.456544561760444223e-01 4.753985092154335845e-01 2.821385239833401615e-01 7.560136035104459973e-01 8.453142510471420845e-01 6.679627143276523071e-01 6.910882868284401459e-01
|
| 20 |
+
8.526493480446283302e-01 1.183917973068240315e-01 6.163988861865119517e-01 5.751899460059114455e-01 1.638797964925038375e-01 8.214597298784013235e-01 5.424670654187370156e-01 1.806631819658732763e-01 9.268107278221827672e-01 4.127397378597359445e-01 7.529877485901653733e-01 1.714251090083847018e-01 2.601487784245806179e-01 2.028326156742237263e-01 5.299879450122358948e-01 7.587877062981395193e-01 4.070738595375062996e-01 3.546903049793261875e-01 8.695365138547607176e-01 1.447085661525142619e-01 3.193366245820845606e-01 8.797841086211429795e-01 2.666562188639977071e-01
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-01
|
| 2 |
+
4.900000000000000355e+00 3.000000000000000000e+00 1.399999999999999911e+00 2.000000000000000111e-01
|
| 3 |
+
4.700000000000000178e+00 3.200000000000000178e+00 1.300000000000000044e+00 2.000000000000000111e-01
|
| 4 |
+
4.599999999999999645e+00 3.100000000000000089e+00 1.500000000000000000e+00 2.000000000000000111e-01
|
| 5 |
+
5.000000000000000000e+00 3.600000000000000089e+00 1.399999999999999911e+00 2.000000000000000111e-01
|
| 6 |
+
5.400000000000000355e+00 3.899999999999999911e+00 1.699999999999999956e+00 4.000000000000000222e-01
|
| 7 |
+
4.599999999999999645e+00 3.399999999999999911e+00 1.399999999999999911e+00 2.999999999999999889e-01
|
| 8 |
+
5.000000000000000000e+00 3.399999999999999911e+00 1.500000000000000000e+00 2.000000000000000111e-01
|
| 9 |
+
4.400000000000000355e+00 2.899999999999999911e+00 1.399999999999999911e+00 2.000000000000000111e-01
|
| 10 |
+
4.900000000000000355e+00 3.100000000000000089e+00 1.500000000000000000e+00 1.000000000000000056e-01
|
| 11 |
+
5.400000000000000355e+00 3.700000000000000178e+00 1.500000000000000000e+00 2.000000000000000111e-01
|
| 12 |
+
4.799999999999999822e+00 3.399999999999999911e+00 1.600000000000000089e+00 2.000000000000000111e-01
|
| 13 |
+
4.799999999999999822e+00 3.000000000000000000e+00 1.399999999999999911e+00 1.000000000000000056e-01
|
| 14 |
+
4.299999999999999822e+00 3.000000000000000000e+00 1.100000000000000089e+00 1.000000000000000056e-01
|
| 15 |
+
5.799999999999999822e+00 4.000000000000000000e+00 1.199999999999999956e+00 2.000000000000000111e-01
|
| 16 |
+
5.700000000000000178e+00 4.400000000000000355e+00 1.500000000000000000e+00 4.000000000000000222e-01
|
| 17 |
+
5.400000000000000355e+00 3.899999999999999911e+00 1.300000000000000044e+00 4.000000000000000222e-01
|
| 18 |
+
5.099999999999999645e+00 3.500000000000000000e+00 1.399999999999999911e+00 2.999999999999999889e-01
|
| 19 |
+
5.700000000000000178e+00 3.799999999999999822e+00 1.699999999999999956e+00 2.999999999999999889e-01
|
| 20 |
+
5.099999999999999645e+00 3.799999999999999822e+00 1.500000000000000000e+00 2.999999999999999889e-01
|
| 21 |
+
5.400000000000000355e+00 3.399999999999999911e+00 1.699999999999999956e+00 2.000000000000000111e-01
|
| 22 |
+
5.099999999999999645e+00 3.700000000000000178e+00 1.500000000000000000e+00 4.000000000000000222e-01
|
| 23 |
+
4.599999999999999645e+00 3.600000000000000089e+00 1.000000000000000000e+00 2.000000000000000111e-01
|
| 24 |
+
5.099999999999999645e+00 3.299999999999999822e+00 1.699999999999999956e+00 5.000000000000000000e-01
|
| 25 |
+
4.799999999999999822e+00 3.399999999999999911e+00 1.899999999999999911e+00 2.000000000000000111e-01
|
| 26 |
+
5.000000000000000000e+00 3.000000000000000000e+00 1.600000000000000089e+00 2.000000000000000111e-01
|
| 27 |
+
5.000000000000000000e+00 3.399999999999999911e+00 1.600000000000000089e+00 4.000000000000000222e-01
|
| 28 |
+
5.200000000000000178e+00 3.500000000000000000e+00 1.500000000000000000e+00 2.000000000000000111e-01
|
| 29 |
+
5.200000000000000178e+00 3.399999999999999911e+00 1.399999999999999911e+00 2.000000000000000111e-01
|
| 30 |
+
4.700000000000000178e+00 3.200000000000000178e+00 1.600000000000000089e+00 2.000000000000000111e-01
|
| 31 |
+
4.799999999999999822e+00 3.100000000000000089e+00 1.600000000000000089e+00 2.000000000000000111e-01
|
| 32 |
+
5.400000000000000355e+00 3.399999999999999911e+00 1.500000000000000000e+00 4.000000000000000222e-01
|
| 33 |
+
5.200000000000000178e+00 4.099999999999999645e+00 1.500000000000000000e+00 1.000000000000000056e-01
|
| 34 |
+
5.500000000000000000e+00 4.200000000000000178e+00 1.399999999999999911e+00 2.000000000000000111e-01
|
| 35 |
+
4.900000000000000355e+00 3.100000000000000089e+00 1.500000000000000000e+00 1.000000000000000056e-01
|
| 36 |
+
5.000000000000000000e+00 3.200000000000000178e+00 1.199999999999999956e+00 2.000000000000000111e-01
|
| 37 |
+
5.500000000000000000e+00 3.500000000000000000e+00 1.300000000000000044e+00 2.000000000000000111e-01
|
| 38 |
+
4.900000000000000355e+00 3.100000000000000089e+00 1.500000000000000000e+00 1.000000000000000056e-01
|
| 39 |
+
4.400000000000000355e+00 3.000000000000000000e+00 1.300000000000000044e+00 2.000000000000000111e-01
|
| 40 |
+
5.099999999999999645e+00 3.399999999999999911e+00 1.500000000000000000e+00 2.000000000000000111e-01
|
| 41 |
+
5.000000000000000000e+00 3.500000000000000000e+00 1.300000000000000044e+00 2.999999999999999889e-01
|
| 42 |
+
4.500000000000000000e+00 2.299999999999999822e+00 1.300000000000000044e+00 2.999999999999999889e-01
|
| 43 |
+
4.400000000000000355e+00 3.200000000000000178e+00 1.300000000000000044e+00 2.000000000000000111e-01
|
| 44 |
+
5.000000000000000000e+00 3.500000000000000000e+00 1.600000000000000089e+00 5.999999999999999778e-01
|
| 45 |
+
5.099999999999999645e+00 3.799999999999999822e+00 1.899999999999999911e+00 4.000000000000000222e-01
|
| 46 |
+
4.799999999999999822e+00 3.000000000000000000e+00 1.399999999999999911e+00 2.999999999999999889e-01
|
| 47 |
+
5.099999999999999645e+00 3.799999999999999822e+00 1.600000000000000089e+00 2.000000000000000111e-01
|
| 48 |
+
4.599999999999999645e+00 3.200000000000000178e+00 1.399999999999999911e+00 2.000000000000000111e-01
|
| 49 |
+
5.299999999999999822e+00 3.700000000000000178e+00 1.500000000000000000e+00 2.000000000000000111e-01
|
| 50 |
+
5.000000000000000000e+00 3.299999999999999822e+00 1.399999999999999911e+00 2.000000000000000111e-01
|
| 51 |
+
7.000000000000000000e+00 3.200000000000000178e+00 4.700000000000000178e+00 1.399999999999999911e+00
|
| 52 |
+
6.400000000000000355e+00 3.200000000000000178e+00 4.500000000000000000e+00 1.500000000000000000e+00
|
| 53 |
+
6.900000000000000355e+00 3.100000000000000089e+00 4.900000000000000355e+00 1.500000000000000000e+00
|
| 54 |
+
5.500000000000000000e+00 2.299999999999999822e+00 4.000000000000000000e+00 1.300000000000000044e+00
|
| 55 |
+
6.500000000000000000e+00 2.799999999999999822e+00 4.599999999999999645e+00 1.500000000000000000e+00
|
| 56 |
+
5.700000000000000178e+00 2.799999999999999822e+00 4.500000000000000000e+00 1.300000000000000044e+00
|
| 57 |
+
6.299999999999999822e+00 3.299999999999999822e+00 4.700000000000000178e+00 1.600000000000000089e+00
|
| 58 |
+
4.900000000000000355e+00 2.399999999999999911e+00 3.299999999999999822e+00 1.000000000000000000e+00
|
| 59 |
+
6.599999999999999645e+00 2.899999999999999911e+00 4.599999999999999645e+00 1.300000000000000044e+00
|
| 60 |
+
5.200000000000000178e+00 2.700000000000000178e+00 3.899999999999999911e+00 1.399999999999999911e+00
|
| 61 |
+
5.000000000000000000e+00 2.000000000000000000e+00 3.500000000000000000e+00 1.000000000000000000e+00
|
| 62 |
+
5.900000000000000355e+00 3.000000000000000000e+00 4.200000000000000178e+00 1.500000000000000000e+00
|
| 63 |
+
6.000000000000000000e+00 2.200000000000000178e+00 4.000000000000000000e+00 1.000000000000000000e+00
|
| 64 |
+
6.099999999999999645e+00 2.899999999999999911e+00 4.700000000000000178e+00 1.399999999999999911e+00
|
| 65 |
+
5.599999999999999645e+00 2.899999999999999911e+00 3.600000000000000089e+00 1.300000000000000044e+00
|
| 66 |
+
6.700000000000000178e+00 3.100000000000000089e+00 4.400000000000000355e+00 1.399999999999999911e+00
|
| 67 |
+
5.599999999999999645e+00 3.000000000000000000e+00 4.500000000000000000e+00 1.500000000000000000e+00
|
| 68 |
+
5.799999999999999822e+00 2.700000000000000178e+00 4.099999999999999645e+00 1.000000000000000000e+00
|
| 69 |
+
6.200000000000000178e+00 2.200000000000000178e+00 4.500000000000000000e+00 1.500000000000000000e+00
|
| 70 |
+
5.599999999999999645e+00 2.500000000000000000e+00 3.899999999999999911e+00 1.100000000000000089e+00
|
| 71 |
+
5.900000000000000355e+00 3.200000000000000178e+00 4.799999999999999822e+00 1.800000000000000044e+00
|
| 72 |
+
6.099999999999999645e+00 2.799999999999999822e+00 4.000000000000000000e+00 1.300000000000000044e+00
|
| 73 |
+
6.299999999999999822e+00 2.500000000000000000e+00 4.900000000000000355e+00 1.500000000000000000e+00
|
| 74 |
+
6.099999999999999645e+00 2.799999999999999822e+00 4.700000000000000178e+00 1.199999999999999956e+00
|
| 75 |
+
6.400000000000000355e+00 2.899999999999999911e+00 4.299999999999999822e+00 1.300000000000000044e+00
|
| 76 |
+
6.599999999999999645e+00 3.000000000000000000e+00 4.400000000000000355e+00 1.399999999999999911e+00
|
| 77 |
+
6.799999999999999822e+00 2.799999999999999822e+00 4.799999999999999822e+00 1.399999999999999911e+00
|
| 78 |
+
6.700000000000000178e+00 3.000000000000000000e+00 5.000000000000000000e+00 1.699999999999999956e+00
|
| 79 |
+
6.000000000000000000e+00 2.899999999999999911e+00 4.500000000000000000e+00 1.500000000000000000e+00
|
| 80 |
+
5.700000000000000178e+00 2.600000000000000089e+00 3.500000000000000000e+00 1.000000000000000000e+00
|
| 81 |
+
5.500000000000000000e+00 2.399999999999999911e+00 3.799999999999999822e+00 1.100000000000000089e+00
|
| 82 |
+
5.500000000000000000e+00 2.399999999999999911e+00 3.700000000000000178e+00 1.000000000000000000e+00
|
| 83 |
+
5.799999999999999822e+00 2.700000000000000178e+00 3.899999999999999911e+00 1.199999999999999956e+00
|
| 84 |
+
6.000000000000000000e+00 2.700000000000000178e+00 5.099999999999999645e+00 1.600000000000000089e+00
|
| 85 |
+
5.400000000000000355e+00 3.000000000000000000e+00 4.500000000000000000e+00 1.500000000000000000e+00
|
| 86 |
+
6.000000000000000000e+00 3.399999999999999911e+00 4.500000000000000000e+00 1.600000000000000089e+00
|
| 87 |
+
6.700000000000000178e+00 3.100000000000000089e+00 4.700000000000000178e+00 1.500000000000000000e+00
|
| 88 |
+
6.299999999999999822e+00 2.299999999999999822e+00 4.400000000000000355e+00 1.300000000000000044e+00
|
| 89 |
+
5.599999999999999645e+00 3.000000000000000000e+00 4.099999999999999645e+00 1.300000000000000044e+00
|
| 90 |
+
5.500000000000000000e+00 2.500000000000000000e+00 4.000000000000000000e+00 1.300000000000000044e+00
|
| 91 |
+
5.500000000000000000e+00 2.600000000000000089e+00 4.400000000000000355e+00 1.199999999999999956e+00
|
| 92 |
+
6.099999999999999645e+00 3.000000000000000000e+00 4.599999999999999645e+00 1.399999999999999911e+00
|
| 93 |
+
5.799999999999999822e+00 2.600000000000000089e+00 4.000000000000000000e+00 1.199999999999999956e+00
|
| 94 |
+
5.000000000000000000e+00 2.299999999999999822e+00 3.299999999999999822e+00 1.000000000000000000e+00
|
| 95 |
+
5.599999999999999645e+00 2.700000000000000178e+00 4.200000000000000178e+00 1.300000000000000044e+00
|
| 96 |
+
5.700000000000000178e+00 3.000000000000000000e+00 4.200000000000000178e+00 1.199999999999999956e+00
|
| 97 |
+
5.700000000000000178e+00 2.899999999999999911e+00 4.200000000000000178e+00 1.300000000000000044e+00
|
| 98 |
+
6.200000000000000178e+00 2.899999999999999911e+00 4.299999999999999822e+00 1.300000000000000044e+00
|
| 99 |
+
5.099999999999999645e+00 2.500000000000000000e+00 3.000000000000000000e+00 1.100000000000000089e+00
|
| 100 |
+
5.700000000000000178e+00 2.799999999999999822e+00 4.099999999999999645e+00 1.300000000000000044e+00
|
| 101 |
+
6.299999999999999822e+00 3.299999999999999822e+00 6.000000000000000000e+00 2.500000000000000000e+00
|
| 102 |
+
5.799999999999999822e+00 2.700000000000000178e+00 5.099999999999999645e+00 1.899999999999999911e+00
|
| 103 |
+
7.099999999999999645e+00 3.000000000000000000e+00 5.900000000000000355e+00 2.100000000000000089e+00
|
| 104 |
+
6.299999999999999822e+00 2.899999999999999911e+00 5.599999999999999645e+00 1.800000000000000044e+00
|
| 105 |
+
6.500000000000000000e+00 3.000000000000000000e+00 5.799999999999999822e+00 2.200000000000000178e+00
|
| 106 |
+
7.599999999999999645e+00 3.000000000000000000e+00 6.599999999999999645e+00 2.100000000000000089e+00
|
| 107 |
+
4.900000000000000355e+00 2.500000000000000000e+00 4.500000000000000000e+00 1.699999999999999956e+00
|
| 108 |
+
7.299999999999999822e+00 2.899999999999999911e+00 6.299999999999999822e+00 1.800000000000000044e+00
|
| 109 |
+
6.700000000000000178e+00 2.500000000000000000e+00 5.799999999999999822e+00 1.800000000000000044e+00
|
| 110 |
+
7.200000000000000178e+00 3.600000000000000089e+00 6.099999999999999645e+00 2.500000000000000000e+00
|
| 111 |
+
6.500000000000000000e+00 3.200000000000000178e+00 5.099999999999999645e+00 2.000000000000000000e+00
|
| 112 |
+
6.400000000000000355e+00 2.700000000000000178e+00 5.299999999999999822e+00 1.899999999999999911e+00
|
| 113 |
+
6.799999999999999822e+00 3.000000000000000000e+00 5.500000000000000000e+00 2.100000000000000089e+00
|
| 114 |
+
5.700000000000000178e+00 2.500000000000000000e+00 5.000000000000000000e+00 2.000000000000000000e+00
|
| 115 |
+
5.799999999999999822e+00 2.799999999999999822e+00 5.099999999999999645e+00 2.399999999999999911e+00
|
| 116 |
+
6.400000000000000355e+00 3.200000000000000178e+00 5.299999999999999822e+00 2.299999999999999822e+00
|
| 117 |
+
6.500000000000000000e+00 3.000000000000000000e+00 5.500000000000000000e+00 1.800000000000000044e+00
|
| 118 |
+
7.700000000000000178e+00 3.799999999999999822e+00 6.700000000000000178e+00 2.200000000000000178e+00
|
| 119 |
+
7.700000000000000178e+00 2.600000000000000089e+00 6.900000000000000355e+00 2.299999999999999822e+00
|
| 120 |
+
6.000000000000000000e+00 2.200000000000000178e+00 5.000000000000000000e+00 1.500000000000000000e+00
|
| 121 |
+
6.900000000000000355e+00 3.200000000000000178e+00 5.700000000000000178e+00 2.299999999999999822e+00
|
| 122 |
+
5.599999999999999645e+00 2.799999999999999822e+00 4.900000000000000355e+00 2.000000000000000000e+00
|
| 123 |
+
7.700000000000000178e+00 2.799999999999999822e+00 6.700000000000000178e+00 2.000000000000000000e+00
|
| 124 |
+
6.299999999999999822e+00 2.700000000000000178e+00 4.900000000000000355e+00 1.800000000000000044e+00
|
| 125 |
+
6.700000000000000178e+00 3.299999999999999822e+00 5.700000000000000178e+00 2.100000000000000089e+00
|
| 126 |
+
7.200000000000000178e+00 3.200000000000000178e+00 6.000000000000000000e+00 1.800000000000000044e+00
|
| 127 |
+
6.200000000000000178e+00 2.799999999999999822e+00 4.799999999999999822e+00 1.800000000000000044e+00
|
| 128 |
+
6.099999999999999645e+00 3.000000000000000000e+00 4.900000000000000355e+00 1.800000000000000044e+00
|
| 129 |
+
6.400000000000000355e+00 2.799999999999999822e+00 5.599999999999999645e+00 2.100000000000000089e+00
|
| 130 |
+
7.200000000000000178e+00 3.000000000000000000e+00 5.799999999999999822e+00 1.600000000000000089e+00
|
| 131 |
+
7.400000000000000355e+00 2.799999999999999822e+00 6.099999999999999645e+00 1.899999999999999911e+00
|
| 132 |
+
7.900000000000000355e+00 3.799999999999999822e+00 6.400000000000000355e+00 2.000000000000000000e+00
|
| 133 |
+
6.400000000000000355e+00 2.799999999999999822e+00 5.599999999999999645e+00 2.200000000000000178e+00
|
| 134 |
+
6.299999999999999822e+00 2.799999999999999822e+00 5.099999999999999645e+00 1.500000000000000000e+00
|
| 135 |
+
6.099999999999999645e+00 2.600000000000000089e+00 5.599999999999999645e+00 1.399999999999999911e+00
|
| 136 |
+
7.700000000000000178e+00 3.000000000000000000e+00 6.099999999999999645e+00 2.299999999999999822e+00
|
| 137 |
+
6.299999999999999822e+00 3.399999999999999911e+00 5.599999999999999645e+00 2.399999999999999911e+00
|
| 138 |
+
6.400000000000000355e+00 3.100000000000000089e+00 5.500000000000000000e+00 1.800000000000000044e+00
|
| 139 |
+
6.000000000000000000e+00 3.000000000000000000e+00 4.799999999999999822e+00 1.800000000000000044e+00
|
| 140 |
+
6.900000000000000355e+00 3.100000000000000089e+00 5.400000000000000355e+00 2.100000000000000089e+00
|
| 141 |
+
6.700000000000000178e+00 3.100000000000000089e+00 5.599999999999999645e+00 2.399999999999999911e+00
|
| 142 |
+
6.900000000000000355e+00 3.100000000000000089e+00 5.099999999999999645e+00 2.299999999999999822e+00
|
| 143 |
+
5.799999999999999822e+00 2.700000000000000178e+00 5.099999999999999645e+00 1.899999999999999911e+00
|
| 144 |
+
6.799999999999999822e+00 3.200000000000000178e+00 5.900000000000000355e+00 2.299999999999999822e+00
|
| 145 |
+
6.700000000000000178e+00 3.299999999999999822e+00 5.700000000000000178e+00 2.500000000000000000e+00
|
| 146 |
+
6.700000000000000178e+00 3.000000000000000000e+00 5.200000000000000178e+00 2.299999999999999822e+00
|
| 147 |
+
6.299999999999999822e+00 2.500000000000000000e+00 5.000000000000000000e+00 1.899999999999999911e+00
|
| 148 |
+
6.500000000000000000e+00 3.000000000000000000e+00 5.200000000000000178e+00 2.000000000000000000e+00
|
| 149 |
+
6.200000000000000178e+00 3.399999999999999911e+00 5.400000000000000355e+00 2.299999999999999822e+00
|
| 150 |
+
5.900000000000000355e+00 3.000000000000000000e+00 5.099999999999999645e+00 1.800000000000000044e+00
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/data/pdist-chebyshev-ml.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
8.9084734e-01 9.3573853e-01 9.3507398e-01 9.6040691e-01 9.2918157e-01 9.6617342e-01 9.0430930e-01 9.5753424e-01 8.7106898e-01 9.2169905e-01 9.7401159e-01 8.9013416e-01 9.3956689e-01 9.0041896e-01 9.2588355e-01 9.3849417e-01 8.9713468e-01 9.1481804e-01 9.7500539e-01 9.0012586e-01 9.0962559e-01 8.5860091e-01 8.6981095e-01 8.9995771e-01 8.8070172e-01 9.1456657e-01 8.6711474e-01 9.2593917e-01 8.7560376e-01 8.5193121e-01 9.0898542e-01 8.7765302e-01 8.6555584e-01 8.6093485e-01 9.0447028e-01 8.7614405e-01 9.4803522e-01 8.4998062e-01 7.8398996e-01 8.9538612e-01 8.3902291e-01 9.9039470e-01 9.5480519e-01 8.9152195e-01 9.1623329e-01 7.9094921e-01 9.1777100e-01 9.8972335e-01 9.0429093e-01 8.7646362e-01 9.2136649e-01 9.7178177e-01 8.9610979e-01 9.4710327e-01 9.3612450e-01 9.0241499e-01 7.7992538e-01 8.7262126e-01 9.3325183e-01 8.5796531e-01 9.4267977e-01 6.7224167e-01 7.9568368e-01 8.6411267e-01 9.3311642e-01 9.0160114e-01 9.0698887e-01 8.5833256e-01 9.6902830e-01 9.5072298e-01 8.6808495e-01 9.7879599e-01 8.8060729e-01 8.2818573e-01 8.4366706e-01 8.4506700e-01 9.4532981e-01 9.1792306e-01 7.8917825e-01 9.8337805e-01 8.1751613e-01 9.3037855e-01 9.1618832e-01 8.6568874e-01 8.9751397e-01 8.7923710e-01 8.6814329e-01 9.0330164e-01 8.2426213e-01 9.4644643e-01 8.8431293e-01 8.8497426e-01 9.0633818e-01 9.5537161e-01 8.2167575e-01 8.7771053e-01 9.0681167e-01 8.7626143e-01 8.7463464e-01 9.8033940e-01 9.2920881e-01 9.5108549e-01 9.1287466e-01 8.0052218e-01 9.2409517e-01 8.8252650e-01 8.7873923e-01 9.2989402e-01 9.1985043e-01 9.6172646e-01 8.8223856e-01 9.4477822e-01 8.8310948e-01 9.4461306e-01 9.1875210e-01 9.1233363e-01 9.2124013e-01 9.5460897e-01 8.4640982e-01 9.0882657e-01 9.8169468e-01 9.7828355e-01 8.4150533e-01 8.6888923e-01 9.7138825e-01 8.7988144e-01 9.6720910e-01 8.9450147e-01 9.5331584e-01 8.8871809e-01 8.9736685e-01 8.6258146e-01 9.1331565e-01 9.0968870e-01 9.4833654e-01 9.0536967e-01 9.5099871e-01 8.0251958e-01 9.2526150e-01 9.8971957e-01 9.0340947e-01 9.4955892e-01 9.6838162e-01 8.7534901e-01 9.1178797e-01 9.2649154e-01 9.5260993e-01 9.3178143e-01 9.4943000e-01 8.7816171e-01 9.6506542e-01 8.3422958e-01 9.3443585e-01 9.3220084e-01 8.5706573e-01 8.4666325e-01 9.0474744e-01 9.1080644e-01 9.2406899e-01 8.7901768e-01 9.3265263e-01 9.5992829e-01 9.5696271e-01 9.1932272e-01 8.0937044e-01 9.0904917e-01 8.9516756e-01 9.4797906e-01 8.4159421e-01 9.6773901e-01 9.7099825e-01 9.6941820e-01 9.8174088e-01 9.7569951e-01 9.3655362e-01 8.4130333e-01 9.5994549e-01 8.4235414e-01 9.1429418e-01 9.3418117e-01 8.4600977e-01 8.8166496e-01 8.7594776e-01 8.8571112e-01 9.6308174e-01 9.5315927e-01 8.6997519e-01 8.9383032e-01 9.4686804e-01 9.4399596e-01
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/data/pdist-double-inp.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
8.278938049410748956e-01 9.035293984476246987e-01 1.862188994679486731e-01 8.921151312310462433e-01 2.061859119379583216e-02 3.440636727385729676e-01 1.533779912830328662e-01 5.701372300009802663e-01 5.510020730211558915e-01 1.792362258426003496e-01 8.086175120876580857e-01 6.115487184317183189e-01 1.233471787164852618e-02 1.441643531871039663e-03 4.044309209045688913e-01 3.561398959499905148e-01 1.281985712929750720e-01 8.663300833847481508e-01 8.696027786291581352e-01 3.611727370363766454e-01 5.283537658772616830e-01 1.440241088090119526e-01 3.112457227138950566e-01 6.031280796897889873e-01 9.230324792742518047e-01 2.332121881136874908e-01 3.192652267403439659e-02 3.466206294995559656e-01 2.988687728046366399e-01 5.116749542048093513e-02 2.584975830914494344e-01 4.302023478042227289e-01 8.003972751713522849e-01 9.364931911368097328e-01 9.737098649964673891e-01 4.718038453972229762e-01 4.526591686607864817e-01 1.056485678520797666e-01 5.883019714285405710e-01 3.846092237676981274e-01 6.461500053435473845e-01 1.013239729848824933e-01 1.216151561651189761e-01 5.159668929484659827e-01 8.452074473510227115e-01 9.885170962247968873e-01 7.623883073490128615e-01 2.291163243615434997e-02 5.775530980802381364e-01 7.820699896828091635e-01 8.239186345842965942e-01 3.391800105260227571e-01 9.546318451614538292e-01 3.789677917867695367e-01 4.526533399649290690e-02 8.366786473238587707e-01 3.082636811049858094e-01 1.173936820793450853e-01 7.631994969169442200e-02 2.997416650722183329e-01 5.795208655160232203e-01 3.942350892542011431e-01 1.175126383297261379e-01 4.928232513950027149e-01 9.421293996225950096e-01 8.365391053841342295e-02 6.868059693571844093e-01 3.589527962429440722e-01 7.592939427166059962e-01 5.623849466131448649e-01 2.110746828032050715e-01 9.824683704668600859e-01 2.661230142246236996e-01 6.162272315007123469e-01 5.023254536607497656e-01 5.202854476669782624e-02 5.835090668842095596e-01 7.864642118889143552e-01 2.504012386867506823e-01 6.728308641135989365e-01 4.610793534576096420e-01 4.820508770515909980e-01 9.720403251022265989e-01 3.100069285263498120e-01 7.681017126461753275e-01 7.956539306007082146e-02 2.593389637887737464e-01 1.137852590403054531e-01 3.885303073284454012e-01 8.599094660075957686e-01 5.215167875918280682e-02 1.620908248572288102e-01 1.859236090457663249e-01 6.247716512610480555e-01 3.415128495520775020e-01 7.034903368378029320e-01 6.037564640019568163e-01 2.338969434423310290e-01 1.002104885609900187e-02 7.866058403969036217e-01
|
| 2 |
+
8.033694116033356369e-01 8.653264545544031572e-01 7.468340410754038539e-01 6.362430919910603278e-01 5.120006306625468628e-02 9.503348372633585450e-01 4.697732609626817935e-01 4.221305288459429317e-01 3.153452119838391354e-01 2.991014843442657556e-01 1.190667967280257811e-01 3.486567714509342109e-01 8.289493649885054660e-01 8.454811050800014049e-01 9.149673018211901265e-01 7.708707837193897738e-01 2.640157732122547785e-01 2.107897022189605396e-01 4.207633055054439408e-01 6.719500284654699174e-01 1.458031684893063007e-01 1.800412735886125493e-02 8.402733435220011149e-02 4.206760156883160295e-02 1.376933515041314227e-01 1.716717341022133692e-01 1.788220727652158892e-01 8.224310433402118869e-01 7.729093666867475898e-01 2.064223621025984556e-01 9.592092036227207741e-01 8.312490243754996344e-01 6.673289360369902834e-01 4.632847903690773261e-02 7.643954098358983762e-01 9.359341525615098023e-01 1.914966319163026176e-01 4.536590469402868031e-01 8.640836016538007147e-01 3.941529178175462444e-02 5.602101995205478469e-01 9.263806161941660067e-01 1.555995325944817820e-01 6.172208102950116348e-01 6.335576752812099866e-01 9.766975460368043649e-02 4.475795689539874278e-02 3.248842796104995934e-01 5.700377122149502540e-01 9.066962967256807504e-01 5.458460621505676347e-01 6.833401285581487405e-01 2.887244409544044155e-01 1.316338647016834784e-01 2.325673305245992140e-01 4.150121963188406760e-01 3.834845466366055833e-01 8.149365773968725302e-01 1.867003849450201702e-01 3.170322173543018707e-01 6.832093662682684476e-01 1.729728518929105618e-01 9.236557359702636250e-01 9.152941252150086360e-01 7.224879983096620384e-01 8.557920626598064517e-01 5.344883059251644974e-01 4.876873274449112783e-01 8.308277804506420949e-01 3.916624489322212410e-01 3.459695122273966916e-01 4.033512499027409604e-01 6.555726444913008155e-01 7.138452409380238173e-01 1.683937314599968094e-01 1.769382143486440961e-01 7.588683655178136700e-01 3.750589892880819010e-01 7.525176245126207197e-01 6.083961152538303052e-01 1.145972309907993258e-01 6.239614485809552580e-01 1.307655482065895880e-01 8.530458750670916190e-01 4.801602070124768584e-01 8.168122189863546989e-02 3.793139622744635675e-01 1.496986997776840189e-01 7.129023878302899186e-01 6.830979237438047358e-01 7.635375943876505644e-01 1.824004963251233402e-01 5.764695848992339444e-01 8.865113248731604223e-01 5.784337085544002388e-01 9.700026628755119562e-01 7.318207347905059112e-01 3.851401393936705331e-01 1.774291851193399161e-01 9.763423229242296220e-01
|
| 3 |
+
9.287178470949695175e-01 1.748282433617460718e-01 9.238531711586964734e-01 8.291274445125006443e-01 9.513259272578692416e-01 7.486316801165745494e-01 6.257378457524477300e-01 2.062711693536473101e-01 3.970721244184766130e-01 2.738325225026445597e-01 8.735038948299954642e-01 5.415282140033768066e-01 5.176317904298315398e-01 5.347036264518250093e-01 7.482056965410627258e-01 4.140672582824351800e-01 8.709067272363142376e-01 9.499605569181273079e-01 5.380266748336398619e-01 4.369252161707162241e-01 8.235722216228258397e-03 4.308187193646527691e-01 6.030581482859224129e-01 7.316831195156517920e-01 5.540499846834291420e-01 2.044203040111662872e-01 8.645251782981867583e-01 1.816095717570278545e-01 9.639119168018674966e-01 3.572031072322333634e-01 5.580226816834680248e-01 5.586629875016585478e-01 7.213854320902782780e-01 8.513998260042524580e-01 6.308764347277173723e-02 4.299855362100638567e-01 8.789303907444128150e-01 9.178850359236285783e-01 2.275205845091231582e-01 1.899395443939643213e-01 7.103070862773533944e-01 9.450015289553428399e-01 1.691856364522159595e-01 7.368719616877857925e-01 9.600189536623833231e-01 5.128846522932454244e-01 6.209162727118655578e-02 7.992250598838029907e-01 9.141050280518014937e-01 1.471297785256820978e-01 7.466162372930541524e-01 4.656107650642931084e-01 6.399324135161845728e-01 2.023617619481610230e-01 1.019104648900100996e-01 4.390693688536728700e-02 9.822620353006089600e-01 2.881951852926285529e-01 6.191575015960482098e-02 8.989580763251467932e-01 4.635958631890454429e-01 1.781973138114967270e-02 7.906911683818984571e-02 6.525270776225711167e-02 3.620583622807886925e-01 2.651673718940715796e-01 5.829372395929610651e-01 2.118159824373908595e-01 5.900287159143694504e-01 9.405929925178391215e-01 9.262415619063500971e-01 5.639581506302312475e-01 4.529556154689695635e-02 2.873819210518682166e-01 5.718545934306838996e-01 9.877670791317306742e-01 4.120364488714320927e-01 9.896078045634184583e-01 3.796586997026456523e-01 1.178183652203194098e-01 6.641068305236120795e-01 4.045960610587706618e-03 2.262690437428437340e-01 7.839938005832693957e-01 7.695391333937223743e-01 3.713918392552509884e-01 4.245533341514018399e-01 1.475072494020331915e-01 6.011975181419888514e-01 5.158174017998343741e-01 1.788706151398071764e-01 8.880707130134481986e-01 6.463351030474082659e-01 6.499920635615744624e-01 8.570273676455353318e-01 6.055019270899113515e-01 2.123561211054603159e-02 2.027688787664126968e-01 1.930834215328548487e-01 5.131906052747271518e-01
|
| 4 |
+
2.599990881903107010e-01 6.767857524909899336e-01 7.188217446352963558e-01 3.037178903357997672e-01 4.252381412838680541e-01 4.070924411439535984e-02 8.426710493038247485e-02 8.301517457289483426e-01 8.254603255702420705e-01 7.258533909453509514e-01 9.958706809470796451e-01 1.323408451651194584e-01 8.523995455245143571e-01 2.572405385832454705e-02 4.715363690065482727e-01 7.920130365690022378e-01 7.613745641534582775e-01 5.108305991695683002e-01 7.908714335912382376e-01 4.641131983754837043e-01 3.112627109831845873e-01 4.218013908715474436e-01 3.291577909008427394e-01 2.538715054071232213e-01 1.362470842487485401e-01 2.716429790290709745e-01 1.485325814161112534e-01 4.514539027544387517e-01 6.900835128673067365e-01 7.793407072946112457e-02 5.938024345270752624e-01 1.497853829906865553e-01 5.399567982652856424e-01 1.419209916759478496e-03 7.719776132867679497e-01 3.130795105576239523e-01 6.670071611167494030e-01 8.900596881158256979e-01 8.011158503301568645e-01 7.089295605187424520e-01 4.671116382997058114e-01 6.682965170673403899e-01 6.524835265739736823e-02 5.454288420771494783e-01 7.751910790556310049e-01 8.192595541387335256e-01 3.098855848167891835e-01 3.689971355659119601e-01 8.666507475054133769e-01 2.749042684253171220e-01 3.566565602478318775e-01 4.838173174723044978e-01 1.032975933616413489e-01 5.063065339610417492e-02 5.791168455729079900e-01 3.573337411289496668e-01 6.714098909652352898e-01 2.917057662433912846e-01 2.654964332620638467e-01 7.171804039048814694e-01 3.314488637898249657e-01 5.230399837442840649e-01 6.866534136026025692e-02 1.252966394621071178e-01 5.349397882659551184e-01 2.841423847455760709e-01 4.158473635710734362e-01 7.197062989831272128e-01 5.123869045047864113e-01 8.675622821594339840e-01 8.097441845042540054e-01 7.317178252133832439e-01 3.300847596465853462e-01 5.922311859141077273e-01 8.852619511417836318e-02 2.673412917259408994e-01 6.878259052441990651e-01 3.223000927116328462e-01 8.859387123976615319e-01 5.722722388300067742e-01 8.254877606669521750e-01 5.705299682290687624e-01 7.046478734972855262e-01 1.316324413616759559e-01 3.056358395675535800e-01 2.396516834600909140e-01 2.041201422493257311e-01 1.610755140653103989e-01 1.617012564641111538e-01 4.449920510036902144e-01 2.731012972755201274e-01 7.826874666257994662e-01 5.193612375350010746e-01 8.688804522977213729e-01 3.742157602758655610e-02 6.649628920608219307e-01 5.978149424619171315e-01 5.345645500553952711e-01 9.443202650415919441e-01 6.105837075491723498e-01
|
| 5 |
+
6.387761328141735584e-01 4.210087412162694109e-01 3.777306694964789324e-01 3.576349403292201634e-01 7.272699618880260619e-01 9.173392803607671731e-02 1.212535698300880593e-01 3.871229381194544183e-01 7.735150198351389284e-01 4.687200483013695962e-01 5.161778571874678923e-01 9.839646447226980674e-01 8.626932748911960713e-01 9.618485576577924245e-01 2.997996427525421170e-01 3.955404657388794654e-01 8.480126027102616870e-01 8.194992325050480808e-01 2.800213436873294492e-01 7.188391466620779324e-01 2.289766105875049584e-01 3.838547514028287644e-01 1.363553401061209369e-01 2.131328253542326134e-01 2.666779468144075960e-02 3.252883844200405994e-01 4.207860197469600605e-01 2.991365385037647595e-01 9.180779845534067229e-01 8.787338732192649937e-01 5.404510999105649471e-01 1.735493827761729335e-01 7.405224640747264386e-01 3.927355563629583157e-01 3.957109873399460298e-01 1.313029813325972128e-01 6.434498219738993274e-01 7.162213694578050127e-01 6.454998257494671821e-01 3.808124530008022424e-01 2.027201015737234435e-01 6.667632842770417900e-01 1.609491052365198405e-01 1.192413785409307536e-02 4.546773323526854815e-01 7.733541911050207940e-01 3.902525737195561284e-01 4.006023779897505133e-01 5.156517815815246930e-01 6.135685498584592112e-01 7.062153114980724844e-01 5.505858882117883324e-01 3.541308807182554919e-01 5.237151122342533771e-01 5.230649229131387745e-01 1.973541027697351957e-01 7.940327858595511712e-01 9.998588700623055603e-01 3.878271015153827994e-01 4.455006584967207139e-01 8.376414508056347907e-01 3.310833863524501597e-01 8.020469097392601832e-01 1.890327633084128989e-01 3.830289472395409511e-01 8.605040171046141051e-02 9.978185524023941433e-01 8.333890591892906263e-01 4.509013468741837061e-01 6.355778557686052599e-01 1.422515991097305088e-01 9.549891485963732940e-01 7.535776302868563148e-01 9.306005301880662106e-01 2.444330347211679522e-01 5.828218427569508142e-01 1.261938242968304591e-01 2.829188731405173352e-01 8.100246952078660190e-01 2.032739130996042975e-01 3.997268448390065565e-01 3.882777703107541667e-01 1.102505652624736765e-01 5.826634725328041498e-01 6.508734477956333864e-01 1.777287661702166011e-01 4.857051012052149286e-02 6.850537712379254351e-01 5.012281307761055071e-01 3.329154880061502286e-01 5.006261767216675374e-01 4.542081454976160115e-01 6.777801995399822532e-01 4.271303586474960445e-01 7.820470659692947413e-01 5.143462618485082904e-01 4.071273891563575997e-02 8.503383643856671226e-01 6.877485768345151795e-01 6.498843855014626580e-01
|
| 6 |
+
5.539512747016193117e-01 6.329206647391879548e-01 2.798533500321682688e-01 4.825977295850051307e-01 7.625297023172977751e-01 9.081309101427640362e-01 4.124792086535029600e-01 3.647019658319609059e-01 7.529595202332928228e-02 3.072404010876803593e-01 7.890673660964639957e-01 4.079781478915127657e-01 1.440519120695739064e-01 2.538968953804546791e-01 1.595028243568367143e-01 9.066545851872198636e-02 6.367601114674349416e-01 7.622263643880089479e-02 3.015728236404162654e-01 2.424070469873378375e-01 5.711440390241000475e-01 5.717001375511508998e-01 2.237853674032181939e-01 7.112101625753678436e-01 4.321054197012103026e-01 2.505322169010260058e-02 5.877307077139551916e-01 4.415771174397812304e-01 3.766022855145171322e-01 9.803490652619811785e-01 1.229258314111529860e-01 8.108351868714478439e-01 8.558595456964329662e-01 2.168217533833206589e-01 2.034022719386595623e-01 8.687457137579783772e-01 9.013327195854559104e-01 8.156766512673154779e-01 2.717576187546973943e-01 1.756417893371479133e-01 7.555856977566548505e-01 6.708809351312817748e-01 8.998789237886926085e-01 1.936367585946979775e-01 7.949724635465026390e-01 3.164799312763589834e-01 5.493048513173155456e-01 1.608917269168268493e-01 3.048667492191803330e-01 5.599401537727016764e-01 5.779501360842279611e-01 1.296714605309662316e-01 9.160752328055997706e-01 8.058674476110374574e-01 4.385508937505578908e-01 9.212419718012100356e-01 2.249887451242467140e-01 6.283927745352599903e-01 3.778992451536005159e-01 3.571958698867505611e-03 7.276526470528231760e-01 9.051678673805297892e-01 8.465837072484881931e-01 4.548317505393462135e-02 3.189318261926020748e-01 4.446388607398673587e-01 4.292356336344156365e-01 4.203980977718795309e-01 4.698059253071955599e-01 6.151991200848159203e-01 8.479986139404802614e-01 9.870993262459623052e-01 3.164206525899861955e-01 6.464672171639846976e-01 8.508781429592480183e-01 4.733667503354813677e-01 8.076014176740163863e-01 6.671443255679101458e-01 6.639213267047979761e-01 3.681688930741919830e-01 4.679870252651611162e-01 1.790041740686979521e-01 8.446070273663058847e-01 3.350737544979878191e-01 6.600272349677447359e-01 4.356083218487936115e-01 7.995134167346013010e-01 9.083660261041469619e-01 9.743975306734570241e-01 8.144839650654719376e-01 6.865011984586443239e-01 1.709747281999153268e-01 8.534933687161740945e-01 9.494753729726415070e-01 8.140124992294850426e-01 8.936241255316055287e-01 9.087976860818796077e-01 9.030687493451383663e-02 4.025785149840914734e-01 9.592005611533803711e-01
|
| 7 |
+
5.714058727476275523e-01 7.913573761505965365e-02 9.301773447377043036e-01 4.302822433307075256e-01 4.618892554175407783e-01 1.882471300213742760e-01 6.231472878215863487e-01 2.350437450940777717e-01 8.483410480771292894e-01 8.580803842040533036e-01 4.246398783388435350e-01 5.667321565946502604e-01 7.247417018955526480e-02 5.373984417482219333e-01 8.794242091541510931e-01 9.699025554453030162e-01 8.254197752548814160e-01 7.739723972867470492e-01 6.365819416181199841e-01 3.451230687021222820e-02 1.829102490094791644e-02 9.179618383026147965e-01 4.481667270072077214e-01 4.771270250445739380e-01 1.588469404953456454e-01 3.766332499200618633e-01 5.057026248713025751e-02 9.125900914275182352e-01 8.438133644246305076e-01 3.282972411719701222e-01 6.042003956122835584e-01 7.423456085393266290e-01 1.389012737541106546e-02 3.674754266702850991e-02 2.126646727703802586e-01 3.085666164246750887e-01 4.303440338750976757e-01 1.749037978865556342e-01 2.177699993322510519e-01 6.675614739991906355e-01 1.926533336347433512e-01 8.032010572660308600e-01 4.611412981769049679e-01 9.907201268457492827e-01 8.973785930837320235e-01 6.286342392657409128e-01 8.111266245859546364e-01 1.154230969025437092e-01 8.382880466301794176e-01 1.053753927827069115e-01 9.921712862234919328e-01 9.041662667920956631e-01 3.626267376021269362e-01 2.262225368932846425e-02 8.669003741626111204e-01 7.597054897704164089e-01 4.700318514995387442e-01 4.338185014241978665e-01 1.205425463362067573e-01 2.413879270602589111e-01 5.483334840461459025e-01 2.042653841254596925e-01 5.452588940366013270e-01 3.164646091706100339e-01 1.878958248945691301e-01 2.188622304737641855e-01 2.970982599823450698e-01 5.952148400199362976e-01 9.614251220149501176e-01 5.446813400697393392e-01 5.900748097930779146e-01 2.653062526715309621e-01 5.459933097767216692e-01 3.174185404661935550e-01 1.412133354129242457e-01 1.487441669790685594e-01 3.953776242211952674e-01 5.274261039692862418e-01 1.756132307607755072e-01 4.481942852746899630e-01 6.390660088765629521e-01 2.860380430081067571e-01 5.866902519902850166e-03 3.026687645174785946e-02 1.952533570196290924e-01 2.154769096186736066e-01 8.920573593276575064e-01 5.644513191915436767e-01 5.551464696654353492e-01 4.378199413349500579e-01 8.685737643974280608e-01 7.493934764293597173e-02 9.556749726352036234e-01 6.386433482536227890e-01 8.714694524097754691e-02 1.722786161701279628e-01 6.526867532768643176e-01 8.950304705281527662e-01 6.158198776753203152e-01 9.587176904005377809e-01
|
| 8 |
+
7.705718397401561948e-01 3.165816092999733655e-01 4.334200859975760878e-01 8.639807015515663657e-01 5.576514209532534849e-03 2.456745447057938625e-01 1.664686313299922338e-01 9.637084729617834133e-01 1.083448720752323569e-01 1.865218070380464388e-01 3.730358890475884426e-01 5.015351872138350542e-01 7.420710795841709562e-01 4.919420674769692248e-01 3.426558201886464872e-02 8.669984854934246199e-01 2.204243734202966376e-01 4.109792246853891662e-01 4.361732572946559472e-01 6.819306998053020763e-02 9.986304248057148447e-01 4.119289455392274313e-01 8.533050041845835487e-01 3.416914861912183632e-01 6.522191951039880697e-01 4.162803668786793088e-01 9.051674379917418189e-02 4.552378661306888397e-02 2.122677193466918633e-01 7.461518531655018105e-01 4.654688019259497489e-01 7.877564083548750373e-01 4.518328005682387127e-01 7.173857464237374248e-01 6.940056370290903498e-02 2.804574410412373764e-01 6.095681113112718652e-01 3.680596478602831123e-01 1.814569150719304025e-01 6.505055517979729807e-01 2.759585245701871026e-01 1.429501104786028431e-01 7.813891153083207808e-02 8.925314279991185540e-01 6.692056941902108091e-01 1.915141341107173822e-01 5.750233129581091562e-01 2.051961006251528108e-01 3.849013692629975614e-01 9.503788222043518807e-01 7.690419386411734282e-01 9.978147530014782607e-01 1.719584162437415298e-01 4.890758882401113894e-01 7.195660736040896399e-01 2.485818040997200828e-01 9.706486601870933928e-01 5.182604282071262558e-01 8.082072245463804983e-01 4.889961284821118248e-01 8.042893959057633158e-01 3.200685313413229593e-01 8.983245016887355661e-01 2.811495336955205371e-01 3.986095833814048417e-01 8.607229214132059436e-01 4.827620119717191960e-01 6.715610252037491623e-01 9.330824374137768329e-01 7.537710530085762750e-01 9.840804224010484269e-01 2.319352541177217564e-01 9.569114943157627229e-01 5.821928104654411351e-01 6.700479524814679788e-01 5.663434680086896211e-01 8.851091082101365526e-01 6.800562815862243315e-01 3.578475213752868589e-01 2.900164669281133367e-01 8.379170683569914235e-02 9.929972839740475177e-02 5.946248553621906741e-01 1.991332889320840405e-01 8.115065723822508792e-01 2.023388190440008616e-01 4.056545651129230823e-01 2.966825350250481552e-01 7.457176343507545546e-01 9.856015771246517954e-01 2.264338016147812160e-01 8.366528670045663141e-01 6.116829813603242849e-01 2.605933184296719274e-01 5.765962146558850643e-01 5.064075092266390188e-01 5.499615769589756287e-01 9.240234698632640020e-01 7.169900155229913530e-02 3.544181364560751168e-01
|
| 9 |
+
8.154844535553099627e-01 4.797965609394789777e-01 7.476703385713100447e-01 9.086708404761600910e-01 3.191752505450355937e-01 7.611128630021511965e-01 6.246790343299296611e-01 1.942001426217137006e-01 2.789860414631386565e-01 3.236359785042408621e-02 3.178191288741717413e-01 8.372264298357038337e-01 8.872692914664047636e-01 9.589758852077276963e-01 3.123722260380168425e-01 8.980164015338999439e-01 7.260784140459818348e-01 6.567013512265649222e-01 1.028743505926521529e-01 6.821705410750319443e-01 6.889838995316139858e-01 5.587525493094736007e-02 6.921487028366646310e-01 3.616312929861494885e-01 1.673758008792780583e-01 6.626504595920326146e-01 9.125680913222075086e-01 1.424077784972291871e-01 6.508496429060767197e-01 6.615417385775157477e-01 9.654167310675311198e-01 5.536662974550183858e-01 7.092622144968085962e-03 6.694595400455760625e-01 1.828533619119211417e-01 3.421514408394116247e-01 1.242580151818144518e-01 9.888774797458224075e-01 9.777955172739735135e-01 4.271370765628749178e-01 1.211608384809655936e-01 1.580132417172936954e-01 3.242705395708289640e-01 3.268994391754735940e-01 5.213767653645562383e-03 4.475169480357120699e-01 9.593245219293577986e-01 6.994304536782350867e-01 7.063863152769014331e-01 8.381620829497931080e-01 2.760441799736219615e-01 3.755200946645842475e-01 3.627729621737311172e-01 9.518310606719182498e-01 3.577273025276901386e-01 3.991159901003488164e-01 4.187060513068554535e-01 7.422605403637314581e-01 6.697944269780702342e-01 6.020599837037767799e-01 1.571185850817550245e-01 7.519860911185742847e-01 6.635775704496444938e-01 9.487848173531471252e-01 7.900030232338028924e-01 4.143783957270819052e-01 5.618429740858444932e-01 3.737804619062014000e-01 6.179941187802344693e-01 6.553638605616040058e-01 1.009709416658691739e-01 4.935037098582963910e-01 5.485489972455533936e-01 1.024147956480448984e-01 1.195764707555347917e-01 4.910516327810896531e-01 3.551185778630389089e-01 3.857601645798814927e-01 2.074975219600547760e-01 2.084038664460790002e-01 5.268616653491025037e-01 6.948014877618717833e-01 6.179744044618615817e-01 7.063658085955483168e-01 7.925757227686872630e-01 6.199016959584816577e-01 1.163676037434490107e-01 7.425752264755586252e-01 5.403115665133301215e-01 2.546191951391015840e-01 6.961300925345208501e-01 4.003013072125547467e-01 5.906120962720950995e-02 5.879915846330325824e-01 1.213602408288709800e-01 3.801780679842765576e-01 1.731477742402802722e-01 4.624568816669496485e-01 3.304453744619206823e-01 8.810445876116090869e-02
|
| 10 |
+
5.140190515373614932e-01 1.419225260054487459e-01 7.777845802285945354e-01 3.327562899409282071e-01 8.916875699762913943e-01 7.212852862736146564e-01 5.727327199433507321e-01 5.897820225918504189e-01 7.318614954542906892e-01 7.393985144455500480e-01 4.531340740296823100e-01 9.903061584426188224e-01 4.213350938331624773e-01 4.542342471963995987e-01 9.788786426453045530e-01 1.881707000343846303e-02 8.005433413647761176e-01 1.523502822273363755e-01 5.630164732287495921e-01 5.946603842470724599e-01 1.225547698678740582e-01 1.531136594724622491e-01 8.157973612638946825e-02 2.752046015644330490e-01 6.809045821946161370e-01 6.455289724528190387e-01 3.830356726830793646e-01 4.446144649678575034e-01 4.969038423960672191e-01 5.497873820641221432e-01 9.471879627821714331e-01 5.933046675329255448e-01 4.099233758501530378e-02 5.790409810134594659e-01 9.546095885251496549e-01 2.608616052375664074e-01 6.910160339170060562e-01 1.293709850476291168e-01 6.407264616302255078e-03 6.186037089828009261e-01 5.537861302543241049e-01 3.527421038298221845e-01 8.033232052121624944e-01 8.128114152830284711e-01 8.319982582278713235e-01 5.939566376046836460e-01 2.291090283499520597e-01 5.438101817725821130e-01 6.881146379117278888e-01 2.421968586304659166e-01 5.874047918543783275e-01 6.210102709484541794e-01 7.041387566450251212e-01 6.959223476278774134e-01 9.133877300988062498e-01 9.230647706207778525e-01 6.856884219815310155e-01 6.997988808693775820e-01 6.177944932528769417e-01 5.512902545683161515e-01 5.818280341729102911e-01 6.538267999985679646e-01 6.946673485935980219e-01 4.817938258357623571e-02 9.352008817207906333e-01 4.774162142215661042e-01 5.768063588692976529e-01 4.589648891483899540e-02 7.998946815651652997e-01 4.434260476954369201e-01 9.850053510925722566e-01 6.648626681529369309e-01 4.606293826856903140e-01 3.309042418210563774e-01 1.438901922508034614e-01 7.986559119276418484e-01 7.037818421334554042e-01 3.605119534240813772e-01 3.785959549258922641e-01 9.562491516841659100e-01 4.997955143590974147e-01 1.029540300938682762e-01 1.819017177001992502e-01 3.665425750262368831e-01 1.688063588370778412e-01 7.030735208313992901e-01 8.922375654244527610e-01 1.055706412056253152e-01 2.664739907746691561e-01 9.906029568647586325e-01 6.043845090140997911e-03 3.495786295043534775e-01 5.989441999519146131e-01 6.776147193866479679e-01 7.012991789852640601e-01 1.825838783477321536e-01 7.612293578749116385e-01 1.564769891240175292e-01 2.762157292905387251e-01 7.641900040015234818e-01
|
| 11 |
+
4.746013333880729768e-01 7.609202966712714788e-01 2.537820854162747830e-01 1.709362234877408460e-01 1.886635378734374813e-01 2.439567014093724229e-02 7.640304718272151741e-01 3.483216170435471382e-01 7.744289278738043514e-01 4.190437573644867353e-01 5.319091476394965934e-02 8.580130976087452233e-01 6.259446446786639529e-01 8.793213970773006150e-01 2.441023074890465994e-01 7.753405549489799098e-01 8.760187573193888300e-01 5.946480724009295393e-02 2.873093046571124631e-01 8.710837851946537924e-01 9.103181731924696596e-01 6.534637257615111272e-01 4.128420398577182793e-01 4.905858108576378607e-01 6.178275806701372108e-02 6.368043900016381320e-01 2.865296941219959148e-01 6.371773028539067241e-01 4.924322796636745325e-01 1.709313290387282080e-01 1.856892551689268700e-01 9.592782603102242289e-01 5.402593764193130976e-02 7.287312244390512506e-01 5.679467572000697073e-01 6.255587794305905724e-02 3.069660218141317953e-01 1.089960430557104232e-01 5.550748245336984965e-01 2.555948886689661803e-01 4.140925514039996980e-01 1.180376445052062628e-01 8.832322629884041820e-01 7.784546946701487169e-02 3.177678935473182698e-01 6.681804863429485764e-02 7.047099396645268854e-01 4.133897376851528582e-01 5.600656990480865627e-01 3.883995683475501837e-01 4.459430113152932362e-01 4.214077227574740681e-01 4.763369230200156235e-01 2.701480661168440545e-01 4.296286564389811824e-01 9.601402258758658936e-01 6.326999441846863359e-01 2.442086919688498670e-01 8.407708423957936938e-01 3.626867985638081437e-01 3.641441713291436733e-01 7.932397565989488530e-01 8.902073520619256941e-01 1.929173010337000838e-01 7.309376779324568973e-01 7.305852858337777977e-01 6.510197444582447313e-01 9.512661608643838695e-01 8.461467164366111016e-01 9.245490147941206605e-01 2.658844813385705663e-01 9.538758859344749208e-01 8.215517204998477041e-01 8.217795540390903097e-01 7.569662091300560780e-01 6.262685322871274218e-01 5.597770510574888725e-01 8.155720175123675197e-01 8.545688745180864965e-01 8.986051518529034610e-01 2.477911506572628708e-01 8.462580108996445860e-01 6.065941220995090255e-01 6.500490804973033665e-01 1.120463882674053169e-01 9.299049132942927010e-02 1.388364074229719858e-02 5.901199124540731367e-01 2.795110110544174464e-02 1.644097083463245124e-01 5.341029647603202646e-01 5.276816677181681570e-01 5.439849107754858304e-01 5.371677986392331405e-02 4.515163125788429488e-01 5.036243367087100964e-01 5.721818679625961801e-01 5.271368612400184617e-03 7.720961020546839304e-01 9.015383457479009266e-01
|
| 12 |
+
8.301526916287945701e-01 8.704609696144033348e-01 2.955689129581380303e-01 1.762209253489944727e-01 2.698172933050072553e-01 1.138095349991521399e-01 4.092588531860634760e-01 8.202978121681584467e-01 2.822241377079557356e-01 6.117376205659387223e-01 7.169923068016897938e-01 9.310256256264415331e-02 3.989664052931106708e-01 1.651874953308862803e-02 7.890202597932294282e-02 9.068686774810821305e-01 5.203866694486933842e-01 4.297748572844445336e-01 5.208786995443430712e-01 2.163224881365530816e-01 7.274307306357226111e-01 1.675784956180090823e-01 5.969822786565782691e-01 8.959750832846602453e-02 1.253794151891943764e-01 5.352628522116801291e-01 2.562706125890066300e-01 6.030433202137867044e-01 8.330717547440393833e-01 9.603613683422040914e-02 7.569714244468559450e-01 3.184801677796517128e-01 1.667069341164499896e-01 3.132470247801235619e-01 6.417752836394801097e-01 6.433909425912354152e-02 4.056860213146201710e-01 3.166772891331335327e-01 9.574059746098845247e-01 1.492907964460536974e-01 8.311513764927496162e-01 6.652928354977717396e-01 2.396804722185036374e-01 5.812361618600220270e-01 9.724228681350225445e-01 2.853983236378453414e-01 5.337719354896472979e-01 6.779446197712412081e-01 5.485102006140557540e-01 9.010109155962182648e-01 5.724439967467525037e-01 5.965540527411405947e-01 1.598667990086183321e-01 1.363934512727023041e-01 5.327536522697270405e-01 4.123866715061276222e-01 4.617251396918636841e-01 6.935944951381239898e-01 4.300337419593377453e-01 1.892407993760835128e-01 1.666936825594794724e-01 4.625634184864588772e-01 4.805197636774838355e-02 7.003542850133466224e-01 2.130226006716084974e-03 8.678863343041013367e-01 4.874478520451258623e-01 7.043560228741558848e-01 6.317719270475393722e-01 5.372392256296196766e-01 2.982649812986511995e-01 1.272558612133412037e-01 2.467337555730741983e-01 6.546893200021091097e-01 6.291921159383098150e-01 8.505920470407707379e-01 4.046520490181828578e-01 3.875732096593392795e-01 8.551517214319142024e-01 4.152602284179877090e-01 9.587779137989138611e-01 6.977437468944928112e-01 3.240620775541913634e-02 4.025873770391376061e-01 5.485549335619134270e-01 7.146066156157020455e-01 3.012702534568838519e-01 3.526414480395153594e-01 3.309707144485515284e-01 4.315687014460974913e-01 6.641934530697197747e-01 2.172886798352815507e-01 4.807480925564590057e-01 5.006795397998469177e-01 5.818100901154411586e-01 2.107716091585690732e-01 6.606606051140029301e-01 9.317629042790995797e-01 9.840326342340242061e-01 5.752000964817773898e-01
|
| 13 |
+
9.843444595454536872e-01 1.339523968066913540e-02 6.082172659959028671e-03 7.828244785439336662e-01 5.069653703872761819e-01 2.804896494365415327e-01 2.112385836660957139e-02 6.016479440778699228e-02 7.457477935084961818e-01 3.445503949245375397e-01 4.063494277166557200e-01 8.630275274433116817e-01 5.948396018456146850e-01 1.400867933474212457e-01 6.997522422654076646e-01 5.766519767930851081e-01 5.419976500582250889e-01 7.474121304089603735e-01 2.951600193008566686e-01 7.980170422334191827e-01 1.829036799578199757e-01 6.317636496261300749e-01 2.812612231140887431e-02 5.464747656105657381e-01 3.909873503320924204e-01 4.940850205957293406e-01 8.157850130814222611e-01 5.111092739445756150e-01 9.336823640685747439e-01 7.157105167170837445e-01 7.778989455994214097e-01 1.398722535910470466e-01 5.642653936300449091e-01 3.218717164845980028e-01 9.717427501967056402e-01 3.665791984428700134e-01 3.874321311211759156e-02 9.437600858738082188e-02 5.679526822961932231e-01 5.141385991358327079e-01 7.497840799582222715e-02 5.736515309094968318e-01 1.928132849879083954e-01 6.924244068001785823e-01 1.748389677952593146e-01 4.469577663506929532e-01 1.738527450963387455e-01 7.195287763517190793e-01 8.861150811892871682e-01 1.058443750714600506e-01 1.941789362229970894e-01 9.188374820700584422e-02 7.706736301449305104e-01 6.718642548609364828e-01 5.981029087121966237e-01 4.832880127232569434e-01 3.073688779938709148e-01 5.156312334804930009e-01 1.777418420119527553e-01 8.885462205165685079e-01 4.486254681289014723e-02 1.345398129556140132e-01 7.467627984379916484e-01 4.384565546058830643e-01 7.217750080760946263e-01 3.949550352625393890e-01 4.307950907642028593e-01 6.087680934849041270e-01 3.294516167246774874e-01 1.316682090209408962e-01 1.824857738754404046e-01 5.332379826483617524e-01 3.567136182864261151e-02 1.976220743086236631e-01 5.849349042822560296e-01 1.133174406357483344e-01 7.711522754393199675e-01 8.557306786807005183e-01 3.038353471344266143e-01 4.422747047768413875e-01 2.537160404215925702e-01 2.372714099723788328e-01 5.906462765375103396e-01 4.849909323133470007e-01 2.692576210504484813e-01 4.540849506602829821e-01 9.664935719107857759e-01 2.044371576459835804e-01 4.505417469690352616e-01 7.110722322201217249e-01 3.051357995214963870e-01 8.978937034341526457e-01 6.090501112506481185e-01 6.595415779178889215e-01 6.565426836745864581e-01 6.565608489824376059e-01 2.679102664248229626e-01 3.819533138204529443e-01 6.609794961162380744e-01 2.289558446859882856e-01
|
| 14 |
+
9.274935298374649140e-01 1.174096651033715855e-01 3.030761852629033637e-01 1.605508209527917174e-01 9.601854834873225775e-01 4.341959513718630648e-01 6.320768160802121560e-01 4.213429090614078110e-01 3.695553969042019160e-01 5.965457437116089556e-01 3.520335041155040479e-01 7.702703502247409961e-01 8.571112772962534709e-01 7.904077282532658844e-01 2.247339318352784554e-01 6.823720204503556097e-01 5.883435710582129996e-02 6.786037033312407596e-01 9.721137137641507886e-01 2.042576970668320557e-01 8.394085754806240862e-01 7.433082729552867862e-01 4.072614159870893147e-01 7.451483066617257123e-01 1.699472962789440045e-01 1.753052015584344314e-01 2.255269204788400428e-01 7.794755643807432799e-01 8.407732260470973662e-01 9.301182862857163558e-01 3.701995309382508648e-01 4.481909027604019657e-01 1.261889085033987001e-01 5.600591735875248833e-01 8.244692493969552061e-01 8.969188061645969601e-01 4.802217973423368313e-01 3.556164122713412201e-02 3.393317823164623270e-01 2.491242957582864292e-01 9.863253789366602797e-01 5.585415885291432625e-01 3.702350606362231344e-01 6.766101432620400535e-01 6.999259389475386284e-01 6.676108316872160220e-01 7.870681827507105544e-01 8.746765411259082024e-01 9.125268371282718727e-01 6.638849997061806452e-01 3.253268113800632522e-01 7.968625619248901337e-01 7.584122525443606211e-01 9.028886850768532701e-01 5.381622293189292083e-02 8.097562873320752752e-01 7.092942088208666895e-01 9.915538877968065323e-01 4.319294903327922652e-01 4.307127933969153721e-01 2.768507739641907772e-01 8.076253078288621046e-01 2.569233696442670967e-01 7.595893829724666979e-01 5.768081727897018673e-01 2.537536777625452045e-01 8.874419624636734616e-01 5.091705681832693342e-01 4.811826624992353585e-01 2.794462461940371290e-01 3.846927898276129021e-01 5.129562951959991679e-01 8.515004062224775794e-01 7.103144978683579858e-01 9.526388607201888847e-01 2.367905569592337889e-01 9.137336039323161740e-01 5.722969943101696710e-02 2.019723935481291255e-01 3.098764675203513619e-02 1.121146613918624357e-01 9.937693067724532314e-01 8.476717958861412772e-02 2.059652110343795917e-01 2.139791918759540446e-01 9.137860316709250919e-01 9.530862653366889425e-03 2.027843281683039400e-03 2.506229951837134484e-01 6.244523528392044165e-01 5.523937894075592325e-01 3.712168074031840792e-01 4.218847794299319665e-01 4.827576239387890711e-01 5.244634168840578425e-01 5.182241092381567604e-01 3.308639956263292881e-03 9.370528021570383448e-01 4.694554875029453012e-01 4.950447554541728135e-01
|
| 15 |
+
1.525818111800841814e-01 4.708012184002630107e-02 3.899035965341954846e-01 3.928304521031263929e-01 5.602286661727436945e-01 9.738256658043862313e-01 9.404465779766183475e-01 5.750862754958349088e-01 9.547546956257608741e-01 2.750275291553152535e-01 1.682773435862793265e-01 5.865928471016079726e-04 8.543378154943809255e-01 3.547649971465383079e-01 5.058056647397523031e-01 9.116332486700751137e-02 7.534666421106954726e-01 3.082429494433007733e-01 4.527145111847344916e-01 5.456680635225539255e-01 2.504131242494785914e-01 2.509240770568589296e-01 3.949236999582302898e-01 8.782959620323271821e-03 2.474641132111736752e-01 8.229417958971670943e-01 3.444225768479134420e-01 4.000027489436257522e-01 4.247741954177396417e-01 2.497745404169693373e-02 4.325768602588443423e-01 7.336592463477830117e-01 7.667663267650381975e-02 4.179022553581047683e-01 8.745172741480690126e-01 9.417705509525042817e-02 2.807522782799587446e-01 8.212710101351362590e-01 2.211181944001613386e-01 4.319929503523877168e-01 1.858636923768219873e-02 6.737037795085246694e-01 7.997187114913413275e-01 2.976552505976116647e-01 3.272347030789168887e-01 5.550935453236346406e-01 9.224109746648162522e-01 3.192827922106745708e-01 3.500098324549234530e-01 7.821988386980260888e-01 4.478417135239194380e-01 1.580956175222456572e-01 5.300807813550156844e-01 5.806154798468634581e-01 9.456842911054151868e-01 7.688127895655872956e-01 8.456527833650537840e-01 1.784229089865225770e-01 8.114517450321339087e-01 8.062506298824222428e-01 2.113482500442499523e-01 2.629226789210241666e-01 6.478686221690072022e-01 6.006672861605766300e-02 7.013679843242253131e-01 8.784753961212666828e-01 3.487138165323044880e-02 4.928426758517070461e-01 5.976224683315064512e-01 7.629063997052759616e-01 2.761721278953045422e-01 7.240740503283805696e-01 6.131065729985127888e-01 1.630885615792579957e-01 8.473783868551159060e-01 8.347614542399306448e-02 8.137265626844719657e-01 8.512508664918938539e-01 2.777097816703766320e-01 1.729154355214796990e-01 2.203382750835449766e-01 6.134780912629795857e-01 3.524352564238901753e-01 5.370314860129862256e-01 8.013986113284543578e-02 2.555842138998117852e-01 6.553915758947851389e-01 9.679125599178584061e-01 2.549566319678178150e-01 4.008180804370896633e-01 9.145789951670967310e-01 2.787926039163850511e-01 8.599455912576436933e-02 9.637558000691170967e-02 8.274101203974880692e-01 1.803747268179315411e-01 2.175735407836230095e-01 7.825994939720237742e-01 7.928519890958951599e-02 8.707949373106749213e-01
|
| 16 |
+
6.398420210047787160e-01 5.739624494012524059e-01 3.359672805578653998e-01 1.130399363175038641e-02 3.349439685346782269e-01 2.315484030880912147e-01 4.575228302577399875e-01 1.149494135594463229e-01 2.888244352925943836e-01 3.625470995156252485e-01 3.795973190611611203e-01 6.567047810450010736e-01 1.484039742710284715e-01 9.273251916560719676e-01 4.334256728976307871e-01 6.734771102219323513e-01 9.125080197222198430e-01 4.974393931097168542e-01 8.301481563280355136e-01 4.526450714147856047e-01 2.414236092573898151e-01 8.070129698367667359e-02 7.260400697427102923e-01 1.396509691839398215e-02 2.496450588391967429e-01 4.335741205447194435e-01 3.089314419194891803e-01 9.543503534526003307e-01 5.457977547458532364e-01 3.139663643587058406e-01 5.034762326753475792e-01 4.756788330475764104e-01 6.849334942793482428e-01 3.880666613022351052e-01 6.483446580176778218e-01 5.217503801099343530e-01 5.371145824070304720e-01 3.121260159429154468e-01 8.314121854062171968e-01 4.538695969561833410e-01 8.598896961203845724e-01 9.961993522734106099e-01 8.865717795946430613e-01 7.828987966783660379e-01 3.412415531643435695e-01 7.421170530151157685e-01 4.484104178639959359e-01 6.793217012099640462e-01 3.756179958191659951e-01 7.821287098222597933e-01 6.227726265188193722e-02 8.552983413221663112e-01 4.824668768009222619e-01 2.241531065858231031e-01 4.939536577599041856e-01 5.129566641128722182e-01 1.057984177672518511e-01 9.541452507300716146e-01 3.396646181755047511e-01 7.452588103611947901e-01 5.315559265659929311e-01 5.493475179850665358e-01 5.214824278139198466e-01 5.150075718147916204e-01 1.196075368500321146e-01 9.035665331176232495e-01 7.522653903639873185e-01 6.638708679914825384e-01 5.584174553800479446e-01 5.015819402508836511e-01 5.507698483308445248e-01 5.978677577011723976e-01 8.450418028759657529e-01 3.266677322748618995e-01 1.321610045897971819e-01 2.394354042746985600e-01 2.723972163557076831e-01 5.523301747352814539e-01 5.518043850608547185e-01 5.283968096837132755e-02 8.192733312104071297e-01 2.277106024970321219e-02 1.414998099027269252e-01 6.517281615256080851e-01 1.811694734825117781e-01 9.472370614713256920e-01 5.454497319021770485e-01 1.364119913158231556e-01 8.446142008509562871e-01 7.671725984742419069e-01 2.461161648406858804e-01 1.421724627107351369e-01 6.290652581179481118e-01 7.094144689448004248e-01 4.419656923472803367e-02 6.614741876652251440e-01 8.712193265403500586e-02 4.734931280852430202e-01 5.382037050480286133e-01 1.396459758005891283e-01
|
| 17 |
+
9.709329844415439670e-01 8.998575745276288229e-01 9.151313462895852568e-01 6.920489275523904471e-01 2.892231405199537919e-01 6.750679746268205550e-01 5.515642485826798280e-01 1.065253097812824956e-01 2.957026803465776510e-01 8.937347659632134400e-01 9.800016515925590310e-01 7.745900896182087436e-01 1.570977683146633774e-01 1.482028765821026273e-01 2.111147779712029271e-01 9.683759902485811200e-01 6.550951580826911425e-01 8.728324682592377703e-01 5.044803166579884257e-01 8.285704754811143991e-01 1.693574499337324735e-02 6.032669995180495182e-02 1.687026879086964692e-01 7.701554026145973619e-01 1.429888016593102718e-01 5.881172815379975827e-02 9.704206919487038396e-01 4.450807650730836951e-01 1.597445784258376689e-01 9.849229394397314152e-01 4.220083573536804744e-01 9.357693600374825671e-01 2.313199262338369033e-01 4.556443403861323294e-01 2.590791012828855822e-01 8.438664994487065085e-01 5.519045677502344427e-01 4.702170125676508050e-01 6.814723205638187897e-01 7.418295483665861001e-01 3.684921032028853904e-01 1.501895844844561845e-01 4.214513377519605308e-01 8.600279963652578408e-01 6.625616611189292238e-01 5.200151456470966105e-01 7.881072743086801058e-01 2.771703241081423519e-01 9.034135930616548071e-01 5.848441705791300738e-01 8.341698181274771473e-01 1.966638677318299777e-01 7.059747894371543042e-01 7.013854316067694716e-01 1.828430942760242983e-01 4.745548949934464966e-01 6.306422394641082452e-01 7.760751707194470939e-01 9.813187212598396547e-01 2.293595795266353266e-01 7.749261876107090830e-01 2.384106107787011819e-01 9.721209688979495223e-01 2.715569353686980714e-01 2.915573577694993146e-01 3.579601509630966349e-01 3.085697512342830962e-01 4.070219981627976047e-01 1.989632411372218579e-01 7.330003339460906542e-01 5.397259604481572381e-01 6.931009942216573849e-01 1.385457419653816080e-01 1.140339999976658358e-01 3.980752590866034613e-01 9.471822621683767540e-01 5.476643721405823895e-01 6.824131903515884279e-02 5.844099130744569992e-01 2.346881692012994236e-01 9.436439228519653000e-01 4.855518260479008141e-02 8.157036123302675579e-01 1.169761256455048581e-01 5.532962903488753970e-01 1.100965596251435308e-01 9.789490602992410029e-01 8.433487462016989733e-01 1.272410782852178013e-01 2.885715258680641160e-01 7.990943955388217779e-01 1.565305358979097727e-01 9.160846960406943129e-02 8.521842244411678147e-01 4.474243106736998099e-01 3.843945818845087015e-01 4.710645906071458944e-01 2.398348154123419729e-01 6.435351435258193087e-01 7.656897921129046658e-01
|
| 18 |
+
4.894328120406804539e-01 7.881019629214267574e-01 6.974585354155089512e-01 2.023858939857701156e-01 1.660984914264745926e-01 4.854517801734643534e-01 2.789848572630315715e-01 2.311636522410289718e-01 9.821076233980715608e-01 1.220641257408076052e-01 2.614036146663852866e-01 7.657560715165320220e-01 3.968360577545695378e-01 4.566023622802184434e-02 1.049701948619241598e-02 9.281162949127452766e-01 4.490137965769909201e-01 2.095846458383606725e-01 9.195504656719085679e-01 9.683515436855471004e-01 9.800174878114910060e-01 5.517610861380117804e-01 6.711570559348770670e-01 5.125258050287277989e-01 2.105581493613526423e-01 8.281813206544574868e-01 4.964783994807770995e-01 7.284974208756571645e-01 1.320629592816270348e-01 6.652194518096135045e-01 9.430156297917950958e-01 7.477263137894260003e-01 2.054087806450300979e-01 4.248209124837907247e-01 7.657518666018259257e-02 1.031614100713345028e-01 4.122242287567021712e-01 4.919658859336810686e-01 3.752650167259050651e-01 4.175771429986683270e-01 6.131376293448997927e-01 5.463797405837259591e-01 3.119918548921774004e-01 6.331762507678504459e-01 5.484632429281035559e-01 6.815448032785871302e-01 8.065695507425107991e-02 8.720129122297424207e-01 8.318188557125294480e-03 2.199323537180564170e-02 8.933872719887463454e-01 1.953120287872067706e-02 2.478721941404590234e-01 5.994061179859005994e-01 6.588362611693047155e-01 6.332808851020984564e-01 3.823849348043323326e-01 5.111091324899629251e-01 7.034808459110406531e-01 4.347681568463539481e-01 4.316973576672314961e-01 9.620411080123215664e-01 6.247837467655984467e-01 8.196961678222113301e-01 5.574601810887074294e-01 8.800635018469276094e-01 8.772255241161972528e-01 5.075275933138404527e-01 8.022583187266906224e-01 2.320670802521890286e-01 1.165626629103270195e-01 4.623759662685936744e-01 7.938327000737943617e-02 7.986374689793115378e-01 6.728842751465858862e-01 8.133909095059230765e-01 1.202639390769081329e-01 1.052937257108800262e-01 8.717600467040409473e-02 2.163819956545051104e-01 6.596483385763984852e-01 1.202843170392309258e-02 1.538789195854695091e-01 3.120247727263308901e-01 3.408168327248596308e-01 3.241861797851740556e-01 3.637074533655986208e-01 1.533669345890729119e-01 4.455921334699539660e-01 5.619140093874478437e-01 1.881731359879111887e-01 9.416670800570559052e-01 1.740018593664415247e-01 7.030242331869680505e-01 5.922055553954849172e-01 9.326211623391688077e-01 6.608322881013140027e-01 7.009721551241574478e-01 1.079126054675583202e-01 6.158176671761947940e-01
|
| 19 |
+
5.185079639625639336e-01 9.613742991518259284e-01 5.555312825626229634e-01 2.647628827924735084e-01 6.003697207460141350e-01 5.392112376769145898e-01 6.781186965667050925e-01 9.908971748181496508e-01 4.124155872095397468e-01 9.814941401724619485e-02 2.684237785531295994e-02 1.774652505962848181e-01 1.707589529595294753e-01 4.640932098465534450e-01 2.882179883914587348e-01 7.276822905806898945e-01 6.145789546745269449e-01 1.100959863917608805e-01 6.798859723042820491e-01 9.096984032948918220e-01 3.971368455178179158e-01 2.959494950971321980e-01 3.742088799298171065e-02 1.960739526210202310e-01 7.536102695342027369e-01 6.680915510628401277e-01 4.136507204312135366e-01 3.613996339406737590e-01 3.605422038261204554e-01 7.098503555159476619e-01 8.093719147087541366e-01 6.344097009128880638e-01 3.990082448083617228e-01 2.805918009906902544e-01 7.078488167363675698e-01 9.969917259866583059e-01 9.442054998992396309e-01 1.329075240769165278e-01 6.810681350588387861e-02 8.503491437913293094e-01 8.347117439165431252e-01 2.381858201903953587e-01 7.884260706938626129e-01 7.109907917419661105e-01 6.390916681983604963e-02 6.174365227062991179e-01 5.085733343630816083e-01 1.716846139694149231e-01 9.065664924270055991e-02 5.625330757196970177e-01 3.539663480209681579e-01 8.937139525947165319e-01 3.981380511900556307e-02 7.403597927449541150e-01 3.803872284089604427e-02 6.729519695709765825e-01 5.306080908840085097e-01 2.091237680402112664e-01 5.902903662907804661e-01 2.094778612095482551e-01 7.323447855684165342e-01 3.644574495843493356e-01 2.006215478057034041e-01 3.737617545555030896e-01 5.253471759602216240e-01 4.287889547869583318e-01 7.086098806190446187e-01 4.510792335515292351e-01 6.383187180169215269e-01 8.779355722397681472e-01 4.221338898667141848e-01 6.375840144651815367e-01 8.683057298299173832e-01 6.093730356952498095e-01 9.297141161056151626e-01 7.770838342807246946e-01 6.549661287008456956e-02 2.835060738158660110e-01 4.474138867374952699e-01 8.530336387421445510e-01 3.160209657891883683e-01 8.301538680518486535e-01 6.646903097549101691e-01 7.187130118106234145e-01 1.651862041735395747e-01 9.578252676762609719e-01 6.490273812885494209e-02 9.777273484666341163e-01 8.930729829254262508e-01 9.851054752118463265e-01 4.094323402286751401e-01 1.139176240124337713e-01 7.612865863899589414e-01 2.266379302491570158e-01 6.998882496157835531e-01 9.945043379099228753e-01 7.111578056749194854e-01 7.806190603886183910e-01 3.410170920712443099e-01 9.446084168886822452e-01
|
| 20 |
+
5.015172758330755931e-01 5.569527971282052237e-01 1.122406928736449094e-01 8.960352822124777461e-01 6.049568585854003810e-02 1.202196001338627918e-01 1.870314295763603196e-01 9.017590029396971296e-01 3.597904628087450485e-01 2.130941062746317671e-01 2.556281834629479111e-01 5.123669364829196438e-01 4.754061129282013409e-01 9.764470380372083369e-01 8.038663983900646848e-01 6.960491266420890666e-01 2.940135977911654264e-01 2.857282759910040326e-03 4.599343225832352999e-02 5.597554495210212977e-01 7.445266674304001908e-01 3.387528030535971180e-01 6.429542922125383031e-01 2.123331785532429627e-01 5.302332654117811739e-01 7.262555377662539557e-01 3.982425859900724507e-01 3.243388301740235402e-01 6.191064123738921898e-01 8.988047781373914580e-01 7.819700328765150088e-01 7.664269102804815992e-01 6.734095355422575757e-03 2.904762329148526945e-01 5.097537644843168625e-01 9.524734606001823423e-01 4.812869576591960463e-01 6.236868013640477493e-01 1.459170943214320726e-01 9.874505139403206844e-01 7.561708982837871407e-01 3.798591332432484924e-01 6.056633451375117438e-01 7.935708170258731764e-01 1.458141583518740569e-01 7.082511296391911237e-01 1.098798009731616343e-02 3.655618484905173160e-01 9.551862303858617009e-01 8.148959351152762487e-02 4.739306219219985294e-02 7.963357515359494876e-01 6.208332695202813944e-01 3.884182264923189409e-01 4.589167647950288531e-01 6.496652974138312775e-01 2.467528128074852889e-01 5.309593064844935206e-01 5.364606369543487574e-01 2.421352989851309756e-01 3.776834556696828660e-02 1.564861233558080267e-01 5.197231021782636740e-01 8.725375120634637494e-01 2.441225493455024820e-01 2.320363366041028330e-01 5.026358683423555185e-01 7.035766000474735771e-01 8.347805591467084563e-01 2.303229841813967393e-01 6.908373419683054850e-01 2.646662377366995056e-01 1.259467197942290007e-01 9.372770922994989595e-01 6.674216272867254940e-01 1.027944489143072238e-01 5.686267290346079806e-01 3.948222804451942958e-01 4.689706944496729868e-01 4.446117700449114807e-02 6.817992275557515081e-01 9.084821829413957106e-01 9.184021015315092518e-01 3.045815734169987632e-01 2.204958624923980537e-03 7.542672057172502553e-01 9.460844786545006269e-01 3.373139094575949848e-02 9.059565314915285494e-01 9.938525461318854504e-01 2.542072661725306437e-01 9.685734112479216229e-02 8.223629541824816203e-01 1.057429056898460118e-01 8.080679390260248063e-01 5.823014244609205914e-01 6.413551528031806725e-01 1.787341975438894170e-01 1.250471413912357388e-01 8.390281297596062782e-01
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/data/pdist-hamming-ml.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
4.6000000e-01 4.3000000e-01 4.3000000e-01 5.4000000e-01 4.1000000e-01 5.3000000e-01 4.3000000e-01 5.9000000e-01 4.8000000e-01 4.7000000e-01 4.6000000e-01 4.9000000e-01 4.5000000e-01 5.5000000e-01 5.3000000e-01 4.5000000e-01 4.8000000e-01 4.7000000e-01 4.8000000e-01 5.1000000e-01 4.9000000e-01 4.4000000e-01 4.9000000e-01 4.7000000e-01 4.9000000e-01 4.7000000e-01 5.2000000e-01 4.7000000e-01 4.2000000e-01 4.9000000e-01 4.7000000e-01 5.5000000e-01 3.9000000e-01 5.5000000e-01 4.6000000e-01 4.5000000e-01 4.0000000e-01 4.8000000e-01 4.5000000e-01 4.8000000e-01 4.8000000e-01 5.0000000e-01 4.8000000e-01 4.5000000e-01 6.4000000e-01 5.7000000e-01 4.6000000e-01 5.4000000e-01 5.6000000e-01 4.8000000e-01 4.8000000e-01 5.3000000e-01 5.4000000e-01 5.3000000e-01 4.5000000e-01 5.8000000e-01 4.2000000e-01 5.4000000e-01 6.0000000e-01 5.1000000e-01 4.6000000e-01 4.1000000e-01 4.4000000e-01 5.6000000e-01 5.4000000e-01 4.8000000e-01 4.8000000e-01 5.1000000e-01 5.2000000e-01 5.5000000e-01 4.5000000e-01 4.3000000e-01 4.7000000e-01 4.7000000e-01 5.6000000e-01 4.9000000e-01 4.8000000e-01 4.5000000e-01 4.9000000e-01 4.7000000e-01 4.5000000e-01 4.5000000e-01 5.6000000e-01 4.9000000e-01 5.8000000e-01 5.4000000e-01 4.6000000e-01 5.8000000e-01 5.3000000e-01 5.4000000e-01 5.5000000e-01 5.0000000e-01 5.2000000e-01 4.8000000e-01 5.0000000e-01 3.8000000e-01 5.3000000e-01 4.8000000e-01 5.1000000e-01 4.8000000e-01 5.2000000e-01 4.7000000e-01 5.0000000e-01 4.3000000e-01 4.8000000e-01 5.2000000e-01 5.0000000e-01 4.2000000e-01 4.2000000e-01 4.7000000e-01 5.4000000e-01 5.1000000e-01 5.4000000e-01 5.1000000e-01 4.8000000e-01 4.7000000e-01 5.2000000e-01 5.2000000e-01 5.4000000e-01 5.4000000e-01 5.0000000e-01 4.5000000e-01 4.4000000e-01 4.1000000e-01 5.7000000e-01 4.6000000e-01 5.1000000e-01 5.2000000e-01 5.0000000e-01 4.8000000e-01 5.0000000e-01 4.4000000e-01 5.3000000e-01 5.2000000e-01 4.9000000e-01 5.7000000e-01 5.8000000e-01 4.9000000e-01 5.1000000e-01 4.5000000e-01 5.3000000e-01 4.5000000e-01 4.4000000e-01 3.5000000e-01 4.2000000e-01 5.3000000e-01 5.2000000e-01 5.0000000e-01 3.8000000e-01 5.2000000e-01 5.6000000e-01 4.7000000e-01 4.4000000e-01 5.1000000e-01 5.7000000e-01 4.5000000e-01 5.7000000e-01 4.3000000e-01 5.1000000e-01 3.8000000e-01 5.3000000e-01 4.8000000e-01 4.4000000e-01 5.0000000e-01 4.8000000e-01 5.0000000e-01 4.7000000e-01 6.4000000e-01 4.9000000e-01 5.2000000e-01 4.8000000e-01 5.6000000e-01 4.3000000e-01 4.8000000e-01 4.7000000e-01 6.0000000e-01 5.4000000e-01 5.5000000e-01 4.0000000e-01 5.5000000e-01 5.6000000e-01 4.9000000e-01 5.0000000e-01 4.3000000e-01 5.7000000e-01 5.0000000e-01 5.7000000e-01 4.9000000e-01 4.2000000e-01 3.9000000e-01
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/data/pdist-jensenshannon-ml-iris.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/test__plotutils.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
import numpy as np
|
| 3 |
+
from numpy.testing import assert_, assert_array_equal, assert_allclose
|
| 4 |
+
|
| 5 |
+
try:
|
| 6 |
+
import matplotlib
|
| 7 |
+
matplotlib.rcParams['backend'] = 'Agg'
|
| 8 |
+
import matplotlib.pyplot as plt
|
| 9 |
+
has_matplotlib = True
|
| 10 |
+
except Exception:
|
| 11 |
+
has_matplotlib = False
|
| 12 |
+
|
| 13 |
+
from scipy.spatial import \
|
| 14 |
+
delaunay_plot_2d, voronoi_plot_2d, convex_hull_plot_2d, \
|
| 15 |
+
Delaunay, Voronoi, ConvexHull
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
@pytest.mark.skipif(not has_matplotlib, reason="Matplotlib not available")
|
| 19 |
+
class TestPlotting:
|
| 20 |
+
points = [(0,0), (0,1), (1,0), (1,1)]
|
| 21 |
+
|
| 22 |
+
def test_delaunay(self):
|
| 23 |
+
# Smoke test
|
| 24 |
+
fig = plt.figure()
|
| 25 |
+
obj = Delaunay(self.points)
|
| 26 |
+
s_before = obj.simplices.copy()
|
| 27 |
+
r = delaunay_plot_2d(obj, ax=fig.gca())
|
| 28 |
+
assert_array_equal(obj.simplices, s_before) # shouldn't modify
|
| 29 |
+
assert_(r is fig)
|
| 30 |
+
delaunay_plot_2d(obj, ax=fig.gca())
|
| 31 |
+
|
| 32 |
+
def test_voronoi(self):
|
| 33 |
+
# Smoke test
|
| 34 |
+
fig = plt.figure()
|
| 35 |
+
obj = Voronoi(self.points)
|
| 36 |
+
r = voronoi_plot_2d(obj, ax=fig.gca())
|
| 37 |
+
assert_(r is fig)
|
| 38 |
+
voronoi_plot_2d(obj)
|
| 39 |
+
voronoi_plot_2d(obj, show_vertices=False)
|
| 40 |
+
|
| 41 |
+
def test_convex_hull(self):
|
| 42 |
+
# Smoke test
|
| 43 |
+
fig = plt.figure()
|
| 44 |
+
tri = ConvexHull(self.points)
|
| 45 |
+
r = convex_hull_plot_2d(tri, ax=fig.gca())
|
| 46 |
+
assert_(r is fig)
|
| 47 |
+
convex_hull_plot_2d(tri)
|
| 48 |
+
|
| 49 |
+
def test_gh_19653(self):
|
| 50 |
+
# aspect ratio sensitivity of voronoi_plot_2d
|
| 51 |
+
# infinite Voronoi edges
|
| 52 |
+
points = np.array([[245.059986986012, 10.971011721360075],
|
| 53 |
+
[320.49044143557785, 10.970258360366753],
|
| 54 |
+
[239.79023081978914, 13.108487516946218],
|
| 55 |
+
[263.38325791238833, 12.93241352743668],
|
| 56 |
+
[219.53334398353175, 13.346107628161008]])
|
| 57 |
+
vor = Voronoi(points)
|
| 58 |
+
fig = voronoi_plot_2d(vor)
|
| 59 |
+
ax = fig.gca()
|
| 60 |
+
infinite_segments = ax.collections[1].get_segments()
|
| 61 |
+
expected_segments = np.array([[[282.77256, -254.76904],
|
| 62 |
+
[282.729714, -4544.744698]],
|
| 63 |
+
[[282.77256014, -254.76904029],
|
| 64 |
+
[430.08561382, 4032.67658742]],
|
| 65 |
+
[[229.26733285, -20.39957514],
|
| 66 |
+
[-168.17167404, -4291.92545966]],
|
| 67 |
+
[[289.93433364, 5151.40412217],
|
| 68 |
+
[330.40553385, 9441.18887532]]])
|
| 69 |
+
assert_allclose(infinite_segments, expected_segments)
|
| 70 |
+
|
| 71 |
+
def test_gh_19653_smaller_aspect(self):
|
| 72 |
+
# reasonable behavior for less extreme aspect
|
| 73 |
+
# ratio
|
| 74 |
+
points = np.array([[24.059986986012, 10.971011721360075],
|
| 75 |
+
[32.49044143557785, 10.970258360366753],
|
| 76 |
+
[23.79023081978914, 13.108487516946218],
|
| 77 |
+
[26.38325791238833, 12.93241352743668],
|
| 78 |
+
[21.53334398353175, 13.346107628161008]])
|
| 79 |
+
vor = Voronoi(points)
|
| 80 |
+
fig = voronoi_plot_2d(vor)
|
| 81 |
+
ax = fig.gca()
|
| 82 |
+
infinite_segments = ax.collections[1].get_segments()
|
| 83 |
+
expected_segments = np.array([[[28.274979, 8.335027],
|
| 84 |
+
[28.270463, -42.19763338]],
|
| 85 |
+
[[28.27497869, 8.33502697],
|
| 86 |
+
[43.73223829, 56.44555501]],
|
| 87 |
+
[[22.51805823, 11.8621754],
|
| 88 |
+
[-12.09266506, -24.95694485]],
|
| 89 |
+
[[29.53092448, 78.46952378],
|
| 90 |
+
[33.82572726, 128.81934455]]])
|
| 91 |
+
assert_allclose(infinite_segments, expected_segments)
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/test__procrustes.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from numpy.testing import assert_allclose, assert_equal, assert_almost_equal
|
| 3 |
+
from pytest import raises as assert_raises
|
| 4 |
+
|
| 5 |
+
from scipy.spatial import procrustes
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestProcrustes:
|
| 9 |
+
def setup_method(self):
|
| 10 |
+
"""creates inputs"""
|
| 11 |
+
# an L
|
| 12 |
+
self.data1 = np.array([[1, 3], [1, 2], [1, 1], [2, 1]], 'd')
|
| 13 |
+
|
| 14 |
+
# a larger, shifted, mirrored L
|
| 15 |
+
self.data2 = np.array([[4, -2], [4, -4], [4, -6], [2, -6]], 'd')
|
| 16 |
+
|
| 17 |
+
# an L shifted up 1, right 1, and with point 4 shifted an extra .5
|
| 18 |
+
# to the right
|
| 19 |
+
# pointwise distance disparity with data1: 3*(2) + (1 + 1.5^2)
|
| 20 |
+
self.data3 = np.array([[2, 4], [2, 3], [2, 2], [3, 2.5]], 'd')
|
| 21 |
+
|
| 22 |
+
# data4, data5 are standardized (trace(A*A') = 1).
|
| 23 |
+
# procrustes should return an identical copy if they are used
|
| 24 |
+
# as the first matrix argument.
|
| 25 |
+
shiftangle = np.pi / 8
|
| 26 |
+
self.data4 = np.array([[1, 0], [0, 1], [-1, 0],
|
| 27 |
+
[0, -1]], 'd') / np.sqrt(4)
|
| 28 |
+
self.data5 = np.array([[np.cos(shiftangle), np.sin(shiftangle)],
|
| 29 |
+
[np.cos(np.pi / 2 - shiftangle),
|
| 30 |
+
np.sin(np.pi / 2 - shiftangle)],
|
| 31 |
+
[-np.cos(shiftangle),
|
| 32 |
+
-np.sin(shiftangle)],
|
| 33 |
+
[-np.cos(np.pi / 2 - shiftangle),
|
| 34 |
+
-np.sin(np.pi / 2 - shiftangle)]],
|
| 35 |
+
'd') / np.sqrt(4)
|
| 36 |
+
|
| 37 |
+
def test_procrustes(self):
|
| 38 |
+
# tests procrustes' ability to match two matrices.
|
| 39 |
+
#
|
| 40 |
+
# the second matrix is a rotated, shifted, scaled, and mirrored version
|
| 41 |
+
# of the first, in two dimensions only
|
| 42 |
+
#
|
| 43 |
+
# can shift, mirror, and scale an 'L'?
|
| 44 |
+
a, b, disparity = procrustes(self.data1, self.data2)
|
| 45 |
+
assert_allclose(b, a)
|
| 46 |
+
assert_almost_equal(disparity, 0.)
|
| 47 |
+
|
| 48 |
+
# if first mtx is standardized, leaves first mtx unchanged?
|
| 49 |
+
m4, m5, disp45 = procrustes(self.data4, self.data5)
|
| 50 |
+
assert_equal(m4, self.data4)
|
| 51 |
+
|
| 52 |
+
# at worst, data3 is an 'L' with one point off by .5
|
| 53 |
+
m1, m3, disp13 = procrustes(self.data1, self.data3)
|
| 54 |
+
#assert_(disp13 < 0.5 ** 2)
|
| 55 |
+
|
| 56 |
+
def test_procrustes2(self):
|
| 57 |
+
# procrustes disparity should not depend on order of matrices
|
| 58 |
+
m1, m3, disp13 = procrustes(self.data1, self.data3)
|
| 59 |
+
m3_2, m1_2, disp31 = procrustes(self.data3, self.data1)
|
| 60 |
+
assert_almost_equal(disp13, disp31)
|
| 61 |
+
|
| 62 |
+
# try with 3d, 8 pts per
|
| 63 |
+
rand1 = np.array([[2.61955202, 0.30522265, 0.55515826],
|
| 64 |
+
[0.41124708, -0.03966978, -0.31854548],
|
| 65 |
+
[0.91910318, 1.39451809, -0.15295084],
|
| 66 |
+
[2.00452023, 0.50150048, 0.29485268],
|
| 67 |
+
[0.09453595, 0.67528885, 0.03283872],
|
| 68 |
+
[0.07015232, 2.18892599, -1.67266852],
|
| 69 |
+
[0.65029688, 1.60551637, 0.80013549],
|
| 70 |
+
[-0.6607528, 0.53644208, 0.17033891]])
|
| 71 |
+
|
| 72 |
+
rand3 = np.array([[0.0809969, 0.09731461, -0.173442],
|
| 73 |
+
[-1.84888465, -0.92589646, -1.29335743],
|
| 74 |
+
[0.67031855, -1.35957463, 0.41938621],
|
| 75 |
+
[0.73967209, -0.20230757, 0.52418027],
|
| 76 |
+
[0.17752796, 0.09065607, 0.29827466],
|
| 77 |
+
[0.47999368, -0.88455717, -0.57547934],
|
| 78 |
+
[-0.11486344, -0.12608506, -0.3395779],
|
| 79 |
+
[-0.86106154, -0.28687488, 0.9644429]])
|
| 80 |
+
res1, res3, disp13 = procrustes(rand1, rand3)
|
| 81 |
+
res3_2, res1_2, disp31 = procrustes(rand3, rand1)
|
| 82 |
+
assert_almost_equal(disp13, disp31)
|
| 83 |
+
|
| 84 |
+
def test_procrustes_shape_mismatch(self):
|
| 85 |
+
assert_raises(ValueError, procrustes,
|
| 86 |
+
np.array([[1, 2], [3, 4]]),
|
| 87 |
+
np.array([[5, 6, 7], [8, 9, 10]]))
|
| 88 |
+
|
| 89 |
+
def test_procrustes_empty_rows_or_cols(self):
|
| 90 |
+
empty = np.array([[]])
|
| 91 |
+
assert_raises(ValueError, procrustes, empty, empty)
|
| 92 |
+
|
| 93 |
+
def test_procrustes_no_variation(self):
|
| 94 |
+
assert_raises(ValueError, procrustes,
|
| 95 |
+
np.array([[42, 42], [42, 42]]),
|
| 96 |
+
np.array([[45, 45], [45, 45]]))
|
| 97 |
+
|
| 98 |
+
def test_procrustes_bad_number_of_dimensions(self):
|
| 99 |
+
# fewer dimensions in one dataset
|
| 100 |
+
assert_raises(ValueError, procrustes,
|
| 101 |
+
np.array([1, 1, 2, 3, 5, 8]),
|
| 102 |
+
np.array([[1, 2], [3, 4]]))
|
| 103 |
+
|
| 104 |
+
# fewer dimensions in both datasets
|
| 105 |
+
assert_raises(ValueError, procrustes,
|
| 106 |
+
np.array([1, 1, 2, 3, 5, 8]),
|
| 107 |
+
np.array([1, 1, 2, 3, 5, 8]))
|
| 108 |
+
|
| 109 |
+
# zero dimensions
|
| 110 |
+
assert_raises(ValueError, procrustes, np.array(7), np.array(11))
|
| 111 |
+
|
| 112 |
+
# extra dimensions
|
| 113 |
+
assert_raises(ValueError, procrustes,
|
| 114 |
+
np.array([[[11], [7]]]),
|
| 115 |
+
np.array([[[5, 13]]]))
|
| 116 |
+
|
openflamingo/lib/python3.10/site-packages/scipy/spatial/tests/test_spherical_voronoi.py
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import itertools
|
| 3 |
+
from numpy.testing import (assert_equal,
|
| 4 |
+
assert_almost_equal,
|
| 5 |
+
assert_array_equal,
|
| 6 |
+
assert_array_almost_equal)
|
| 7 |
+
import pytest
|
| 8 |
+
from pytest import raises as assert_raises
|
| 9 |
+
from scipy.spatial import SphericalVoronoi, distance
|
| 10 |
+
from scipy.optimize import linear_sum_assignment
|
| 11 |
+
from scipy.constants import golden as phi
|
| 12 |
+
from scipy.special import gamma
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
TOL = 1E-10
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def _generate_tetrahedron():
|
| 19 |
+
return np.array([[1, 1, 1], [1, -1, -1], [-1, 1, -1], [-1, -1, 1]])
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _generate_cube():
|
| 23 |
+
return np.array(list(itertools.product([-1, 1.], repeat=3)))
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def _generate_octahedron():
|
| 27 |
+
return np.array([[-1, 0, 0], [+1, 0, 0], [0, -1, 0],
|
| 28 |
+
[0, +1, 0], [0, 0, -1], [0, 0, +1]])
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _generate_dodecahedron():
|
| 32 |
+
|
| 33 |
+
x1 = _generate_cube()
|
| 34 |
+
x2 = np.array([[0, -phi, -1 / phi],
|
| 35 |
+
[0, -phi, +1 / phi],
|
| 36 |
+
[0, +phi, -1 / phi],
|
| 37 |
+
[0, +phi, +1 / phi]])
|
| 38 |
+
x3 = np.array([[-1 / phi, 0, -phi],
|
| 39 |
+
[+1 / phi, 0, -phi],
|
| 40 |
+
[-1 / phi, 0, +phi],
|
| 41 |
+
[+1 / phi, 0, +phi]])
|
| 42 |
+
x4 = np.array([[-phi, -1 / phi, 0],
|
| 43 |
+
[-phi, +1 / phi, 0],
|
| 44 |
+
[+phi, -1 / phi, 0],
|
| 45 |
+
[+phi, +1 / phi, 0]])
|
| 46 |
+
return np.concatenate((x1, x2, x3, x4))
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def _generate_icosahedron():
|
| 50 |
+
x = np.array([[0, -1, -phi],
|
| 51 |
+
[0, -1, +phi],
|
| 52 |
+
[0, +1, -phi],
|
| 53 |
+
[0, +1, +phi]])
|
| 54 |
+
return np.concatenate([np.roll(x, i, axis=1) for i in range(3)])
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _generate_polytope(name):
|
| 58 |
+
polygons = ["triangle", "square", "pentagon", "hexagon", "heptagon",
|
| 59 |
+
"octagon", "nonagon", "decagon", "undecagon", "dodecagon"]
|
| 60 |
+
polyhedra = ["tetrahedron", "cube", "octahedron", "dodecahedron",
|
| 61 |
+
"icosahedron"]
|
| 62 |
+
if name not in polygons and name not in polyhedra:
|
| 63 |
+
raise ValueError("unrecognized polytope")
|
| 64 |
+
|
| 65 |
+
if name in polygons:
|
| 66 |
+
n = polygons.index(name) + 3
|
| 67 |
+
thetas = np.linspace(0, 2 * np.pi, n, endpoint=False)
|
| 68 |
+
p = np.vstack([np.cos(thetas), np.sin(thetas)]).T
|
| 69 |
+
elif name == "tetrahedron":
|
| 70 |
+
p = _generate_tetrahedron()
|
| 71 |
+
elif name == "cube":
|
| 72 |
+
p = _generate_cube()
|
| 73 |
+
elif name == "octahedron":
|
| 74 |
+
p = _generate_octahedron()
|
| 75 |
+
elif name == "dodecahedron":
|
| 76 |
+
p = _generate_dodecahedron()
|
| 77 |
+
elif name == "icosahedron":
|
| 78 |
+
p = _generate_icosahedron()
|
| 79 |
+
|
| 80 |
+
return p / np.linalg.norm(p, axis=1, keepdims=True)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _hypersphere_area(dim, radius):
|
| 84 |
+
# https://en.wikipedia.org/wiki/N-sphere#Closed_forms
|
| 85 |
+
return 2 * np.pi**(dim / 2) / gamma(dim / 2) * radius**(dim - 1)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def _sample_sphere(n, dim, seed=None):
|
| 89 |
+
# Sample points uniformly at random from the hypersphere
|
| 90 |
+
rng = np.random.RandomState(seed=seed)
|
| 91 |
+
points = rng.randn(n, dim)
|
| 92 |
+
points /= np.linalg.norm(points, axis=1, keepdims=True)
|
| 93 |
+
return points
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class TestSphericalVoronoi:
|
| 97 |
+
|
| 98 |
+
def setup_method(self):
|
| 99 |
+
self.points = np.array([
|
| 100 |
+
[-0.78928481, -0.16341094, 0.59188373],
|
| 101 |
+
[-0.66839141, 0.73309634, 0.12578818],
|
| 102 |
+
[0.32535778, -0.92476944, -0.19734181],
|
| 103 |
+
[-0.90177102, -0.03785291, -0.43055335],
|
| 104 |
+
[0.71781344, 0.68428936, 0.12842096],
|
| 105 |
+
[-0.96064876, 0.23492353, -0.14820556],
|
| 106 |
+
[0.73181537, -0.22025898, -0.6449281],
|
| 107 |
+
[0.79979205, 0.54555747, 0.25039913]]
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
def test_constructor(self):
|
| 111 |
+
center = np.array([1, 2, 3])
|
| 112 |
+
radius = 2
|
| 113 |
+
s1 = SphericalVoronoi(self.points)
|
| 114 |
+
# user input checks in SphericalVoronoi now require
|
| 115 |
+
# the radius / center to match the generators so adjust
|
| 116 |
+
# accordingly here
|
| 117 |
+
s2 = SphericalVoronoi(self.points * radius, radius)
|
| 118 |
+
s3 = SphericalVoronoi(self.points + center, center=center)
|
| 119 |
+
s4 = SphericalVoronoi(self.points * radius + center, radius, center)
|
| 120 |
+
assert_array_equal(s1.center, np.array([0, 0, 0]))
|
| 121 |
+
assert_equal(s1.radius, 1)
|
| 122 |
+
assert_array_equal(s2.center, np.array([0, 0, 0]))
|
| 123 |
+
assert_equal(s2.radius, 2)
|
| 124 |
+
assert_array_equal(s3.center, center)
|
| 125 |
+
assert_equal(s3.radius, 1)
|
| 126 |
+
assert_array_equal(s4.center, center)
|
| 127 |
+
assert_equal(s4.radius, radius)
|
| 128 |
+
|
| 129 |
+
# Test a non-sequence/-ndarray based array-like
|
| 130 |
+
s5 = SphericalVoronoi(memoryview(self.points)) # type: ignore[arg-type]
|
| 131 |
+
assert_array_equal(s5.center, np.array([0, 0, 0]))
|
| 132 |
+
assert_equal(s5.radius, 1)
|
| 133 |
+
|
| 134 |
+
def test_vertices_regions_translation_invariance(self):
|
| 135 |
+
sv_origin = SphericalVoronoi(self.points)
|
| 136 |
+
center = np.array([1, 1, 1])
|
| 137 |
+
sv_translated = SphericalVoronoi(self.points + center, center=center)
|
| 138 |
+
assert_equal(sv_origin.regions, sv_translated.regions)
|
| 139 |
+
assert_array_almost_equal(sv_origin.vertices + center,
|
| 140 |
+
sv_translated.vertices)
|
| 141 |
+
|
| 142 |
+
def test_vertices_regions_scaling_invariance(self):
|
| 143 |
+
sv_unit = SphericalVoronoi(self.points)
|
| 144 |
+
sv_scaled = SphericalVoronoi(self.points * 2, 2)
|
| 145 |
+
assert_equal(sv_unit.regions, sv_scaled.regions)
|
| 146 |
+
assert_array_almost_equal(sv_unit.vertices * 2,
|
| 147 |
+
sv_scaled.vertices)
|
| 148 |
+
|
| 149 |
+
def test_old_radius_api_error(self):
|
| 150 |
+
with pytest.raises(ValueError, match='`radius` is `None`. *'):
|
| 151 |
+
SphericalVoronoi(self.points, radius=None)
|
| 152 |
+
|
| 153 |
+
def test_sort_vertices_of_regions(self):
|
| 154 |
+
sv = SphericalVoronoi(self.points)
|
| 155 |
+
unsorted_regions = sv.regions
|
| 156 |
+
sv.sort_vertices_of_regions()
|
| 157 |
+
assert_equal(sorted(sv.regions), sorted(unsorted_regions))
|
| 158 |
+
|
| 159 |
+
def test_sort_vertices_of_regions_flattened(self):
|
| 160 |
+
expected = sorted([[0, 6, 5, 2, 3], [2, 3, 10, 11, 8, 7], [0, 6, 4, 1],
|
| 161 |
+
[4, 8, 7, 5, 6], [9, 11, 10], [2, 7, 5],
|
| 162 |
+
[1, 4, 8, 11, 9], [0, 3, 10, 9, 1]])
|
| 163 |
+
expected = list(itertools.chain(*sorted(expected))) # type: ignore
|
| 164 |
+
sv = SphericalVoronoi(self.points)
|
| 165 |
+
sv.sort_vertices_of_regions()
|
| 166 |
+
actual = list(itertools.chain(*sorted(sv.regions)))
|
| 167 |
+
assert_array_equal(actual, expected)
|
| 168 |
+
|
| 169 |
+
def test_sort_vertices_of_regions_dimensionality(self):
|
| 170 |
+
points = np.array([[1, 0, 0, 0],
|
| 171 |
+
[0, 1, 0, 0],
|
| 172 |
+
[0, 0, 1, 0],
|
| 173 |
+
[0, 0, 0, 1],
|
| 174 |
+
[0.5, 0.5, 0.5, 0.5]])
|
| 175 |
+
with pytest.raises(TypeError, match="three-dimensional"):
|
| 176 |
+
sv = SphericalVoronoi(points)
|
| 177 |
+
sv.sort_vertices_of_regions()
|
| 178 |
+
|
| 179 |
+
def test_num_vertices(self):
|
| 180 |
+
# for any n >= 3, a spherical Voronoi diagram has 2n - 4
|
| 181 |
+
# vertices; this is a direct consequence of Euler's formula
|
| 182 |
+
# as explained by Dinis and Mamede (2010) Proceedings of the
|
| 183 |
+
# 2010 International Symposium on Voronoi Diagrams in Science
|
| 184 |
+
# and Engineering
|
| 185 |
+
sv = SphericalVoronoi(self.points)
|
| 186 |
+
expected = self.points.shape[0] * 2 - 4
|
| 187 |
+
actual = sv.vertices.shape[0]
|
| 188 |
+
assert_equal(actual, expected)
|
| 189 |
+
|
| 190 |
+
def test_voronoi_circles(self):
|
| 191 |
+
sv = SphericalVoronoi(self.points)
|
| 192 |
+
for vertex in sv.vertices:
|
| 193 |
+
distances = distance.cdist(sv.points, np.array([vertex]))
|
| 194 |
+
closest = np.array(sorted(distances)[0:3])
|
| 195 |
+
assert_almost_equal(closest[0], closest[1], 7, str(vertex))
|
| 196 |
+
assert_almost_equal(closest[0], closest[2], 7, str(vertex))
|
| 197 |
+
|
| 198 |
+
def test_duplicate_point_handling(self):
|
| 199 |
+
# an exception should be raised for degenerate generators
|
| 200 |
+
# related to Issue# 7046
|
| 201 |
+
self.degenerate = np.concatenate((self.points, self.points))
|
| 202 |
+
with assert_raises(ValueError):
|
| 203 |
+
SphericalVoronoi(self.degenerate)
|
| 204 |
+
|
| 205 |
+
def test_incorrect_radius_handling(self):
|
| 206 |
+
# an exception should be raised if the radius provided
|
| 207 |
+
# cannot possibly match the input generators
|
| 208 |
+
with assert_raises(ValueError):
|
| 209 |
+
SphericalVoronoi(self.points, radius=0.98)
|
| 210 |
+
|
| 211 |
+
def test_incorrect_center_handling(self):
|
| 212 |
+
# an exception should be raised if the center provided
|
| 213 |
+
# cannot possibly match the input generators
|
| 214 |
+
with assert_raises(ValueError):
|
| 215 |
+
SphericalVoronoi(self.points, center=[0.1, 0, 0])
|
| 216 |
+
|
| 217 |
+
@pytest.mark.parametrize("dim", range(2, 6))
|
| 218 |
+
@pytest.mark.parametrize("shift", [False, True])
|
| 219 |
+
def test_single_hemisphere_handling(self, dim, shift):
|
| 220 |
+
n = 10
|
| 221 |
+
points = _sample_sphere(n, dim, seed=0)
|
| 222 |
+
points[:, 0] = np.abs(points[:, 0])
|
| 223 |
+
center = (np.arange(dim) + 1) * shift
|
| 224 |
+
sv = SphericalVoronoi(points + center, center=center)
|
| 225 |
+
dots = np.einsum('ij,ij->i', sv.vertices - center,
|
| 226 |
+
sv.points[sv._simplices[:, 0]] - center)
|
| 227 |
+
circumradii = np.arccos(np.clip(dots, -1, 1))
|
| 228 |
+
assert np.max(circumradii) > np.pi / 2
|
| 229 |
+
|
| 230 |
+
@pytest.mark.parametrize("n", [1, 2, 10])
|
| 231 |
+
@pytest.mark.parametrize("dim", range(2, 6))
|
| 232 |
+
@pytest.mark.parametrize("shift", [False, True])
|
| 233 |
+
def test_rank_deficient(self, n, dim, shift):
|
| 234 |
+
center = (np.arange(dim) + 1) * shift
|
| 235 |
+
points = _sample_sphere(n, dim - 1, seed=0)
|
| 236 |
+
points = np.hstack([points, np.zeros((n, 1))])
|
| 237 |
+
with pytest.raises(ValueError, match="Rank of input points"):
|
| 238 |
+
SphericalVoronoi(points + center, center=center)
|
| 239 |
+
|
| 240 |
+
@pytest.mark.parametrize("dim", range(2, 6))
|
| 241 |
+
def test_higher_dimensions(self, dim):
|
| 242 |
+
n = 100
|
| 243 |
+
points = _sample_sphere(n, dim, seed=0)
|
| 244 |
+
sv = SphericalVoronoi(points)
|
| 245 |
+
assert sv.vertices.shape[1] == dim
|
| 246 |
+
assert len(sv.regions) == n
|
| 247 |
+
|
| 248 |
+
# verify Euler characteristic
|
| 249 |
+
cell_counts = []
|
| 250 |
+
simplices = np.sort(sv._simplices)
|
| 251 |
+
for i in range(1, dim + 1):
|
| 252 |
+
cells = []
|
| 253 |
+
for indices in itertools.combinations(range(dim), i):
|
| 254 |
+
cells.append(simplices[:, list(indices)])
|
| 255 |
+
cells = np.unique(np.concatenate(cells), axis=0)
|
| 256 |
+
cell_counts.append(len(cells))
|
| 257 |
+
expected_euler = 1 + (-1)**(dim-1)
|
| 258 |
+
actual_euler = sum([(-1)**i * e for i, e in enumerate(cell_counts)])
|
| 259 |
+
assert expected_euler == actual_euler
|
| 260 |
+
|
| 261 |
+
@pytest.mark.parametrize("dim", range(2, 6))
|
| 262 |
+
def test_cross_polytope_regions(self, dim):
|
| 263 |
+
# The hypercube is the dual of the cross-polytope, so the voronoi
|
| 264 |
+
# vertices of the cross-polytope lie on the points of the hypercube.
|
| 265 |
+
|
| 266 |
+
# generate points of the cross-polytope
|
| 267 |
+
points = np.concatenate((-np.eye(dim), np.eye(dim)))
|
| 268 |
+
sv = SphericalVoronoi(points)
|
| 269 |
+
assert all([len(e) == 2**(dim - 1) for e in sv.regions])
|
| 270 |
+
|
| 271 |
+
# generate points of the hypercube
|
| 272 |
+
expected = np.vstack(list(itertools.product([-1, 1], repeat=dim)))
|
| 273 |
+
expected = expected.astype(np.float64) / np.sqrt(dim)
|
| 274 |
+
|
| 275 |
+
# test that Voronoi vertices are correctly placed
|
| 276 |
+
dist = distance.cdist(sv.vertices, expected)
|
| 277 |
+
res = linear_sum_assignment(dist)
|
| 278 |
+
assert dist[res].sum() < TOL
|
| 279 |
+
|
| 280 |
+
@pytest.mark.parametrize("dim", range(2, 6))
|
| 281 |
+
def test_hypercube_regions(self, dim):
|
| 282 |
+
# The cross-polytope is the dual of the hypercube, so the voronoi
|
| 283 |
+
# vertices of the hypercube lie on the points of the cross-polytope.
|
| 284 |
+
|
| 285 |
+
# generate points of the hypercube
|
| 286 |
+
points = np.vstack(list(itertools.product([-1, 1], repeat=dim)))
|
| 287 |
+
points = points.astype(np.float64) / np.sqrt(dim)
|
| 288 |
+
sv = SphericalVoronoi(points)
|
| 289 |
+
|
| 290 |
+
# generate points of the cross-polytope
|
| 291 |
+
expected = np.concatenate((-np.eye(dim), np.eye(dim)))
|
| 292 |
+
|
| 293 |
+
# test that Voronoi vertices are correctly placed
|
| 294 |
+
dist = distance.cdist(sv.vertices, expected)
|
| 295 |
+
res = linear_sum_assignment(dist)
|
| 296 |
+
assert dist[res].sum() < TOL
|
| 297 |
+
|
| 298 |
+
@pytest.mark.parametrize("n", [10, 500])
|
| 299 |
+
@pytest.mark.parametrize("dim", [2, 3])
|
| 300 |
+
@pytest.mark.parametrize("radius", [0.5, 1, 2])
|
| 301 |
+
@pytest.mark.parametrize("shift", [False, True])
|
| 302 |
+
@pytest.mark.parametrize("single_hemisphere", [False, True])
|
| 303 |
+
def test_area_reconstitution(self, n, dim, radius, shift,
|
| 304 |
+
single_hemisphere):
|
| 305 |
+
points = _sample_sphere(n, dim, seed=0)
|
| 306 |
+
|
| 307 |
+
# move all points to one side of the sphere for single-hemisphere test
|
| 308 |
+
if single_hemisphere:
|
| 309 |
+
points[:, 0] = np.abs(points[:, 0])
|
| 310 |
+
|
| 311 |
+
center = (np.arange(dim) + 1) * shift
|
| 312 |
+
points = radius * points + center
|
| 313 |
+
|
| 314 |
+
sv = SphericalVoronoi(points, radius=radius, center=center)
|
| 315 |
+
areas = sv.calculate_areas()
|
| 316 |
+
assert_almost_equal(areas.sum(), _hypersphere_area(dim, radius))
|
| 317 |
+
|
| 318 |
+
@pytest.mark.parametrize("poly", ["triangle", "dodecagon",
|
| 319 |
+
"tetrahedron", "cube", "octahedron",
|
| 320 |
+
"dodecahedron", "icosahedron"])
|
| 321 |
+
def test_equal_area_reconstitution(self, poly):
|
| 322 |
+
points = _generate_polytope(poly)
|
| 323 |
+
n, dim = points.shape
|
| 324 |
+
sv = SphericalVoronoi(points)
|
| 325 |
+
areas = sv.calculate_areas()
|
| 326 |
+
assert_almost_equal(areas, _hypersphere_area(dim, 1) / n)
|
| 327 |
+
|
| 328 |
+
def test_area_unsupported_dimension(self):
|
| 329 |
+
dim = 4
|
| 330 |
+
points = np.concatenate((-np.eye(dim), np.eye(dim)))
|
| 331 |
+
sv = SphericalVoronoi(points)
|
| 332 |
+
with pytest.raises(TypeError, match="Only supported"):
|
| 333 |
+
sv.calculate_areas()
|
| 334 |
+
|
| 335 |
+
@pytest.mark.parametrize("radius", [1, 1.])
|
| 336 |
+
@pytest.mark.parametrize("center", [None, (1, 2, 3), (1., 2., 3.)])
|
| 337 |
+
def test_attribute_types(self, radius, center):
|
| 338 |
+
points = radius * self.points
|
| 339 |
+
if center is not None:
|
| 340 |
+
points += center
|
| 341 |
+
|
| 342 |
+
sv = SphericalVoronoi(points, radius=radius, center=center)
|
| 343 |
+
assert sv.points.dtype is np.dtype(np.float64)
|
| 344 |
+
assert sv.center.dtype is np.dtype(np.float64)
|
| 345 |
+
assert isinstance(sv.radius, float)
|
| 346 |
+
|
| 347 |
+
def test_region_types(self):
|
| 348 |
+
# Tests that region integer type does not change
|
| 349 |
+
# See Issue #13412
|
| 350 |
+
sv = SphericalVoronoi(self.points)
|
| 351 |
+
dtype = type(sv.regions[0][0])
|
| 352 |
+
# also enforce nested list type per gh-19177
|
| 353 |
+
for region in sv.regions:
|
| 354 |
+
assert isinstance(region, list)
|
| 355 |
+
sv.sort_vertices_of_regions()
|
| 356 |
+
assert type(sv.regions[0][0]) == dtype
|
| 357 |
+
sv.sort_vertices_of_regions()
|
| 358 |
+
assert type(sv.regions[0][0]) == dtype
|
phi4/lib/python3.10/site-packages/numpy/_core/__pycache__/fromnumeric.cpython-310.pyc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cf135b5f582a3ff2dc30b3e7699e7af572e82048a193bf6c1b2589997c2d67b4
|
| 3 |
+
size 139645
|
phi4/lib/python3.10/site-packages/scipy/_lib/_array_api.py
ADDED
|
@@ -0,0 +1,595 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Utility functions to use Python Array API compatible libraries.
|
| 2 |
+
|
| 3 |
+
For the context about the Array API see:
|
| 4 |
+
https://data-apis.org/array-api/latest/purpose_and_scope.html
|
| 5 |
+
|
| 6 |
+
The SciPy use case of the Array API is described on the following page:
|
| 7 |
+
https://data-apis.org/array-api/latest/use_cases.html#use-case-scipy
|
| 8 |
+
"""
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
from types import ModuleType
|
| 12 |
+
from typing import Any, Literal, TypeAlias
|
| 13 |
+
|
| 14 |
+
import numpy as np
|
| 15 |
+
import numpy.typing as npt
|
| 16 |
+
|
| 17 |
+
from scipy._lib import array_api_compat
|
| 18 |
+
from scipy._lib.array_api_compat import (
|
| 19 |
+
is_array_api_obj,
|
| 20 |
+
size as xp_size,
|
| 21 |
+
numpy as np_compat,
|
| 22 |
+
device as xp_device,
|
| 23 |
+
is_numpy_namespace as is_numpy,
|
| 24 |
+
is_cupy_namespace as is_cupy,
|
| 25 |
+
is_torch_namespace as is_torch,
|
| 26 |
+
is_jax_namespace as is_jax,
|
| 27 |
+
is_array_api_strict_namespace as is_array_api_strict
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
__all__ = [
|
| 31 |
+
'_asarray', 'array_namespace', 'assert_almost_equal', 'assert_array_almost_equal',
|
| 32 |
+
'get_xp_devices',
|
| 33 |
+
'is_array_api_strict', 'is_complex', 'is_cupy', 'is_jax', 'is_numpy', 'is_torch',
|
| 34 |
+
'SCIPY_ARRAY_API', 'SCIPY_DEVICE', 'scipy_namespace_for',
|
| 35 |
+
'xp_assert_close', 'xp_assert_equal', 'xp_assert_less',
|
| 36 |
+
'xp_copy', 'xp_copysign', 'xp_device',
|
| 37 |
+
'xp_moveaxis_to_end', 'xp_ravel', 'xp_real', 'xp_sign', 'xp_size',
|
| 38 |
+
'xp_take_along_axis', 'xp_unsupported_param_msg', 'xp_vector_norm',
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# To enable array API and strict array-like input validation
|
| 43 |
+
SCIPY_ARRAY_API: str | bool = os.environ.get("SCIPY_ARRAY_API", False)
|
| 44 |
+
# To control the default device - for use in the test suite only
|
| 45 |
+
SCIPY_DEVICE = os.environ.get("SCIPY_DEVICE", "cpu")
|
| 46 |
+
|
| 47 |
+
_GLOBAL_CONFIG = {
|
| 48 |
+
"SCIPY_ARRAY_API": SCIPY_ARRAY_API,
|
| 49 |
+
"SCIPY_DEVICE": SCIPY_DEVICE,
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Array: TypeAlias = Any # To be changed to a Protocol later (see array-api#589)
|
| 54 |
+
ArrayLike: TypeAlias = Array | npt.ArrayLike
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _compliance_scipy(arrays):
|
| 58 |
+
"""Raise exceptions on known-bad subclasses.
|
| 59 |
+
|
| 60 |
+
The following subclasses are not supported and raise and error:
|
| 61 |
+
- `numpy.ma.MaskedArray`
|
| 62 |
+
- `numpy.matrix`
|
| 63 |
+
- NumPy arrays which do not have a boolean or numerical dtype
|
| 64 |
+
- Any array-like which is neither array API compatible nor coercible by NumPy
|
| 65 |
+
- Any array-like which is coerced by NumPy to an unsupported dtype
|
| 66 |
+
"""
|
| 67 |
+
for i in range(len(arrays)):
|
| 68 |
+
array = arrays[i]
|
| 69 |
+
|
| 70 |
+
from scipy.sparse import issparse
|
| 71 |
+
# this comes from `_util._asarray_validated`
|
| 72 |
+
if issparse(array):
|
| 73 |
+
msg = ('Sparse arrays/matrices are not supported by this function. '
|
| 74 |
+
'Perhaps one of the `scipy.sparse.linalg` functions '
|
| 75 |
+
'would work instead.')
|
| 76 |
+
raise ValueError(msg)
|
| 77 |
+
|
| 78 |
+
if isinstance(array, np.ma.MaskedArray):
|
| 79 |
+
raise TypeError("Inputs of type `numpy.ma.MaskedArray` are not supported.")
|
| 80 |
+
elif isinstance(array, np.matrix):
|
| 81 |
+
raise TypeError("Inputs of type `numpy.matrix` are not supported.")
|
| 82 |
+
if isinstance(array, np.ndarray | np.generic):
|
| 83 |
+
dtype = array.dtype
|
| 84 |
+
if not (np.issubdtype(dtype, np.number) or np.issubdtype(dtype, np.bool_)):
|
| 85 |
+
raise TypeError(f"An argument has dtype `{dtype!r}`; "
|
| 86 |
+
f"only boolean and numerical dtypes are supported.")
|
| 87 |
+
elif not is_array_api_obj(array):
|
| 88 |
+
try:
|
| 89 |
+
array = np.asanyarray(array)
|
| 90 |
+
except TypeError:
|
| 91 |
+
raise TypeError("An argument is neither array API compatible nor "
|
| 92 |
+
"coercible by NumPy.")
|
| 93 |
+
dtype = array.dtype
|
| 94 |
+
if not (np.issubdtype(dtype, np.number) or np.issubdtype(dtype, np.bool_)):
|
| 95 |
+
message = (
|
| 96 |
+
f"An argument was coerced to an unsupported dtype `{dtype!r}`; "
|
| 97 |
+
f"only boolean and numerical dtypes are supported."
|
| 98 |
+
)
|
| 99 |
+
raise TypeError(message)
|
| 100 |
+
arrays[i] = array
|
| 101 |
+
return arrays
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def _check_finite(array: Array, xp: ModuleType) -> None:
|
| 105 |
+
"""Check for NaNs or Infs."""
|
| 106 |
+
msg = "array must not contain infs or NaNs"
|
| 107 |
+
try:
|
| 108 |
+
if not xp.all(xp.isfinite(array)):
|
| 109 |
+
raise ValueError(msg)
|
| 110 |
+
except TypeError:
|
| 111 |
+
raise ValueError(msg)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def array_namespace(*arrays: Array) -> ModuleType:
|
| 115 |
+
"""Get the array API compatible namespace for the arrays xs.
|
| 116 |
+
|
| 117 |
+
Parameters
|
| 118 |
+
----------
|
| 119 |
+
*arrays : sequence of array_like
|
| 120 |
+
Arrays used to infer the common namespace.
|
| 121 |
+
|
| 122 |
+
Returns
|
| 123 |
+
-------
|
| 124 |
+
namespace : module
|
| 125 |
+
Common namespace.
|
| 126 |
+
|
| 127 |
+
Notes
|
| 128 |
+
-----
|
| 129 |
+
Thin wrapper around `array_api_compat.array_namespace`.
|
| 130 |
+
|
| 131 |
+
1. Check for the global switch: SCIPY_ARRAY_API. This can also be accessed
|
| 132 |
+
dynamically through ``_GLOBAL_CONFIG['SCIPY_ARRAY_API']``.
|
| 133 |
+
2. `_compliance_scipy` raise exceptions on known-bad subclasses. See
|
| 134 |
+
its definition for more details.
|
| 135 |
+
|
| 136 |
+
When the global switch is False, it defaults to the `numpy` namespace.
|
| 137 |
+
In that case, there is no compliance check. This is a convenience to
|
| 138 |
+
ease the adoption. Otherwise, arrays must comply with the new rules.
|
| 139 |
+
"""
|
| 140 |
+
if not _GLOBAL_CONFIG["SCIPY_ARRAY_API"]:
|
| 141 |
+
# here we could wrap the namespace if needed
|
| 142 |
+
return np_compat
|
| 143 |
+
|
| 144 |
+
_arrays = [array for array in arrays if array is not None]
|
| 145 |
+
|
| 146 |
+
_arrays = _compliance_scipy(_arrays)
|
| 147 |
+
|
| 148 |
+
return array_api_compat.array_namespace(*_arrays)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def _asarray(
|
| 152 |
+
array: ArrayLike,
|
| 153 |
+
dtype: Any = None,
|
| 154 |
+
order: Literal['K', 'A', 'C', 'F'] | None = None,
|
| 155 |
+
copy: bool | None = None,
|
| 156 |
+
*,
|
| 157 |
+
xp: ModuleType | None = None,
|
| 158 |
+
check_finite: bool = False,
|
| 159 |
+
subok: bool = False,
|
| 160 |
+
) -> Array:
|
| 161 |
+
"""SciPy-specific replacement for `np.asarray` with `order`, `check_finite`, and
|
| 162 |
+
`subok`.
|
| 163 |
+
|
| 164 |
+
Memory layout parameter `order` is not exposed in the Array API standard.
|
| 165 |
+
`order` is only enforced if the input array implementation
|
| 166 |
+
is NumPy based, otherwise `order` is just silently ignored.
|
| 167 |
+
|
| 168 |
+
`check_finite` is also not a keyword in the array API standard; included
|
| 169 |
+
here for convenience rather than that having to be a separate function
|
| 170 |
+
call inside SciPy functions.
|
| 171 |
+
|
| 172 |
+
`subok` is included to allow this function to preserve the behaviour of
|
| 173 |
+
`np.asanyarray` for NumPy based inputs.
|
| 174 |
+
"""
|
| 175 |
+
if xp is None:
|
| 176 |
+
xp = array_namespace(array)
|
| 177 |
+
if is_numpy(xp):
|
| 178 |
+
# Use NumPy API to support order
|
| 179 |
+
if copy is True:
|
| 180 |
+
array = np.array(array, order=order, dtype=dtype, subok=subok)
|
| 181 |
+
elif subok:
|
| 182 |
+
array = np.asanyarray(array, order=order, dtype=dtype)
|
| 183 |
+
else:
|
| 184 |
+
array = np.asarray(array, order=order, dtype=dtype)
|
| 185 |
+
else:
|
| 186 |
+
try:
|
| 187 |
+
array = xp.asarray(array, dtype=dtype, copy=copy)
|
| 188 |
+
except TypeError:
|
| 189 |
+
coerced_xp = array_namespace(xp.asarray(3))
|
| 190 |
+
array = coerced_xp.asarray(array, dtype=dtype, copy=copy)
|
| 191 |
+
|
| 192 |
+
if check_finite:
|
| 193 |
+
_check_finite(array, xp)
|
| 194 |
+
|
| 195 |
+
return array
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def xp_copy(x: Array, *, xp: ModuleType | None = None) -> Array:
|
| 199 |
+
"""
|
| 200 |
+
Copies an array.
|
| 201 |
+
|
| 202 |
+
Parameters
|
| 203 |
+
----------
|
| 204 |
+
x : array
|
| 205 |
+
|
| 206 |
+
xp : array_namespace
|
| 207 |
+
|
| 208 |
+
Returns
|
| 209 |
+
-------
|
| 210 |
+
copy : array
|
| 211 |
+
Copied array
|
| 212 |
+
|
| 213 |
+
Notes
|
| 214 |
+
-----
|
| 215 |
+
This copy function does not offer all the semantics of `np.copy`, i.e. the
|
| 216 |
+
`subok` and `order` keywords are not used.
|
| 217 |
+
"""
|
| 218 |
+
# Note: for older NumPy versions, `np.asarray` did not support the `copy` kwarg,
|
| 219 |
+
# so this uses our other helper `_asarray`.
|
| 220 |
+
if xp is None:
|
| 221 |
+
xp = array_namespace(x)
|
| 222 |
+
|
| 223 |
+
return _asarray(x, copy=True, xp=xp)
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def _strict_check(actual, desired, xp, *,
|
| 227 |
+
check_namespace=True, check_dtype=True, check_shape=True,
|
| 228 |
+
check_0d=True):
|
| 229 |
+
__tracebackhide__ = True # Hide traceback for py.test
|
| 230 |
+
if check_namespace:
|
| 231 |
+
_assert_matching_namespace(actual, desired)
|
| 232 |
+
|
| 233 |
+
# only NumPy distinguishes between scalars and arrays; we do if check_0d=True.
|
| 234 |
+
# do this first so we can then cast to array (and thus use the array API) below.
|
| 235 |
+
if is_numpy(xp) and check_0d:
|
| 236 |
+
_msg = ("Array-ness does not match:\n Actual: "
|
| 237 |
+
f"{type(actual)}\n Desired: {type(desired)}")
|
| 238 |
+
assert ((xp.isscalar(actual) and xp.isscalar(desired))
|
| 239 |
+
or (not xp.isscalar(actual) and not xp.isscalar(desired))), _msg
|
| 240 |
+
|
| 241 |
+
actual = xp.asarray(actual)
|
| 242 |
+
desired = xp.asarray(desired)
|
| 243 |
+
|
| 244 |
+
if check_dtype:
|
| 245 |
+
_msg = f"dtypes do not match.\nActual: {actual.dtype}\nDesired: {desired.dtype}"
|
| 246 |
+
assert actual.dtype == desired.dtype, _msg
|
| 247 |
+
|
| 248 |
+
if check_shape:
|
| 249 |
+
_msg = f"Shapes do not match.\nActual: {actual.shape}\nDesired: {desired.shape}"
|
| 250 |
+
assert actual.shape == desired.shape, _msg
|
| 251 |
+
|
| 252 |
+
desired = xp.broadcast_to(desired, actual.shape)
|
| 253 |
+
return actual, desired
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def _assert_matching_namespace(actual, desired):
|
| 257 |
+
__tracebackhide__ = True # Hide traceback for py.test
|
| 258 |
+
actual = actual if isinstance(actual, tuple) else (actual,)
|
| 259 |
+
desired_space = array_namespace(desired)
|
| 260 |
+
for arr in actual:
|
| 261 |
+
arr_space = array_namespace(arr)
|
| 262 |
+
_msg = (f"Namespaces do not match.\n"
|
| 263 |
+
f"Actual: {arr_space.__name__}\n"
|
| 264 |
+
f"Desired: {desired_space.__name__}")
|
| 265 |
+
assert arr_space == desired_space, _msg
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def xp_assert_equal(actual, desired, *, check_namespace=True, check_dtype=True,
|
| 269 |
+
check_shape=True, check_0d=True, err_msg='', xp=None):
|
| 270 |
+
__tracebackhide__ = True # Hide traceback for py.test
|
| 271 |
+
if xp is None:
|
| 272 |
+
xp = array_namespace(actual)
|
| 273 |
+
|
| 274 |
+
actual, desired = _strict_check(
|
| 275 |
+
actual, desired, xp, check_namespace=check_namespace,
|
| 276 |
+
check_dtype=check_dtype, check_shape=check_shape,
|
| 277 |
+
check_0d=check_0d
|
| 278 |
+
)
|
| 279 |
+
|
| 280 |
+
if is_cupy(xp):
|
| 281 |
+
return xp.testing.assert_array_equal(actual, desired, err_msg=err_msg)
|
| 282 |
+
elif is_torch(xp):
|
| 283 |
+
# PyTorch recommends using `rtol=0, atol=0` like this
|
| 284 |
+
# to test for exact equality
|
| 285 |
+
err_msg = None if err_msg == '' else err_msg
|
| 286 |
+
return xp.testing.assert_close(actual, desired, rtol=0, atol=0, equal_nan=True,
|
| 287 |
+
check_dtype=False, msg=err_msg)
|
| 288 |
+
# JAX uses `np.testing`
|
| 289 |
+
return np.testing.assert_array_equal(actual, desired, err_msg=err_msg)
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
def xp_assert_close(actual, desired, *, rtol=None, atol=0, check_namespace=True,
|
| 293 |
+
check_dtype=True, check_shape=True, check_0d=True,
|
| 294 |
+
err_msg='', xp=None):
|
| 295 |
+
__tracebackhide__ = True # Hide traceback for py.test
|
| 296 |
+
if xp is None:
|
| 297 |
+
xp = array_namespace(actual)
|
| 298 |
+
|
| 299 |
+
actual, desired = _strict_check(
|
| 300 |
+
actual, desired, xp,
|
| 301 |
+
check_namespace=check_namespace, check_dtype=check_dtype,
|
| 302 |
+
check_shape=check_shape, check_0d=check_0d
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
+
floating = xp.isdtype(actual.dtype, ('real floating', 'complex floating'))
|
| 306 |
+
if rtol is None and floating:
|
| 307 |
+
# multiplier of 4 is used as for `np.float64` this puts the default `rtol`
|
| 308 |
+
# roughly half way between sqrt(eps) and the default for
|
| 309 |
+
# `numpy.testing.assert_allclose`, 1e-7
|
| 310 |
+
rtol = xp.finfo(actual.dtype).eps**0.5 * 4
|
| 311 |
+
elif rtol is None:
|
| 312 |
+
rtol = 1e-7
|
| 313 |
+
|
| 314 |
+
if is_cupy(xp):
|
| 315 |
+
return xp.testing.assert_allclose(actual, desired, rtol=rtol,
|
| 316 |
+
atol=atol, err_msg=err_msg)
|
| 317 |
+
elif is_torch(xp):
|
| 318 |
+
err_msg = None if err_msg == '' else err_msg
|
| 319 |
+
return xp.testing.assert_close(actual, desired, rtol=rtol, atol=atol,
|
| 320 |
+
equal_nan=True, check_dtype=False, msg=err_msg)
|
| 321 |
+
# JAX uses `np.testing`
|
| 322 |
+
return np.testing.assert_allclose(actual, desired, rtol=rtol,
|
| 323 |
+
atol=atol, err_msg=err_msg)
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def xp_assert_less(actual, desired, *, check_namespace=True, check_dtype=True,
|
| 327 |
+
check_shape=True, check_0d=True, err_msg='', verbose=True, xp=None):
|
| 328 |
+
__tracebackhide__ = True # Hide traceback for py.test
|
| 329 |
+
if xp is None:
|
| 330 |
+
xp = array_namespace(actual)
|
| 331 |
+
|
| 332 |
+
actual, desired = _strict_check(
|
| 333 |
+
actual, desired, xp, check_namespace=check_namespace,
|
| 334 |
+
check_dtype=check_dtype, check_shape=check_shape,
|
| 335 |
+
check_0d=check_0d
|
| 336 |
+
)
|
| 337 |
+
|
| 338 |
+
if is_cupy(xp):
|
| 339 |
+
return xp.testing.assert_array_less(actual, desired,
|
| 340 |
+
err_msg=err_msg, verbose=verbose)
|
| 341 |
+
elif is_torch(xp):
|
| 342 |
+
if actual.device.type != 'cpu':
|
| 343 |
+
actual = actual.cpu()
|
| 344 |
+
if desired.device.type != 'cpu':
|
| 345 |
+
desired = desired.cpu()
|
| 346 |
+
# JAX uses `np.testing`
|
| 347 |
+
return np.testing.assert_array_less(actual, desired,
|
| 348 |
+
err_msg=err_msg, verbose=verbose)
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
def assert_array_almost_equal(actual, desired, decimal=6, *args, **kwds):
|
| 352 |
+
"""Backwards compatible replacement. In new code, use xp_assert_close instead.
|
| 353 |
+
"""
|
| 354 |
+
rtol, atol = 0, 1.5*10**(-decimal)
|
| 355 |
+
return xp_assert_close(actual, desired,
|
| 356 |
+
atol=atol, rtol=rtol, check_dtype=False, check_shape=False,
|
| 357 |
+
*args, **kwds)
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
def assert_almost_equal(actual, desired, decimal=7, *args, **kwds):
|
| 361 |
+
"""Backwards compatible replacement. In new code, use xp_assert_close instead.
|
| 362 |
+
"""
|
| 363 |
+
rtol, atol = 0, 1.5*10**(-decimal)
|
| 364 |
+
return xp_assert_close(actual, desired,
|
| 365 |
+
atol=atol, rtol=rtol, check_dtype=False, check_shape=False,
|
| 366 |
+
*args, **kwds)
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
def xp_unsupported_param_msg(param: Any) -> str:
|
| 370 |
+
return f'Providing {param!r} is only supported for numpy arrays.'
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
def is_complex(x: Array, xp: ModuleType) -> bool:
|
| 374 |
+
return xp.isdtype(x.dtype, 'complex floating')
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def get_xp_devices(xp: ModuleType) -> list[str] | list[None]:
|
| 378 |
+
"""Returns a list of available devices for the given namespace."""
|
| 379 |
+
devices: list[str] = []
|
| 380 |
+
if is_torch(xp):
|
| 381 |
+
devices += ['cpu']
|
| 382 |
+
import torch # type: ignore[import]
|
| 383 |
+
num_cuda = torch.cuda.device_count()
|
| 384 |
+
for i in range(0, num_cuda):
|
| 385 |
+
devices += [f'cuda:{i}']
|
| 386 |
+
if torch.backends.mps.is_available():
|
| 387 |
+
devices += ['mps']
|
| 388 |
+
return devices
|
| 389 |
+
elif is_cupy(xp):
|
| 390 |
+
import cupy # type: ignore[import]
|
| 391 |
+
num_cuda = cupy.cuda.runtime.getDeviceCount()
|
| 392 |
+
for i in range(0, num_cuda):
|
| 393 |
+
devices += [f'cuda:{i}']
|
| 394 |
+
return devices
|
| 395 |
+
elif is_jax(xp):
|
| 396 |
+
import jax # type: ignore[import]
|
| 397 |
+
num_cpu = jax.device_count(backend='cpu')
|
| 398 |
+
for i in range(0, num_cpu):
|
| 399 |
+
devices += [f'cpu:{i}']
|
| 400 |
+
num_gpu = jax.device_count(backend='gpu')
|
| 401 |
+
for i in range(0, num_gpu):
|
| 402 |
+
devices += [f'gpu:{i}']
|
| 403 |
+
num_tpu = jax.device_count(backend='tpu')
|
| 404 |
+
for i in range(0, num_tpu):
|
| 405 |
+
devices += [f'tpu:{i}']
|
| 406 |
+
return devices
|
| 407 |
+
|
| 408 |
+
# given namespace is not known to have a list of available devices;
|
| 409 |
+
# return `[None]` so that one can use this in tests for `device=None`.
|
| 410 |
+
return [None]
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def scipy_namespace_for(xp: ModuleType) -> ModuleType | None:
|
| 414 |
+
"""Return the `scipy`-like namespace of a non-NumPy backend
|
| 415 |
+
|
| 416 |
+
That is, return the namespace corresponding with backend `xp` that contains
|
| 417 |
+
`scipy` sub-namespaces like `linalg` and `special`. If no such namespace
|
| 418 |
+
exists, return ``None``. Useful for dispatching.
|
| 419 |
+
"""
|
| 420 |
+
|
| 421 |
+
if is_cupy(xp):
|
| 422 |
+
import cupyx # type: ignore[import-not-found,import-untyped]
|
| 423 |
+
return cupyx.scipy
|
| 424 |
+
|
| 425 |
+
if is_jax(xp):
|
| 426 |
+
import jax # type: ignore[import-not-found]
|
| 427 |
+
return jax.scipy
|
| 428 |
+
|
| 429 |
+
if is_torch(xp):
|
| 430 |
+
return xp
|
| 431 |
+
|
| 432 |
+
return None
|
| 433 |
+
|
| 434 |
+
|
| 435 |
+
# temporary substitute for xp.moveaxis, which is not yet in all backends
|
| 436 |
+
# or covered by array_api_compat.
|
| 437 |
+
def xp_moveaxis_to_end(
|
| 438 |
+
x: Array,
|
| 439 |
+
source: int,
|
| 440 |
+
/, *,
|
| 441 |
+
xp: ModuleType | None = None) -> Array:
|
| 442 |
+
xp = array_namespace(xp) if xp is None else xp
|
| 443 |
+
axes = list(range(x.ndim))
|
| 444 |
+
temp = axes.pop(source)
|
| 445 |
+
axes = axes + [temp]
|
| 446 |
+
return xp.permute_dims(x, axes)
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
# temporary substitute for xp.copysign, which is not yet in all backends
|
| 450 |
+
# or covered by array_api_compat.
|
| 451 |
+
def xp_copysign(x1: Array, x2: Array, /, *, xp: ModuleType | None = None) -> Array:
|
| 452 |
+
# no attempt to account for special cases
|
| 453 |
+
xp = array_namespace(x1, x2) if xp is None else xp
|
| 454 |
+
abs_x1 = xp.abs(x1)
|
| 455 |
+
return xp.where(x2 >= 0, abs_x1, -abs_x1)
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
# partial substitute for xp.sign, which does not cover the NaN special case
|
| 459 |
+
# that I need. (https://github.com/data-apis/array-api-compat/issues/136)
|
| 460 |
+
def xp_sign(x: Array, /, *, xp: ModuleType | None = None) -> Array:
|
| 461 |
+
xp = array_namespace(x) if xp is None else xp
|
| 462 |
+
if is_numpy(xp): # only NumPy implements the special cases correctly
|
| 463 |
+
return xp.sign(x)
|
| 464 |
+
sign = xp.zeros_like(x)
|
| 465 |
+
one = xp.asarray(1, dtype=x.dtype)
|
| 466 |
+
sign = xp.where(x > 0, one, sign)
|
| 467 |
+
sign = xp.where(x < 0, -one, sign)
|
| 468 |
+
sign = xp.where(xp.isnan(x), xp.nan*one, sign)
|
| 469 |
+
return sign
|
| 470 |
+
|
| 471 |
+
# maybe use `scipy.linalg` if/when array API support is added
|
| 472 |
+
def xp_vector_norm(x: Array, /, *,
|
| 473 |
+
axis: int | tuple[int] | None = None,
|
| 474 |
+
keepdims: bool = False,
|
| 475 |
+
ord: int | float = 2,
|
| 476 |
+
xp: ModuleType | None = None) -> Array:
|
| 477 |
+
xp = array_namespace(x) if xp is None else xp
|
| 478 |
+
|
| 479 |
+
if SCIPY_ARRAY_API:
|
| 480 |
+
# check for optional `linalg` extension
|
| 481 |
+
if hasattr(xp, 'linalg'):
|
| 482 |
+
return xp.linalg.vector_norm(x, axis=axis, keepdims=keepdims, ord=ord)
|
| 483 |
+
else:
|
| 484 |
+
if ord != 2:
|
| 485 |
+
raise ValueError(
|
| 486 |
+
"only the Euclidean norm (`ord=2`) is currently supported in "
|
| 487 |
+
"`xp_vector_norm` for backends not implementing the `linalg` "
|
| 488 |
+
"extension."
|
| 489 |
+
)
|
| 490 |
+
# return (x @ x)**0.5
|
| 491 |
+
# or to get the right behavior with nd, complex arrays
|
| 492 |
+
return xp.sum(xp.conj(x) * x, axis=axis, keepdims=keepdims)**0.5
|
| 493 |
+
else:
|
| 494 |
+
# to maintain backwards compatibility
|
| 495 |
+
return np.linalg.norm(x, ord=ord, axis=axis, keepdims=keepdims)
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
def xp_ravel(x: Array, /, *, xp: ModuleType | None = None) -> Array:
|
| 499 |
+
# Equivalent of np.ravel written in terms of array API
|
| 500 |
+
# Even though it's one line, it comes up so often that it's worth having
|
| 501 |
+
# this function for readability
|
| 502 |
+
xp = array_namespace(x) if xp is None else xp
|
| 503 |
+
return xp.reshape(x, (-1,))
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def xp_real(x: Array, /, *, xp: ModuleType | None = None) -> Array:
|
| 507 |
+
# Convenience wrapper of xp.real that allows non-complex input;
|
| 508 |
+
# see data-apis/array-api#824
|
| 509 |
+
xp = array_namespace(x) if xp is None else xp
|
| 510 |
+
return xp.real(x) if xp.isdtype(x.dtype, 'complex floating') else x
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
def xp_take_along_axis(arr: Array,
|
| 514 |
+
indices: Array, /, *,
|
| 515 |
+
axis: int = -1,
|
| 516 |
+
xp: ModuleType | None = None) -> Array:
|
| 517 |
+
# Dispatcher for np.take_along_axis for backends that support it;
|
| 518 |
+
# see data-apis/array-api/pull#816
|
| 519 |
+
xp = array_namespace(arr) if xp is None else xp
|
| 520 |
+
if is_torch(xp):
|
| 521 |
+
return xp.take_along_dim(arr, indices, dim=axis)
|
| 522 |
+
elif is_array_api_strict(xp):
|
| 523 |
+
raise NotImplementedError("Array API standard does not define take_along_axis")
|
| 524 |
+
else:
|
| 525 |
+
return xp.take_along_axis(arr, indices, axis)
|
| 526 |
+
|
| 527 |
+
|
| 528 |
+
# utility to broadcast arrays and promote to common dtype
|
| 529 |
+
def xp_broadcast_promote(*args, ensure_writeable=False, force_floating=False, xp=None):
|
| 530 |
+
xp = array_namespace(*args) if xp is None else xp
|
| 531 |
+
|
| 532 |
+
args = [(_asarray(arg, subok=True) if arg is not None else arg) for arg in args]
|
| 533 |
+
args_not_none = [arg for arg in args if arg is not None]
|
| 534 |
+
|
| 535 |
+
# determine minimum dtype
|
| 536 |
+
default_float = xp.asarray(1.).dtype
|
| 537 |
+
dtypes = [arg.dtype for arg in args_not_none]
|
| 538 |
+
try: # follow library's prefered mixed promotion rules
|
| 539 |
+
dtype = xp.result_type(*dtypes)
|
| 540 |
+
if force_floating and xp.isdtype(dtype, 'integral'):
|
| 541 |
+
# If we were to add `default_float` before checking whether the result
|
| 542 |
+
# type is otherwise integral, we risk promotion from lower float.
|
| 543 |
+
dtype = xp.result_type(dtype, default_float)
|
| 544 |
+
except TypeError: # mixed type promotion isn't defined
|
| 545 |
+
float_dtypes = [dtype for dtype in dtypes
|
| 546 |
+
if not xp.isdtype(dtype, 'integral')]
|
| 547 |
+
if float_dtypes:
|
| 548 |
+
dtype = xp.result_type(*float_dtypes, default_float)
|
| 549 |
+
elif force_floating:
|
| 550 |
+
dtype = default_float
|
| 551 |
+
else:
|
| 552 |
+
dtype = xp.result_type(*dtypes)
|
| 553 |
+
|
| 554 |
+
# determine result shape
|
| 555 |
+
shapes = {arg.shape for arg in args_not_none}
|
| 556 |
+
try:
|
| 557 |
+
shape = (np.broadcast_shapes(*shapes) if len(shapes) != 1
|
| 558 |
+
else args_not_none[0].shape)
|
| 559 |
+
except ValueError as e:
|
| 560 |
+
message = "Array shapes are incompatible for broadcasting."
|
| 561 |
+
raise ValueError(message) from e
|
| 562 |
+
|
| 563 |
+
out = []
|
| 564 |
+
for arg in args:
|
| 565 |
+
if arg is None:
|
| 566 |
+
out.append(arg)
|
| 567 |
+
continue
|
| 568 |
+
|
| 569 |
+
# broadcast only if needed
|
| 570 |
+
# Even if two arguments need broadcasting, this is faster than
|
| 571 |
+
# `broadcast_arrays`, especially since we've already determined `shape`
|
| 572 |
+
if arg.shape != shape:
|
| 573 |
+
kwargs = {'subok': True} if is_numpy(xp) else {}
|
| 574 |
+
arg = xp.broadcast_to(arg, shape, **kwargs)
|
| 575 |
+
|
| 576 |
+
# convert dtype/copy only if needed
|
| 577 |
+
if (arg.dtype != dtype) or ensure_writeable:
|
| 578 |
+
arg = xp.astype(arg, dtype, copy=True)
|
| 579 |
+
out.append(arg)
|
| 580 |
+
|
| 581 |
+
return out
|
| 582 |
+
|
| 583 |
+
|
| 584 |
+
def xp_float_to_complex(arr: Array, xp: ModuleType | None = None) -> Array:
|
| 585 |
+
xp = array_namespace(arr) if xp is None else xp
|
| 586 |
+
arr_dtype = arr.dtype
|
| 587 |
+
# The standard float dtypes are float32 and float64.
|
| 588 |
+
# Convert float32 to complex64,
|
| 589 |
+
# and float64 (and non-standard real dtypes) to complex128
|
| 590 |
+
if xp.isdtype(arr_dtype, xp.float32):
|
| 591 |
+
arr = xp.astype(arr, xp.complex64)
|
| 592 |
+
elif xp.isdtype(arr_dtype, 'real floating'):
|
| 593 |
+
arr = xp.astype(arr, xp.complex128)
|
| 594 |
+
|
| 595 |
+
return arr
|
phi4/lib/python3.10/site-packages/scipy/_lib/_bunch.py
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys as _sys
|
| 2 |
+
from keyword import iskeyword as _iskeyword
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def _validate_names(typename, field_names, extra_field_names):
|
| 6 |
+
"""
|
| 7 |
+
Ensure that all the given names are valid Python identifiers that
|
| 8 |
+
do not start with '_'. Also check that there are no duplicates
|
| 9 |
+
among field_names + extra_field_names.
|
| 10 |
+
"""
|
| 11 |
+
for name in [typename] + field_names + extra_field_names:
|
| 12 |
+
if not isinstance(name, str):
|
| 13 |
+
raise TypeError('typename and all field names must be strings')
|
| 14 |
+
if not name.isidentifier():
|
| 15 |
+
raise ValueError('typename and all field names must be valid '
|
| 16 |
+
f'identifiers: {name!r}')
|
| 17 |
+
if _iskeyword(name):
|
| 18 |
+
raise ValueError('typename and all field names cannot be a '
|
| 19 |
+
f'keyword: {name!r}')
|
| 20 |
+
|
| 21 |
+
seen = set()
|
| 22 |
+
for name in field_names + extra_field_names:
|
| 23 |
+
if name.startswith('_'):
|
| 24 |
+
raise ValueError('Field names cannot start with an underscore: '
|
| 25 |
+
f'{name!r}')
|
| 26 |
+
if name in seen:
|
| 27 |
+
raise ValueError(f'Duplicate field name: {name!r}')
|
| 28 |
+
seen.add(name)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
# Note: This code is adapted from CPython:Lib/collections/__init__.py
|
| 32 |
+
def _make_tuple_bunch(typename, field_names, extra_field_names=None,
|
| 33 |
+
module=None):
|
| 34 |
+
"""
|
| 35 |
+
Create a namedtuple-like class with additional attributes.
|
| 36 |
+
|
| 37 |
+
This function creates a subclass of tuple that acts like a namedtuple
|
| 38 |
+
and that has additional attributes.
|
| 39 |
+
|
| 40 |
+
The additional attributes are listed in `extra_field_names`. The
|
| 41 |
+
values assigned to these attributes are not part of the tuple.
|
| 42 |
+
|
| 43 |
+
The reason this function exists is to allow functions in SciPy
|
| 44 |
+
that currently return a tuple or a namedtuple to returned objects
|
| 45 |
+
that have additional attributes, while maintaining backwards
|
| 46 |
+
compatibility.
|
| 47 |
+
|
| 48 |
+
This should only be used to enhance *existing* functions in SciPy.
|
| 49 |
+
New functions are free to create objects as return values without
|
| 50 |
+
having to maintain backwards compatibility with an old tuple or
|
| 51 |
+
namedtuple return value.
|
| 52 |
+
|
| 53 |
+
Parameters
|
| 54 |
+
----------
|
| 55 |
+
typename : str
|
| 56 |
+
The name of the type.
|
| 57 |
+
field_names : list of str
|
| 58 |
+
List of names of the values to be stored in the tuple. These names
|
| 59 |
+
will also be attributes of instances, so the values in the tuple
|
| 60 |
+
can be accessed by indexing or as attributes. At least one name
|
| 61 |
+
is required. See the Notes for additional restrictions.
|
| 62 |
+
extra_field_names : list of str, optional
|
| 63 |
+
List of names of values that will be stored as attributes of the
|
| 64 |
+
object. See the notes for additional restrictions.
|
| 65 |
+
|
| 66 |
+
Returns
|
| 67 |
+
-------
|
| 68 |
+
cls : type
|
| 69 |
+
The new class.
|
| 70 |
+
|
| 71 |
+
Notes
|
| 72 |
+
-----
|
| 73 |
+
There are restrictions on the names that may be used in `field_names`
|
| 74 |
+
and `extra_field_names`:
|
| 75 |
+
|
| 76 |
+
* The names must be unique--no duplicates allowed.
|
| 77 |
+
* The names must be valid Python identifiers, and must not begin with
|
| 78 |
+
an underscore.
|
| 79 |
+
* The names must not be Python keywords (e.g. 'def', 'and', etc., are
|
| 80 |
+
not allowed).
|
| 81 |
+
|
| 82 |
+
Examples
|
| 83 |
+
--------
|
| 84 |
+
>>> from scipy._lib._bunch import _make_tuple_bunch
|
| 85 |
+
|
| 86 |
+
Create a class that acts like a namedtuple with length 2 (with field
|
| 87 |
+
names `x` and `y`) that will also have the attributes `w` and `beta`:
|
| 88 |
+
|
| 89 |
+
>>> Result = _make_tuple_bunch('Result', ['x', 'y'], ['w', 'beta'])
|
| 90 |
+
|
| 91 |
+
`Result` is the new class. We call it with keyword arguments to create
|
| 92 |
+
a new instance with given values.
|
| 93 |
+
|
| 94 |
+
>>> result1 = Result(x=1, y=2, w=99, beta=0.5)
|
| 95 |
+
>>> result1
|
| 96 |
+
Result(x=1, y=2, w=99, beta=0.5)
|
| 97 |
+
|
| 98 |
+
`result1` acts like a tuple of length 2:
|
| 99 |
+
|
| 100 |
+
>>> len(result1)
|
| 101 |
+
2
|
| 102 |
+
>>> result1[:]
|
| 103 |
+
(1, 2)
|
| 104 |
+
|
| 105 |
+
The values assigned when the instance was created are available as
|
| 106 |
+
attributes:
|
| 107 |
+
|
| 108 |
+
>>> result1.y
|
| 109 |
+
2
|
| 110 |
+
>>> result1.beta
|
| 111 |
+
0.5
|
| 112 |
+
"""
|
| 113 |
+
if len(field_names) == 0:
|
| 114 |
+
raise ValueError('field_names must contain at least one name')
|
| 115 |
+
|
| 116 |
+
if extra_field_names is None:
|
| 117 |
+
extra_field_names = []
|
| 118 |
+
_validate_names(typename, field_names, extra_field_names)
|
| 119 |
+
|
| 120 |
+
typename = _sys.intern(str(typename))
|
| 121 |
+
field_names = tuple(map(_sys.intern, field_names))
|
| 122 |
+
extra_field_names = tuple(map(_sys.intern, extra_field_names))
|
| 123 |
+
|
| 124 |
+
all_names = field_names + extra_field_names
|
| 125 |
+
arg_list = ', '.join(field_names)
|
| 126 |
+
full_list = ', '.join(all_names)
|
| 127 |
+
repr_fmt = ''.join(('(',
|
| 128 |
+
', '.join(f'{name}=%({name})r' for name in all_names),
|
| 129 |
+
')'))
|
| 130 |
+
tuple_new = tuple.__new__
|
| 131 |
+
_dict, _tuple, _zip = dict, tuple, zip
|
| 132 |
+
|
| 133 |
+
# Create all the named tuple methods to be added to the class namespace
|
| 134 |
+
|
| 135 |
+
s = f"""\
|
| 136 |
+
def __new__(_cls, {arg_list}, **extra_fields):
|
| 137 |
+
return _tuple_new(_cls, ({arg_list},))
|
| 138 |
+
|
| 139 |
+
def __init__(self, {arg_list}, **extra_fields):
|
| 140 |
+
for key in self._extra_fields:
|
| 141 |
+
if key not in extra_fields:
|
| 142 |
+
raise TypeError("missing keyword argument '%s'" % (key,))
|
| 143 |
+
for key, val in extra_fields.items():
|
| 144 |
+
if key not in self._extra_fields:
|
| 145 |
+
raise TypeError("unexpected keyword argument '%s'" % (key,))
|
| 146 |
+
self.__dict__[key] = val
|
| 147 |
+
|
| 148 |
+
def __setattr__(self, key, val):
|
| 149 |
+
if key in {repr(field_names)}:
|
| 150 |
+
raise AttributeError("can't set attribute %r of class %r"
|
| 151 |
+
% (key, self.__class__.__name__))
|
| 152 |
+
else:
|
| 153 |
+
self.__dict__[key] = val
|
| 154 |
+
"""
|
| 155 |
+
del arg_list
|
| 156 |
+
namespace = {'_tuple_new': tuple_new,
|
| 157 |
+
'__builtins__': dict(TypeError=TypeError,
|
| 158 |
+
AttributeError=AttributeError),
|
| 159 |
+
'__name__': f'namedtuple_{typename}'}
|
| 160 |
+
exec(s, namespace)
|
| 161 |
+
__new__ = namespace['__new__']
|
| 162 |
+
__new__.__doc__ = f'Create new instance of {typename}({full_list})'
|
| 163 |
+
__init__ = namespace['__init__']
|
| 164 |
+
__init__.__doc__ = f'Instantiate instance of {typename}({full_list})'
|
| 165 |
+
__setattr__ = namespace['__setattr__']
|
| 166 |
+
|
| 167 |
+
def __repr__(self):
|
| 168 |
+
'Return a nicely formatted representation string'
|
| 169 |
+
return self.__class__.__name__ + repr_fmt % self._asdict()
|
| 170 |
+
|
| 171 |
+
def _asdict(self):
|
| 172 |
+
'Return a new dict which maps field names to their values.'
|
| 173 |
+
out = _dict(_zip(self._fields, self))
|
| 174 |
+
out.update(self.__dict__)
|
| 175 |
+
return out
|
| 176 |
+
|
| 177 |
+
def __getnewargs_ex__(self):
|
| 178 |
+
'Return self as a plain tuple. Used by copy and pickle.'
|
| 179 |
+
return _tuple(self), self.__dict__
|
| 180 |
+
|
| 181 |
+
# Modify function metadata to help with introspection and debugging
|
| 182 |
+
for method in (__new__, __repr__, _asdict, __getnewargs_ex__):
|
| 183 |
+
method.__qualname__ = f'{typename}.{method.__name__}'
|
| 184 |
+
|
| 185 |
+
# Build-up the class namespace dictionary
|
| 186 |
+
# and use type() to build the result class
|
| 187 |
+
class_namespace = {
|
| 188 |
+
'__doc__': f'{typename}({full_list})',
|
| 189 |
+
'_fields': field_names,
|
| 190 |
+
'__new__': __new__,
|
| 191 |
+
'__init__': __init__,
|
| 192 |
+
'__repr__': __repr__,
|
| 193 |
+
'__setattr__': __setattr__,
|
| 194 |
+
'_asdict': _asdict,
|
| 195 |
+
'_extra_fields': extra_field_names,
|
| 196 |
+
'__getnewargs_ex__': __getnewargs_ex__,
|
| 197 |
+
}
|
| 198 |
+
for index, name in enumerate(field_names):
|
| 199 |
+
|
| 200 |
+
def _get(self, index=index):
|
| 201 |
+
return self[index]
|
| 202 |
+
class_namespace[name] = property(_get)
|
| 203 |
+
for name in extra_field_names:
|
| 204 |
+
|
| 205 |
+
def _get(self, name=name):
|
| 206 |
+
return self.__dict__[name]
|
| 207 |
+
class_namespace[name] = property(_get)
|
| 208 |
+
|
| 209 |
+
result = type(typename, (tuple,), class_namespace)
|
| 210 |
+
|
| 211 |
+
# For pickling to work, the __module__ variable needs to be set to the
|
| 212 |
+
# frame where the named tuple is created. Bypass this step in environments
|
| 213 |
+
# where sys._getframe is not defined (Jython for example) or sys._getframe
|
| 214 |
+
# is not defined for arguments greater than 0 (IronPython), or where the
|
| 215 |
+
# user has specified a particular module.
|
| 216 |
+
if module is None:
|
| 217 |
+
try:
|
| 218 |
+
module = _sys._getframe(1).f_globals.get('__name__', '__main__')
|
| 219 |
+
except (AttributeError, ValueError):
|
| 220 |
+
pass
|
| 221 |
+
if module is not None:
|
| 222 |
+
result.__module__ = module
|
| 223 |
+
__new__.__module__ = module
|
| 224 |
+
|
| 225 |
+
return result
|
phi4/lib/python3.10/site-packages/scipy/_lib/_ccallback.py
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from . import _ccallback_c
|
| 2 |
+
|
| 3 |
+
import ctypes
|
| 4 |
+
|
| 5 |
+
PyCFuncPtr = ctypes.CFUNCTYPE(ctypes.c_void_p).__bases__[0]
|
| 6 |
+
|
| 7 |
+
ffi = None
|
| 8 |
+
|
| 9 |
+
class CData:
|
| 10 |
+
pass
|
| 11 |
+
|
| 12 |
+
def _import_cffi():
|
| 13 |
+
global ffi, CData
|
| 14 |
+
|
| 15 |
+
if ffi is not None:
|
| 16 |
+
return
|
| 17 |
+
|
| 18 |
+
try:
|
| 19 |
+
import cffi
|
| 20 |
+
ffi = cffi.FFI()
|
| 21 |
+
CData = ffi.CData
|
| 22 |
+
except ImportError:
|
| 23 |
+
ffi = False
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class LowLevelCallable(tuple):
|
| 27 |
+
"""
|
| 28 |
+
Low-level callback function.
|
| 29 |
+
|
| 30 |
+
Some functions in SciPy take as arguments callback functions, which
|
| 31 |
+
can either be python callables or low-level compiled functions. Using
|
| 32 |
+
compiled callback functions can improve performance somewhat by
|
| 33 |
+
avoiding wrapping data in Python objects.
|
| 34 |
+
|
| 35 |
+
Such low-level functions in SciPy are wrapped in `LowLevelCallable`
|
| 36 |
+
objects, which can be constructed from function pointers obtained from
|
| 37 |
+
ctypes, cffi, Cython, or contained in Python `PyCapsule` objects.
|
| 38 |
+
|
| 39 |
+
.. seealso::
|
| 40 |
+
|
| 41 |
+
Functions accepting low-level callables:
|
| 42 |
+
|
| 43 |
+
`scipy.integrate.quad`, `scipy.ndimage.generic_filter`,
|
| 44 |
+
`scipy.ndimage.generic_filter1d`, `scipy.ndimage.geometric_transform`
|
| 45 |
+
|
| 46 |
+
Usage examples:
|
| 47 |
+
|
| 48 |
+
:ref:`ndimage-ccallbacks`, :ref:`quad-callbacks`
|
| 49 |
+
|
| 50 |
+
Parameters
|
| 51 |
+
----------
|
| 52 |
+
function : {PyCapsule, ctypes function pointer, cffi function pointer}
|
| 53 |
+
Low-level callback function.
|
| 54 |
+
user_data : {PyCapsule, ctypes void pointer, cffi void pointer}
|
| 55 |
+
User data to pass on to the callback function.
|
| 56 |
+
signature : str, optional
|
| 57 |
+
Signature of the function. If omitted, determined from *function*,
|
| 58 |
+
if possible.
|
| 59 |
+
|
| 60 |
+
Attributes
|
| 61 |
+
----------
|
| 62 |
+
function
|
| 63 |
+
Callback function given.
|
| 64 |
+
user_data
|
| 65 |
+
User data given.
|
| 66 |
+
signature
|
| 67 |
+
Signature of the function.
|
| 68 |
+
|
| 69 |
+
Methods
|
| 70 |
+
-------
|
| 71 |
+
from_cython
|
| 72 |
+
Class method for constructing callables from Cython C-exported
|
| 73 |
+
functions.
|
| 74 |
+
|
| 75 |
+
Notes
|
| 76 |
+
-----
|
| 77 |
+
The argument ``function`` can be one of:
|
| 78 |
+
|
| 79 |
+
- PyCapsule, whose name contains the C function signature
|
| 80 |
+
- ctypes function pointer
|
| 81 |
+
- cffi function pointer
|
| 82 |
+
|
| 83 |
+
The signature of the low-level callback must match one of those expected
|
| 84 |
+
by the routine it is passed to.
|
| 85 |
+
|
| 86 |
+
If constructing low-level functions from a PyCapsule, the name of the
|
| 87 |
+
capsule must be the corresponding signature, in the format::
|
| 88 |
+
|
| 89 |
+
return_type (arg1_type, arg2_type, ...)
|
| 90 |
+
|
| 91 |
+
For example::
|
| 92 |
+
|
| 93 |
+
"void (double)"
|
| 94 |
+
"double (double, int *, void *)"
|
| 95 |
+
|
| 96 |
+
The context of a PyCapsule passed in as ``function`` is used as ``user_data``,
|
| 97 |
+
if an explicit value for ``user_data`` was not given.
|
| 98 |
+
|
| 99 |
+
"""
|
| 100 |
+
|
| 101 |
+
# Make the class immutable
|
| 102 |
+
__slots__ = ()
|
| 103 |
+
|
| 104 |
+
def __new__(cls, function, user_data=None, signature=None):
|
| 105 |
+
# We need to hold a reference to the function & user data,
|
| 106 |
+
# to prevent them going out of scope
|
| 107 |
+
item = cls._parse_callback(function, user_data, signature)
|
| 108 |
+
return tuple.__new__(cls, (item, function, user_data))
|
| 109 |
+
|
| 110 |
+
def __repr__(self):
|
| 111 |
+
return f"LowLevelCallable({self.function!r}, {self.user_data!r})"
|
| 112 |
+
|
| 113 |
+
@property
|
| 114 |
+
def function(self):
|
| 115 |
+
return tuple.__getitem__(self, 1)
|
| 116 |
+
|
| 117 |
+
@property
|
| 118 |
+
def user_data(self):
|
| 119 |
+
return tuple.__getitem__(self, 2)
|
| 120 |
+
|
| 121 |
+
@property
|
| 122 |
+
def signature(self):
|
| 123 |
+
return _ccallback_c.get_capsule_signature(tuple.__getitem__(self, 0))
|
| 124 |
+
|
| 125 |
+
def __getitem__(self, idx):
|
| 126 |
+
raise ValueError()
|
| 127 |
+
|
| 128 |
+
@classmethod
|
| 129 |
+
def from_cython(cls, module, name, user_data=None, signature=None):
|
| 130 |
+
"""
|
| 131 |
+
Create a low-level callback function from an exported Cython function.
|
| 132 |
+
|
| 133 |
+
Parameters
|
| 134 |
+
----------
|
| 135 |
+
module : module
|
| 136 |
+
Cython module where the exported function resides
|
| 137 |
+
name : str
|
| 138 |
+
Name of the exported function
|
| 139 |
+
user_data : {PyCapsule, ctypes void pointer, cffi void pointer}, optional
|
| 140 |
+
User data to pass on to the callback function.
|
| 141 |
+
signature : str, optional
|
| 142 |
+
Signature of the function. If omitted, determined from *function*.
|
| 143 |
+
|
| 144 |
+
"""
|
| 145 |
+
try:
|
| 146 |
+
function = module.__pyx_capi__[name]
|
| 147 |
+
except AttributeError as e:
|
| 148 |
+
message = "Given module is not a Cython module with __pyx_capi__ attribute"
|
| 149 |
+
raise ValueError(message) from e
|
| 150 |
+
except KeyError as e:
|
| 151 |
+
message = f"No function {name!r} found in __pyx_capi__ of the module"
|
| 152 |
+
raise ValueError(message) from e
|
| 153 |
+
return cls(function, user_data, signature)
|
| 154 |
+
|
| 155 |
+
@classmethod
|
| 156 |
+
def _parse_callback(cls, obj, user_data=None, signature=None):
|
| 157 |
+
_import_cffi()
|
| 158 |
+
|
| 159 |
+
if isinstance(obj, LowLevelCallable):
|
| 160 |
+
func = tuple.__getitem__(obj, 0)
|
| 161 |
+
elif isinstance(obj, PyCFuncPtr):
|
| 162 |
+
func, signature = _get_ctypes_func(obj, signature)
|
| 163 |
+
elif isinstance(obj, CData):
|
| 164 |
+
func, signature = _get_cffi_func(obj, signature)
|
| 165 |
+
elif _ccallback_c.check_capsule(obj):
|
| 166 |
+
func = obj
|
| 167 |
+
else:
|
| 168 |
+
raise ValueError("Given input is not a callable or a "
|
| 169 |
+
"low-level callable (pycapsule/ctypes/cffi)")
|
| 170 |
+
|
| 171 |
+
if isinstance(user_data, ctypes.c_void_p):
|
| 172 |
+
context = _get_ctypes_data(user_data)
|
| 173 |
+
elif isinstance(user_data, CData):
|
| 174 |
+
context = _get_cffi_data(user_data)
|
| 175 |
+
elif user_data is None:
|
| 176 |
+
context = 0
|
| 177 |
+
elif _ccallback_c.check_capsule(user_data):
|
| 178 |
+
context = user_data
|
| 179 |
+
else:
|
| 180 |
+
raise ValueError("Given user data is not a valid "
|
| 181 |
+
"low-level void* pointer (pycapsule/ctypes/cffi)")
|
| 182 |
+
|
| 183 |
+
return _ccallback_c.get_raw_capsule(func, signature, context)
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
#
|
| 187 |
+
# ctypes helpers
|
| 188 |
+
#
|
| 189 |
+
|
| 190 |
+
def _get_ctypes_func(func, signature=None):
|
| 191 |
+
# Get function pointer
|
| 192 |
+
func_ptr = ctypes.cast(func, ctypes.c_void_p).value
|
| 193 |
+
|
| 194 |
+
# Construct function signature
|
| 195 |
+
if signature is None:
|
| 196 |
+
signature = _typename_from_ctypes(func.restype) + " ("
|
| 197 |
+
for j, arg in enumerate(func.argtypes):
|
| 198 |
+
if j == 0:
|
| 199 |
+
signature += _typename_from_ctypes(arg)
|
| 200 |
+
else:
|
| 201 |
+
signature += ", " + _typename_from_ctypes(arg)
|
| 202 |
+
signature += ")"
|
| 203 |
+
|
| 204 |
+
return func_ptr, signature
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def _typename_from_ctypes(item):
|
| 208 |
+
if item is None:
|
| 209 |
+
return "void"
|
| 210 |
+
elif item is ctypes.c_void_p:
|
| 211 |
+
return "void *"
|
| 212 |
+
|
| 213 |
+
name = item.__name__
|
| 214 |
+
|
| 215 |
+
pointer_level = 0
|
| 216 |
+
while name.startswith("LP_"):
|
| 217 |
+
pointer_level += 1
|
| 218 |
+
name = name[3:]
|
| 219 |
+
|
| 220 |
+
if name.startswith('c_'):
|
| 221 |
+
name = name[2:]
|
| 222 |
+
|
| 223 |
+
if pointer_level > 0:
|
| 224 |
+
name += " " + "*"*pointer_level
|
| 225 |
+
|
| 226 |
+
return name
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def _get_ctypes_data(data):
|
| 230 |
+
# Get voidp pointer
|
| 231 |
+
return ctypes.cast(data, ctypes.c_void_p).value
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
#
|
| 235 |
+
# CFFI helpers
|
| 236 |
+
#
|
| 237 |
+
|
| 238 |
+
def _get_cffi_func(func, signature=None):
|
| 239 |
+
# Get function pointer
|
| 240 |
+
func_ptr = ffi.cast('uintptr_t', func)
|
| 241 |
+
|
| 242 |
+
# Get signature
|
| 243 |
+
if signature is None:
|
| 244 |
+
signature = ffi.getctype(ffi.typeof(func)).replace('(*)', ' ')
|
| 245 |
+
|
| 246 |
+
return func_ptr, signature
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def _get_cffi_data(data):
|
| 250 |
+
# Get pointer
|
| 251 |
+
return ffi.cast('uintptr_t', data)
|
phi4/lib/python3.10/site-packages/scipy/_lib/_disjoint_set.py
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Disjoint set data structure
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class DisjointSet:
|
| 7 |
+
""" Disjoint set data structure for incremental connectivity queries.
|
| 8 |
+
|
| 9 |
+
.. versionadded:: 1.6.0
|
| 10 |
+
|
| 11 |
+
Attributes
|
| 12 |
+
----------
|
| 13 |
+
n_subsets : int
|
| 14 |
+
The number of subsets.
|
| 15 |
+
|
| 16 |
+
Methods
|
| 17 |
+
-------
|
| 18 |
+
add
|
| 19 |
+
merge
|
| 20 |
+
connected
|
| 21 |
+
subset
|
| 22 |
+
subset_size
|
| 23 |
+
subsets
|
| 24 |
+
__getitem__
|
| 25 |
+
|
| 26 |
+
Notes
|
| 27 |
+
-----
|
| 28 |
+
This class implements the disjoint set [1]_, also known as the *union-find*
|
| 29 |
+
or *merge-find* data structure. The *find* operation (implemented in
|
| 30 |
+
`__getitem__`) implements the *path halving* variant. The *merge* method
|
| 31 |
+
implements the *merge by size* variant.
|
| 32 |
+
|
| 33 |
+
References
|
| 34 |
+
----------
|
| 35 |
+
.. [1] https://en.wikipedia.org/wiki/Disjoint-set_data_structure
|
| 36 |
+
|
| 37 |
+
Examples
|
| 38 |
+
--------
|
| 39 |
+
>>> from scipy.cluster.hierarchy import DisjointSet
|
| 40 |
+
|
| 41 |
+
Initialize a disjoint set:
|
| 42 |
+
|
| 43 |
+
>>> disjoint_set = DisjointSet([1, 2, 3, 'a', 'b'])
|
| 44 |
+
|
| 45 |
+
Merge some subsets:
|
| 46 |
+
|
| 47 |
+
>>> disjoint_set.merge(1, 2)
|
| 48 |
+
True
|
| 49 |
+
>>> disjoint_set.merge(3, 'a')
|
| 50 |
+
True
|
| 51 |
+
>>> disjoint_set.merge('a', 'b')
|
| 52 |
+
True
|
| 53 |
+
>>> disjoint_set.merge('b', 'b')
|
| 54 |
+
False
|
| 55 |
+
|
| 56 |
+
Find root elements:
|
| 57 |
+
|
| 58 |
+
>>> disjoint_set[2]
|
| 59 |
+
1
|
| 60 |
+
>>> disjoint_set['b']
|
| 61 |
+
3
|
| 62 |
+
|
| 63 |
+
Test connectivity:
|
| 64 |
+
|
| 65 |
+
>>> disjoint_set.connected(1, 2)
|
| 66 |
+
True
|
| 67 |
+
>>> disjoint_set.connected(1, 'b')
|
| 68 |
+
False
|
| 69 |
+
|
| 70 |
+
List elements in disjoint set:
|
| 71 |
+
|
| 72 |
+
>>> list(disjoint_set)
|
| 73 |
+
[1, 2, 3, 'a', 'b']
|
| 74 |
+
|
| 75 |
+
Get the subset containing 'a':
|
| 76 |
+
|
| 77 |
+
>>> disjoint_set.subset('a')
|
| 78 |
+
{'a', 3, 'b'}
|
| 79 |
+
|
| 80 |
+
Get the size of the subset containing 'a' (without actually instantiating
|
| 81 |
+
the subset):
|
| 82 |
+
|
| 83 |
+
>>> disjoint_set.subset_size('a')
|
| 84 |
+
3
|
| 85 |
+
|
| 86 |
+
Get all subsets in the disjoint set:
|
| 87 |
+
|
| 88 |
+
>>> disjoint_set.subsets()
|
| 89 |
+
[{1, 2}, {'a', 3, 'b'}]
|
| 90 |
+
"""
|
| 91 |
+
def __init__(self, elements=None):
|
| 92 |
+
self.n_subsets = 0
|
| 93 |
+
self._sizes = {}
|
| 94 |
+
self._parents = {}
|
| 95 |
+
# _nbrs is a circular linked list which links connected elements.
|
| 96 |
+
self._nbrs = {}
|
| 97 |
+
# _indices tracks the element insertion order in `__iter__`.
|
| 98 |
+
self._indices = {}
|
| 99 |
+
if elements is not None:
|
| 100 |
+
for x in elements:
|
| 101 |
+
self.add(x)
|
| 102 |
+
|
| 103 |
+
def __iter__(self):
|
| 104 |
+
"""Returns an iterator of the elements in the disjoint set.
|
| 105 |
+
|
| 106 |
+
Elements are ordered by insertion order.
|
| 107 |
+
"""
|
| 108 |
+
return iter(self._indices)
|
| 109 |
+
|
| 110 |
+
def __len__(self):
|
| 111 |
+
return len(self._indices)
|
| 112 |
+
|
| 113 |
+
def __contains__(self, x):
|
| 114 |
+
return x in self._indices
|
| 115 |
+
|
| 116 |
+
def __getitem__(self, x):
|
| 117 |
+
"""Find the root element of `x`.
|
| 118 |
+
|
| 119 |
+
Parameters
|
| 120 |
+
----------
|
| 121 |
+
x : hashable object
|
| 122 |
+
Input element.
|
| 123 |
+
|
| 124 |
+
Returns
|
| 125 |
+
-------
|
| 126 |
+
root : hashable object
|
| 127 |
+
Root element of `x`.
|
| 128 |
+
"""
|
| 129 |
+
if x not in self._indices:
|
| 130 |
+
raise KeyError(x)
|
| 131 |
+
|
| 132 |
+
# find by "path halving"
|
| 133 |
+
parents = self._parents
|
| 134 |
+
while self._indices[x] != self._indices[parents[x]]:
|
| 135 |
+
parents[x] = parents[parents[x]]
|
| 136 |
+
x = parents[x]
|
| 137 |
+
return x
|
| 138 |
+
|
| 139 |
+
def add(self, x):
|
| 140 |
+
"""Add element `x` to disjoint set
|
| 141 |
+
"""
|
| 142 |
+
if x in self._indices:
|
| 143 |
+
return
|
| 144 |
+
|
| 145 |
+
self._sizes[x] = 1
|
| 146 |
+
self._parents[x] = x
|
| 147 |
+
self._nbrs[x] = x
|
| 148 |
+
self._indices[x] = len(self._indices)
|
| 149 |
+
self.n_subsets += 1
|
| 150 |
+
|
| 151 |
+
def merge(self, x, y):
|
| 152 |
+
"""Merge the subsets of `x` and `y`.
|
| 153 |
+
|
| 154 |
+
The smaller subset (the child) is merged into the larger subset (the
|
| 155 |
+
parent). If the subsets are of equal size, the root element which was
|
| 156 |
+
first inserted into the disjoint set is selected as the parent.
|
| 157 |
+
|
| 158 |
+
Parameters
|
| 159 |
+
----------
|
| 160 |
+
x, y : hashable object
|
| 161 |
+
Elements to merge.
|
| 162 |
+
|
| 163 |
+
Returns
|
| 164 |
+
-------
|
| 165 |
+
merged : bool
|
| 166 |
+
True if `x` and `y` were in disjoint sets, False otherwise.
|
| 167 |
+
"""
|
| 168 |
+
xr = self[x]
|
| 169 |
+
yr = self[y]
|
| 170 |
+
if self._indices[xr] == self._indices[yr]:
|
| 171 |
+
return False
|
| 172 |
+
|
| 173 |
+
sizes = self._sizes
|
| 174 |
+
if (sizes[xr], self._indices[yr]) < (sizes[yr], self._indices[xr]):
|
| 175 |
+
xr, yr = yr, xr
|
| 176 |
+
self._parents[yr] = xr
|
| 177 |
+
self._sizes[xr] += self._sizes[yr]
|
| 178 |
+
self._nbrs[xr], self._nbrs[yr] = self._nbrs[yr], self._nbrs[xr]
|
| 179 |
+
self.n_subsets -= 1
|
| 180 |
+
return True
|
| 181 |
+
|
| 182 |
+
def connected(self, x, y):
|
| 183 |
+
"""Test whether `x` and `y` are in the same subset.
|
| 184 |
+
|
| 185 |
+
Parameters
|
| 186 |
+
----------
|
| 187 |
+
x, y : hashable object
|
| 188 |
+
Elements to test.
|
| 189 |
+
|
| 190 |
+
Returns
|
| 191 |
+
-------
|
| 192 |
+
result : bool
|
| 193 |
+
True if `x` and `y` are in the same set, False otherwise.
|
| 194 |
+
"""
|
| 195 |
+
return self._indices[self[x]] == self._indices[self[y]]
|
| 196 |
+
|
| 197 |
+
def subset(self, x):
|
| 198 |
+
"""Get the subset containing `x`.
|
| 199 |
+
|
| 200 |
+
Parameters
|
| 201 |
+
----------
|
| 202 |
+
x : hashable object
|
| 203 |
+
Input element.
|
| 204 |
+
|
| 205 |
+
Returns
|
| 206 |
+
-------
|
| 207 |
+
result : set
|
| 208 |
+
Subset containing `x`.
|
| 209 |
+
"""
|
| 210 |
+
if x not in self._indices:
|
| 211 |
+
raise KeyError(x)
|
| 212 |
+
|
| 213 |
+
result = [x]
|
| 214 |
+
nxt = self._nbrs[x]
|
| 215 |
+
while self._indices[nxt] != self._indices[x]:
|
| 216 |
+
result.append(nxt)
|
| 217 |
+
nxt = self._nbrs[nxt]
|
| 218 |
+
return set(result)
|
| 219 |
+
|
| 220 |
+
def subset_size(self, x):
|
| 221 |
+
"""Get the size of the subset containing `x`.
|
| 222 |
+
|
| 223 |
+
Note that this method is faster than ``len(self.subset(x))`` because
|
| 224 |
+
the size is directly read off an internal field, without the need to
|
| 225 |
+
instantiate the full subset.
|
| 226 |
+
|
| 227 |
+
Parameters
|
| 228 |
+
----------
|
| 229 |
+
x : hashable object
|
| 230 |
+
Input element.
|
| 231 |
+
|
| 232 |
+
Returns
|
| 233 |
+
-------
|
| 234 |
+
result : int
|
| 235 |
+
Size of the subset containing `x`.
|
| 236 |
+
"""
|
| 237 |
+
return self._sizes[self[x]]
|
| 238 |
+
|
| 239 |
+
def subsets(self):
|
| 240 |
+
"""Get all the subsets in the disjoint set.
|
| 241 |
+
|
| 242 |
+
Returns
|
| 243 |
+
-------
|
| 244 |
+
result : list
|
| 245 |
+
Subsets in the disjoint set.
|
| 246 |
+
"""
|
| 247 |
+
result = []
|
| 248 |
+
visited = set()
|
| 249 |
+
for x in self:
|
| 250 |
+
if x not in visited:
|
| 251 |
+
xset = self.subset(x)
|
| 252 |
+
visited.update(xset)
|
| 253 |
+
result.append(xset)
|
| 254 |
+
return result
|
phi4/lib/python3.10/site-packages/scipy/_lib/_gcutils.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Module for testing automatic garbage collection of objects
|
| 3 |
+
|
| 4 |
+
.. autosummary::
|
| 5 |
+
:toctree: generated/
|
| 6 |
+
|
| 7 |
+
set_gc_state - enable or disable garbage collection
|
| 8 |
+
gc_state - context manager for given state of garbage collector
|
| 9 |
+
assert_deallocated - context manager to check for circular references on object
|
| 10 |
+
|
| 11 |
+
"""
|
| 12 |
+
import weakref
|
| 13 |
+
import gc
|
| 14 |
+
|
| 15 |
+
from contextlib import contextmanager
|
| 16 |
+
from platform import python_implementation
|
| 17 |
+
|
| 18 |
+
__all__ = ['set_gc_state', 'gc_state', 'assert_deallocated']
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
IS_PYPY = python_implementation() == 'PyPy'
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class ReferenceError(AssertionError):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def set_gc_state(state):
|
| 29 |
+
""" Set status of garbage collector """
|
| 30 |
+
if gc.isenabled() == state:
|
| 31 |
+
return
|
| 32 |
+
if state:
|
| 33 |
+
gc.enable()
|
| 34 |
+
else:
|
| 35 |
+
gc.disable()
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@contextmanager
|
| 39 |
+
def gc_state(state):
|
| 40 |
+
""" Context manager to set state of garbage collector to `state`
|
| 41 |
+
|
| 42 |
+
Parameters
|
| 43 |
+
----------
|
| 44 |
+
state : bool
|
| 45 |
+
True for gc enabled, False for disabled
|
| 46 |
+
|
| 47 |
+
Examples
|
| 48 |
+
--------
|
| 49 |
+
>>> with gc_state(False):
|
| 50 |
+
... assert not gc.isenabled()
|
| 51 |
+
>>> with gc_state(True):
|
| 52 |
+
... assert gc.isenabled()
|
| 53 |
+
"""
|
| 54 |
+
orig_state = gc.isenabled()
|
| 55 |
+
set_gc_state(state)
|
| 56 |
+
yield
|
| 57 |
+
set_gc_state(orig_state)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
@contextmanager
|
| 61 |
+
def assert_deallocated(func, *args, **kwargs):
|
| 62 |
+
"""Context manager to check that object is deallocated
|
| 63 |
+
|
| 64 |
+
This is useful for checking that an object can be freed directly by
|
| 65 |
+
reference counting, without requiring gc to break reference cycles.
|
| 66 |
+
GC is disabled inside the context manager.
|
| 67 |
+
|
| 68 |
+
This check is not available on PyPy.
|
| 69 |
+
|
| 70 |
+
Parameters
|
| 71 |
+
----------
|
| 72 |
+
func : callable
|
| 73 |
+
Callable to create object to check
|
| 74 |
+
\\*args : sequence
|
| 75 |
+
positional arguments to `func` in order to create object to check
|
| 76 |
+
\\*\\*kwargs : dict
|
| 77 |
+
keyword arguments to `func` in order to create object to check
|
| 78 |
+
|
| 79 |
+
Examples
|
| 80 |
+
--------
|
| 81 |
+
>>> class C: pass
|
| 82 |
+
>>> with assert_deallocated(C) as c:
|
| 83 |
+
... # do something
|
| 84 |
+
... del c
|
| 85 |
+
|
| 86 |
+
>>> class C:
|
| 87 |
+
... def __init__(self):
|
| 88 |
+
... self._circular = self # Make circular reference
|
| 89 |
+
>>> with assert_deallocated(C) as c: #doctest: +IGNORE_EXCEPTION_DETAIL
|
| 90 |
+
... # do something
|
| 91 |
+
... del c
|
| 92 |
+
Traceback (most recent call last):
|
| 93 |
+
...
|
| 94 |
+
ReferenceError: Remaining reference(s) to object
|
| 95 |
+
"""
|
| 96 |
+
if IS_PYPY:
|
| 97 |
+
raise RuntimeError("assert_deallocated is unavailable on PyPy")
|
| 98 |
+
|
| 99 |
+
with gc_state(False):
|
| 100 |
+
obj = func(*args, **kwargs)
|
| 101 |
+
ref = weakref.ref(obj)
|
| 102 |
+
yield obj
|
| 103 |
+
del obj
|
| 104 |
+
if ref() is not None:
|
| 105 |
+
raise ReferenceError("Remaining reference(s) to object")
|
phi4/lib/python3.10/site-packages/scipy/_lib/_pep440.py
ADDED
|
@@ -0,0 +1,487 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Utility to compare pep440 compatible version strings.
|
| 2 |
+
|
| 3 |
+
The LooseVersion and StrictVersion classes that distutils provides don't
|
| 4 |
+
work; they don't recognize anything like alpha/beta/rc/dev versions.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
# Copyright (c) Donald Stufft and individual contributors.
|
| 8 |
+
# All rights reserved.
|
| 9 |
+
|
| 10 |
+
# Redistribution and use in source and binary forms, with or without
|
| 11 |
+
# modification, are permitted provided that the following conditions are met:
|
| 12 |
+
|
| 13 |
+
# 1. Redistributions of source code must retain the above copyright notice,
|
| 14 |
+
# this list of conditions and the following disclaimer.
|
| 15 |
+
|
| 16 |
+
# 2. Redistributions in binary form must reproduce the above copyright
|
| 17 |
+
# notice, this list of conditions and the following disclaimer in the
|
| 18 |
+
# documentation and/or other materials provided with the distribution.
|
| 19 |
+
|
| 20 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 21 |
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 22 |
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 23 |
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
| 24 |
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
| 25 |
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
| 26 |
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 27 |
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 28 |
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 29 |
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 30 |
+
# POSSIBILITY OF SUCH DAMAGE.
|
| 31 |
+
|
| 32 |
+
import collections
|
| 33 |
+
import itertools
|
| 34 |
+
import re
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
__all__ = [
|
| 38 |
+
"parse", "Version", "LegacyVersion", "InvalidVersion", "VERSION_PATTERN",
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# BEGIN packaging/_structures.py
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class Infinity:
|
| 46 |
+
def __repr__(self):
|
| 47 |
+
return "Infinity"
|
| 48 |
+
|
| 49 |
+
def __hash__(self):
|
| 50 |
+
return hash(repr(self))
|
| 51 |
+
|
| 52 |
+
def __lt__(self, other):
|
| 53 |
+
return False
|
| 54 |
+
|
| 55 |
+
def __le__(self, other):
|
| 56 |
+
return False
|
| 57 |
+
|
| 58 |
+
def __eq__(self, other):
|
| 59 |
+
return isinstance(other, self.__class__)
|
| 60 |
+
|
| 61 |
+
def __ne__(self, other):
|
| 62 |
+
return not isinstance(other, self.__class__)
|
| 63 |
+
|
| 64 |
+
def __gt__(self, other):
|
| 65 |
+
return True
|
| 66 |
+
|
| 67 |
+
def __ge__(self, other):
|
| 68 |
+
return True
|
| 69 |
+
|
| 70 |
+
def __neg__(self):
|
| 71 |
+
return NegativeInfinity
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
Infinity = Infinity()
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class NegativeInfinity:
|
| 78 |
+
def __repr__(self):
|
| 79 |
+
return "-Infinity"
|
| 80 |
+
|
| 81 |
+
def __hash__(self):
|
| 82 |
+
return hash(repr(self))
|
| 83 |
+
|
| 84 |
+
def __lt__(self, other):
|
| 85 |
+
return True
|
| 86 |
+
|
| 87 |
+
def __le__(self, other):
|
| 88 |
+
return True
|
| 89 |
+
|
| 90 |
+
def __eq__(self, other):
|
| 91 |
+
return isinstance(other, self.__class__)
|
| 92 |
+
|
| 93 |
+
def __ne__(self, other):
|
| 94 |
+
return not isinstance(other, self.__class__)
|
| 95 |
+
|
| 96 |
+
def __gt__(self, other):
|
| 97 |
+
return False
|
| 98 |
+
|
| 99 |
+
def __ge__(self, other):
|
| 100 |
+
return False
|
| 101 |
+
|
| 102 |
+
def __neg__(self):
|
| 103 |
+
return Infinity
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
# BEGIN packaging/version.py
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
NegativeInfinity = NegativeInfinity()
|
| 110 |
+
|
| 111 |
+
_Version = collections.namedtuple(
|
| 112 |
+
"_Version",
|
| 113 |
+
["epoch", "release", "dev", "pre", "post", "local"],
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def parse(version):
|
| 118 |
+
"""
|
| 119 |
+
Parse the given version string and return either a :class:`Version` object
|
| 120 |
+
or a :class:`LegacyVersion` object depending on if the given version is
|
| 121 |
+
a valid PEP 440 version or a legacy version.
|
| 122 |
+
"""
|
| 123 |
+
try:
|
| 124 |
+
return Version(version)
|
| 125 |
+
except InvalidVersion:
|
| 126 |
+
return LegacyVersion(version)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
class InvalidVersion(ValueError):
|
| 130 |
+
"""
|
| 131 |
+
An invalid version was found, users should refer to PEP 440.
|
| 132 |
+
"""
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
class _BaseVersion:
|
| 136 |
+
|
| 137 |
+
def __hash__(self):
|
| 138 |
+
return hash(self._key)
|
| 139 |
+
|
| 140 |
+
def __lt__(self, other):
|
| 141 |
+
return self._compare(other, lambda s, o: s < o)
|
| 142 |
+
|
| 143 |
+
def __le__(self, other):
|
| 144 |
+
return self._compare(other, lambda s, o: s <= o)
|
| 145 |
+
|
| 146 |
+
def __eq__(self, other):
|
| 147 |
+
return self._compare(other, lambda s, o: s == o)
|
| 148 |
+
|
| 149 |
+
def __ge__(self, other):
|
| 150 |
+
return self._compare(other, lambda s, o: s >= o)
|
| 151 |
+
|
| 152 |
+
def __gt__(self, other):
|
| 153 |
+
return self._compare(other, lambda s, o: s > o)
|
| 154 |
+
|
| 155 |
+
def __ne__(self, other):
|
| 156 |
+
return self._compare(other, lambda s, o: s != o)
|
| 157 |
+
|
| 158 |
+
def _compare(self, other, method):
|
| 159 |
+
if not isinstance(other, _BaseVersion):
|
| 160 |
+
return NotImplemented
|
| 161 |
+
|
| 162 |
+
return method(self._key, other._key)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
class LegacyVersion(_BaseVersion):
|
| 166 |
+
|
| 167 |
+
def __init__(self, version):
|
| 168 |
+
self._version = str(version)
|
| 169 |
+
self._key = _legacy_cmpkey(self._version)
|
| 170 |
+
|
| 171 |
+
def __str__(self):
|
| 172 |
+
return self._version
|
| 173 |
+
|
| 174 |
+
def __repr__(self):
|
| 175 |
+
return f"<LegacyVersion({repr(str(self))})>"
|
| 176 |
+
|
| 177 |
+
@property
|
| 178 |
+
def public(self):
|
| 179 |
+
return self._version
|
| 180 |
+
|
| 181 |
+
@property
|
| 182 |
+
def base_version(self):
|
| 183 |
+
return self._version
|
| 184 |
+
|
| 185 |
+
@property
|
| 186 |
+
def local(self):
|
| 187 |
+
return None
|
| 188 |
+
|
| 189 |
+
@property
|
| 190 |
+
def is_prerelease(self):
|
| 191 |
+
return False
|
| 192 |
+
|
| 193 |
+
@property
|
| 194 |
+
def is_postrelease(self):
|
| 195 |
+
return False
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
_legacy_version_component_re = re.compile(
|
| 199 |
+
r"(\d+ | [a-z]+ | \.| -)", re.VERBOSE,
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
_legacy_version_replacement_map = {
|
| 203 |
+
"pre": "c", "preview": "c", "-": "final-", "rc": "c", "dev": "@",
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def _parse_version_parts(s):
|
| 208 |
+
for part in _legacy_version_component_re.split(s):
|
| 209 |
+
part = _legacy_version_replacement_map.get(part, part)
|
| 210 |
+
|
| 211 |
+
if not part or part == ".":
|
| 212 |
+
continue
|
| 213 |
+
|
| 214 |
+
if part[:1] in "0123456789":
|
| 215 |
+
# pad for numeric comparison
|
| 216 |
+
yield part.zfill(8)
|
| 217 |
+
else:
|
| 218 |
+
yield "*" + part
|
| 219 |
+
|
| 220 |
+
# ensure that alpha/beta/candidate are before final
|
| 221 |
+
yield "*final"
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def _legacy_cmpkey(version):
|
| 225 |
+
# We hardcode an epoch of -1 here. A PEP 440 version can only have an epoch
|
| 226 |
+
# greater than or equal to 0. This will effectively put the LegacyVersion,
|
| 227 |
+
# which uses the defacto standard originally implemented by setuptools,
|
| 228 |
+
# as before all PEP 440 versions.
|
| 229 |
+
epoch = -1
|
| 230 |
+
|
| 231 |
+
# This scheme is taken from pkg_resources.parse_version setuptools prior to
|
| 232 |
+
# its adoption of the packaging library.
|
| 233 |
+
parts = []
|
| 234 |
+
for part in _parse_version_parts(version.lower()):
|
| 235 |
+
if part.startswith("*"):
|
| 236 |
+
# remove "-" before a prerelease tag
|
| 237 |
+
if part < "*final":
|
| 238 |
+
while parts and parts[-1] == "*final-":
|
| 239 |
+
parts.pop()
|
| 240 |
+
|
| 241 |
+
# remove trailing zeros from each series of numeric parts
|
| 242 |
+
while parts and parts[-1] == "00000000":
|
| 243 |
+
parts.pop()
|
| 244 |
+
|
| 245 |
+
parts.append(part)
|
| 246 |
+
parts = tuple(parts)
|
| 247 |
+
|
| 248 |
+
return epoch, parts
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
# Deliberately not anchored to the start and end of the string, to make it
|
| 252 |
+
# easier for 3rd party code to reuse
|
| 253 |
+
VERSION_PATTERN = r"""
|
| 254 |
+
v?
|
| 255 |
+
(?:
|
| 256 |
+
(?:(?P<epoch>[0-9]+)!)? # epoch
|
| 257 |
+
(?P<release>[0-9]+(?:\.[0-9]+)*) # release segment
|
| 258 |
+
(?P<pre> # pre-release
|
| 259 |
+
[-_\.]?
|
| 260 |
+
(?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
|
| 261 |
+
[-_\.]?
|
| 262 |
+
(?P<pre_n>[0-9]+)?
|
| 263 |
+
)?
|
| 264 |
+
(?P<post> # post release
|
| 265 |
+
(?:-(?P<post_n1>[0-9]+))
|
| 266 |
+
|
|
| 267 |
+
(?:
|
| 268 |
+
[-_\.]?
|
| 269 |
+
(?P<post_l>post|rev|r)
|
| 270 |
+
[-_\.]?
|
| 271 |
+
(?P<post_n2>[0-9]+)?
|
| 272 |
+
)
|
| 273 |
+
)?
|
| 274 |
+
(?P<dev> # dev release
|
| 275 |
+
[-_\.]?
|
| 276 |
+
(?P<dev_l>dev)
|
| 277 |
+
[-_\.]?
|
| 278 |
+
(?P<dev_n>[0-9]+)?
|
| 279 |
+
)?
|
| 280 |
+
)
|
| 281 |
+
(?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))? # local version
|
| 282 |
+
"""
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
class Version(_BaseVersion):
|
| 286 |
+
|
| 287 |
+
_regex = re.compile(
|
| 288 |
+
r"^\s*" + VERSION_PATTERN + r"\s*$",
|
| 289 |
+
re.VERBOSE | re.IGNORECASE,
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
def __init__(self, version):
|
| 293 |
+
# Validate the version and parse it into pieces
|
| 294 |
+
match = self._regex.search(version)
|
| 295 |
+
if not match:
|
| 296 |
+
raise InvalidVersion(f"Invalid version: '{version}'")
|
| 297 |
+
|
| 298 |
+
# Store the parsed out pieces of the version
|
| 299 |
+
self._version = _Version(
|
| 300 |
+
epoch=int(match.group("epoch")) if match.group("epoch") else 0,
|
| 301 |
+
release=tuple(int(i) for i in match.group("release").split(".")),
|
| 302 |
+
pre=_parse_letter_version(
|
| 303 |
+
match.group("pre_l"),
|
| 304 |
+
match.group("pre_n"),
|
| 305 |
+
),
|
| 306 |
+
post=_parse_letter_version(
|
| 307 |
+
match.group("post_l"),
|
| 308 |
+
match.group("post_n1") or match.group("post_n2"),
|
| 309 |
+
),
|
| 310 |
+
dev=_parse_letter_version(
|
| 311 |
+
match.group("dev_l"),
|
| 312 |
+
match.group("dev_n"),
|
| 313 |
+
),
|
| 314 |
+
local=_parse_local_version(match.group("local")),
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
# Generate a key which will be used for sorting
|
| 318 |
+
self._key = _cmpkey(
|
| 319 |
+
self._version.epoch,
|
| 320 |
+
self._version.release,
|
| 321 |
+
self._version.pre,
|
| 322 |
+
self._version.post,
|
| 323 |
+
self._version.dev,
|
| 324 |
+
self._version.local,
|
| 325 |
+
)
|
| 326 |
+
|
| 327 |
+
def __repr__(self):
|
| 328 |
+
return f"<Version({repr(str(self))})>"
|
| 329 |
+
|
| 330 |
+
def __str__(self):
|
| 331 |
+
parts = []
|
| 332 |
+
|
| 333 |
+
# Epoch
|
| 334 |
+
if self._version.epoch != 0:
|
| 335 |
+
parts.append(f"{self._version.epoch}!")
|
| 336 |
+
|
| 337 |
+
# Release segment
|
| 338 |
+
parts.append(".".join(str(x) for x in self._version.release))
|
| 339 |
+
|
| 340 |
+
# Pre-release
|
| 341 |
+
if self._version.pre is not None:
|
| 342 |
+
parts.append("".join(str(x) for x in self._version.pre))
|
| 343 |
+
|
| 344 |
+
# Post-release
|
| 345 |
+
if self._version.post is not None:
|
| 346 |
+
parts.append(f".post{self._version.post[1]}")
|
| 347 |
+
|
| 348 |
+
# Development release
|
| 349 |
+
if self._version.dev is not None:
|
| 350 |
+
parts.append(f".dev{self._version.dev[1]}")
|
| 351 |
+
|
| 352 |
+
# Local version segment
|
| 353 |
+
if self._version.local is not None:
|
| 354 |
+
parts.append(
|
| 355 |
+
"+{}".format(".".join(str(x) for x in self._version.local))
|
| 356 |
+
)
|
| 357 |
+
|
| 358 |
+
return "".join(parts)
|
| 359 |
+
|
| 360 |
+
@property
|
| 361 |
+
def public(self):
|
| 362 |
+
return str(self).split("+", 1)[0]
|
| 363 |
+
|
| 364 |
+
@property
|
| 365 |
+
def base_version(self):
|
| 366 |
+
parts = []
|
| 367 |
+
|
| 368 |
+
# Epoch
|
| 369 |
+
if self._version.epoch != 0:
|
| 370 |
+
parts.append(f"{self._version.epoch}!")
|
| 371 |
+
|
| 372 |
+
# Release segment
|
| 373 |
+
parts.append(".".join(str(x) for x in self._version.release))
|
| 374 |
+
|
| 375 |
+
return "".join(parts)
|
| 376 |
+
|
| 377 |
+
@property
|
| 378 |
+
def local(self):
|
| 379 |
+
version_string = str(self)
|
| 380 |
+
if "+" in version_string:
|
| 381 |
+
return version_string.split("+", 1)[1]
|
| 382 |
+
|
| 383 |
+
@property
|
| 384 |
+
def is_prerelease(self):
|
| 385 |
+
return bool(self._version.dev or self._version.pre)
|
| 386 |
+
|
| 387 |
+
@property
|
| 388 |
+
def is_postrelease(self):
|
| 389 |
+
return bool(self._version.post)
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
def _parse_letter_version(letter, number):
|
| 393 |
+
if letter:
|
| 394 |
+
# We assume there is an implicit 0 in a pre-release if there is
|
| 395 |
+
# no numeral associated with it.
|
| 396 |
+
if number is None:
|
| 397 |
+
number = 0
|
| 398 |
+
|
| 399 |
+
# We normalize any letters to their lower-case form
|
| 400 |
+
letter = letter.lower()
|
| 401 |
+
|
| 402 |
+
# We consider some words to be alternate spellings of other words and
|
| 403 |
+
# in those cases we want to normalize the spellings to our preferred
|
| 404 |
+
# spelling.
|
| 405 |
+
if letter == "alpha":
|
| 406 |
+
letter = "a"
|
| 407 |
+
elif letter == "beta":
|
| 408 |
+
letter = "b"
|
| 409 |
+
elif letter in ["c", "pre", "preview"]:
|
| 410 |
+
letter = "rc"
|
| 411 |
+
elif letter in ["rev", "r"]:
|
| 412 |
+
letter = "post"
|
| 413 |
+
|
| 414 |
+
return letter, int(number)
|
| 415 |
+
if not letter and number:
|
| 416 |
+
# We assume that if we are given a number but not given a letter,
|
| 417 |
+
# then this is using the implicit post release syntax (e.g., 1.0-1)
|
| 418 |
+
letter = "post"
|
| 419 |
+
|
| 420 |
+
return letter, int(number)
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
_local_version_seperators = re.compile(r"[\._-]")
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
def _parse_local_version(local):
|
| 427 |
+
"""
|
| 428 |
+
Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
|
| 429 |
+
"""
|
| 430 |
+
if local is not None:
|
| 431 |
+
return tuple(
|
| 432 |
+
part.lower() if not part.isdigit() else int(part)
|
| 433 |
+
for part in _local_version_seperators.split(local)
|
| 434 |
+
)
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
def _cmpkey(epoch, release, pre, post, dev, local):
|
| 438 |
+
# When we compare a release version, we want to compare it with all of the
|
| 439 |
+
# trailing zeros removed. So we'll use a reverse the list, drop all the now
|
| 440 |
+
# leading zeros until we come to something non-zero, then take the rest,
|
| 441 |
+
# re-reverse it back into the correct order, and make it a tuple and use
|
| 442 |
+
# that for our sorting key.
|
| 443 |
+
release = tuple(
|
| 444 |
+
reversed(list(
|
| 445 |
+
itertools.dropwhile(
|
| 446 |
+
lambda x: x == 0,
|
| 447 |
+
reversed(release),
|
| 448 |
+
)
|
| 449 |
+
))
|
| 450 |
+
)
|
| 451 |
+
|
| 452 |
+
# We need to "trick" the sorting algorithm to put 1.0.dev0 before 1.0a0.
|
| 453 |
+
# We'll do this by abusing the pre-segment, but we _only_ want to do this
|
| 454 |
+
# if there is no pre- or a post-segment. If we have one of those, then
|
| 455 |
+
# the normal sorting rules will handle this case correctly.
|
| 456 |
+
if pre is None and post is None and dev is not None:
|
| 457 |
+
pre = -Infinity
|
| 458 |
+
# Versions without a pre-release (except as noted above) should sort after
|
| 459 |
+
# those with one.
|
| 460 |
+
elif pre is None:
|
| 461 |
+
pre = Infinity
|
| 462 |
+
|
| 463 |
+
# Versions without a post-segment should sort before those with one.
|
| 464 |
+
if post is None:
|
| 465 |
+
post = -Infinity
|
| 466 |
+
|
| 467 |
+
# Versions without a development segment should sort after those with one.
|
| 468 |
+
if dev is None:
|
| 469 |
+
dev = Infinity
|
| 470 |
+
|
| 471 |
+
if local is None:
|
| 472 |
+
# Versions without a local segment should sort before those with one.
|
| 473 |
+
local = -Infinity
|
| 474 |
+
else:
|
| 475 |
+
# Versions with a local segment need that segment parsed to implement
|
| 476 |
+
# the sorting rules in PEP440.
|
| 477 |
+
# - Alphanumeric segments sort before numeric segments
|
| 478 |
+
# - Alphanumeric segments sort lexicographically
|
| 479 |
+
# - Numeric segments sort numerically
|
| 480 |
+
# - Shorter versions sort before longer versions when the prefixes
|
| 481 |
+
# match exactly
|
| 482 |
+
local = tuple(
|
| 483 |
+
(i, "") if isinstance(i, int) else (-Infinity, i)
|
| 484 |
+
for i in local
|
| 485 |
+
)
|
| 486 |
+
|
| 487 |
+
return epoch, release, pre, post, dev, local
|
phi4/lib/python3.10/site-packages/scipy/_lib/_test_deprecation_call.cpython-310-x86_64-linux-gnu.so
ADDED
|
Binary file (49.5 kB). View file
|
|
|
phi4/lib/python3.10/site-packages/scipy/_lib/_test_deprecation_def.cpython-310-x86_64-linux-gnu.so
ADDED
|
Binary file (34.4 kB). View file
|
|
|
phi4/lib/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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Generic test utilities.
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import inspect
|
| 7 |
+
import os
|
| 8 |
+
import re
|
| 9 |
+
import shutil
|
| 10 |
+
import subprocess
|
| 11 |
+
import sys
|
| 12 |
+
import sysconfig
|
| 13 |
+
import threading
|
| 14 |
+
from importlib.util import module_from_spec, spec_from_file_location
|
| 15 |
+
|
| 16 |
+
import numpy as np
|
| 17 |
+
import scipy
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
# Need type: ignore[import-untyped] for mypy >= 1.6
|
| 21 |
+
import cython # type: ignore[import-untyped]
|
| 22 |
+
from Cython.Compiler.Version import ( # type: ignore[import-untyped]
|
| 23 |
+
version as cython_version,
|
| 24 |
+
)
|
| 25 |
+
except ImportError:
|
| 26 |
+
cython = None
|
| 27 |
+
else:
|
| 28 |
+
from scipy._lib import _pep440
|
| 29 |
+
required_version = '3.0.8'
|
| 30 |
+
if _pep440.parse(cython_version) < _pep440.Version(required_version):
|
| 31 |
+
# too old or wrong cython, skip Cython API tests
|
| 32 |
+
cython = None
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
__all__ = ['PytestTester', 'check_free_memory', '_TestPythranFunc', 'IS_MUSL']
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
IS_MUSL = False
|
| 39 |
+
# alternate way is
|
| 40 |
+
# from packaging.tags import sys_tags
|
| 41 |
+
# _tags = list(sys_tags())
|
| 42 |
+
# if 'musllinux' in _tags[0].platform:
|
| 43 |
+
_v = sysconfig.get_config_var('HOST_GNU_TYPE') or ''
|
| 44 |
+
if 'musl' in _v:
|
| 45 |
+
IS_MUSL = True
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
IS_EDITABLE = 'editable' in scipy.__path__[0]
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class FPUModeChangeWarning(RuntimeWarning):
|
| 52 |
+
"""Warning about FPU mode change"""
|
| 53 |
+
pass
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class PytestTester:
|
| 57 |
+
"""
|
| 58 |
+
Run tests for this namespace
|
| 59 |
+
|
| 60 |
+
``scipy.test()`` runs tests for all of SciPy, with the default settings.
|
| 61 |
+
When used from a submodule (e.g., ``scipy.cluster.test()``, only the tests
|
| 62 |
+
for that namespace are run.
|
| 63 |
+
|
| 64 |
+
Parameters
|
| 65 |
+
----------
|
| 66 |
+
label : {'fast', 'full'}, optional
|
| 67 |
+
Whether to run only the fast tests, or also those marked as slow.
|
| 68 |
+
Default is 'fast'.
|
| 69 |
+
verbose : int, optional
|
| 70 |
+
Test output verbosity. Default is 1.
|
| 71 |
+
extra_argv : list, optional
|
| 72 |
+
Arguments to pass through to Pytest.
|
| 73 |
+
doctests : bool, optional
|
| 74 |
+
Whether to run doctests or not. Default is False.
|
| 75 |
+
coverage : bool, optional
|
| 76 |
+
Whether to run tests with code coverage measurements enabled.
|
| 77 |
+
Default is False.
|
| 78 |
+
tests : list of str, optional
|
| 79 |
+
List of module names to run tests for. By default, uses the module
|
| 80 |
+
from which the ``test`` function is called.
|
| 81 |
+
parallel : int, optional
|
| 82 |
+
Run tests in parallel with pytest-xdist, if number given is larger than
|
| 83 |
+
1. Default is 1.
|
| 84 |
+
|
| 85 |
+
"""
|
| 86 |
+
def __init__(self, module_name):
|
| 87 |
+
self.module_name = module_name
|
| 88 |
+
|
| 89 |
+
def __call__(self, label="fast", verbose=1, extra_argv=None, doctests=False,
|
| 90 |
+
coverage=False, tests=None, parallel=None):
|
| 91 |
+
import pytest
|
| 92 |
+
|
| 93 |
+
module = sys.modules[self.module_name]
|
| 94 |
+
module_path = os.path.abspath(module.__path__[0])
|
| 95 |
+
|
| 96 |
+
pytest_args = ['--showlocals', '--tb=short']
|
| 97 |
+
|
| 98 |
+
if extra_argv:
|
| 99 |
+
pytest_args += list(extra_argv)
|
| 100 |
+
|
| 101 |
+
if verbose and int(verbose) > 1:
|
| 102 |
+
pytest_args += ["-" + "v"*(int(verbose)-1)]
|
| 103 |
+
|
| 104 |
+
if coverage:
|
| 105 |
+
pytest_args += ["--cov=" + module_path]
|
| 106 |
+
|
| 107 |
+
if label == "fast":
|
| 108 |
+
pytest_args += ["-m", "not slow"]
|
| 109 |
+
elif label != "full":
|
| 110 |
+
pytest_args += ["-m", label]
|
| 111 |
+
|
| 112 |
+
if tests is None:
|
| 113 |
+
tests = [self.module_name]
|
| 114 |
+
|
| 115 |
+
if parallel is not None and parallel > 1:
|
| 116 |
+
if _pytest_has_xdist():
|
| 117 |
+
pytest_args += ['-n', str(parallel)]
|
| 118 |
+
else:
|
| 119 |
+
import warnings
|
| 120 |
+
warnings.warn('Could not run tests in parallel because '
|
| 121 |
+
'pytest-xdist plugin is not available.',
|
| 122 |
+
stacklevel=2)
|
| 123 |
+
|
| 124 |
+
pytest_args += ['--pyargs'] + list(tests)
|
| 125 |
+
|
| 126 |
+
try:
|
| 127 |
+
code = pytest.main(pytest_args)
|
| 128 |
+
except SystemExit as exc:
|
| 129 |
+
code = exc.code
|
| 130 |
+
|
| 131 |
+
return (code == 0)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
class _TestPythranFunc:
|
| 135 |
+
'''
|
| 136 |
+
These are situations that can be tested in our pythran tests:
|
| 137 |
+
- A function with multiple array arguments and then
|
| 138 |
+
other positional and keyword arguments.
|
| 139 |
+
- A function with array-like keywords (e.g. `def somefunc(x0, x1=None)`.
|
| 140 |
+
Note: list/tuple input is not yet tested!
|
| 141 |
+
|
| 142 |
+
`self.arguments`: A dictionary which key is the index of the argument,
|
| 143 |
+
value is tuple(array value, all supported dtypes)
|
| 144 |
+
`self.partialfunc`: A function used to freeze some non-array argument
|
| 145 |
+
that of no interests in the original function
|
| 146 |
+
'''
|
| 147 |
+
ALL_INTEGER = [np.int8, np.int16, np.int32, np.int64, np.intc, np.intp]
|
| 148 |
+
ALL_FLOAT = [np.float32, np.float64]
|
| 149 |
+
ALL_COMPLEX = [np.complex64, np.complex128]
|
| 150 |
+
|
| 151 |
+
def setup_method(self):
|
| 152 |
+
self.arguments = {}
|
| 153 |
+
self.partialfunc = None
|
| 154 |
+
self.expected = None
|
| 155 |
+
|
| 156 |
+
def get_optional_args(self, func):
|
| 157 |
+
# get optional arguments with its default value,
|
| 158 |
+
# used for testing keywords
|
| 159 |
+
signature = inspect.signature(func)
|
| 160 |
+
optional_args = {}
|
| 161 |
+
for k, v in signature.parameters.items():
|
| 162 |
+
if v.default is not inspect.Parameter.empty:
|
| 163 |
+
optional_args[k] = v.default
|
| 164 |
+
return optional_args
|
| 165 |
+
|
| 166 |
+
def get_max_dtype_list_length(self):
|
| 167 |
+
# get the max supported dtypes list length in all arguments
|
| 168 |
+
max_len = 0
|
| 169 |
+
for arg_idx in self.arguments:
|
| 170 |
+
cur_len = len(self.arguments[arg_idx][1])
|
| 171 |
+
if cur_len > max_len:
|
| 172 |
+
max_len = cur_len
|
| 173 |
+
return max_len
|
| 174 |
+
|
| 175 |
+
def get_dtype(self, dtype_list, dtype_idx):
|
| 176 |
+
# get the dtype from dtype_list via index
|
| 177 |
+
# if the index is out of range, then return the last dtype
|
| 178 |
+
if dtype_idx > len(dtype_list)-1:
|
| 179 |
+
return dtype_list[-1]
|
| 180 |
+
else:
|
| 181 |
+
return dtype_list[dtype_idx]
|
| 182 |
+
|
| 183 |
+
def test_all_dtypes(self):
|
| 184 |
+
for type_idx in range(self.get_max_dtype_list_length()):
|
| 185 |
+
args_array = []
|
| 186 |
+
for arg_idx in self.arguments:
|
| 187 |
+
new_dtype = self.get_dtype(self.arguments[arg_idx][1],
|
| 188 |
+
type_idx)
|
| 189 |
+
args_array.append(self.arguments[arg_idx][0].astype(new_dtype))
|
| 190 |
+
self.pythranfunc(*args_array)
|
| 191 |
+
|
| 192 |
+
def test_views(self):
|
| 193 |
+
args_array = []
|
| 194 |
+
for arg_idx in self.arguments:
|
| 195 |
+
args_array.append(self.arguments[arg_idx][0][::-1][::-1])
|
| 196 |
+
self.pythranfunc(*args_array)
|
| 197 |
+
|
| 198 |
+
def test_strided(self):
|
| 199 |
+
args_array = []
|
| 200 |
+
for arg_idx in self.arguments:
|
| 201 |
+
args_array.append(np.repeat(self.arguments[arg_idx][0],
|
| 202 |
+
2, axis=0)[::2])
|
| 203 |
+
self.pythranfunc(*args_array)
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
def _pytest_has_xdist():
|
| 207 |
+
"""
|
| 208 |
+
Check if the pytest-xdist plugin is installed, providing parallel tests
|
| 209 |
+
"""
|
| 210 |
+
# Check xdist exists without importing, otherwise pytests emits warnings
|
| 211 |
+
from importlib.util import find_spec
|
| 212 |
+
return find_spec('xdist') is not None
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def check_free_memory(free_mb):
|
| 216 |
+
"""
|
| 217 |
+
Check *free_mb* of memory is available, otherwise do pytest.skip
|
| 218 |
+
"""
|
| 219 |
+
import pytest
|
| 220 |
+
|
| 221 |
+
try:
|
| 222 |
+
mem_free = _parse_size(os.environ['SCIPY_AVAILABLE_MEM'])
|
| 223 |
+
msg = '{} MB memory required, but environment SCIPY_AVAILABLE_MEM={}'.format(
|
| 224 |
+
free_mb, os.environ['SCIPY_AVAILABLE_MEM'])
|
| 225 |
+
except KeyError:
|
| 226 |
+
mem_free = _get_mem_available()
|
| 227 |
+
if mem_free is None:
|
| 228 |
+
pytest.skip("Could not determine available memory; set SCIPY_AVAILABLE_MEM "
|
| 229 |
+
"variable to free memory in MB to run the test.")
|
| 230 |
+
msg = f'{free_mb} MB memory required, but {mem_free/1e6} MB available'
|
| 231 |
+
|
| 232 |
+
if mem_free < free_mb * 1e6:
|
| 233 |
+
pytest.skip(msg)
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def _parse_size(size_str):
|
| 237 |
+
suffixes = {'': 1e6,
|
| 238 |
+
'b': 1.0,
|
| 239 |
+
'k': 1e3, 'M': 1e6, 'G': 1e9, 'T': 1e12,
|
| 240 |
+
'kb': 1e3, 'Mb': 1e6, 'Gb': 1e9, 'Tb': 1e12,
|
| 241 |
+
'kib': 1024.0, 'Mib': 1024.0**2, 'Gib': 1024.0**3, 'Tib': 1024.0**4}
|
| 242 |
+
m = re.match(r'^\s*(\d+)\s*({})\s*$'.format('|'.join(suffixes.keys())),
|
| 243 |
+
size_str,
|
| 244 |
+
re.I)
|
| 245 |
+
if not m or m.group(2) not in suffixes:
|
| 246 |
+
raise ValueError("Invalid size string")
|
| 247 |
+
|
| 248 |
+
return float(m.group(1)) * suffixes[m.group(2)]
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def _get_mem_available():
|
| 252 |
+
"""
|
| 253 |
+
Get information about memory available, not counting swap.
|
| 254 |
+
"""
|
| 255 |
+
try:
|
| 256 |
+
import psutil
|
| 257 |
+
return psutil.virtual_memory().available
|
| 258 |
+
except (ImportError, AttributeError):
|
| 259 |
+
pass
|
| 260 |
+
|
| 261 |
+
if sys.platform.startswith('linux'):
|
| 262 |
+
info = {}
|
| 263 |
+
with open('/proc/meminfo') as f:
|
| 264 |
+
for line in f:
|
| 265 |
+
p = line.split()
|
| 266 |
+
info[p[0].strip(':').lower()] = float(p[1]) * 1e3
|
| 267 |
+
|
| 268 |
+
if 'memavailable' in info:
|
| 269 |
+
# Linux >= 3.14
|
| 270 |
+
return info['memavailable']
|
| 271 |
+
else:
|
| 272 |
+
return info['memfree'] + info['cached']
|
| 273 |
+
|
| 274 |
+
return None
|
| 275 |
+
|
| 276 |
+
def _test_cython_extension(tmp_path, srcdir):
|
| 277 |
+
"""
|
| 278 |
+
Helper function to test building and importing Cython modules that
|
| 279 |
+
make use of the Cython APIs for BLAS, LAPACK, optimize, and special.
|
| 280 |
+
"""
|
| 281 |
+
import pytest
|
| 282 |
+
try:
|
| 283 |
+
subprocess.check_call(["meson", "--version"])
|
| 284 |
+
except FileNotFoundError:
|
| 285 |
+
pytest.skip("No usable 'meson' found")
|
| 286 |
+
|
| 287 |
+
# Make safe for being called by multiple threads within one test
|
| 288 |
+
tmp_path = tmp_path / str(threading.get_ident())
|
| 289 |
+
|
| 290 |
+
# build the examples in a temporary directory
|
| 291 |
+
mod_name = os.path.split(srcdir)[1]
|
| 292 |
+
shutil.copytree(srcdir, tmp_path / mod_name)
|
| 293 |
+
build_dir = tmp_path / mod_name / 'tests' / '_cython_examples'
|
| 294 |
+
target_dir = build_dir / 'build'
|
| 295 |
+
os.makedirs(target_dir, exist_ok=True)
|
| 296 |
+
|
| 297 |
+
# Ensure we use the correct Python interpreter even when `meson` is
|
| 298 |
+
# installed in a different Python environment (see numpy#24956)
|
| 299 |
+
native_file = str(build_dir / 'interpreter-native-file.ini')
|
| 300 |
+
with open(native_file, 'w') as f:
|
| 301 |
+
f.write("[binaries]\n")
|
| 302 |
+
f.write(f"python = '{sys.executable}'")
|
| 303 |
+
|
| 304 |
+
if sys.platform == "win32":
|
| 305 |
+
subprocess.check_call(["meson", "setup",
|
| 306 |
+
"--buildtype=release",
|
| 307 |
+
"--native-file", native_file,
|
| 308 |
+
"--vsenv", str(build_dir)],
|
| 309 |
+
cwd=target_dir,
|
| 310 |
+
)
|
| 311 |
+
else:
|
| 312 |
+
subprocess.check_call(["meson", "setup",
|
| 313 |
+
"--native-file", native_file, str(build_dir)],
|
| 314 |
+
cwd=target_dir
|
| 315 |
+
)
|
| 316 |
+
subprocess.check_call(["meson", "compile", "-vv"], cwd=target_dir)
|
| 317 |
+
|
| 318 |
+
# import without adding the directory to sys.path
|
| 319 |
+
suffix = sysconfig.get_config_var('EXT_SUFFIX')
|
| 320 |
+
|
| 321 |
+
def load(modname):
|
| 322 |
+
so = (target_dir / modname).with_suffix(suffix)
|
| 323 |
+
spec = spec_from_file_location(modname, so)
|
| 324 |
+
mod = module_from_spec(spec)
|
| 325 |
+
spec.loader.exec_module(mod)
|
| 326 |
+
return mod
|
| 327 |
+
|
| 328 |
+
# test that the module can be imported
|
| 329 |
+
return load("extending"), load("extending_cpp")
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
def _run_concurrent_barrier(n_workers, fn, *args, **kwargs):
|
| 333 |
+
"""
|
| 334 |
+
Run a given function concurrently across a given number of threads.
|
| 335 |
+
|
| 336 |
+
This is equivalent to using a ThreadPoolExecutor, but using the threading
|
| 337 |
+
primitives instead. This function ensures that the closure passed by
|
| 338 |
+
parameter gets called concurrently by setting up a barrier before it gets
|
| 339 |
+
called before any of the threads.
|
| 340 |
+
|
| 341 |
+
Arguments
|
| 342 |
+
---------
|
| 343 |
+
n_workers: int
|
| 344 |
+
Number of concurrent threads to spawn.
|
| 345 |
+
fn: callable
|
| 346 |
+
Function closure to execute concurrently. Its first argument will
|
| 347 |
+
be the thread id.
|
| 348 |
+
*args: tuple
|
| 349 |
+
Variable number of positional arguments to pass to the function.
|
| 350 |
+
**kwargs: dict
|
| 351 |
+
Keyword arguments to pass to the function.
|
| 352 |
+
"""
|
| 353 |
+
barrier = threading.Barrier(n_workers)
|
| 354 |
+
|
| 355 |
+
def closure(i, *args, **kwargs):
|
| 356 |
+
barrier.wait()
|
| 357 |
+
fn(i, *args, **kwargs)
|
| 358 |
+
|
| 359 |
+
workers = []
|
| 360 |
+
for i in range(0, n_workers):
|
| 361 |
+
workers.append(threading.Thread(
|
| 362 |
+
target=closure,
|
| 363 |
+
args=(i,) + args, kwargs=kwargs))
|
| 364 |
+
|
| 365 |
+
for worker in workers:
|
| 366 |
+
worker.start()
|
| 367 |
+
|
| 368 |
+
for worker in workers:
|
| 369 |
+
worker.join()
|
phi4/lib/python3.10/site-packages/scipy/_lib/_tmpdirs.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
''' Contexts for *with* statement providing temporary directories
|
| 2 |
+
'''
|
| 3 |
+
import os
|
| 4 |
+
from contextlib import contextmanager
|
| 5 |
+
from shutil import rmtree
|
| 6 |
+
from tempfile import mkdtemp
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@contextmanager
|
| 10 |
+
def tempdir():
|
| 11 |
+
"""Create and return a temporary directory. This has the same
|
| 12 |
+
behavior as mkdtemp but can be used as a context manager.
|
| 13 |
+
|
| 14 |
+
Upon exiting the context, the directory and everything contained
|
| 15 |
+
in it are removed.
|
| 16 |
+
|
| 17 |
+
Examples
|
| 18 |
+
--------
|
| 19 |
+
>>> import os
|
| 20 |
+
>>> with tempdir() as tmpdir:
|
| 21 |
+
... fname = os.path.join(tmpdir, 'example_file.txt')
|
| 22 |
+
... with open(fname, 'wt') as fobj:
|
| 23 |
+
... _ = fobj.write('a string\\n')
|
| 24 |
+
>>> os.path.exists(tmpdir)
|
| 25 |
+
False
|
| 26 |
+
"""
|
| 27 |
+
d = mkdtemp()
|
| 28 |
+
yield d
|
| 29 |
+
rmtree(d)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
@contextmanager
|
| 33 |
+
def in_tempdir():
|
| 34 |
+
''' Create, return, and change directory to a temporary directory
|
| 35 |
+
|
| 36 |
+
Examples
|
| 37 |
+
--------
|
| 38 |
+
>>> import os
|
| 39 |
+
>>> my_cwd = os.getcwd()
|
| 40 |
+
>>> with in_tempdir() as tmpdir:
|
| 41 |
+
... _ = open('test.txt', 'wt').write('some text')
|
| 42 |
+
... assert os.path.isfile('test.txt')
|
| 43 |
+
... assert os.path.isfile(os.path.join(tmpdir, 'test.txt'))
|
| 44 |
+
>>> os.path.exists(tmpdir)
|
| 45 |
+
False
|
| 46 |
+
>>> os.getcwd() == my_cwd
|
| 47 |
+
True
|
| 48 |
+
'''
|
| 49 |
+
pwd = os.getcwd()
|
| 50 |
+
d = mkdtemp()
|
| 51 |
+
os.chdir(d)
|
| 52 |
+
yield d
|
| 53 |
+
os.chdir(pwd)
|
| 54 |
+
rmtree(d)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
@contextmanager
|
| 58 |
+
def in_dir(dir=None):
|
| 59 |
+
""" Change directory to given directory for duration of ``with`` block
|
| 60 |
+
|
| 61 |
+
Useful when you want to use `in_tempdir` for the final test, but
|
| 62 |
+
you are still debugging. For example, you may want to do this in the end:
|
| 63 |
+
|
| 64 |
+
>>> with in_tempdir() as tmpdir:
|
| 65 |
+
... # do something complicated which might break
|
| 66 |
+
... pass
|
| 67 |
+
|
| 68 |
+
But, indeed, the complicated thing does break, and meanwhile, the
|
| 69 |
+
``in_tempdir`` context manager wiped out the directory with the
|
| 70 |
+
temporary files that you wanted for debugging. So, while debugging, you
|
| 71 |
+
replace with something like:
|
| 72 |
+
|
| 73 |
+
>>> with in_dir() as tmpdir: # Use working directory by default
|
| 74 |
+
... # do something complicated which might break
|
| 75 |
+
... pass
|
| 76 |
+
|
| 77 |
+
You can then look at the temporary file outputs to debug what is happening,
|
| 78 |
+
fix, and finally replace ``in_dir`` with ``in_tempdir`` again.
|
| 79 |
+
"""
|
| 80 |
+
cwd = os.getcwd()
|
| 81 |
+
if dir is None:
|
| 82 |
+
yield cwd
|
| 83 |
+
return
|
| 84 |
+
os.chdir(dir)
|
| 85 |
+
yield dir
|
| 86 |
+
os.chdir(cwd)
|
phi4/lib/python3.10/site-packages/scipy/_lib/_util.py
ADDED
|
@@ -0,0 +1,1179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
from contextlib import contextmanager
|
| 3 |
+
import functools
|
| 4 |
+
import operator
|
| 5 |
+
import warnings
|
| 6 |
+
import numbers
|
| 7 |
+
from collections import namedtuple
|
| 8 |
+
import inspect
|
| 9 |
+
import math
|
| 10 |
+
from typing import TypeAlias, TypeVar
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
from scipy._lib._array_api import array_namespace, is_numpy, xp_size
|
| 14 |
+
from scipy._lib._docscrape import FunctionDoc, Parameter
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
AxisError: type[Exception]
|
| 18 |
+
ComplexWarning: type[Warning]
|
| 19 |
+
VisibleDeprecationWarning: type[Warning]
|
| 20 |
+
|
| 21 |
+
if np.lib.NumpyVersion(np.__version__) >= '1.25.0':
|
| 22 |
+
from numpy.exceptions import (
|
| 23 |
+
AxisError, ComplexWarning, VisibleDeprecationWarning,
|
| 24 |
+
DTypePromotionError
|
| 25 |
+
)
|
| 26 |
+
else:
|
| 27 |
+
from numpy import ( # type: ignore[attr-defined, no-redef]
|
| 28 |
+
AxisError, ComplexWarning, VisibleDeprecationWarning # noqa: F401
|
| 29 |
+
)
|
| 30 |
+
DTypePromotionError = TypeError # type: ignore
|
| 31 |
+
|
| 32 |
+
np_long: type
|
| 33 |
+
np_ulong: type
|
| 34 |
+
|
| 35 |
+
if np.lib.NumpyVersion(np.__version__) >= "2.0.0.dev0":
|
| 36 |
+
try:
|
| 37 |
+
with warnings.catch_warnings():
|
| 38 |
+
warnings.filterwarnings(
|
| 39 |
+
"ignore",
|
| 40 |
+
r".*In the future `np\.long` will be defined as.*",
|
| 41 |
+
FutureWarning,
|
| 42 |
+
)
|
| 43 |
+
np_long = np.long # type: ignore[attr-defined]
|
| 44 |
+
np_ulong = np.ulong # type: ignore[attr-defined]
|
| 45 |
+
except AttributeError:
|
| 46 |
+
np_long = np.int_
|
| 47 |
+
np_ulong = np.uint
|
| 48 |
+
else:
|
| 49 |
+
np_long = np.int_
|
| 50 |
+
np_ulong = np.uint
|
| 51 |
+
|
| 52 |
+
IntNumber = int | np.integer
|
| 53 |
+
DecimalNumber = float | np.floating | np.integer
|
| 54 |
+
|
| 55 |
+
copy_if_needed: bool | None
|
| 56 |
+
|
| 57 |
+
if np.lib.NumpyVersion(np.__version__) >= "2.0.0":
|
| 58 |
+
copy_if_needed = None
|
| 59 |
+
elif np.lib.NumpyVersion(np.__version__) < "1.28.0":
|
| 60 |
+
copy_if_needed = False
|
| 61 |
+
else:
|
| 62 |
+
# 2.0.0 dev versions, handle cases where copy may or may not exist
|
| 63 |
+
try:
|
| 64 |
+
np.array([1]).__array__(copy=None) # type: ignore[call-overload]
|
| 65 |
+
copy_if_needed = None
|
| 66 |
+
except TypeError:
|
| 67 |
+
copy_if_needed = False
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
_RNG: TypeAlias = np.random.Generator | np.random.RandomState
|
| 71 |
+
SeedType: TypeAlias = IntNumber | _RNG | None
|
| 72 |
+
|
| 73 |
+
GeneratorType = TypeVar("GeneratorType", bound=_RNG)
|
| 74 |
+
|
| 75 |
+
# Since Generator was introduced in numpy 1.17, the following condition is needed for
|
| 76 |
+
# backward compatibility
|
| 77 |
+
try:
|
| 78 |
+
from numpy.random import Generator as Generator
|
| 79 |
+
except ImportError:
|
| 80 |
+
class Generator: # type: ignore[no-redef]
|
| 81 |
+
pass
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def _lazywhere(cond, arrays, f, fillvalue=None, f2=None):
|
| 85 |
+
"""Return elements chosen from two possibilities depending on a condition
|
| 86 |
+
|
| 87 |
+
Equivalent to ``f(*arrays) if cond else fillvalue`` performed elementwise.
|
| 88 |
+
|
| 89 |
+
Parameters
|
| 90 |
+
----------
|
| 91 |
+
cond : array
|
| 92 |
+
The condition (expressed as a boolean array).
|
| 93 |
+
arrays : tuple of array
|
| 94 |
+
Arguments to `f` (and `f2`). Must be broadcastable with `cond`.
|
| 95 |
+
f : callable
|
| 96 |
+
Where `cond` is True, output will be ``f(arr1[cond], arr2[cond], ...)``
|
| 97 |
+
fillvalue : object
|
| 98 |
+
If provided, value with which to fill output array where `cond` is
|
| 99 |
+
not True.
|
| 100 |
+
f2 : callable
|
| 101 |
+
If provided, output will be ``f2(arr1[cond], arr2[cond], ...)`` where
|
| 102 |
+
`cond` is not True.
|
| 103 |
+
|
| 104 |
+
Returns
|
| 105 |
+
-------
|
| 106 |
+
out : array
|
| 107 |
+
An array with elements from the output of `f` where `cond` is True
|
| 108 |
+
and `fillvalue` (or elements from the output of `f2`) elsewhere. The
|
| 109 |
+
returned array has data type determined by Type Promotion Rules
|
| 110 |
+
with the output of `f` and `fillvalue` (or the output of `f2`).
|
| 111 |
+
|
| 112 |
+
Notes
|
| 113 |
+
-----
|
| 114 |
+
``xp.where(cond, x, fillvalue)`` requires explicitly forming `x` even where
|
| 115 |
+
`cond` is False. This function evaluates ``f(arr1[cond], arr2[cond], ...)``
|
| 116 |
+
onle where `cond` ``is True.
|
| 117 |
+
|
| 118 |
+
Examples
|
| 119 |
+
--------
|
| 120 |
+
>>> import numpy as np
|
| 121 |
+
>>> a, b = np.array([1, 2, 3, 4]), np.array([5, 6, 7, 8])
|
| 122 |
+
>>> def f(a, b):
|
| 123 |
+
... return a*b
|
| 124 |
+
>>> _lazywhere(a > 2, (a, b), f, np.nan)
|
| 125 |
+
array([ nan, nan, 21., 32.])
|
| 126 |
+
|
| 127 |
+
"""
|
| 128 |
+
xp = array_namespace(cond, *arrays)
|
| 129 |
+
|
| 130 |
+
if (f2 is fillvalue is None) or (f2 is not None and fillvalue is not None):
|
| 131 |
+
raise ValueError("Exactly one of `fillvalue` or `f2` must be given.")
|
| 132 |
+
|
| 133 |
+
args = xp.broadcast_arrays(cond, *arrays)
|
| 134 |
+
bool_dtype = xp.asarray([True]).dtype # numpy 1.xx doesn't have `bool`
|
| 135 |
+
cond, arrays = xp.astype(args[0], bool_dtype, copy=False), args[1:]
|
| 136 |
+
|
| 137 |
+
temp1 = xp.asarray(f(*(arr[cond] for arr in arrays)))
|
| 138 |
+
|
| 139 |
+
if f2 is None:
|
| 140 |
+
# If `fillvalue` is a Python scalar and we convert to `xp.asarray`, it gets the
|
| 141 |
+
# default `int` or `float` type of `xp`, so `result_type` could be wrong.
|
| 142 |
+
# `result_type` should/will handle mixed array/Python scalars;
|
| 143 |
+
# remove this special logic when it does.
|
| 144 |
+
if type(fillvalue) in {bool, int, float, complex}:
|
| 145 |
+
with np.errstate(invalid='ignore'):
|
| 146 |
+
dtype = (temp1 * fillvalue).dtype
|
| 147 |
+
else:
|
| 148 |
+
dtype = xp.result_type(temp1.dtype, fillvalue)
|
| 149 |
+
out = xp.full(cond.shape, dtype=dtype,
|
| 150 |
+
fill_value=xp.asarray(fillvalue, dtype=dtype))
|
| 151 |
+
else:
|
| 152 |
+
ncond = ~cond
|
| 153 |
+
temp2 = xp.asarray(f2(*(arr[ncond] for arr in arrays)))
|
| 154 |
+
dtype = xp.result_type(temp1, temp2)
|
| 155 |
+
out = xp.empty(cond.shape, dtype=dtype)
|
| 156 |
+
out[ncond] = temp2
|
| 157 |
+
|
| 158 |
+
out[cond] = temp1
|
| 159 |
+
|
| 160 |
+
return out
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def _lazyselect(condlist, choicelist, arrays, default=0):
|
| 164 |
+
"""
|
| 165 |
+
Mimic `np.select(condlist, choicelist)`.
|
| 166 |
+
|
| 167 |
+
Notice, it assumes that all `arrays` are of the same shape or can be
|
| 168 |
+
broadcasted together.
|
| 169 |
+
|
| 170 |
+
All functions in `choicelist` must accept array arguments in the order
|
| 171 |
+
given in `arrays` and must return an array of the same shape as broadcasted
|
| 172 |
+
`arrays`.
|
| 173 |
+
|
| 174 |
+
Examples
|
| 175 |
+
--------
|
| 176 |
+
>>> import numpy as np
|
| 177 |
+
>>> x = np.arange(6)
|
| 178 |
+
>>> np.select([x <3, x > 3], [x**2, x**3], default=0)
|
| 179 |
+
array([ 0, 1, 4, 0, 64, 125])
|
| 180 |
+
|
| 181 |
+
>>> _lazyselect([x < 3, x > 3], [lambda x: x**2, lambda x: x**3], (x,))
|
| 182 |
+
array([ 0., 1., 4., 0., 64., 125.])
|
| 183 |
+
|
| 184 |
+
>>> a = -np.ones_like(x)
|
| 185 |
+
>>> _lazyselect([x < 3, x > 3],
|
| 186 |
+
... [lambda x, a: x**2, lambda x, a: a * x**3],
|
| 187 |
+
... (x, a), default=np.nan)
|
| 188 |
+
array([ 0., 1., 4., nan, -64., -125.])
|
| 189 |
+
|
| 190 |
+
"""
|
| 191 |
+
arrays = np.broadcast_arrays(*arrays)
|
| 192 |
+
tcode = np.mintypecode([a.dtype.char for a in arrays])
|
| 193 |
+
out = np.full(np.shape(arrays[0]), fill_value=default, dtype=tcode)
|
| 194 |
+
for func, cond in zip(choicelist, condlist):
|
| 195 |
+
if np.all(cond is False):
|
| 196 |
+
continue
|
| 197 |
+
cond, _ = np.broadcast_arrays(cond, arrays[0])
|
| 198 |
+
temp = tuple(np.extract(cond, arr) for arr in arrays)
|
| 199 |
+
np.place(out, cond, func(*temp))
|
| 200 |
+
return out
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def _aligned_zeros(shape, dtype=float, order="C", align=None):
|
| 204 |
+
"""Allocate a new ndarray with aligned memory.
|
| 205 |
+
|
| 206 |
+
Primary use case for this currently is working around a f2py issue
|
| 207 |
+
in NumPy 1.9.1, where dtype.alignment is such that np.zeros() does
|
| 208 |
+
not necessarily create arrays aligned up to it.
|
| 209 |
+
|
| 210 |
+
"""
|
| 211 |
+
dtype = np.dtype(dtype)
|
| 212 |
+
if align is None:
|
| 213 |
+
align = dtype.alignment
|
| 214 |
+
if not hasattr(shape, '__len__'):
|
| 215 |
+
shape = (shape,)
|
| 216 |
+
size = functools.reduce(operator.mul, shape) * dtype.itemsize
|
| 217 |
+
buf = np.empty(size + align + 1, np.uint8)
|
| 218 |
+
offset = buf.__array_interface__['data'][0] % align
|
| 219 |
+
if offset != 0:
|
| 220 |
+
offset = align - offset
|
| 221 |
+
# Note: slices producing 0-size arrays do not necessarily change
|
| 222 |
+
# data pointer --- so we use and allocate size+1
|
| 223 |
+
buf = buf[offset:offset+size+1][:-1]
|
| 224 |
+
data = np.ndarray(shape, dtype, buf, order=order)
|
| 225 |
+
data.fill(0)
|
| 226 |
+
return data
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def _prune_array(array):
|
| 230 |
+
"""Return an array equivalent to the input array. If the input
|
| 231 |
+
array is a view of a much larger array, copy its contents to a
|
| 232 |
+
newly allocated array. Otherwise, return the input unchanged.
|
| 233 |
+
"""
|
| 234 |
+
if array.base is not None and array.size < array.base.size // 2:
|
| 235 |
+
return array.copy()
|
| 236 |
+
return array
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
def float_factorial(n: int) -> float:
|
| 240 |
+
"""Compute the factorial and return as a float
|
| 241 |
+
|
| 242 |
+
Returns infinity when result is too large for a double
|
| 243 |
+
"""
|
| 244 |
+
return float(math.factorial(n)) if n < 171 else np.inf
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
_rng_desc = (
|
| 248 |
+
r"""If `rng` is passed by keyword, types other than `numpy.random.Generator` are
|
| 249 |
+
passed to `numpy.random.default_rng` to instantiate a ``Generator``.
|
| 250 |
+
If `rng` is already a ``Generator`` instance, then the provided instance is
|
| 251 |
+
used. Specify `rng` for repeatable function behavior.
|
| 252 |
+
|
| 253 |
+
If this argument is passed by position or `{old_name}` is passed by keyword,
|
| 254 |
+
legacy behavior for the argument `{old_name}` applies:
|
| 255 |
+
|
| 256 |
+
- If `{old_name}` is None (or `numpy.random`), the `numpy.random.RandomState`
|
| 257 |
+
singleton is used.
|
| 258 |
+
- If `{old_name}` is an int, a new ``RandomState`` instance is used,
|
| 259 |
+
seeded with `{old_name}`.
|
| 260 |
+
- If `{old_name}` is already a ``Generator`` or ``RandomState`` instance then
|
| 261 |
+
that instance is used.
|
| 262 |
+
|
| 263 |
+
.. versionchanged:: 1.15.0
|
| 264 |
+
As part of the `SPEC-007 <https://scientific-python.org/specs/spec-0007/>`_
|
| 265 |
+
transition from use of `numpy.random.RandomState` to
|
| 266 |
+
`numpy.random.Generator`, this keyword was changed from `{old_name}` to `rng`.
|
| 267 |
+
For an interim period, both keywords will continue to work, although only one
|
| 268 |
+
may be specified at a time. After the interim period, function calls using the
|
| 269 |
+
`{old_name}` keyword will emit warnings. The behavior of both `{old_name}` and
|
| 270 |
+
`rng` are outlined above, but only the `rng` keyword should be used in new code.
|
| 271 |
+
"""
|
| 272 |
+
)
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
# SPEC 7
|
| 276 |
+
def _transition_to_rng(old_name, *, position_num=None, end_version=None,
|
| 277 |
+
replace_doc=True):
|
| 278 |
+
"""Example decorator to transition from old PRNG usage to new `rng` behavior
|
| 279 |
+
|
| 280 |
+
Suppose the decorator is applied to a function that used to accept parameter
|
| 281 |
+
`old_name='random_state'` either by keyword or as a positional argument at
|
| 282 |
+
`position_num=1`. At the time of application, the name of the argument in the
|
| 283 |
+
function signature is manually changed to the new name, `rng`. If positional
|
| 284 |
+
use was allowed before, this is not changed.*
|
| 285 |
+
|
| 286 |
+
- If the function is called with both `random_state` and `rng`, the decorator
|
| 287 |
+
raises an error.
|
| 288 |
+
- If `random_state` is provided as a keyword argument, the decorator passes
|
| 289 |
+
`random_state` to the function's `rng` argument as a keyword. If `end_version`
|
| 290 |
+
is specified, the decorator will emit a `DeprecationWarning` about the
|
| 291 |
+
deprecation of keyword `random_state`.
|
| 292 |
+
- If `random_state` is provided as a positional argument, the decorator passes
|
| 293 |
+
`random_state` to the function's `rng` argument by position. If `end_version`
|
| 294 |
+
is specified, the decorator will emit a `FutureWarning` about the changing
|
| 295 |
+
interpretation of the argument.
|
| 296 |
+
- If `rng` is provided as a keyword argument, the decorator validates `rng` using
|
| 297 |
+
`numpy.random.default_rng` before passing it to the function.
|
| 298 |
+
- If `end_version` is specified and neither `random_state` nor `rng` is provided
|
| 299 |
+
by the user, the decorator checks whether `np.random.seed` has been used to set
|
| 300 |
+
the global seed. If so, it emits a `FutureWarning`, noting that usage of
|
| 301 |
+
`numpy.random.seed` will eventually have no effect. Either way, the decorator
|
| 302 |
+
calls the function without explicitly passing the `rng` argument.
|
| 303 |
+
|
| 304 |
+
If `end_version` is specified, a user must pass `rng` as a keyword to avoid
|
| 305 |
+
warnings.
|
| 306 |
+
|
| 307 |
+
After the deprecation period, the decorator can be removed, and the function
|
| 308 |
+
can simply validate the `rng` argument by calling `np.random.default_rng(rng)`.
|
| 309 |
+
|
| 310 |
+
* A `FutureWarning` is emitted when the PRNG argument is used by
|
| 311 |
+
position. It indicates that the "Hinsen principle" (same
|
| 312 |
+
code yielding different results in two versions of the software)
|
| 313 |
+
will be violated, unless positional use is deprecated. Specifically:
|
| 314 |
+
|
| 315 |
+
- If `None` is passed by position and `np.random.seed` has been used,
|
| 316 |
+
the function will change from being seeded to being unseeded.
|
| 317 |
+
- If an integer is passed by position, the random stream will change.
|
| 318 |
+
- If `np.random` or an instance of `RandomState` is passed by position,
|
| 319 |
+
an error will be raised.
|
| 320 |
+
|
| 321 |
+
We suggest that projects consider deprecating positional use of
|
| 322 |
+
`random_state`/`rng` (i.e., change their function signatures to
|
| 323 |
+
``def my_func(..., *, rng=None)``); that might not make sense
|
| 324 |
+
for all projects, so this SPEC does not make that
|
| 325 |
+
recommendation, neither does this decorator enforce it.
|
| 326 |
+
|
| 327 |
+
Parameters
|
| 328 |
+
----------
|
| 329 |
+
old_name : str
|
| 330 |
+
The old name of the PRNG argument (e.g. `seed` or `random_state`).
|
| 331 |
+
position_num : int, optional
|
| 332 |
+
The (0-indexed) position of the old PRNG argument (if accepted by position).
|
| 333 |
+
Maintainers are welcome to eliminate this argument and use, for example,
|
| 334 |
+
`inspect`, if preferred.
|
| 335 |
+
end_version : str, optional
|
| 336 |
+
The full version number of the library when the behavior described in
|
| 337 |
+
`DeprecationWarning`s and `FutureWarning`s will take effect. If left
|
| 338 |
+
unspecified, no warnings will be emitted by the decorator.
|
| 339 |
+
replace_doc : bool, default: True
|
| 340 |
+
Whether the decorator should replace the documentation for parameter `rng` with
|
| 341 |
+
`_rng_desc` (defined above), which documents both new `rng` keyword behavior
|
| 342 |
+
and typical legacy `random_state`/`seed` behavior. If True, manually replace
|
| 343 |
+
the first paragraph of the function's old `random_state`/`seed` documentation
|
| 344 |
+
with the desired *final* `rng` documentation; this way, no changes to
|
| 345 |
+
documentation are needed when the decorator is removed. Documentation of `rng`
|
| 346 |
+
after the first blank line is preserved. Use False if the function's old
|
| 347 |
+
`random_state`/`seed` behavior does not match that described by `_rng_desc`.
|
| 348 |
+
|
| 349 |
+
"""
|
| 350 |
+
NEW_NAME = "rng"
|
| 351 |
+
|
| 352 |
+
cmn_msg = (
|
| 353 |
+
"To silence this warning and ensure consistent behavior in SciPy "
|
| 354 |
+
f"{end_version}, control the RNG using argument `{NEW_NAME}`. Arguments passed "
|
| 355 |
+
f"to keyword `{NEW_NAME}` will be validated by `np.random.default_rng`, so the "
|
| 356 |
+
"behavior corresponding with a given value may change compared to use of "
|
| 357 |
+
f"`{old_name}`. For example, "
|
| 358 |
+
"1) `None` will result in unpredictable random numbers, "
|
| 359 |
+
"2) an integer will result in a different stream of random numbers, (with the "
|
| 360 |
+
"same distribution), and "
|
| 361 |
+
"3) `np.random` or `RandomState` instances will result in an error. "
|
| 362 |
+
"See the documentation of `default_rng` for more information."
|
| 363 |
+
)
|
| 364 |
+
|
| 365 |
+
def decorator(fun):
|
| 366 |
+
@functools.wraps(fun)
|
| 367 |
+
def wrapper(*args, **kwargs):
|
| 368 |
+
# Determine how PRNG was passed
|
| 369 |
+
as_old_kwarg = old_name in kwargs
|
| 370 |
+
as_new_kwarg = NEW_NAME in kwargs
|
| 371 |
+
as_pos_arg = position_num is not None and len(args) >= position_num + 1
|
| 372 |
+
emit_warning = end_version is not None
|
| 373 |
+
|
| 374 |
+
# Can only specify PRNG one of the three ways
|
| 375 |
+
if int(as_old_kwarg) + int(as_new_kwarg) + int(as_pos_arg) > 1:
|
| 376 |
+
message = (
|
| 377 |
+
f"{fun.__name__}() got multiple values for "
|
| 378 |
+
f"argument now known as `{NEW_NAME}`. Specify one of "
|
| 379 |
+
f"`{NEW_NAME}` or `{old_name}`."
|
| 380 |
+
)
|
| 381 |
+
raise TypeError(message)
|
| 382 |
+
|
| 383 |
+
# Check whether global random state has been set
|
| 384 |
+
global_seed_set = np.random.mtrand._rand._bit_generator._seed_seq is None
|
| 385 |
+
|
| 386 |
+
if as_old_kwarg: # warn about deprecated use of old kwarg
|
| 387 |
+
kwargs[NEW_NAME] = kwargs.pop(old_name)
|
| 388 |
+
if emit_warning:
|
| 389 |
+
message = (
|
| 390 |
+
f"Use of keyword argument `{old_name}` is "
|
| 391 |
+
f"deprecated and replaced by `{NEW_NAME}`. "
|
| 392 |
+
f"Support for `{old_name}` will be removed "
|
| 393 |
+
f"in SciPy {end_version}. "
|
| 394 |
+
) + cmn_msg
|
| 395 |
+
warnings.warn(message, DeprecationWarning, stacklevel=2)
|
| 396 |
+
|
| 397 |
+
elif as_pos_arg:
|
| 398 |
+
# Warn about changing meaning of positional arg
|
| 399 |
+
|
| 400 |
+
# Note that this decorator does not deprecate positional use of the
|
| 401 |
+
# argument; it only warns that the behavior will change in the future.
|
| 402 |
+
# Simultaneously transitioning to keyword-only use is another option.
|
| 403 |
+
|
| 404 |
+
arg = args[position_num]
|
| 405 |
+
# If the argument is None and the global seed wasn't set, or if the
|
| 406 |
+
# argument is one of a few new classes, the user will not notice change
|
| 407 |
+
# in behavior.
|
| 408 |
+
ok_classes = (
|
| 409 |
+
np.random.Generator,
|
| 410 |
+
np.random.SeedSequence,
|
| 411 |
+
np.random.BitGenerator,
|
| 412 |
+
)
|
| 413 |
+
if (arg is None and not global_seed_set) or isinstance(arg, ok_classes):
|
| 414 |
+
pass
|
| 415 |
+
elif emit_warning:
|
| 416 |
+
message = (
|
| 417 |
+
f"Positional use of `{NEW_NAME}` (formerly known as "
|
| 418 |
+
f"`{old_name}`) is still allowed, but the behavior is "
|
| 419 |
+
"changing: the argument will be normalized using "
|
| 420 |
+
f"`np.random.default_rng` beginning in SciPy {end_version}, "
|
| 421 |
+
"and the resulting `Generator` will be used to generate "
|
| 422 |
+
"random numbers."
|
| 423 |
+
) + cmn_msg
|
| 424 |
+
warnings.warn(message, FutureWarning, stacklevel=2)
|
| 425 |
+
|
| 426 |
+
elif as_new_kwarg: # no warnings; this is the preferred use
|
| 427 |
+
# After the removal of the decorator, normalization with
|
| 428 |
+
# np.random.default_rng will be done inside the decorated function
|
| 429 |
+
kwargs[NEW_NAME] = np.random.default_rng(kwargs[NEW_NAME])
|
| 430 |
+
|
| 431 |
+
elif global_seed_set and emit_warning:
|
| 432 |
+
# Emit FutureWarning if `np.random.seed` was used and no PRNG was passed
|
| 433 |
+
message = (
|
| 434 |
+
"The NumPy global RNG was seeded by calling "
|
| 435 |
+
f"`np.random.seed`. Beginning in {end_version}, this "
|
| 436 |
+
"function will no longer use the global RNG."
|
| 437 |
+
) + cmn_msg
|
| 438 |
+
warnings.warn(message, FutureWarning, stacklevel=2)
|
| 439 |
+
|
| 440 |
+
return fun(*args, **kwargs)
|
| 441 |
+
|
| 442 |
+
if replace_doc:
|
| 443 |
+
doc = FunctionDoc(wrapper)
|
| 444 |
+
parameter_names = [param.name for param in doc['Parameters']]
|
| 445 |
+
if 'rng' in parameter_names:
|
| 446 |
+
_type = "{None, int, `numpy.random.Generator`}, optional"
|
| 447 |
+
_desc = _rng_desc.replace("{old_name}", old_name)
|
| 448 |
+
old_doc = doc['Parameters'][parameter_names.index('rng')].desc
|
| 449 |
+
old_doc_keep = old_doc[old_doc.index("") + 1:] if "" in old_doc else []
|
| 450 |
+
new_doc = [_desc] + old_doc_keep
|
| 451 |
+
_rng_parameter_doc = Parameter('rng', _type, new_doc)
|
| 452 |
+
doc['Parameters'][parameter_names.index('rng')] = _rng_parameter_doc
|
| 453 |
+
doc = str(doc).split("\n", 1)[1] # remove signature
|
| 454 |
+
wrapper.__doc__ = str(doc)
|
| 455 |
+
return wrapper
|
| 456 |
+
|
| 457 |
+
return decorator
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
# copy-pasted from scikit-learn utils/validation.py
|
| 461 |
+
def check_random_state(seed):
|
| 462 |
+
"""Turn `seed` into a `np.random.RandomState` instance.
|
| 463 |
+
|
| 464 |
+
Parameters
|
| 465 |
+
----------
|
| 466 |
+
seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
|
| 467 |
+
If `seed` is None (or `np.random`), the `numpy.random.RandomState`
|
| 468 |
+
singleton is used.
|
| 469 |
+
If `seed` is an int, a new ``RandomState`` instance is used,
|
| 470 |
+
seeded with `seed`.
|
| 471 |
+
If `seed` is already a ``Generator`` or ``RandomState`` instance then
|
| 472 |
+
that instance is used.
|
| 473 |
+
|
| 474 |
+
Returns
|
| 475 |
+
-------
|
| 476 |
+
seed : {`numpy.random.Generator`, `numpy.random.RandomState`}
|
| 477 |
+
Random number generator.
|
| 478 |
+
|
| 479 |
+
"""
|
| 480 |
+
if seed is None or seed is np.random:
|
| 481 |
+
return np.random.mtrand._rand
|
| 482 |
+
if isinstance(seed, numbers.Integral | np.integer):
|
| 483 |
+
return np.random.RandomState(seed)
|
| 484 |
+
if isinstance(seed, np.random.RandomState | np.random.Generator):
|
| 485 |
+
return seed
|
| 486 |
+
|
| 487 |
+
raise ValueError(f"'{seed}' cannot be used to seed a numpy.random.RandomState"
|
| 488 |
+
" instance")
|
| 489 |
+
|
| 490 |
+
|
| 491 |
+
def _asarray_validated(a, check_finite=True,
|
| 492 |
+
sparse_ok=False, objects_ok=False, mask_ok=False,
|
| 493 |
+
as_inexact=False):
|
| 494 |
+
"""
|
| 495 |
+
Helper function for SciPy argument validation.
|
| 496 |
+
|
| 497 |
+
Many SciPy linear algebra functions do support arbitrary array-like
|
| 498 |
+
input arguments. Examples of commonly unsupported inputs include
|
| 499 |
+
matrices containing inf/nan, sparse matrix representations, and
|
| 500 |
+
matrices with complicated elements.
|
| 501 |
+
|
| 502 |
+
Parameters
|
| 503 |
+
----------
|
| 504 |
+
a : array_like
|
| 505 |
+
The array-like input.
|
| 506 |
+
check_finite : bool, optional
|
| 507 |
+
Whether to check that the input matrices contain only finite numbers.
|
| 508 |
+
Disabling may give a performance gain, but may result in problems
|
| 509 |
+
(crashes, non-termination) if the inputs do contain infinities or NaNs.
|
| 510 |
+
Default: True
|
| 511 |
+
sparse_ok : bool, optional
|
| 512 |
+
True if scipy sparse matrices are allowed.
|
| 513 |
+
objects_ok : bool, optional
|
| 514 |
+
True if arrays with dype('O') are allowed.
|
| 515 |
+
mask_ok : bool, optional
|
| 516 |
+
True if masked arrays are allowed.
|
| 517 |
+
as_inexact : bool, optional
|
| 518 |
+
True to convert the input array to a np.inexact dtype.
|
| 519 |
+
|
| 520 |
+
Returns
|
| 521 |
+
-------
|
| 522 |
+
ret : ndarray
|
| 523 |
+
The converted validated array.
|
| 524 |
+
|
| 525 |
+
"""
|
| 526 |
+
if not sparse_ok:
|
| 527 |
+
import scipy.sparse
|
| 528 |
+
if scipy.sparse.issparse(a):
|
| 529 |
+
msg = ('Sparse arrays/matrices are not supported by this function. '
|
| 530 |
+
'Perhaps one of the `scipy.sparse.linalg` functions '
|
| 531 |
+
'would work instead.')
|
| 532 |
+
raise ValueError(msg)
|
| 533 |
+
if not mask_ok:
|
| 534 |
+
if np.ma.isMaskedArray(a):
|
| 535 |
+
raise ValueError('masked arrays are not supported')
|
| 536 |
+
toarray = np.asarray_chkfinite if check_finite else np.asarray
|
| 537 |
+
a = toarray(a)
|
| 538 |
+
if not objects_ok:
|
| 539 |
+
if a.dtype is np.dtype('O'):
|
| 540 |
+
raise ValueError('object arrays are not supported')
|
| 541 |
+
if as_inexact:
|
| 542 |
+
if not np.issubdtype(a.dtype, np.inexact):
|
| 543 |
+
a = toarray(a, dtype=np.float64)
|
| 544 |
+
return a
|
| 545 |
+
|
| 546 |
+
|
| 547 |
+
def _validate_int(k, name, minimum=None):
|
| 548 |
+
"""
|
| 549 |
+
Validate a scalar integer.
|
| 550 |
+
|
| 551 |
+
This function can be used to validate an argument to a function
|
| 552 |
+
that expects the value to be an integer. It uses `operator.index`
|
| 553 |
+
to validate the value (so, for example, k=2.0 results in a
|
| 554 |
+
TypeError).
|
| 555 |
+
|
| 556 |
+
Parameters
|
| 557 |
+
----------
|
| 558 |
+
k : int
|
| 559 |
+
The value to be validated.
|
| 560 |
+
name : str
|
| 561 |
+
The name of the parameter.
|
| 562 |
+
minimum : int, optional
|
| 563 |
+
An optional lower bound.
|
| 564 |
+
"""
|
| 565 |
+
try:
|
| 566 |
+
k = operator.index(k)
|
| 567 |
+
except TypeError:
|
| 568 |
+
raise TypeError(f'{name} must be an integer.') from None
|
| 569 |
+
if minimum is not None and k < minimum:
|
| 570 |
+
raise ValueError(f'{name} must be an integer not less '
|
| 571 |
+
f'than {minimum}') from None
|
| 572 |
+
return k
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
# Add a replacement for inspect.getfullargspec()/
|
| 576 |
+
# The version below is borrowed from Django,
|
| 577 |
+
# https://github.com/django/django/pull/4846.
|
| 578 |
+
|
| 579 |
+
# Note an inconsistency between inspect.getfullargspec(func) and
|
| 580 |
+
# inspect.signature(func). If `func` is a bound method, the latter does *not*
|
| 581 |
+
# list `self` as a first argument, while the former *does*.
|
| 582 |
+
# Hence, cook up a common ground replacement: `getfullargspec_no_self` which
|
| 583 |
+
# mimics `inspect.getfullargspec` but does not list `self`.
|
| 584 |
+
#
|
| 585 |
+
# This way, the caller code does not need to know whether it uses a legacy
|
| 586 |
+
# .getfullargspec or a bright and shiny .signature.
|
| 587 |
+
|
| 588 |
+
FullArgSpec = namedtuple('FullArgSpec',
|
| 589 |
+
['args', 'varargs', 'varkw', 'defaults',
|
| 590 |
+
'kwonlyargs', 'kwonlydefaults', 'annotations'])
|
| 591 |
+
|
| 592 |
+
|
| 593 |
+
def getfullargspec_no_self(func):
|
| 594 |
+
"""inspect.getfullargspec replacement using inspect.signature.
|
| 595 |
+
|
| 596 |
+
If func is a bound method, do not list the 'self' parameter.
|
| 597 |
+
|
| 598 |
+
Parameters
|
| 599 |
+
----------
|
| 600 |
+
func : callable
|
| 601 |
+
A callable to inspect
|
| 602 |
+
|
| 603 |
+
Returns
|
| 604 |
+
-------
|
| 605 |
+
fullargspec : FullArgSpec(args, varargs, varkw, defaults, kwonlyargs,
|
| 606 |
+
kwonlydefaults, annotations)
|
| 607 |
+
|
| 608 |
+
NOTE: if the first argument of `func` is self, it is *not*, I repeat
|
| 609 |
+
*not*, included in fullargspec.args.
|
| 610 |
+
This is done for consistency between inspect.getargspec() under
|
| 611 |
+
Python 2.x, and inspect.signature() under Python 3.x.
|
| 612 |
+
|
| 613 |
+
"""
|
| 614 |
+
sig = inspect.signature(func)
|
| 615 |
+
args = [
|
| 616 |
+
p.name for p in sig.parameters.values()
|
| 617 |
+
if p.kind in [inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
| 618 |
+
inspect.Parameter.POSITIONAL_ONLY]
|
| 619 |
+
]
|
| 620 |
+
varargs = [
|
| 621 |
+
p.name for p in sig.parameters.values()
|
| 622 |
+
if p.kind == inspect.Parameter.VAR_POSITIONAL
|
| 623 |
+
]
|
| 624 |
+
varargs = varargs[0] if varargs else None
|
| 625 |
+
varkw = [
|
| 626 |
+
p.name for p in sig.parameters.values()
|
| 627 |
+
if p.kind == inspect.Parameter.VAR_KEYWORD
|
| 628 |
+
]
|
| 629 |
+
varkw = varkw[0] if varkw else None
|
| 630 |
+
defaults = tuple(
|
| 631 |
+
p.default for p in sig.parameters.values()
|
| 632 |
+
if (p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD and
|
| 633 |
+
p.default is not p.empty)
|
| 634 |
+
) or None
|
| 635 |
+
kwonlyargs = [
|
| 636 |
+
p.name for p in sig.parameters.values()
|
| 637 |
+
if p.kind == inspect.Parameter.KEYWORD_ONLY
|
| 638 |
+
]
|
| 639 |
+
kwdefaults = {p.name: p.default for p in sig.parameters.values()
|
| 640 |
+
if p.kind == inspect.Parameter.KEYWORD_ONLY and
|
| 641 |
+
p.default is not p.empty}
|
| 642 |
+
annotations = {p.name: p.annotation for p in sig.parameters.values()
|
| 643 |
+
if p.annotation is not p.empty}
|
| 644 |
+
return FullArgSpec(args, varargs, varkw, defaults, kwonlyargs,
|
| 645 |
+
kwdefaults or None, annotations)
|
| 646 |
+
|
| 647 |
+
|
| 648 |
+
class _FunctionWrapper:
|
| 649 |
+
"""
|
| 650 |
+
Object to wrap user's function, allowing picklability
|
| 651 |
+
"""
|
| 652 |
+
def __init__(self, f, args):
|
| 653 |
+
self.f = f
|
| 654 |
+
self.args = [] if args is None else args
|
| 655 |
+
|
| 656 |
+
def __call__(self, x):
|
| 657 |
+
return self.f(x, *self.args)
|
| 658 |
+
|
| 659 |
+
|
| 660 |
+
class MapWrapper:
|
| 661 |
+
"""
|
| 662 |
+
Parallelisation wrapper for working with map-like callables, such as
|
| 663 |
+
`multiprocessing.Pool.map`.
|
| 664 |
+
|
| 665 |
+
Parameters
|
| 666 |
+
----------
|
| 667 |
+
pool : int or map-like callable
|
| 668 |
+
If `pool` is an integer, then it specifies the number of threads to
|
| 669 |
+
use for parallelization. If ``int(pool) == 1``, then no parallel
|
| 670 |
+
processing is used and the map builtin is used.
|
| 671 |
+
If ``pool == -1``, then the pool will utilize all available CPUs.
|
| 672 |
+
If `pool` is a map-like callable that follows the same
|
| 673 |
+
calling sequence as the built-in map function, then this callable is
|
| 674 |
+
used for parallelization.
|
| 675 |
+
"""
|
| 676 |
+
def __init__(self, pool=1):
|
| 677 |
+
self.pool = None
|
| 678 |
+
self._mapfunc = map
|
| 679 |
+
self._own_pool = False
|
| 680 |
+
|
| 681 |
+
if callable(pool):
|
| 682 |
+
self.pool = pool
|
| 683 |
+
self._mapfunc = self.pool
|
| 684 |
+
else:
|
| 685 |
+
from multiprocessing import Pool
|
| 686 |
+
# user supplies a number
|
| 687 |
+
if int(pool) == -1:
|
| 688 |
+
# use as many processors as possible
|
| 689 |
+
self.pool = Pool()
|
| 690 |
+
self._mapfunc = self.pool.map
|
| 691 |
+
self._own_pool = True
|
| 692 |
+
elif int(pool) == 1:
|
| 693 |
+
pass
|
| 694 |
+
elif int(pool) > 1:
|
| 695 |
+
# use the number of processors requested
|
| 696 |
+
self.pool = Pool(processes=int(pool))
|
| 697 |
+
self._mapfunc = self.pool.map
|
| 698 |
+
self._own_pool = True
|
| 699 |
+
else:
|
| 700 |
+
raise RuntimeError("Number of workers specified must be -1,"
|
| 701 |
+
" an int >= 1, or an object with a 'map' "
|
| 702 |
+
"method")
|
| 703 |
+
|
| 704 |
+
def __enter__(self):
|
| 705 |
+
return self
|
| 706 |
+
|
| 707 |
+
def terminate(self):
|
| 708 |
+
if self._own_pool:
|
| 709 |
+
self.pool.terminate()
|
| 710 |
+
|
| 711 |
+
def join(self):
|
| 712 |
+
if self._own_pool:
|
| 713 |
+
self.pool.join()
|
| 714 |
+
|
| 715 |
+
def close(self):
|
| 716 |
+
if self._own_pool:
|
| 717 |
+
self.pool.close()
|
| 718 |
+
|
| 719 |
+
def __exit__(self, exc_type, exc_value, traceback):
|
| 720 |
+
if self._own_pool:
|
| 721 |
+
self.pool.close()
|
| 722 |
+
self.pool.terminate()
|
| 723 |
+
|
| 724 |
+
def __call__(self, func, iterable):
|
| 725 |
+
# only accept one iterable because that's all Pool.map accepts
|
| 726 |
+
try:
|
| 727 |
+
return self._mapfunc(func, iterable)
|
| 728 |
+
except TypeError as e:
|
| 729 |
+
# wrong number of arguments
|
| 730 |
+
raise TypeError("The map-like callable must be of the"
|
| 731 |
+
" form f(func, iterable)") from e
|
| 732 |
+
|
| 733 |
+
|
| 734 |
+
def rng_integers(gen, low, high=None, size=None, dtype='int64',
|
| 735 |
+
endpoint=False):
|
| 736 |
+
"""
|
| 737 |
+
Return random integers from low (inclusive) to high (exclusive), or if
|
| 738 |
+
endpoint=True, low (inclusive) to high (inclusive). Replaces
|
| 739 |
+
`RandomState.randint` (with endpoint=False) and
|
| 740 |
+
`RandomState.random_integers` (with endpoint=True).
|
| 741 |
+
|
| 742 |
+
Return random integers from the "discrete uniform" distribution of the
|
| 743 |
+
specified dtype. If high is None (the default), then results are from
|
| 744 |
+
0 to low.
|
| 745 |
+
|
| 746 |
+
Parameters
|
| 747 |
+
----------
|
| 748 |
+
gen : {None, np.random.RandomState, np.random.Generator}
|
| 749 |
+
Random number generator. If None, then the np.random.RandomState
|
| 750 |
+
singleton is used.
|
| 751 |
+
low : int or array-like of ints
|
| 752 |
+
Lowest (signed) integers to be drawn from the distribution (unless
|
| 753 |
+
high=None, in which case this parameter is 0 and this value is used
|
| 754 |
+
for high).
|
| 755 |
+
high : int or array-like of ints
|
| 756 |
+
If provided, one above the largest (signed) integer to be drawn from
|
| 757 |
+
the distribution (see above for behavior if high=None). If array-like,
|
| 758 |
+
must contain integer values.
|
| 759 |
+
size : array-like of ints, optional
|
| 760 |
+
Output shape. If the given shape is, e.g., (m, n, k), then m * n * k
|
| 761 |
+
samples are drawn. Default is None, in which case a single value is
|
| 762 |
+
returned.
|
| 763 |
+
dtype : {str, dtype}, optional
|
| 764 |
+
Desired dtype of the result. All dtypes are determined by their name,
|
| 765 |
+
i.e., 'int64', 'int', etc, so byteorder is not available and a specific
|
| 766 |
+
precision may have different C types depending on the platform.
|
| 767 |
+
The default value is 'int64'.
|
| 768 |
+
endpoint : bool, optional
|
| 769 |
+
If True, sample from the interval [low, high] instead of the default
|
| 770 |
+
[low, high) Defaults to False.
|
| 771 |
+
|
| 772 |
+
Returns
|
| 773 |
+
-------
|
| 774 |
+
out: int or ndarray of ints
|
| 775 |
+
size-shaped array of random integers from the appropriate distribution,
|
| 776 |
+
or a single such random int if size not provided.
|
| 777 |
+
"""
|
| 778 |
+
if isinstance(gen, Generator):
|
| 779 |
+
return gen.integers(low, high=high, size=size, dtype=dtype,
|
| 780 |
+
endpoint=endpoint)
|
| 781 |
+
else:
|
| 782 |
+
if gen is None:
|
| 783 |
+
# default is RandomState singleton used by np.random.
|
| 784 |
+
gen = np.random.mtrand._rand
|
| 785 |
+
if endpoint:
|
| 786 |
+
# inclusive of endpoint
|
| 787 |
+
# remember that low and high can be arrays, so don't modify in
|
| 788 |
+
# place
|
| 789 |
+
if high is None:
|
| 790 |
+
return gen.randint(low + 1, size=size, dtype=dtype)
|
| 791 |
+
if high is not None:
|
| 792 |
+
return gen.randint(low, high=high + 1, size=size, dtype=dtype)
|
| 793 |
+
|
| 794 |
+
# exclusive
|
| 795 |
+
return gen.randint(low, high=high, size=size, dtype=dtype)
|
| 796 |
+
|
| 797 |
+
|
| 798 |
+
@contextmanager
|
| 799 |
+
def _fixed_default_rng(seed=1638083107694713882823079058616272161):
|
| 800 |
+
"""Context with a fixed np.random.default_rng seed."""
|
| 801 |
+
orig_fun = np.random.default_rng
|
| 802 |
+
np.random.default_rng = lambda seed=seed: orig_fun(seed)
|
| 803 |
+
try:
|
| 804 |
+
yield
|
| 805 |
+
finally:
|
| 806 |
+
np.random.default_rng = orig_fun
|
| 807 |
+
|
| 808 |
+
|
| 809 |
+
def _rng_html_rewrite(func):
|
| 810 |
+
"""Rewrite the HTML rendering of ``np.random.default_rng``.
|
| 811 |
+
|
| 812 |
+
This is intended to decorate
|
| 813 |
+
``numpydoc.docscrape_sphinx.SphinxDocString._str_examples``.
|
| 814 |
+
|
| 815 |
+
Examples are only run by Sphinx when there are plot involved. Even so,
|
| 816 |
+
it does not change the result values getting printed.
|
| 817 |
+
"""
|
| 818 |
+
# hexadecimal or number seed, case-insensitive
|
| 819 |
+
pattern = re.compile(r'np.random.default_rng\((0x[0-9A-F]+|\d+)\)', re.I)
|
| 820 |
+
|
| 821 |
+
def _wrapped(*args, **kwargs):
|
| 822 |
+
res = func(*args, **kwargs)
|
| 823 |
+
lines = [
|
| 824 |
+
re.sub(pattern, 'np.random.default_rng()', line)
|
| 825 |
+
for line in res
|
| 826 |
+
]
|
| 827 |
+
return lines
|
| 828 |
+
|
| 829 |
+
return _wrapped
|
| 830 |
+
|
| 831 |
+
|
| 832 |
+
def _argmin(a, keepdims=False, axis=None):
|
| 833 |
+
"""
|
| 834 |
+
argmin with a `keepdims` parameter.
|
| 835 |
+
|
| 836 |
+
See https://github.com/numpy/numpy/issues/8710
|
| 837 |
+
|
| 838 |
+
If axis is not None, a.shape[axis] must be greater than 0.
|
| 839 |
+
"""
|
| 840 |
+
res = np.argmin(a, axis=axis)
|
| 841 |
+
if keepdims and axis is not None:
|
| 842 |
+
res = np.expand_dims(res, axis=axis)
|
| 843 |
+
return res
|
| 844 |
+
|
| 845 |
+
|
| 846 |
+
def _first_nonnan(a, axis):
|
| 847 |
+
"""
|
| 848 |
+
Return the first non-nan value along the given axis.
|
| 849 |
+
|
| 850 |
+
If a slice is all nan, nan is returned for that slice.
|
| 851 |
+
|
| 852 |
+
The shape of the return value corresponds to ``keepdims=True``.
|
| 853 |
+
|
| 854 |
+
Examples
|
| 855 |
+
--------
|
| 856 |
+
>>> import numpy as np
|
| 857 |
+
>>> nan = np.nan
|
| 858 |
+
>>> a = np.array([[ 3., 3., nan, 3.],
|
| 859 |
+
[ 1., nan, 2., 4.],
|
| 860 |
+
[nan, nan, 9., -1.],
|
| 861 |
+
[nan, 5., 4., 3.],
|
| 862 |
+
[ 2., 2., 2., 2.],
|
| 863 |
+
[nan, nan, nan, nan]])
|
| 864 |
+
>>> _first_nonnan(a, axis=0)
|
| 865 |
+
array([[3., 3., 2., 3.]])
|
| 866 |
+
>>> _first_nonnan(a, axis=1)
|
| 867 |
+
array([[ 3.],
|
| 868 |
+
[ 1.],
|
| 869 |
+
[ 9.],
|
| 870 |
+
[ 5.],
|
| 871 |
+
[ 2.],
|
| 872 |
+
[nan]])
|
| 873 |
+
"""
|
| 874 |
+
k = _argmin(np.isnan(a), axis=axis, keepdims=True)
|
| 875 |
+
return np.take_along_axis(a, k, axis=axis)
|
| 876 |
+
|
| 877 |
+
|
| 878 |
+
def _nan_allsame(a, axis, keepdims=False):
|
| 879 |
+
"""
|
| 880 |
+
Determine if the values along an axis are all the same.
|
| 881 |
+
|
| 882 |
+
nan values are ignored.
|
| 883 |
+
|
| 884 |
+
`a` must be a numpy array.
|
| 885 |
+
|
| 886 |
+
`axis` is assumed to be normalized; that is, 0 <= axis < a.ndim.
|
| 887 |
+
|
| 888 |
+
For an axis of length 0, the result is True. That is, we adopt the
|
| 889 |
+
convention that ``allsame([])`` is True. (There are no values in the
|
| 890 |
+
input that are different.)
|
| 891 |
+
|
| 892 |
+
`True` is returned for slices that are all nan--not because all the
|
| 893 |
+
values are the same, but because this is equivalent to ``allsame([])``.
|
| 894 |
+
|
| 895 |
+
Examples
|
| 896 |
+
--------
|
| 897 |
+
>>> from numpy import nan, array
|
| 898 |
+
>>> a = array([[ 3., 3., nan, 3.],
|
| 899 |
+
... [ 1., nan, 2., 4.],
|
| 900 |
+
... [nan, nan, 9., -1.],
|
| 901 |
+
... [nan, 5., 4., 3.],
|
| 902 |
+
... [ 2., 2., 2., 2.],
|
| 903 |
+
... [nan, nan, nan, nan]])
|
| 904 |
+
>>> _nan_allsame(a, axis=1, keepdims=True)
|
| 905 |
+
array([[ True],
|
| 906 |
+
[False],
|
| 907 |
+
[False],
|
| 908 |
+
[False],
|
| 909 |
+
[ True],
|
| 910 |
+
[ True]])
|
| 911 |
+
"""
|
| 912 |
+
if axis is None:
|
| 913 |
+
if a.size == 0:
|
| 914 |
+
return True
|
| 915 |
+
a = a.ravel()
|
| 916 |
+
axis = 0
|
| 917 |
+
else:
|
| 918 |
+
shp = a.shape
|
| 919 |
+
if shp[axis] == 0:
|
| 920 |
+
shp = shp[:axis] + (1,)*keepdims + shp[axis + 1:]
|
| 921 |
+
return np.full(shp, fill_value=True, dtype=bool)
|
| 922 |
+
a0 = _first_nonnan(a, axis=axis)
|
| 923 |
+
return ((a0 == a) | np.isnan(a)).all(axis=axis, keepdims=keepdims)
|
| 924 |
+
|
| 925 |
+
|
| 926 |
+
def _contains_nan(a, nan_policy='propagate', policies=None, *,
|
| 927 |
+
xp_omit_okay=False, xp=None):
|
| 928 |
+
# Regarding `xp_omit_okay`: Temporarily, while `_axis_nan_policy` does not
|
| 929 |
+
# handle non-NumPy arrays, most functions that call `_contains_nan` want
|
| 930 |
+
# it to raise an error if `nan_policy='omit'` and `xp` is not `np`.
|
| 931 |
+
# Some functions support `nan_policy='omit'` natively, so setting this to
|
| 932 |
+
# `True` prevents the error from being raised.
|
| 933 |
+
if xp is None:
|
| 934 |
+
xp = array_namespace(a)
|
| 935 |
+
not_numpy = not is_numpy(xp)
|
| 936 |
+
|
| 937 |
+
if policies is None:
|
| 938 |
+
policies = {'propagate', 'raise', 'omit'}
|
| 939 |
+
if nan_policy not in policies:
|
| 940 |
+
raise ValueError(f"nan_policy must be one of {set(policies)}.")
|
| 941 |
+
|
| 942 |
+
if xp_size(a) == 0:
|
| 943 |
+
contains_nan = False
|
| 944 |
+
elif xp.isdtype(a.dtype, "real floating"):
|
| 945 |
+
# Faster and less memory-intensive than xp.any(xp.isnan(a)), and unlike other
|
| 946 |
+
# reductions, `max`/`min` won't return NaN unless there is a NaN in the data.
|
| 947 |
+
contains_nan = xp.isnan(xp.max(a))
|
| 948 |
+
elif xp.isdtype(a.dtype, "complex floating"):
|
| 949 |
+
# Typically `real` and `imag` produce views; otherwise, `xp.any(xp.isnan(a))`
|
| 950 |
+
# would be more efficient.
|
| 951 |
+
contains_nan = xp.isnan(xp.max(xp.real(a))) | xp.isnan(xp.max(xp.imag(a)))
|
| 952 |
+
elif is_numpy(xp) and np.issubdtype(a.dtype, object):
|
| 953 |
+
contains_nan = False
|
| 954 |
+
for el in a.ravel():
|
| 955 |
+
# isnan doesn't work on non-numeric elements
|
| 956 |
+
if np.issubdtype(type(el), np.number) and np.isnan(el):
|
| 957 |
+
contains_nan = True
|
| 958 |
+
break
|
| 959 |
+
else:
|
| 960 |
+
# Only `object` and `inexact` arrays can have NaNs
|
| 961 |
+
contains_nan = False
|
| 962 |
+
|
| 963 |
+
if contains_nan and nan_policy == 'raise':
|
| 964 |
+
raise ValueError("The input contains nan values")
|
| 965 |
+
|
| 966 |
+
if not xp_omit_okay and not_numpy and contains_nan and nan_policy=='omit':
|
| 967 |
+
message = "`nan_policy='omit' is incompatible with non-NumPy arrays."
|
| 968 |
+
raise ValueError(message)
|
| 969 |
+
|
| 970 |
+
return contains_nan, nan_policy
|
| 971 |
+
|
| 972 |
+
|
| 973 |
+
def _rename_parameter(old_name, new_name, dep_version=None):
|
| 974 |
+
"""
|
| 975 |
+
Generate decorator for backward-compatible keyword renaming.
|
| 976 |
+
|
| 977 |
+
Apply the decorator generated by `_rename_parameter` to functions with a
|
| 978 |
+
recently renamed parameter to maintain backward-compatibility.
|
| 979 |
+
|
| 980 |
+
After decoration, the function behaves as follows:
|
| 981 |
+
If only the new parameter is passed into the function, behave as usual.
|
| 982 |
+
If only the old parameter is passed into the function (as a keyword), raise
|
| 983 |
+
a DeprecationWarning if `dep_version` is provided, and behave as usual
|
| 984 |
+
otherwise.
|
| 985 |
+
If both old and new parameters are passed into the function, raise a
|
| 986 |
+
DeprecationWarning if `dep_version` is provided, and raise the appropriate
|
| 987 |
+
TypeError (function got multiple values for argument).
|
| 988 |
+
|
| 989 |
+
Parameters
|
| 990 |
+
----------
|
| 991 |
+
old_name : str
|
| 992 |
+
Old name of parameter
|
| 993 |
+
new_name : str
|
| 994 |
+
New name of parameter
|
| 995 |
+
dep_version : str, optional
|
| 996 |
+
Version of SciPy in which old parameter was deprecated in the format
|
| 997 |
+
'X.Y.Z'. If supplied, the deprecation message will indicate that
|
| 998 |
+
support for the old parameter will be removed in version 'X.Y+2.Z'
|
| 999 |
+
|
| 1000 |
+
Notes
|
| 1001 |
+
-----
|
| 1002 |
+
Untested with functions that accept *args. Probably won't work as written.
|
| 1003 |
+
|
| 1004 |
+
"""
|
| 1005 |
+
def decorator(fun):
|
| 1006 |
+
@functools.wraps(fun)
|
| 1007 |
+
def wrapper(*args, **kwargs):
|
| 1008 |
+
if old_name in kwargs:
|
| 1009 |
+
if dep_version:
|
| 1010 |
+
end_version = dep_version.split('.')
|
| 1011 |
+
end_version[1] = str(int(end_version[1]) + 2)
|
| 1012 |
+
end_version = '.'.join(end_version)
|
| 1013 |
+
message = (f"Use of keyword argument `{old_name}` is "
|
| 1014 |
+
f"deprecated and replaced by `{new_name}`. "
|
| 1015 |
+
f"Support for `{old_name}` will be removed "
|
| 1016 |
+
f"in SciPy {end_version}.")
|
| 1017 |
+
warnings.warn(message, DeprecationWarning, stacklevel=2)
|
| 1018 |
+
if new_name in kwargs:
|
| 1019 |
+
message = (f"{fun.__name__}() got multiple values for "
|
| 1020 |
+
f"argument now known as `{new_name}`")
|
| 1021 |
+
raise TypeError(message)
|
| 1022 |
+
kwargs[new_name] = kwargs.pop(old_name)
|
| 1023 |
+
return fun(*args, **kwargs)
|
| 1024 |
+
return wrapper
|
| 1025 |
+
return decorator
|
| 1026 |
+
|
| 1027 |
+
|
| 1028 |
+
def _rng_spawn(rng, n_children):
|
| 1029 |
+
# spawns independent RNGs from a parent RNG
|
| 1030 |
+
bg = rng._bit_generator
|
| 1031 |
+
ss = bg._seed_seq
|
| 1032 |
+
child_rngs = [np.random.Generator(type(bg)(child_ss))
|
| 1033 |
+
for child_ss in ss.spawn(n_children)]
|
| 1034 |
+
return child_rngs
|
| 1035 |
+
|
| 1036 |
+
|
| 1037 |
+
def _get_nan(*data, xp=None):
|
| 1038 |
+
xp = array_namespace(*data) if xp is None else xp
|
| 1039 |
+
# Get NaN of appropriate dtype for data
|
| 1040 |
+
data = [xp.asarray(item) for item in data]
|
| 1041 |
+
try:
|
| 1042 |
+
min_float = getattr(xp, 'float16', xp.float32)
|
| 1043 |
+
dtype = xp.result_type(*data, min_float) # must be at least a float
|
| 1044 |
+
except DTypePromotionError:
|
| 1045 |
+
# fallback to float64
|
| 1046 |
+
dtype = xp.float64
|
| 1047 |
+
return xp.asarray(xp.nan, dtype=dtype)[()]
|
| 1048 |
+
|
| 1049 |
+
|
| 1050 |
+
def normalize_axis_index(axis, ndim):
|
| 1051 |
+
# Check if `axis` is in the correct range and normalize it
|
| 1052 |
+
if axis < -ndim or axis >= ndim:
|
| 1053 |
+
msg = f"axis {axis} is out of bounds for array of dimension {ndim}"
|
| 1054 |
+
raise AxisError(msg)
|
| 1055 |
+
|
| 1056 |
+
if axis < 0:
|
| 1057 |
+
axis = axis + ndim
|
| 1058 |
+
return axis
|
| 1059 |
+
|
| 1060 |
+
|
| 1061 |
+
def _call_callback_maybe_halt(callback, res):
|
| 1062 |
+
"""Call wrapped callback; return True if algorithm should stop.
|
| 1063 |
+
|
| 1064 |
+
Parameters
|
| 1065 |
+
----------
|
| 1066 |
+
callback : callable or None
|
| 1067 |
+
A user-provided callback wrapped with `_wrap_callback`
|
| 1068 |
+
res : OptimizeResult
|
| 1069 |
+
Information about the current iterate
|
| 1070 |
+
|
| 1071 |
+
Returns
|
| 1072 |
+
-------
|
| 1073 |
+
halt : bool
|
| 1074 |
+
True if minimization should stop
|
| 1075 |
+
|
| 1076 |
+
"""
|
| 1077 |
+
if callback is None:
|
| 1078 |
+
return False
|
| 1079 |
+
try:
|
| 1080 |
+
callback(res)
|
| 1081 |
+
return False
|
| 1082 |
+
except StopIteration:
|
| 1083 |
+
callback.stop_iteration = True
|
| 1084 |
+
return True
|
| 1085 |
+
|
| 1086 |
+
|
| 1087 |
+
class _RichResult(dict):
|
| 1088 |
+
""" Container for multiple outputs with pretty-printing """
|
| 1089 |
+
def __getattr__(self, name):
|
| 1090 |
+
try:
|
| 1091 |
+
return self[name]
|
| 1092 |
+
except KeyError as e:
|
| 1093 |
+
raise AttributeError(name) from e
|
| 1094 |
+
|
| 1095 |
+
__setattr__ = dict.__setitem__ # type: ignore[assignment]
|
| 1096 |
+
__delattr__ = dict.__delitem__ # type: ignore[assignment]
|
| 1097 |
+
|
| 1098 |
+
def __repr__(self):
|
| 1099 |
+
order_keys = ['message', 'success', 'status', 'fun', 'funl', 'x', 'xl',
|
| 1100 |
+
'col_ind', 'nit', 'lower', 'upper', 'eqlin', 'ineqlin',
|
| 1101 |
+
'converged', 'flag', 'function_calls', 'iterations',
|
| 1102 |
+
'root']
|
| 1103 |
+
order_keys = getattr(self, '_order_keys', order_keys)
|
| 1104 |
+
# 'slack', 'con' are redundant with residuals
|
| 1105 |
+
# 'crossover_nit' is probably not interesting to most users
|
| 1106 |
+
omit_keys = {'slack', 'con', 'crossover_nit', '_order_keys'}
|
| 1107 |
+
|
| 1108 |
+
def key(item):
|
| 1109 |
+
try:
|
| 1110 |
+
return order_keys.index(item[0].lower())
|
| 1111 |
+
except ValueError: # item not in list
|
| 1112 |
+
return np.inf
|
| 1113 |
+
|
| 1114 |
+
def omit_redundant(items):
|
| 1115 |
+
for item in items:
|
| 1116 |
+
if item[0] in omit_keys:
|
| 1117 |
+
continue
|
| 1118 |
+
yield item
|
| 1119 |
+
|
| 1120 |
+
def item_sorter(d):
|
| 1121 |
+
return sorted(omit_redundant(d.items()), key=key)
|
| 1122 |
+
|
| 1123 |
+
if self.keys():
|
| 1124 |
+
return _dict_formatter(self, sorter=item_sorter)
|
| 1125 |
+
else:
|
| 1126 |
+
return self.__class__.__name__ + "()"
|
| 1127 |
+
|
| 1128 |
+
def __dir__(self):
|
| 1129 |
+
return list(self.keys())
|
| 1130 |
+
|
| 1131 |
+
|
| 1132 |
+
def _indenter(s, n=0):
|
| 1133 |
+
"""
|
| 1134 |
+
Ensures that lines after the first are indented by the specified amount
|
| 1135 |
+
"""
|
| 1136 |
+
split = s.split("\n")
|
| 1137 |
+
indent = " "*n
|
| 1138 |
+
return ("\n" + indent).join(split)
|
| 1139 |
+
|
| 1140 |
+
|
| 1141 |
+
def _float_formatter_10(x):
|
| 1142 |
+
"""
|
| 1143 |
+
Returns a string representation of a float with exactly ten characters
|
| 1144 |
+
"""
|
| 1145 |
+
if np.isposinf(x):
|
| 1146 |
+
return " inf"
|
| 1147 |
+
elif np.isneginf(x):
|
| 1148 |
+
return " -inf"
|
| 1149 |
+
elif np.isnan(x):
|
| 1150 |
+
return " nan"
|
| 1151 |
+
return np.format_float_scientific(x, precision=3, pad_left=2, unique=False)
|
| 1152 |
+
|
| 1153 |
+
|
| 1154 |
+
def _dict_formatter(d, n=0, mplus=1, sorter=None):
|
| 1155 |
+
"""
|
| 1156 |
+
Pretty printer for dictionaries
|
| 1157 |
+
|
| 1158 |
+
`n` keeps track of the starting indentation;
|
| 1159 |
+
lines are indented by this much after a line break.
|
| 1160 |
+
`mplus` is additional left padding applied to keys
|
| 1161 |
+
"""
|
| 1162 |
+
if isinstance(d, dict):
|
| 1163 |
+
m = max(map(len, list(d.keys()))) + mplus # width to print keys
|
| 1164 |
+
s = '\n'.join([k.rjust(m) + ': ' + # right justified, width m
|
| 1165 |
+
_indenter(_dict_formatter(v, m+n+2, 0, sorter), m+2)
|
| 1166 |
+
for k, v in sorter(d)]) # +2 for ': '
|
| 1167 |
+
else:
|
| 1168 |
+
# By default, NumPy arrays print with linewidth=76. `n` is
|
| 1169 |
+
# the indent at which a line begins printing, so it is subtracted
|
| 1170 |
+
# from the default to avoid exceeding 76 characters total.
|
| 1171 |
+
# `edgeitems` is the number of elements to include before and after
|
| 1172 |
+
# ellipses when arrays are not shown in full.
|
| 1173 |
+
# `threshold` is the maximum number of elements for which an
|
| 1174 |
+
# array is shown in full.
|
| 1175 |
+
# These values tend to work well for use with OptimizeResult.
|
| 1176 |
+
with np.printoptions(linewidth=76-n, edgeitems=2, threshold=12,
|
| 1177 |
+
formatter={'float_kind': _float_formatter_10}):
|
| 1178 |
+
s = str(d)
|
| 1179 |
+
return s
|
phi4/lib/python3.10/site-packages/scipy/_lib/array_api_compat/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
NumPy Array API compatibility library
|
| 3 |
+
|
| 4 |
+
This is a small wrapper around NumPy and CuPy that is compatible with the
|
| 5 |
+
Array API standard https://data-apis.org/array-api/latest/. See also NEP 47
|
| 6 |
+
https://numpy.org/neps/nep-0047-array-api-standard.html.
|
| 7 |
+
|
| 8 |
+
Unlike array_api_strict, this is not a strict minimal implementation of the
|
| 9 |
+
Array API, but rather just an extension of the main NumPy namespace with
|
| 10 |
+
changes needed to be compliant with the Array API. See
|
| 11 |
+
https://numpy.org/doc/stable/reference/array_api.html for a full list of
|
| 12 |
+
changes. In particular, unlike array_api_strict, this package does not use a
|
| 13 |
+
separate Array object, but rather just uses numpy.ndarray directly.
|
| 14 |
+
|
| 15 |
+
Library authors using the Array API may wish to test against array_api_strict
|
| 16 |
+
to ensure they are not using functionality outside of the standard, but prefer
|
| 17 |
+
this implementation for the default when working with NumPy arrays.
|
| 18 |
+
|
| 19 |
+
"""
|
| 20 |
+
__version__ = '1.9.1'
|
| 21 |
+
|
| 22 |
+
from .common import * # noqa: F401, F403
|
phi4/lib/python3.10/site-packages/scipy/_lib/array_api_compat/_internal.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Internal helpers
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from functools import wraps
|
| 6 |
+
from inspect import signature
|
| 7 |
+
|
| 8 |
+
def get_xp(xp):
|
| 9 |
+
"""
|
| 10 |
+
Decorator to automatically replace xp with the corresponding array module.
|
| 11 |
+
|
| 12 |
+
Use like
|
| 13 |
+
|
| 14 |
+
import numpy as np
|
| 15 |
+
|
| 16 |
+
@get_xp(np)
|
| 17 |
+
def func(x, /, xp, kwarg=None):
|
| 18 |
+
return xp.func(x, kwarg=kwarg)
|
| 19 |
+
|
| 20 |
+
Note that xp must be a keyword argument and come after all non-keyword
|
| 21 |
+
arguments.
|
| 22 |
+
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
def inner(f):
|
| 26 |
+
@wraps(f)
|
| 27 |
+
def wrapped_f(*args, **kwargs):
|
| 28 |
+
return f(*args, xp=xp, **kwargs)
|
| 29 |
+
|
| 30 |
+
sig = signature(f)
|
| 31 |
+
new_sig = sig.replace(
|
| 32 |
+
parameters=[sig.parameters[i] for i in sig.parameters if i != "xp"]
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
if wrapped_f.__doc__ is None:
|
| 36 |
+
wrapped_f.__doc__ = f"""\
|
| 37 |
+
Array API compatibility wrapper for {f.__name__}.
|
| 38 |
+
|
| 39 |
+
See the corresponding documentation in NumPy/CuPy and/or the array API
|
| 40 |
+
specification for more details.
|
| 41 |
+
|
| 42 |
+
"""
|
| 43 |
+
wrapped_f.__signature__ = new_sig
|
| 44 |
+
return wrapped_f
|
| 45 |
+
|
| 46 |
+
return inner
|
phi4/lib/python3.10/site-packages/scipy/_lib/array_api_compat/cupy/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from cupy import * # noqa: F403
|
| 2 |
+
|
| 3 |
+
# from cupy import * doesn't overwrite these builtin names
|
| 4 |
+
from cupy import abs, max, min, round # noqa: F401
|
| 5 |
+
|
| 6 |
+
# These imports may overwrite names from the import * above.
|
| 7 |
+
from ._aliases import * # noqa: F403
|
| 8 |
+
|
| 9 |
+
# See the comment in the numpy __init__.py
|
| 10 |
+
__import__(__package__ + '.linalg')
|
| 11 |
+
|
| 12 |
+
__import__(__package__ + '.fft')
|
| 13 |
+
|
| 14 |
+
from ..common._helpers import * # noqa: F401,F403
|
| 15 |
+
|
| 16 |
+
__array_api_version__ = '2023.12'
|
phi4/lib/python3.10/site-packages/scipy/_lib/array_api_compat/cupy/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (436 Bytes). View file
|
|
|