Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,6 @@ dmypy.json

# docs
docs/source/api/*rst

# VSCode
.vscode/
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ default_stages:
minimum_pre_commit_version: 2.9.0
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
rev: v0.991
hooks:
- id: mypy
additional_dependencies: [numpy==1.20.0, scipy>=1.6.0]
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 22.12.0
hooks:
- id: black
additional_dependencies: [toml]
- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
rev: 5.11.4
hooks:
- id: isort
additional_dependencies: [toml]
Expand All @@ -28,12 +28,12 @@ repos:
- id: yesqa
additional_dependencies: [flake8-tidy-imports, flake8-docstrings, flake8-rst-docstrings, flake8-comprehensions, flake8-bugbear, flake8-logging-format, flake8-blind-except, flake8-builtins, flake8-pytest-style, flake8-string-format]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.4.0
rev: v2.5.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '4', --preserve-quotes]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: detect-private-key
- id: check-merge-conflict
Expand All @@ -55,13 +55,13 @@ repos:
- id: check-yaml
- id: check-toml
- id: requirements-txt-fixer
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-tidy-imports, flake8-docstrings, flake8-rst-docstrings, flake8-comprehensions, flake8-bugbear, flake8-logging-format, flake8-blind-except, flake8-builtins, flake8-pytest-style, flake8-string-format]
- repo: https://github.com/myint/autoflake
rev: v1.7.1
rev: v2.0.0
hooks:
- id: autoflake
args: [--in-place, --remove-all-unused-imports, --remove-unused-variable, --ignore-init-module-imports]
Expand All @@ -77,7 +77,7 @@ repos:
- id: blacken-docs
additional_dependencies: [black==22.10.0]
- repo: https://github.com/asottile/pyupgrade
rev: v3.0.0
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py3-plus, --py37-plus]
Expand All @@ -91,6 +91,6 @@ repos:
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/PyCQA/doc8
rev: v1.0.0
rev: v1.1.1
hooks:
- id: doc8
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
:target: https://doi.org/10.5281/zenodo.6914001
:alt: Zenodo

.. |CI| image:: https://img.shields.io/github/workflow/status/msmdev/pygpcca/CI/main
.. |CI| image:: https://img.shields.io/github/actions/workflow/status/msmdev/pygpcca/ci.yml?branch=main
:target: https://github.com/msmdev/pygpcca/actions
:alt: CI

Expand Down
5 changes: 5 additions & 0 deletions docs/source/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ Röblitz
Sikorski
Zuse
mypy
numpy
Zenodo
Konstantin
pre
intersphinx
8 changes: 5 additions & 3 deletions pygpcca/_sorted_schur.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@
import numpy as np

from pygpcca.utils._docs import d
from pygpcca.utils._checks import assert_petsc_real_scalar_type
from pygpcca._sort_real_schur import sort_real_schur
from pygpcca.utils._constants import EPS, DEFAULT_SCHUR_METHOD, NO_PETSC_SLEPC_FOUND_MSG

try:
import petsc4py
import slepc4py
except ImportError:
petsc4py = None
slepc4py = None

assert_petsc_real_scalar_type()
except (ImportError, TypeError):
petsc4py = slepc4py = None

__all__ = ["sorted_schur"]

Expand Down
23 changes: 22 additions & 1 deletion pygpcca/utils/_checks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Tuple, Union, Optional
import logging

from scipy.sparse import issparse, spmatrix
import numpy as np

from pygpcca.utils._docs import d

__all__ = ["ensure_ndarray_or_sparse"]
__all__ = ["ensure_ndarray_or_sparse", "assert_petsc_real_scalar_type"]


@d.get_sections(base="assert_array", sections=["Parameters"])
Expand Down Expand Up @@ -122,3 +123,23 @@ def ensure_ndarray_or_sparse(
assert_array(A, shape=shape, uniform=uniform, ndim=ndim, size=size, dtype=dtype, kind=kind)

return A


def assert_petsc_real_scalar_type() -> None:
"""Check if PETSc was compiled using `–with-scalar-type=real`."""
try:
from petsc4py import PETSc

if np.isrealobj(PETSc.ScalarType()):
return
else:
raise TypeError(
"PETSc was compiled with complex scalar type. "
"Please recompile PETSc with `--with-scalar-type=real` or "
"provide alternative `PETSC_ARCH=...` with correct scalar type."
)
except Exception as e:
logging.error(
f"Unable to determine PETSc's scalar type. Reason: `{e}`. Assuming true, " # noqa: G004
f"but please ensure that PETSc was compiled using `--with-scalar-type=real`.",
)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ deps =
slepc: petsc4py==3.18.0
slepc: slepc==3.18.0
slepc: slepc4py==3.18.0
passenv = TOXENV CI CODECOV_* GITHUB_ACTIONS PETSC_* SLEPC_*
passenv = TOXENV,CI,CODECOV_*,GITHUB_ACTIONS,PETSC_*,SLEPC_*
usedevelop = true
commands = python -m pytest --cov --cov-append --cov-report=term-missing --cov-config={toxinidir}/tox.ini --ignore docs/ {posargs:-vv}

Expand Down