Skip to content

Commit a218560

Browse files
committed
sparse.linalg: type-tests for the LinearOperator constructor
1 parent adfe788 commit a218560

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from typing import Any, assert_type
2+
3+
import numpy as np
4+
import numpy.typing as npt
5+
6+
from scipy.sparse.linalg import LinearOperator
7+
from scipy.sparse.linalg._interface import _CustomLinearOperator
8+
9+
int_type: type[int]
10+
float_type: type[float]
11+
complex_type: type[complex]
12+
13+
###
14+
15+
def mv(v: npt.NDArray[np.float64 | np.complex128]) -> npt.NDArray[np.float64 | np.complex128]: ...
16+
17+
assert_type(LinearOperator((2, 2), matvec=mv, dtype=np.int16), _CustomLinearOperator[np.int16])
18+
assert_type(LinearOperator((2, 2), matvec=mv, dtype=int), _CustomLinearOperator[np.int_])
19+
assert_type(LinearOperator((2, 2), matvec=mv, dtype=float), _CustomLinearOperator[np.float64])
20+
assert_type(LinearOperator((2, 2), matvec=mv, dtype=complex), _CustomLinearOperator[np.complex128])
21+
assert_type(LinearOperator((2, 2), matvec=mv), _CustomLinearOperator[np.int8 | Any])
22+
23+
# TODO(jorenham): add more tests for `LinearOperator`
24+
# TODO(jorenham): add tests for `aslinearoperator`

0 commit comments

Comments
 (0)