Skip to content

Commit 0cd212d

Browse files
authored
🐛 sparse.csgraph: add missing callable return type for laplacian with form="function" (#1583)
🐛 `sparse.csgraph`: add missing callable return type for `laplacian` with `form="function"`
1 parent 22e8694 commit 0cd212d

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

scipy-stubs/sparse/csgraph/_laplacian.pyi

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections.abc import Callable
12
from typing import Literal, TypeAlias, overload
23

34
import numpy.typing as npt
@@ -7,13 +8,38 @@ import optype.numpy.compat as npc
78
from scipy.sparse._base import _spbase
89
from scipy.sparse.linalg import LinearOperator
910

11+
_LaplacianFunction: TypeAlias = Callable[[onp.ToComplex2D], onp.Array2D[npc.number]]
1012
_LaplacianMatrix: TypeAlias = onp.Array2D[npc.number] | _spbase | LinearOperator
1113
_LaplacianDiag: TypeAlias = onp.Array1D[npc.number]
1214
_ToCSGraph: TypeAlias = onp.ToComplex2D | _spbase
13-
_Form: TypeAlias = Literal["array", "function", "lo"]
15+
_Form: TypeAlias = Literal["array", "lo"]
1416

1517
###
1618

19+
@overload
20+
def laplacian(
21+
csgraph: _ToCSGraph,
22+
normed: bool = False,
23+
return_diag: onp.ToFalse = False,
24+
use_out_degree: bool = False,
25+
*,
26+
copy: bool = True,
27+
form: Literal["function"],
28+
dtype: npt.DTypeLike | None = None,
29+
symmetrized: bool = False,
30+
) -> _LaplacianFunction: ...
31+
@overload
32+
def laplacian(
33+
csgraph: _ToCSGraph,
34+
normed: bool = False,
35+
*,
36+
return_diag: onp.ToTrue,
37+
use_out_degree: bool = False,
38+
copy: bool = True,
39+
form: Literal["function"],
40+
dtype: npt.DTypeLike | None = None,
41+
symmetrized: bool = False,
42+
) -> tuple[_LaplacianFunction, _LaplacianDiag]: ...
1743
@overload
1844
def laplacian(
1945
csgraph: _ToCSGraph,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from collections.abc import Callable
2+
3+
import numpy as np
4+
import numpy.typing as npt
5+
import optype as op
6+
import optype.numpy as onp
7+
import optype.numpy.compat as npc
8+
9+
from scipy.sparse.csgraph import laplacian
10+
11+
_f64_nd: npt.NDArray[np.float64]
12+
13+
fn = laplacian(_f64_nd, form="function")
14+
op.test.assert_subtype[Callable[[onp.ToComplex2D], onp.Array2D[npc.number]]](fn)
15+
16+
fn2, diag = laplacian(_f64_nd, form="function", return_diag=True)
17+
op.test.assert_subtype[Callable[[onp.ToComplex2D], onp.Array2D[npc.number]]](fn2)
18+
op.test.assert_subtype[onp.Array1D[npc.number]](diag)

0 commit comments

Comments
 (0)