-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨
sparse.linalg
: complete LaplacianNd
& accept in dtypes in `Line…
…arOperator` (#301)
- Loading branch information
Showing
2 changed files
with
65 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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 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,44 +1,49 @@ | ||
from scipy._typing import Untyped | ||
from typing import Any, Final, Generic, Literal, TypeAlias, overload | ||
from typing_extensions import TypeVar | ||
|
||
import numpy as np | ||
import optype.numpy as onp | ||
from scipy.sparse import bsr_array, coo_array, csc_array, csr_array, dia_array, dok_array, lil_array | ||
from scipy.sparse.linalg import LinearOperator | ||
|
||
__all__ = ["LaplacianNd"] | ||
|
||
class LaplacianNd(LinearOperator): | ||
grid_shape: Untyped | ||
boundary_conditions: Untyped | ||
|
||
def __init__(self, /, grid_shape: Untyped, *, boundary_conditions: str = "neumann", dtype: Untyped = ...) -> None: ... | ||
def eigenvalues(self, /, m: Untyped | None = None) -> Untyped: ... | ||
def eigenvectors(self, /, m: Untyped | None = None) -> Untyped: ... | ||
def toarray(self, /) -> Untyped: ... | ||
def tosparse(self, /) -> Untyped: ... | ||
|
||
class Sakurai(LinearOperator): | ||
n: Untyped | ||
def __init__(self, /, n: Untyped, dtype: Untyped = ...) -> None: ... | ||
def eigenvalues(self, /, m: Untyped | None = None) -> Untyped: ... | ||
def tobanded(self, /) -> Untyped: ... | ||
def tosparse(self, /) -> Untyped: ... | ||
def toarray(self, /) -> Untyped: ... | ||
|
||
class MikotaM(LinearOperator): | ||
def __init__(self, /, shape: Untyped, dtype: Untyped = ...) -> None: ... | ||
def tobanded(self, /) -> Untyped: ... | ||
def tosparse(self, /) -> Untyped: ... | ||
def toarray(self, /) -> Untyped: ... | ||
|
||
class MikotaK(LinearOperator): | ||
def __init__(self, /, shape: Untyped, dtype: Untyped = ...) -> None: ... | ||
def tobanded(self, /) -> Untyped: ... | ||
def tosparse(self, /) -> Untyped: ... | ||
def toarray(self, /) -> Untyped: ... | ||
|
||
class MikotaPair: | ||
n: Untyped | ||
dtype: Untyped | ||
shape: Untyped | ||
m: Untyped | ||
k: Untyped | ||
|
||
def __init__(self, /, n: Untyped, dtype: Untyped = ...) -> None: ... | ||
def eigenvalues(self, /, m: Untyped | None = None) -> Untyped: ... | ||
_SCT = TypeVar("_SCT", bound=np.number[Any]) | ||
_SCT_co = TypeVar("_SCT_co", bound=np.number[Any], default=np.int8, covariant=True) | ||
|
||
_BoundaryConditions: TypeAlias = Literal["dirichlet", "neumann", "periodic"] | ||
_ToDType: TypeAlias = type[_SCT] | np.dtype[_SCT] | onp.HasDType[np.dtype[_SCT]] | ||
|
||
# because `scipy.sparse.sparray` does not implement anything :( | ||
_SpArray: TypeAlias = bsr_array | coo_array | csc_array | csr_array | dia_array | dok_array | lil_array | ||
|
||
### | ||
|
||
class LaplacianNd(LinearOperator[_SCT_co], Generic[_SCT_co]): | ||
grid_shape: Final[onp.AtLeast1D] | ||
boundary_conditions: Final[_BoundaryConditions] | ||
|
||
@overload # default dtype (int8) | ||
def __init__( | ||
self: LaplacianNd[np.int8], | ||
/, | ||
grid_shape: onp.AtLeast1D, | ||
*, | ||
boundary_conditions: _BoundaryConditions = "neumann", | ||
dtype: _ToDType[np.int8] = ..., # default: np.int8 | ||
) -> None: ... | ||
@overload # know dtype | ||
def __init__( | ||
self, | ||
/, | ||
grid_shape: onp.AtLeast1D, | ||
*, | ||
boundary_conditions: _BoundaryConditions = "neumann", | ||
dtype: _ToDType[_SCT_co] = ..., # default: np.int8 | ||
) -> None: ... | ||
|
||
# | ||
def eigenvalues(self, /, m: onp.ToJustInt | None = None) -> onp.Array1D[np.float64]: ... | ||
def eigenvectors(self, /, m: onp.ToJustInt | None = None) -> onp.Array2D[np.float64]: ... | ||
def toarray(self, /) -> onp.Array2D[_SCT_co]: ... | ||
def tosparse(self, /) -> _SpArray: ... |