-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
networkx: annotate the linalg module #14551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hamdanal
wants to merge
1
commit into
python:main
Choose a base branch
from
hamdanal:networkx-linalg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from typing import TypeVar | ||
from typing_extensions import TypeAlias | ||
|
||
import numpy as np | ||
|
||
_G = TypeVar("_G", bound=np.generic) | ||
|
||
# numpy aliases | ||
Array1D: TypeAlias = np.ndarray[tuple[int], np.dtype[_G]] | ||
Array2D: TypeAlias = np.ndarray[tuple[int, int], np.dtype[_G]] | ||
Seed: TypeAlias = int | np.random.Generator | np.random.RandomState |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,45 @@ | ||
from typing import Literal | ||
|
||
import numpy as np | ||
from networkx._typing import Array1D, Seed | ||
from networkx.classes.graph import Graph, _Node | ||
from networkx.utils.backends import _dispatchable | ||
|
||
__all__ = ["algebraic_connectivity", "fiedler_vector", "spectral_ordering", "spectral_bisection"] | ||
|
||
class _PCGSolver: | ||
def __init__(self, A, M) -> None: ... | ||
def solve(self, B, tol): ... | ||
|
||
class _LUSolver: | ||
def __init__(self, A) -> None: ... | ||
def solve(self, B, tol=None): ... | ||
|
||
@_dispatchable | ||
def algebraic_connectivity( | ||
G, weight: str = "weight", normalized: bool = False, tol: float = 1e-08, method: str = "tracemin_pcg", seed=None | ||
): ... | ||
G: Graph[_Node], | ||
weight: str | None = "weight", | ||
normalized: bool = False, | ||
tol: float = 1e-08, | ||
method: Literal["tracemin_pcg", "tracemin_lu", "lanczos", "lobpcg"] = "tracemin_pcg", | ||
seed: Seed | None = None, | ||
) -> float: ... | ||
@_dispatchable | ||
def fiedler_vector( | ||
G, weight: str = "weight", normalized: bool = False, tol: float = 1e-08, method: str = "tracemin_pcg", seed=None | ||
): ... | ||
G: Graph[_Node], | ||
weight: str | None = "weight", | ||
normalized: bool = False, | ||
tol: float = 1e-08, | ||
method: Literal["tracemin_pcg", "tracemin_lu", "lanczos", "lobpcg"] = "tracemin_pcg", | ||
seed: Seed | None = None, | ||
) -> Array1D[np.float64]: ... | ||
@_dispatchable | ||
def spectral_ordering( | ||
G, weight: str = "weight", normalized: bool = False, tol: float = 1e-08, method: str = "tracemin_pcg", seed=None | ||
): ... | ||
G: Graph[_Node], | ||
weight: str | None = "weight", | ||
normalized: bool = False, | ||
tol: float = 1e-08, | ||
method: Literal["tracemin_pcg", "tracemin_lu", "lanczos", "lobpcg"] = "tracemin_pcg", | ||
seed: Seed | None = None, | ||
) -> list[_Node]: ... | ||
@_dispatchable | ||
def spectral_bisection( | ||
G, weight: str = "weight", normalized: bool = False, tol: float = 1e-08, method: str = "tracemin_pcg", seed=None | ||
): ... | ||
G: Graph[_Node], | ||
weight: str | None = "weight", | ||
normalized: bool = False, | ||
tol: float = 1e-08, | ||
method: Literal["tracemin_pcg", "tracemin_lu", "lanczos", "lobpcg"] = "tracemin_pcg", | ||
seed: Seed | None = None, | ||
) -> tuple[set[_Node], set[_Node]]: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,41 @@ | ||
from _typeshed import Incomplete | ||
from collections.abc import Collection | ||
from typing import Any, Literal | ||
|
||
from networkx._typing import Array2D | ||
from networkx.classes.graph import Graph, _Node | ||
from networkx.utils.backends import _dispatchable | ||
from numpy.typing import DTypeLike | ||
from scipy.sparse import lil_array # type: ignore[import-untyped] # pyright: ignore[reportMissingImports] | ||
|
||
__all__ = ["attr_matrix", "attr_sparse_matrix"] | ||
|
||
@_dispatchable | ||
def attr_matrix(G, edge_attr=None, node_attr=None, normalized: bool = False, rc_order=None, dtype=None, order=None): ... | ||
def attr_matrix( | ||
G: Graph[_Node], | ||
edge_attr: str | None = None, | ||
node_attr: str | None = None, # runtime also accepts `Callable[[_Node], object]`, but it is not documented | ||
normalized: bool = False, # runtime also accepts `Callable[[_Node, _Node], object]`, but it is not documented | ||
rc_order: Collection[_Node] | None = None, | ||
dtype: DTypeLike | None = None, | ||
order: Literal["C", "F"] | None = None, | ||
# TODO: overload on rc_order and node_attr | ||
# (rc_order:[node], node_attr:None) -> 2D-array | ||
# (rc_order:[any], node_attr:str) -> 2D-array | ||
# (rc_order:None, node_attr:None) -> (2D-array, list[node]) | ||
# (rc_order:None, node_attr:str) -> (2D-array, list[any]) | ||
) -> Array2D[Incomplete] | tuple[Array2D[Incomplete], list[_Node] | list[Any]]: ... | ||
@_dispatchable | ||
def attr_sparse_matrix(G, edge_attr=None, node_attr=None, normalized: bool = False, rc_order=None, dtype=None): ... | ||
def attr_sparse_matrix( | ||
G: Graph[_Node], | ||
edge_attr: str | None = None, | ||
node_attr: str | None = None, # runtime also accepts `Callable[[_Node], object]`, but it is not documented | ||
normalized: bool = False, # runtime also accepts `Callable[[_Node, _Node], object]`, but it is not documented | ||
rc_order: Collection[_Node] | None = None, | ||
dtype: DTypeLike | None = None, | ||
# TODO: overload on rc_order and node_attr | ||
# (rc_order:[node], node_attr:None) -> lil_array | ||
# (rc_order:[any], node_attr:str) -> lil_array | ||
# (rc_order:None, node_attr:None) -> (lil_array, list[node]) | ||
# (rc_order:None, node_attr:str) -> (lil_array, list[any]) | ||
) -> lil_array | tuple[lil_array, list[_Node] | list[Any]]: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from _typeshed import Incomplete | ||
from collections.abc import Collection | ||
|
||
from networkx.classes.graph import Graph, _Node | ||
from networkx.utils.backends import _dispatchable | ||
from scipy.sparse import csr_array # type: ignore[import-untyped] # pyright: ignore[reportMissingImports] | ||
|
||
__all__ = ["bethe_hessian_matrix"] | ||
|
||
@_dispatchable | ||
def bethe_hessian_matrix(G, r=None, nodelist: Collection[Incomplete] | None = None): ... | ||
def bethe_hessian_matrix(G: Graph[_Node], r: float | None = None, nodelist: Collection[_Node] | None = None) -> csr_array: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
from _typeshed import Incomplete | ||
from collections.abc import Collection | ||
from collections.abc import Collection, Hashable | ||
|
||
from networkx.classes.graph import Graph, _Node | ||
from networkx.utils.backends import _dispatchable | ||
from numpy.typing import DTypeLike | ||
from scipy.sparse import csc_array, csr_array # type: ignore[import-untyped] # pyright: ignore[reportMissingImports] | ||
|
||
__all__ = ["incidence_matrix", "adjacency_matrix"] | ||
|
||
@_dispatchable | ||
def incidence_matrix(G, nodelist: Collection[Incomplete] | None = None, edgelist=None, oriented: bool = False, weight=None): ... | ||
def incidence_matrix( | ||
G: Graph[_Node], | ||
nodelist: Collection[_Node] | None = None, | ||
edgelist: ( | ||
Collection[ | ||
# Requiring tuples to represent an edge might be too strict as runtime does not check the type of | ||
# the collection. We can replace the tuples by `Collection[_Node | Hashable]` if people complain. | ||
tuple[_Node, _Node] # for normal graphs, this is (u, v) | ||
| tuple[_Node, _Node, Hashable] # for multigraphs, this is (u, v, key) | ||
] | ||
| None | ||
) = None, | ||
oriented: bool = False, | ||
weight: str | None = None, | ||
*, | ||
dtype: DTypeLike | None = None, | ||
) -> csc_array: ... | ||
@_dispatchable | ||
def adjacency_matrix(G, nodelist: Collection[Incomplete] | None = None, dtype=None, weight: str = "weight"): ... | ||
def adjacency_matrix( | ||
G: Graph[_Node], nodelist: Collection[_Node] | None = None, dtype: DTypeLike | None = None, weight: str | None = "weight" | ||
) -> csr_array: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
from _typeshed import Incomplete | ||
from collections.abc import Collection | ||
|
||
import numpy as np | ||
from networkx._typing import Array2D | ||
from networkx.classes.digraph import DiGraph | ||
from networkx.classes.graph import Graph, _Node | ||
from networkx.utils.backends import _dispatchable | ||
|
||
__all__ = ["modularity_matrix", "directed_modularity_matrix"] | ||
|
||
@_dispatchable | ||
def modularity_matrix(G, nodelist: Collection[Incomplete] | None = None, weight=None): ... | ||
def modularity_matrix( | ||
G: Graph[_Node], nodelist: Collection[_Node] | None = None, weight: str | None = None | ||
) -> Array2D[np.float64]: ... | ||
@_dispatchable | ||
def directed_modularity_matrix(G, nodelist: Collection[Incomplete] | None = None, weight=None): ... | ||
def directed_modularity_matrix( | ||
G: DiGraph[_Node], nodelist: Collection[_Node] | None = None, weight: str | None = None | ||
) -> Array2D[np.float64]: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a comment to the top of this file: