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 +10 -0
- evalkit_cambrian/lib/python3.10/site-packages/gradio/node/dev/node_modules/esbuild-wasm/esbuild.wasm +3 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/__init__.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_base.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_bsr.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_compressed.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_construct.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_coo.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_csc.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_csr.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_data.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_dia.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_dok.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_extract.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_index.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_lil.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_matrix.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_matrix_io.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_spfuncs.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_sputils.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/base.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/bsr.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/compressed.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/construct.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/coo.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/csc.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/csr.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/data.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/dia.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/dok.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/extract.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/lil.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/sparsetools.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/spfuncs.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/sputils.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/_sparsetools.cpython-310-x86_64-linux-gnu.so +3 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/__init__.py +210 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/__pycache__/__init__.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/__pycache__/_laplacian.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/__pycache__/_validation.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_flow.cpython-310-x86_64-linux-gnu.so +3 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_laplacian.py +563 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_matching.cpython-310-x86_64-linux-gnu.so +3 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_reordering.cpython-310-x86_64-linux-gnu.so +3 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_shortest_path.cpython-310-x86_64-linux-gnu.so +3 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_tools.cpython-310-x86_64-linux-gnu.so +3 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_validation.py +66 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/tests/__init__.py +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/tests/__pycache__/test_connected_components.cpython-310.pyc +0 -0
.gitattributes
CHANGED
|
@@ -919,3 +919,13 @@ infer_4_47_1/lib/python3.10/site-packages/scipy/special/tests/__pycache__/test_b
|
|
| 919 |
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/linalg/_eigen/arpack/_arpack.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 920 |
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/linalg/_propack/_dpropack.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 921 |
infer_4_47_1/lib/python3.10/site-packages/scipy/optimize/__pycache__/_optimize.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 919 |
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/linalg/_eigen/arpack/_arpack.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 920 |
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/linalg/_propack/_dpropack.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 921 |
infer_4_47_1/lib/python3.10/site-packages/scipy/optimize/__pycache__/_optimize.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 922 |
+
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/tests/__pycache__/test_base.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 923 |
+
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/linalg/_propack/_zpropack.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 924 |
+
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_flow.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 925 |
+
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/_sparsetools.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 926 |
+
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_matching.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 927 |
+
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_shortest_path.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 928 |
+
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_tools.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 929 |
+
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_reordering.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 930 |
+
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/linalg/_propack/_cpropack.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 931 |
+
infer_4_47_1/lib/python3.10/site-packages/scipy/special/__pycache__/_basic.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
evalkit_cambrian/lib/python3.10/site-packages/gradio/node/dev/node_modules/esbuild-wasm/esbuild.wasm
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3ee66612f95701f4b6f3b2126cef3d17e520935e76526e3e081bb9e46bbf4074
|
| 3 |
+
size 11171775
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (9.47 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_base.cpython-310.pyc
ADDED
|
Binary file (44.1 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_bsr.cpython-310.pyc
ADDED
|
Binary file (23.5 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_compressed.cpython-310.pyc
ADDED
|
Binary file (37.2 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_construct.cpython-310.pyc
ADDED
|
Binary file (43.3 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_coo.cpython-310.pyc
ADDED
|
Binary file (48.6 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_csc.cpython-310.pyc
ADDED
|
Binary file (11.2 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_csr.cpython-310.pyc
ADDED
|
Binary file (16.9 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_data.cpython-310.pyc
ADDED
|
Binary file (18.3 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_dia.cpython-310.pyc
ADDED
|
Binary file (15.4 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_dok.cpython-310.pyc
ADDED
|
Binary file (23.9 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_extract.cpython-310.pyc
ADDED
|
Binary file (5.08 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_index.cpython-310.pyc
ADDED
|
Binary file (10.9 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_lil.cpython-310.pyc
ADDED
|
Binary file (19.2 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_matrix.cpython-310.pyc
ADDED
|
Binary file (5.65 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_matrix_io.cpython-310.pyc
ADDED
|
Binary file (5.31 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_spfuncs.cpython-310.pyc
ADDED
|
Binary file (1.81 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/_sputils.cpython-310.pyc
ADDED
|
Binary file (18.5 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/base.cpython-310.pyc
ADDED
|
Binary file (776 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/bsr.cpython-310.pyc
ADDED
|
Binary file (777 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/compressed.cpython-310.pyc
ADDED
|
Binary file (940 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/construct.cpython-310.pyc
ADDED
|
Binary file (849 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/coo.cpython-310.pyc
ADDED
|
Binary file (804 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/csc.cpython-310.pyc
ADDED
|
Binary file (641 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/csr.cpython-310.pyc
ADDED
|
Binary file (678 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/data.cpython-310.pyc
ADDED
|
Binary file (617 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/dia.cpython-310.pyc
ADDED
|
Binary file (697 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/dok.cpython-310.pyc
ADDED
|
Binary file (723 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/extract.cpython-310.pyc
ADDED
|
Binary file (615 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/lil.cpython-310.pyc
ADDED
|
Binary file (612 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/sparsetools.cpython-310.pyc
ADDED
|
Binary file (638 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/spfuncs.cpython-310.pyc
ADDED
|
Binary file (626 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/__pycache__/sputils.cpython-310.pyc
ADDED
|
Binary file (626 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/_sparsetools.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dde4efc97631ffb3b348260a62b5601e48c56257cc3b6a43841c5ca5d78f8bd7
|
| 3 |
+
size 4560912
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/__init__.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
r"""
|
| 2 |
+
Compressed sparse graph routines (:mod:`scipy.sparse.csgraph`)
|
| 3 |
+
==============================================================
|
| 4 |
+
|
| 5 |
+
.. currentmodule:: scipy.sparse.csgraph
|
| 6 |
+
|
| 7 |
+
Fast graph algorithms based on sparse matrix representations.
|
| 8 |
+
|
| 9 |
+
Contents
|
| 10 |
+
--------
|
| 11 |
+
|
| 12 |
+
.. autosummary::
|
| 13 |
+
:toctree: generated/
|
| 14 |
+
|
| 15 |
+
connected_components -- determine connected components of a graph
|
| 16 |
+
laplacian -- compute the laplacian of a graph
|
| 17 |
+
shortest_path -- compute the shortest path between points on a positive graph
|
| 18 |
+
dijkstra -- use Dijkstra's algorithm for shortest path
|
| 19 |
+
floyd_warshall -- use the Floyd-Warshall algorithm for shortest path
|
| 20 |
+
bellman_ford -- use the Bellman-Ford algorithm for shortest path
|
| 21 |
+
johnson -- use Johnson's algorithm for shortest path
|
| 22 |
+
yen -- use Yen's algorithm for K-shortest paths between to nodes.
|
| 23 |
+
breadth_first_order -- compute a breadth-first order of nodes
|
| 24 |
+
depth_first_order -- compute a depth-first order of nodes
|
| 25 |
+
breadth_first_tree -- construct the breadth-first tree from a given node
|
| 26 |
+
depth_first_tree -- construct a depth-first tree from a given node
|
| 27 |
+
minimum_spanning_tree -- construct the minimum spanning tree of a graph
|
| 28 |
+
reverse_cuthill_mckee -- compute permutation for reverse Cuthill-McKee ordering
|
| 29 |
+
maximum_flow -- solve the maximum flow problem for a graph
|
| 30 |
+
maximum_bipartite_matching -- compute a maximum matching of a bipartite graph
|
| 31 |
+
min_weight_full_bipartite_matching - compute a minimum weight full matching of a bipartite graph
|
| 32 |
+
structural_rank -- compute the structural rank of a graph
|
| 33 |
+
NegativeCycleError
|
| 34 |
+
|
| 35 |
+
.. autosummary::
|
| 36 |
+
:toctree: generated/
|
| 37 |
+
|
| 38 |
+
construct_dist_matrix
|
| 39 |
+
csgraph_from_dense
|
| 40 |
+
csgraph_from_masked
|
| 41 |
+
csgraph_masked_from_dense
|
| 42 |
+
csgraph_to_dense
|
| 43 |
+
csgraph_to_masked
|
| 44 |
+
reconstruct_path
|
| 45 |
+
|
| 46 |
+
Graph Representations
|
| 47 |
+
---------------------
|
| 48 |
+
This module uses graphs which are stored in a matrix format. A
|
| 49 |
+
graph with N nodes can be represented by an (N x N) adjacency matrix G.
|
| 50 |
+
If there is a connection from node i to node j, then G[i, j] = w, where
|
| 51 |
+
w is the weight of the connection. For nodes i and j which are
|
| 52 |
+
not connected, the value depends on the representation:
|
| 53 |
+
|
| 54 |
+
- for dense array representations, non-edges are represented by
|
| 55 |
+
G[i, j] = 0, infinity, or NaN.
|
| 56 |
+
|
| 57 |
+
- for dense masked representations (of type np.ma.MaskedArray), non-edges
|
| 58 |
+
are represented by masked values. This can be useful when graphs with
|
| 59 |
+
zero-weight edges are desired.
|
| 60 |
+
|
| 61 |
+
- for sparse array representations, non-edges are represented by
|
| 62 |
+
non-entries in the matrix. This sort of sparse representation also
|
| 63 |
+
allows for edges with zero weights.
|
| 64 |
+
|
| 65 |
+
As a concrete example, imagine that you would like to represent the following
|
| 66 |
+
undirected graph::
|
| 67 |
+
|
| 68 |
+
G
|
| 69 |
+
|
| 70 |
+
(0)
|
| 71 |
+
/ \
|
| 72 |
+
1 2
|
| 73 |
+
/ \
|
| 74 |
+
(2) (1)
|
| 75 |
+
|
| 76 |
+
This graph has three nodes, where node 0 and 1 are connected by an edge of
|
| 77 |
+
weight 2, and nodes 0 and 2 are connected by an edge of weight 1.
|
| 78 |
+
We can construct the dense, masked, and sparse representations as follows,
|
| 79 |
+
keeping in mind that an undirected graph is represented by a symmetric matrix::
|
| 80 |
+
|
| 81 |
+
>>> import numpy as np
|
| 82 |
+
>>> G_dense = np.array([[0, 2, 1],
|
| 83 |
+
... [2, 0, 0],
|
| 84 |
+
... [1, 0, 0]])
|
| 85 |
+
>>> G_masked = np.ma.masked_values(G_dense, 0)
|
| 86 |
+
>>> from scipy.sparse import csr_array
|
| 87 |
+
>>> G_sparse = csr_array(G_dense)
|
| 88 |
+
|
| 89 |
+
This becomes more difficult when zero edges are significant. For example,
|
| 90 |
+
consider the situation when we slightly modify the above graph::
|
| 91 |
+
|
| 92 |
+
G2
|
| 93 |
+
|
| 94 |
+
(0)
|
| 95 |
+
/ \
|
| 96 |
+
0 2
|
| 97 |
+
/ \
|
| 98 |
+
(2) (1)
|
| 99 |
+
|
| 100 |
+
This is identical to the previous graph, except nodes 0 and 2 are connected
|
| 101 |
+
by an edge of zero weight. In this case, the dense representation above
|
| 102 |
+
leads to ambiguities: how can non-edges be represented if zero is a meaningful
|
| 103 |
+
value? In this case, either a masked or sparse representation must be used
|
| 104 |
+
to eliminate the ambiguity::
|
| 105 |
+
|
| 106 |
+
>>> import numpy as np
|
| 107 |
+
>>> G2_data = np.array([[np.inf, 2, 0 ],
|
| 108 |
+
... [2, np.inf, np.inf],
|
| 109 |
+
... [0, np.inf, np.inf]])
|
| 110 |
+
>>> G2_masked = np.ma.masked_invalid(G2_data)
|
| 111 |
+
>>> from scipy.sparse.csgraph import csgraph_from_dense
|
| 112 |
+
>>> # G2_sparse = csr_array(G2_data) would give the wrong result
|
| 113 |
+
>>> G2_sparse = csgraph_from_dense(G2_data, null_value=np.inf)
|
| 114 |
+
>>> G2_sparse.data
|
| 115 |
+
array([ 2., 0., 2., 0.])
|
| 116 |
+
|
| 117 |
+
Here we have used a utility routine from the csgraph submodule in order to
|
| 118 |
+
convert the dense representation to a sparse representation which can be
|
| 119 |
+
understood by the algorithms in submodule. By viewing the data array, we
|
| 120 |
+
can see that the zero values are explicitly encoded in the graph.
|
| 121 |
+
|
| 122 |
+
Directed vs. undirected
|
| 123 |
+
^^^^^^^^^^^^^^^^^^^^^^^
|
| 124 |
+
Matrices may represent either directed or undirected graphs. This is
|
| 125 |
+
specified throughout the csgraph module by a boolean keyword. Graphs are
|
| 126 |
+
assumed to be directed by default. In a directed graph, traversal from node
|
| 127 |
+
i to node j can be accomplished over the edge G[i, j], but not the edge
|
| 128 |
+
G[j, i]. Consider the following dense graph::
|
| 129 |
+
|
| 130 |
+
>>> import numpy as np
|
| 131 |
+
>>> G_dense = np.array([[0, 1, 0],
|
| 132 |
+
... [2, 0, 3],
|
| 133 |
+
... [0, 4, 0]])
|
| 134 |
+
|
| 135 |
+
When ``directed=True`` we get the graph::
|
| 136 |
+
|
| 137 |
+
---1--> ---3-->
|
| 138 |
+
(0) (1) (2)
|
| 139 |
+
<--2--- <--4---
|
| 140 |
+
|
| 141 |
+
In a non-directed graph, traversal from node i to node j can be
|
| 142 |
+
accomplished over either G[i, j] or G[j, i]. If both edges are not null,
|
| 143 |
+
and the two have unequal weights, then the smaller of the two is used.
|
| 144 |
+
|
| 145 |
+
So for the same graph, when ``directed=False`` we get the graph::
|
| 146 |
+
|
| 147 |
+
(0)--1--(1)--3--(2)
|
| 148 |
+
|
| 149 |
+
Note that a symmetric matrix will represent an undirected graph, regardless
|
| 150 |
+
of whether the 'directed' keyword is set to True or False. In this case,
|
| 151 |
+
using ``directed=True`` generally leads to more efficient computation.
|
| 152 |
+
|
| 153 |
+
The routines in this module accept as input either scipy.sparse representations
|
| 154 |
+
(csr, csc, or lil format), masked representations, or dense representations
|
| 155 |
+
with non-edges indicated by zeros, infinities, and NaN entries.
|
| 156 |
+
""" # noqa: E501
|
| 157 |
+
|
| 158 |
+
__docformat__ = "restructuredtext en"
|
| 159 |
+
|
| 160 |
+
__all__ = ['connected_components',
|
| 161 |
+
'laplacian',
|
| 162 |
+
'shortest_path',
|
| 163 |
+
'floyd_warshall',
|
| 164 |
+
'dijkstra',
|
| 165 |
+
'bellman_ford',
|
| 166 |
+
'johnson',
|
| 167 |
+
'yen',
|
| 168 |
+
'breadth_first_order',
|
| 169 |
+
'depth_first_order',
|
| 170 |
+
'breadth_first_tree',
|
| 171 |
+
'depth_first_tree',
|
| 172 |
+
'minimum_spanning_tree',
|
| 173 |
+
'reverse_cuthill_mckee',
|
| 174 |
+
'maximum_flow',
|
| 175 |
+
'maximum_bipartite_matching',
|
| 176 |
+
'min_weight_full_bipartite_matching',
|
| 177 |
+
'structural_rank',
|
| 178 |
+
'construct_dist_matrix',
|
| 179 |
+
'reconstruct_path',
|
| 180 |
+
'csgraph_masked_from_dense',
|
| 181 |
+
'csgraph_from_dense',
|
| 182 |
+
'csgraph_from_masked',
|
| 183 |
+
'csgraph_to_dense',
|
| 184 |
+
'csgraph_to_masked',
|
| 185 |
+
'NegativeCycleError']
|
| 186 |
+
|
| 187 |
+
from ._laplacian import laplacian
|
| 188 |
+
from ._shortest_path import (
|
| 189 |
+
shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, yen,
|
| 190 |
+
NegativeCycleError
|
| 191 |
+
)
|
| 192 |
+
from ._traversal import (
|
| 193 |
+
breadth_first_order, depth_first_order, breadth_first_tree,
|
| 194 |
+
depth_first_tree, connected_components
|
| 195 |
+
)
|
| 196 |
+
from ._min_spanning_tree import minimum_spanning_tree
|
| 197 |
+
from ._flow import maximum_flow
|
| 198 |
+
from ._matching import (
|
| 199 |
+
maximum_bipartite_matching, min_weight_full_bipartite_matching
|
| 200 |
+
)
|
| 201 |
+
from ._reordering import reverse_cuthill_mckee, structural_rank
|
| 202 |
+
from ._tools import (
|
| 203 |
+
construct_dist_matrix, reconstruct_path, csgraph_from_dense,
|
| 204 |
+
csgraph_to_dense, csgraph_masked_from_dense, csgraph_from_masked,
|
| 205 |
+
csgraph_to_masked
|
| 206 |
+
)
|
| 207 |
+
|
| 208 |
+
from scipy._lib._testutils import PytestTester
|
| 209 |
+
test = PytestTester(__name__)
|
| 210 |
+
del PytestTester
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (7.54 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/__pycache__/_laplacian.cpython-310.pyc
ADDED
|
Binary file (16.7 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/__pycache__/_validation.cpython-310.pyc
ADDED
|
Binary file (1.65 kB). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_flow.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:70c4ace45253414e81052736c442dc374b1a77957faa64b63e137e212614d75f
|
| 3 |
+
size 354320
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_laplacian.py
ADDED
|
@@ -0,0 +1,563 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Laplacian of a compressed-sparse graph
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
from scipy.sparse import issparse
|
| 7 |
+
from scipy.sparse.linalg import LinearOperator
|
| 8 |
+
from scipy.sparse._sputils import convert_pydata_sparse_to_scipy, is_pydata_spmatrix
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
###############################################################################
|
| 12 |
+
# Graph laplacian
|
| 13 |
+
def laplacian(
|
| 14 |
+
csgraph,
|
| 15 |
+
normed=False,
|
| 16 |
+
return_diag=False,
|
| 17 |
+
use_out_degree=False,
|
| 18 |
+
*,
|
| 19 |
+
copy=True,
|
| 20 |
+
form="array",
|
| 21 |
+
dtype=None,
|
| 22 |
+
symmetrized=False,
|
| 23 |
+
):
|
| 24 |
+
"""
|
| 25 |
+
Return the Laplacian of a directed graph.
|
| 26 |
+
|
| 27 |
+
Parameters
|
| 28 |
+
----------
|
| 29 |
+
csgraph : array_like or sparse array or matrix, 2 dimensions
|
| 30 |
+
compressed-sparse graph, with shape (N, N).
|
| 31 |
+
normed : bool, optional
|
| 32 |
+
If True, then compute symmetrically normalized Laplacian.
|
| 33 |
+
Default: False.
|
| 34 |
+
return_diag : bool, optional
|
| 35 |
+
If True, then also return an array related to vertex degrees.
|
| 36 |
+
Default: False.
|
| 37 |
+
use_out_degree : bool, optional
|
| 38 |
+
If True, then use out-degree instead of in-degree.
|
| 39 |
+
This distinction matters only if the graph is asymmetric.
|
| 40 |
+
Default: False.
|
| 41 |
+
copy: bool, optional
|
| 42 |
+
If False, then change `csgraph` in place if possible,
|
| 43 |
+
avoiding doubling the memory use.
|
| 44 |
+
Default: True, for backward compatibility.
|
| 45 |
+
form: 'array', or 'function', or 'lo'
|
| 46 |
+
Determines the format of the output Laplacian:
|
| 47 |
+
|
| 48 |
+
* 'array' is a numpy array;
|
| 49 |
+
* 'function' is a pointer to evaluating the Laplacian-vector
|
| 50 |
+
or Laplacian-matrix product;
|
| 51 |
+
* 'lo' results in the format of the `LinearOperator`.
|
| 52 |
+
|
| 53 |
+
Choosing 'function' or 'lo' always avoids doubling
|
| 54 |
+
the memory use, ignoring `copy` value.
|
| 55 |
+
Default: 'array', for backward compatibility.
|
| 56 |
+
dtype: None or one of numeric numpy dtypes, optional
|
| 57 |
+
The dtype of the output. If ``dtype=None``, the dtype of the
|
| 58 |
+
output matches the dtype of the input csgraph, except for
|
| 59 |
+
the case ``normed=True`` and integer-like csgraph, where
|
| 60 |
+
the output dtype is 'float' allowing accurate normalization,
|
| 61 |
+
but dramatically increasing the memory use.
|
| 62 |
+
Default: None, for backward compatibility.
|
| 63 |
+
symmetrized: bool, optional
|
| 64 |
+
If True, then the output Laplacian is symmetric/Hermitian.
|
| 65 |
+
The symmetrization is done by ``csgraph + csgraph.T.conj``
|
| 66 |
+
without dividing by 2 to preserve integer dtypes if possible
|
| 67 |
+
prior to the construction of the Laplacian.
|
| 68 |
+
The symmetrization will increase the memory footprint of
|
| 69 |
+
sparse matrices unless the sparsity pattern is symmetric or
|
| 70 |
+
`form` is 'function' or 'lo'.
|
| 71 |
+
Default: False, for backward compatibility.
|
| 72 |
+
|
| 73 |
+
Returns
|
| 74 |
+
-------
|
| 75 |
+
lap : ndarray, or sparse array or matrix, or `LinearOperator`
|
| 76 |
+
The N x N Laplacian of csgraph. It will be a NumPy array (dense)
|
| 77 |
+
if the input was dense, or a sparse array otherwise, or
|
| 78 |
+
the format of a function or `LinearOperator` if
|
| 79 |
+
`form` equals 'function' or 'lo', respectively.
|
| 80 |
+
diag : ndarray, optional
|
| 81 |
+
The length-N main diagonal of the Laplacian matrix.
|
| 82 |
+
For the normalized Laplacian, this is the array of square roots
|
| 83 |
+
of vertex degrees or 1 if the degree is zero.
|
| 84 |
+
|
| 85 |
+
Notes
|
| 86 |
+
-----
|
| 87 |
+
The Laplacian matrix of a graph is sometimes referred to as the
|
| 88 |
+
"Kirchhoff matrix" or just the "Laplacian", and is useful in many
|
| 89 |
+
parts of spectral graph theory.
|
| 90 |
+
In particular, the eigen-decomposition of the Laplacian can give
|
| 91 |
+
insight into many properties of the graph, e.g.,
|
| 92 |
+
is commonly used for spectral data embedding and clustering.
|
| 93 |
+
|
| 94 |
+
The constructed Laplacian doubles the memory use if ``copy=True`` and
|
| 95 |
+
``form="array"`` which is the default.
|
| 96 |
+
Choosing ``copy=False`` has no effect unless ``form="array"``
|
| 97 |
+
or the matrix is sparse in the ``coo`` format, or dense array, except
|
| 98 |
+
for the integer input with ``normed=True`` that forces the float output.
|
| 99 |
+
|
| 100 |
+
Sparse input is reformatted into ``coo`` if ``form="array"``,
|
| 101 |
+
which is the default.
|
| 102 |
+
|
| 103 |
+
If the input adjacency matrix is not symmetric, the Laplacian is
|
| 104 |
+
also non-symmetric unless ``symmetrized=True`` is used.
|
| 105 |
+
|
| 106 |
+
Diagonal entries of the input adjacency matrix are ignored and
|
| 107 |
+
replaced with zeros for the purpose of normalization where ``normed=True``.
|
| 108 |
+
The normalization uses the inverse square roots of row-sums of the input
|
| 109 |
+
adjacency matrix, and thus may fail if the row-sums contain
|
| 110 |
+
negative or complex with a non-zero imaginary part values.
|
| 111 |
+
|
| 112 |
+
The normalization is symmetric, making the normalized Laplacian also
|
| 113 |
+
symmetric if the input csgraph was symmetric.
|
| 114 |
+
|
| 115 |
+
References
|
| 116 |
+
----------
|
| 117 |
+
.. [1] Laplacian matrix. https://en.wikipedia.org/wiki/Laplacian_matrix
|
| 118 |
+
|
| 119 |
+
Examples
|
| 120 |
+
--------
|
| 121 |
+
>>> import numpy as np
|
| 122 |
+
>>> from scipy.sparse import csgraph
|
| 123 |
+
|
| 124 |
+
Our first illustration is the symmetric graph
|
| 125 |
+
|
| 126 |
+
>>> G = np.arange(4) * np.arange(4)[:, np.newaxis]
|
| 127 |
+
>>> G
|
| 128 |
+
array([[0, 0, 0, 0],
|
| 129 |
+
[0, 1, 2, 3],
|
| 130 |
+
[0, 2, 4, 6],
|
| 131 |
+
[0, 3, 6, 9]])
|
| 132 |
+
|
| 133 |
+
and its symmetric Laplacian matrix
|
| 134 |
+
|
| 135 |
+
>>> csgraph.laplacian(G)
|
| 136 |
+
array([[ 0, 0, 0, 0],
|
| 137 |
+
[ 0, 5, -2, -3],
|
| 138 |
+
[ 0, -2, 8, -6],
|
| 139 |
+
[ 0, -3, -6, 9]])
|
| 140 |
+
|
| 141 |
+
The non-symmetric graph
|
| 142 |
+
|
| 143 |
+
>>> G = np.arange(9).reshape(3, 3)
|
| 144 |
+
>>> G
|
| 145 |
+
array([[0, 1, 2],
|
| 146 |
+
[3, 4, 5],
|
| 147 |
+
[6, 7, 8]])
|
| 148 |
+
|
| 149 |
+
has different row- and column sums, resulting in two varieties
|
| 150 |
+
of the Laplacian matrix, using an in-degree, which is the default
|
| 151 |
+
|
| 152 |
+
>>> L_in_degree = csgraph.laplacian(G)
|
| 153 |
+
>>> L_in_degree
|
| 154 |
+
array([[ 9, -1, -2],
|
| 155 |
+
[-3, 8, -5],
|
| 156 |
+
[-6, -7, 7]])
|
| 157 |
+
|
| 158 |
+
or alternatively an out-degree
|
| 159 |
+
|
| 160 |
+
>>> L_out_degree = csgraph.laplacian(G, use_out_degree=True)
|
| 161 |
+
>>> L_out_degree
|
| 162 |
+
array([[ 3, -1, -2],
|
| 163 |
+
[-3, 8, -5],
|
| 164 |
+
[-6, -7, 13]])
|
| 165 |
+
|
| 166 |
+
Constructing a symmetric Laplacian matrix, one can add the two as
|
| 167 |
+
|
| 168 |
+
>>> L_in_degree + L_out_degree.T
|
| 169 |
+
array([[ 12, -4, -8],
|
| 170 |
+
[ -4, 16, -12],
|
| 171 |
+
[ -8, -12, 20]])
|
| 172 |
+
|
| 173 |
+
or use the ``symmetrized=True`` option
|
| 174 |
+
|
| 175 |
+
>>> csgraph.laplacian(G, symmetrized=True)
|
| 176 |
+
array([[ 12, -4, -8],
|
| 177 |
+
[ -4, 16, -12],
|
| 178 |
+
[ -8, -12, 20]])
|
| 179 |
+
|
| 180 |
+
that is equivalent to symmetrizing the original graph
|
| 181 |
+
|
| 182 |
+
>>> csgraph.laplacian(G + G.T)
|
| 183 |
+
array([[ 12, -4, -8],
|
| 184 |
+
[ -4, 16, -12],
|
| 185 |
+
[ -8, -12, 20]])
|
| 186 |
+
|
| 187 |
+
The goal of normalization is to make the non-zero diagonal entries
|
| 188 |
+
of the Laplacian matrix to be all unit, also scaling off-diagonal
|
| 189 |
+
entries correspondingly. The normalization can be done manually, e.g.,
|
| 190 |
+
|
| 191 |
+
>>> G = np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]])
|
| 192 |
+
>>> L, d = csgraph.laplacian(G, return_diag=True)
|
| 193 |
+
>>> L
|
| 194 |
+
array([[ 2, -1, -1],
|
| 195 |
+
[-1, 2, -1],
|
| 196 |
+
[-1, -1, 2]])
|
| 197 |
+
>>> d
|
| 198 |
+
array([2, 2, 2])
|
| 199 |
+
>>> scaling = np.sqrt(d)
|
| 200 |
+
>>> scaling
|
| 201 |
+
array([1.41421356, 1.41421356, 1.41421356])
|
| 202 |
+
>>> (1/scaling)*L*(1/scaling)
|
| 203 |
+
array([[ 1. , -0.5, -0.5],
|
| 204 |
+
[-0.5, 1. , -0.5],
|
| 205 |
+
[-0.5, -0.5, 1. ]])
|
| 206 |
+
|
| 207 |
+
Or using ``normed=True`` option
|
| 208 |
+
|
| 209 |
+
>>> L, d = csgraph.laplacian(G, return_diag=True, normed=True)
|
| 210 |
+
>>> L
|
| 211 |
+
array([[ 1. , -0.5, -0.5],
|
| 212 |
+
[-0.5, 1. , -0.5],
|
| 213 |
+
[-0.5, -0.5, 1. ]])
|
| 214 |
+
|
| 215 |
+
which now instead of the diagonal returns the scaling coefficients
|
| 216 |
+
|
| 217 |
+
>>> d
|
| 218 |
+
array([1.41421356, 1.41421356, 1.41421356])
|
| 219 |
+
|
| 220 |
+
Zero scaling coefficients are substituted with 1s, where scaling
|
| 221 |
+
has thus no effect, e.g.,
|
| 222 |
+
|
| 223 |
+
>>> G = np.array([[0, 0, 0], [0, 0, 1], [0, 1, 0]])
|
| 224 |
+
>>> G
|
| 225 |
+
array([[0, 0, 0],
|
| 226 |
+
[0, 0, 1],
|
| 227 |
+
[0, 1, 0]])
|
| 228 |
+
>>> L, d = csgraph.laplacian(G, return_diag=True, normed=True)
|
| 229 |
+
>>> L
|
| 230 |
+
array([[ 0., -0., -0.],
|
| 231 |
+
[-0., 1., -1.],
|
| 232 |
+
[-0., -1., 1.]])
|
| 233 |
+
>>> d
|
| 234 |
+
array([1., 1., 1.])
|
| 235 |
+
|
| 236 |
+
Only the symmetric normalization is implemented, resulting
|
| 237 |
+
in a symmetric Laplacian matrix if and only if its graph is symmetric
|
| 238 |
+
and has all non-negative degrees, like in the examples above.
|
| 239 |
+
|
| 240 |
+
The output Laplacian matrix is by default a dense array or a sparse
|
| 241 |
+
array or matrix inferring its class, shape, format, and dtype from
|
| 242 |
+
the input graph matrix:
|
| 243 |
+
|
| 244 |
+
>>> G = np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]]).astype(np.float32)
|
| 245 |
+
>>> G
|
| 246 |
+
array([[0., 1., 1.],
|
| 247 |
+
[1., 0., 1.],
|
| 248 |
+
[1., 1., 0.]], dtype=float32)
|
| 249 |
+
>>> csgraph.laplacian(G)
|
| 250 |
+
array([[ 2., -1., -1.],
|
| 251 |
+
[-1., 2., -1.],
|
| 252 |
+
[-1., -1., 2.]], dtype=float32)
|
| 253 |
+
|
| 254 |
+
but can alternatively be generated matrix-free as a LinearOperator:
|
| 255 |
+
|
| 256 |
+
>>> L = csgraph.laplacian(G, form="lo")
|
| 257 |
+
>>> L
|
| 258 |
+
<3x3 _CustomLinearOperator with dtype=float32>
|
| 259 |
+
>>> L(np.eye(3))
|
| 260 |
+
array([[ 2., -1., -1.],
|
| 261 |
+
[-1., 2., -1.],
|
| 262 |
+
[-1., -1., 2.]])
|
| 263 |
+
|
| 264 |
+
or as a lambda-function:
|
| 265 |
+
|
| 266 |
+
>>> L = csgraph.laplacian(G, form="function")
|
| 267 |
+
>>> L
|
| 268 |
+
<function _laplace.<locals>.<lambda> at 0x0000012AE6F5A598>
|
| 269 |
+
>>> L(np.eye(3))
|
| 270 |
+
array([[ 2., -1., -1.],
|
| 271 |
+
[-1., 2., -1.],
|
| 272 |
+
[-1., -1., 2.]])
|
| 273 |
+
|
| 274 |
+
The Laplacian matrix is used for
|
| 275 |
+
spectral data clustering and embedding
|
| 276 |
+
as well as for spectral graph partitioning.
|
| 277 |
+
Our final example illustrates the latter
|
| 278 |
+
for a noisy directed linear graph.
|
| 279 |
+
|
| 280 |
+
>>> from scipy.sparse import diags_array, random_array
|
| 281 |
+
>>> from scipy.sparse.linalg import lobpcg
|
| 282 |
+
|
| 283 |
+
Create a directed linear graph with ``N=35`` vertices
|
| 284 |
+
using a sparse adjacency matrix ``G``:
|
| 285 |
+
|
| 286 |
+
>>> N = 35
|
| 287 |
+
>>> G = diags_array(np.ones(N - 1), offsets=1, format="csr")
|
| 288 |
+
|
| 289 |
+
Fix a random seed ``rng`` and add a random sparse noise to the graph ``G``:
|
| 290 |
+
|
| 291 |
+
>>> rng = np.random.default_rng()
|
| 292 |
+
>>> G += 1e-2 * random_array((N, N), density=0.1, rng=rng)
|
| 293 |
+
|
| 294 |
+
Set initial approximations for eigenvectors:
|
| 295 |
+
|
| 296 |
+
>>> X = rng.random((N, 2))
|
| 297 |
+
|
| 298 |
+
The constant vector of ones is always a trivial eigenvector
|
| 299 |
+
of the non-normalized Laplacian to be filtered out:
|
| 300 |
+
|
| 301 |
+
>>> Y = np.ones((N, 1))
|
| 302 |
+
|
| 303 |
+
Alternating (1) the sign of the graph weights allows determining
|
| 304 |
+
labels for spectral max- and min- cuts in a single loop.
|
| 305 |
+
Since the graph is undirected, the option ``symmetrized=True``
|
| 306 |
+
must be used in the construction of the Laplacian.
|
| 307 |
+
The option ``normed=True`` cannot be used in (2) for the negative weights
|
| 308 |
+
here as the symmetric normalization evaluates square roots.
|
| 309 |
+
The option ``form="lo"`` in (2) is matrix-free, i.e., guarantees
|
| 310 |
+
a fixed memory footprint and read-only access to the graph.
|
| 311 |
+
Calling the eigenvalue solver ``lobpcg`` (3) computes the Fiedler vector
|
| 312 |
+
that determines the labels as the signs of its components in (5).
|
| 313 |
+
Since the sign in an eigenvector is not deterministic and can flip,
|
| 314 |
+
we fix the sign of the first component to be always +1 in (4).
|
| 315 |
+
|
| 316 |
+
>>> for cut in ["max", "min"]:
|
| 317 |
+
... G = -G # 1.
|
| 318 |
+
... L = csgraph.laplacian(G, symmetrized=True, form="lo") # 2.
|
| 319 |
+
... _, eves = lobpcg(L, X, Y=Y, largest=False, tol=1e-2) # 3.
|
| 320 |
+
... eves *= np.sign(eves[0, 0]) # 4.
|
| 321 |
+
... print(cut + "-cut labels:\\n", 1 * (eves[:, 0]>0)) # 5.
|
| 322 |
+
max-cut labels:
|
| 323 |
+
[1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1]
|
| 324 |
+
min-cut labels:
|
| 325 |
+
[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
|
| 326 |
+
|
| 327 |
+
As anticipated for a (slightly noisy) linear graph,
|
| 328 |
+
the max-cut strips all the edges of the graph coloring all
|
| 329 |
+
odd vertices into one color and all even vertices into another one,
|
| 330 |
+
while the balanced min-cut partitions the graph
|
| 331 |
+
in the middle by deleting a single edge.
|
| 332 |
+
Both determined partitions are optimal.
|
| 333 |
+
"""
|
| 334 |
+
is_pydata_sparse = is_pydata_spmatrix(csgraph)
|
| 335 |
+
if is_pydata_sparse:
|
| 336 |
+
pydata_sparse_cls = csgraph.__class__
|
| 337 |
+
csgraph = convert_pydata_sparse_to_scipy(csgraph)
|
| 338 |
+
if csgraph.ndim != 2 or csgraph.shape[0] != csgraph.shape[1]:
|
| 339 |
+
raise ValueError('csgraph must be a square matrix or array')
|
| 340 |
+
|
| 341 |
+
if normed and (
|
| 342 |
+
np.issubdtype(csgraph.dtype, np.signedinteger)
|
| 343 |
+
or np.issubdtype(csgraph.dtype, np.uint)
|
| 344 |
+
):
|
| 345 |
+
csgraph = csgraph.astype(np.float64)
|
| 346 |
+
|
| 347 |
+
if form == "array":
|
| 348 |
+
create_lap = (
|
| 349 |
+
_laplacian_sparse if issparse(csgraph) else _laplacian_dense
|
| 350 |
+
)
|
| 351 |
+
else:
|
| 352 |
+
create_lap = (
|
| 353 |
+
_laplacian_sparse_flo
|
| 354 |
+
if issparse(csgraph)
|
| 355 |
+
else _laplacian_dense_flo
|
| 356 |
+
)
|
| 357 |
+
|
| 358 |
+
degree_axis = 1 if use_out_degree else 0
|
| 359 |
+
|
| 360 |
+
lap, d = create_lap(
|
| 361 |
+
csgraph,
|
| 362 |
+
normed=normed,
|
| 363 |
+
axis=degree_axis,
|
| 364 |
+
copy=copy,
|
| 365 |
+
form=form,
|
| 366 |
+
dtype=dtype,
|
| 367 |
+
symmetrized=symmetrized,
|
| 368 |
+
)
|
| 369 |
+
if is_pydata_sparse:
|
| 370 |
+
lap = pydata_sparse_cls.from_scipy_sparse(lap)
|
| 371 |
+
if return_diag:
|
| 372 |
+
return lap, d
|
| 373 |
+
return lap
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
def _setdiag_dense(m, d):
|
| 377 |
+
step = len(d) + 1
|
| 378 |
+
m.flat[::step] = d
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
def _laplace(m, d):
|
| 382 |
+
return lambda v: v * d[:, np.newaxis] - m @ v
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
def _laplace_normed(m, d, nd):
|
| 386 |
+
laplace = _laplace(m, d)
|
| 387 |
+
return lambda v: nd[:, np.newaxis] * laplace(v * nd[:, np.newaxis])
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
def _laplace_sym(m, d):
|
| 391 |
+
return (
|
| 392 |
+
lambda v: v * d[:, np.newaxis]
|
| 393 |
+
- m @ v
|
| 394 |
+
- np.transpose(np.conjugate(np.transpose(np.conjugate(v)) @ m))
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def _laplace_normed_sym(m, d, nd):
|
| 399 |
+
laplace_sym = _laplace_sym(m, d)
|
| 400 |
+
return lambda v: nd[:, np.newaxis] * laplace_sym(v * nd[:, np.newaxis])
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
def _linearoperator(mv, shape, dtype):
|
| 404 |
+
return LinearOperator(matvec=mv, matmat=mv, shape=shape, dtype=dtype)
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
def _laplacian_sparse_flo(graph, normed, axis, copy, form, dtype, symmetrized):
|
| 408 |
+
# The keyword argument `copy` is unused and has no effect here.
|
| 409 |
+
del copy
|
| 410 |
+
|
| 411 |
+
if dtype is None:
|
| 412 |
+
dtype = graph.dtype
|
| 413 |
+
|
| 414 |
+
graph_sum = np.asarray(graph.sum(axis=axis)).ravel()
|
| 415 |
+
graph_diagonal = graph.diagonal()
|
| 416 |
+
diag = graph_sum - graph_diagonal
|
| 417 |
+
if symmetrized:
|
| 418 |
+
graph_sum += np.asarray(graph.sum(axis=1 - axis)).ravel()
|
| 419 |
+
diag = graph_sum - graph_diagonal - graph_diagonal
|
| 420 |
+
|
| 421 |
+
if normed:
|
| 422 |
+
isolated_node_mask = diag == 0
|
| 423 |
+
w = np.where(isolated_node_mask, 1, np.sqrt(diag))
|
| 424 |
+
if symmetrized:
|
| 425 |
+
md = _laplace_normed_sym(graph, graph_sum, 1.0 / w)
|
| 426 |
+
else:
|
| 427 |
+
md = _laplace_normed(graph, graph_sum, 1.0 / w)
|
| 428 |
+
if form == "function":
|
| 429 |
+
return md, w.astype(dtype, copy=False)
|
| 430 |
+
elif form == "lo":
|
| 431 |
+
m = _linearoperator(md, shape=graph.shape, dtype=dtype)
|
| 432 |
+
return m, w.astype(dtype, copy=False)
|
| 433 |
+
else:
|
| 434 |
+
raise ValueError(f"Invalid form: {form!r}")
|
| 435 |
+
else:
|
| 436 |
+
if symmetrized:
|
| 437 |
+
md = _laplace_sym(graph, graph_sum)
|
| 438 |
+
else:
|
| 439 |
+
md = _laplace(graph, graph_sum)
|
| 440 |
+
if form == "function":
|
| 441 |
+
return md, diag.astype(dtype, copy=False)
|
| 442 |
+
elif form == "lo":
|
| 443 |
+
m = _linearoperator(md, shape=graph.shape, dtype=dtype)
|
| 444 |
+
return m, diag.astype(dtype, copy=False)
|
| 445 |
+
else:
|
| 446 |
+
raise ValueError(f"Invalid form: {form!r}")
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
def _laplacian_sparse(graph, normed, axis, copy, form, dtype, symmetrized):
|
| 450 |
+
# The keyword argument `form` is unused and has no effect here.
|
| 451 |
+
del form
|
| 452 |
+
|
| 453 |
+
if dtype is None:
|
| 454 |
+
dtype = graph.dtype
|
| 455 |
+
|
| 456 |
+
needs_copy = False
|
| 457 |
+
if graph.format in ('lil', 'dok'):
|
| 458 |
+
m = graph.tocoo()
|
| 459 |
+
else:
|
| 460 |
+
m = graph
|
| 461 |
+
if copy:
|
| 462 |
+
needs_copy = True
|
| 463 |
+
|
| 464 |
+
if symmetrized:
|
| 465 |
+
m += m.T.conj()
|
| 466 |
+
|
| 467 |
+
w = np.asarray(m.sum(axis=axis)).ravel() - m.diagonal()
|
| 468 |
+
if normed:
|
| 469 |
+
m = m.tocoo(copy=needs_copy)
|
| 470 |
+
isolated_node_mask = (w == 0)
|
| 471 |
+
w = np.where(isolated_node_mask, 1, np.sqrt(w))
|
| 472 |
+
m.data /= w[m.row]
|
| 473 |
+
m.data /= w[m.col]
|
| 474 |
+
m.data *= -1
|
| 475 |
+
m.setdiag(1 - isolated_node_mask)
|
| 476 |
+
else:
|
| 477 |
+
if m.format == 'dia':
|
| 478 |
+
m = m.copy()
|
| 479 |
+
else:
|
| 480 |
+
m = m.tocoo(copy=needs_copy)
|
| 481 |
+
m.data *= -1
|
| 482 |
+
m.setdiag(w)
|
| 483 |
+
|
| 484 |
+
return m.astype(dtype, copy=False), w.astype(dtype)
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def _laplacian_dense_flo(graph, normed, axis, copy, form, dtype, symmetrized):
|
| 488 |
+
|
| 489 |
+
if copy:
|
| 490 |
+
m = np.array(graph)
|
| 491 |
+
else:
|
| 492 |
+
m = np.asarray(graph)
|
| 493 |
+
|
| 494 |
+
if dtype is None:
|
| 495 |
+
dtype = m.dtype
|
| 496 |
+
|
| 497 |
+
graph_sum = m.sum(axis=axis)
|
| 498 |
+
graph_diagonal = m.diagonal()
|
| 499 |
+
diag = graph_sum - graph_diagonal
|
| 500 |
+
if symmetrized:
|
| 501 |
+
graph_sum += m.sum(axis=1 - axis)
|
| 502 |
+
diag = graph_sum - graph_diagonal - graph_diagonal
|
| 503 |
+
|
| 504 |
+
if normed:
|
| 505 |
+
isolated_node_mask = diag == 0
|
| 506 |
+
w = np.where(isolated_node_mask, 1, np.sqrt(diag))
|
| 507 |
+
if symmetrized:
|
| 508 |
+
md = _laplace_normed_sym(m, graph_sum, 1.0 / w)
|
| 509 |
+
else:
|
| 510 |
+
md = _laplace_normed(m, graph_sum, 1.0 / w)
|
| 511 |
+
if form == "function":
|
| 512 |
+
return md, w.astype(dtype, copy=False)
|
| 513 |
+
elif form == "lo":
|
| 514 |
+
m = _linearoperator(md, shape=graph.shape, dtype=dtype)
|
| 515 |
+
return m, w.astype(dtype, copy=False)
|
| 516 |
+
else:
|
| 517 |
+
raise ValueError(f"Invalid form: {form!r}")
|
| 518 |
+
else:
|
| 519 |
+
if symmetrized:
|
| 520 |
+
md = _laplace_sym(m, graph_sum)
|
| 521 |
+
else:
|
| 522 |
+
md = _laplace(m, graph_sum)
|
| 523 |
+
if form == "function":
|
| 524 |
+
return md, diag.astype(dtype, copy=False)
|
| 525 |
+
elif form == "lo":
|
| 526 |
+
m = _linearoperator(md, shape=graph.shape, dtype=dtype)
|
| 527 |
+
return m, diag.astype(dtype, copy=False)
|
| 528 |
+
else:
|
| 529 |
+
raise ValueError(f"Invalid form: {form!r}")
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
def _laplacian_dense(graph, normed, axis, copy, form, dtype, symmetrized):
|
| 533 |
+
|
| 534 |
+
if form != "array":
|
| 535 |
+
raise ValueError(f'{form!r} must be "array"')
|
| 536 |
+
|
| 537 |
+
if dtype is None:
|
| 538 |
+
dtype = graph.dtype
|
| 539 |
+
|
| 540 |
+
if copy:
|
| 541 |
+
m = np.array(graph)
|
| 542 |
+
else:
|
| 543 |
+
m = np.asarray(graph)
|
| 544 |
+
|
| 545 |
+
if dtype is None:
|
| 546 |
+
dtype = m.dtype
|
| 547 |
+
|
| 548 |
+
if symmetrized:
|
| 549 |
+
m += m.T.conj()
|
| 550 |
+
np.fill_diagonal(m, 0)
|
| 551 |
+
w = m.sum(axis=axis)
|
| 552 |
+
if normed:
|
| 553 |
+
isolated_node_mask = (w == 0)
|
| 554 |
+
w = np.where(isolated_node_mask, 1, np.sqrt(w))
|
| 555 |
+
m /= w
|
| 556 |
+
m /= w[:, np.newaxis]
|
| 557 |
+
m *= -1
|
| 558 |
+
_setdiag_dense(m, 1 - isolated_node_mask)
|
| 559 |
+
else:
|
| 560 |
+
m *= -1
|
| 561 |
+
_setdiag_dense(m, w)
|
| 562 |
+
|
| 563 |
+
return m.astype(dtype, copy=False), w.astype(dtype, copy=False)
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_matching.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:024ed86a38fcc11f573e9ab45e1ab4a67afacc5943ddd3f898fd615e3af40adf
|
| 3 |
+
size 357288
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_reordering.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:19e0904338ccf737ca9620943f93a252ec8e7f480ba209836955abd0a71ac37e
|
| 3 |
+
size 331928
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_shortest_path.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0657b6c19490df55f526d08bc9e6c0f5d40a8bd7e04521feec1bf075c15d477c
|
| 3 |
+
size 576328
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_tools.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7c2bb28014fe407d3bbdd94563115b1210b40a90b0ee85264186ab4d22efccd1
|
| 3 |
+
size 218744
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/_validation.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from scipy.sparse import issparse
|
| 3 |
+
from scipy.sparse._sputils import convert_pydata_sparse_to_scipy
|
| 4 |
+
from scipy.sparse.csgraph._tools import (
|
| 5 |
+
csgraph_to_dense, csgraph_from_dense,
|
| 6 |
+
csgraph_masked_from_dense, csgraph_from_masked
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
DTYPE = np.float64
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def validate_graph(csgraph, directed, dtype=DTYPE,
|
| 13 |
+
csr_output=True, dense_output=True,
|
| 14 |
+
copy_if_dense=False, copy_if_sparse=False,
|
| 15 |
+
null_value_in=0, null_value_out=np.inf,
|
| 16 |
+
infinity_null=True, nan_null=True):
|
| 17 |
+
"""Routine for validation and conversion of csgraph inputs"""
|
| 18 |
+
if not (csr_output or dense_output):
|
| 19 |
+
raise ValueError("Internal: dense or csr output must be true")
|
| 20 |
+
|
| 21 |
+
accept_fv = [null_value_in]
|
| 22 |
+
if infinity_null:
|
| 23 |
+
accept_fv.append(np.inf)
|
| 24 |
+
if nan_null:
|
| 25 |
+
accept_fv.append(np.nan)
|
| 26 |
+
csgraph = convert_pydata_sparse_to_scipy(csgraph, accept_fv=accept_fv)
|
| 27 |
+
|
| 28 |
+
# if undirected and csc storage, then transposing in-place
|
| 29 |
+
# is quicker than later converting to csr.
|
| 30 |
+
if (not directed) and issparse(csgraph) and csgraph.format == "csc":
|
| 31 |
+
csgraph = csgraph.T
|
| 32 |
+
|
| 33 |
+
if issparse(csgraph):
|
| 34 |
+
if csr_output:
|
| 35 |
+
csgraph = csgraph.tocsr(copy=copy_if_sparse).astype(DTYPE, copy=False)
|
| 36 |
+
else:
|
| 37 |
+
csgraph = csgraph_to_dense(csgraph, null_value=null_value_out)
|
| 38 |
+
elif np.ma.isMaskedArray(csgraph):
|
| 39 |
+
if dense_output:
|
| 40 |
+
mask = csgraph.mask
|
| 41 |
+
csgraph = np.array(csgraph.data, dtype=DTYPE, copy=copy_if_dense)
|
| 42 |
+
csgraph[mask] = null_value_out
|
| 43 |
+
else:
|
| 44 |
+
csgraph = csgraph_from_masked(csgraph)
|
| 45 |
+
else:
|
| 46 |
+
if dense_output:
|
| 47 |
+
csgraph = csgraph_masked_from_dense(csgraph,
|
| 48 |
+
copy=copy_if_dense,
|
| 49 |
+
null_value=null_value_in,
|
| 50 |
+
nan_null=nan_null,
|
| 51 |
+
infinity_null=infinity_null)
|
| 52 |
+
mask = csgraph.mask
|
| 53 |
+
csgraph = np.asarray(csgraph.data, dtype=DTYPE)
|
| 54 |
+
csgraph[mask] = null_value_out
|
| 55 |
+
else:
|
| 56 |
+
csgraph = csgraph_from_dense(csgraph, null_value=null_value_in,
|
| 57 |
+
infinity_null=infinity_null,
|
| 58 |
+
nan_null=nan_null)
|
| 59 |
+
|
| 60 |
+
if csgraph.ndim != 2:
|
| 61 |
+
raise ValueError("compressed-sparse graph must be 2-D")
|
| 62 |
+
|
| 63 |
+
if csgraph.shape[0] != csgraph.shape[1]:
|
| 64 |
+
raise ValueError("compressed-sparse graph must be shape (N, N)")
|
| 65 |
+
|
| 66 |
+
return csgraph
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/tests/__init__.py
ADDED
|
File without changes
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/tests/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (184 Bytes). View file
|
|
|
infer_4_47_1/lib/python3.10/site-packages/scipy/sparse/csgraph/tests/__pycache__/test_connected_components.cpython-310.pyc
ADDED
|
Binary file (3.22 kB). View file
|
|
|