kernelforge 0.1.16__tar.gz → 0.1.17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {kernelforge-0.1.16 → kernelforge-0.1.17}/.github/workflows/ci.yml +2 -2
- {kernelforge-0.1.16 → kernelforge-0.1.17}/.github/workflows/code-quality.yml +13 -12
- {kernelforge-0.1.16 → kernelforge-0.1.17}/.github/workflows/release.yaml +2 -2
- {kernelforge-0.1.16 → kernelforge-0.1.17}/PKG-INFO +2 -2
- {kernelforge-0.1.16 → kernelforge-0.1.17}/pyproject.toml +5 -60
- kernelforge-0.1.17/python/kernelforge/_cholesky.pyi +21 -0
- kernelforge-0.1.17/python/kernelforge/_fchl19.pyi +81 -0
- kernelforge-0.1.17/python/kernelforge/_invdist.pyi +10 -0
- kernelforge-0.1.17/python/kernelforge/_kernels.pyi +29 -0
- kernelforge-0.1.17/python/kernelforge/py.typed +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/tests/test_cholesky.py +5 -5
- {kernelforge-0.1.16 → kernelforge-0.1.17}/tests/test_fchl19.py +22 -23
- {kernelforge-0.1.16 → kernelforge-0.1.17}/tests/test_fchl19_gradient.py +5 -5
- {kernelforge-0.1.16 → kernelforge-0.1.17}/tests/test_hessian.py +6 -6
- {kernelforge-0.1.16 → kernelforge-0.1.17}/tests/test_invdist.py +4 -4
- {kernelforge-0.1.16 → kernelforge-0.1.17}/tests/test_jacobian.py +7 -7
- {kernelforge-0.1.16 → kernelforge-0.1.17}/tests/test_kernels.py +7 -39
- {kernelforge-0.1.16 → kernelforge-0.1.17}/tests/test_rfp.py +5 -5
- kernelforge-0.1.17/wheelhouse/kernelforge-0.1.17-cp310-cp310-macosx_15_0_arm64.whl +0 -0
- kernelforge-0.1.16/wheelhouse/kernelforge-0.1.16-cp311-cp311-macosx_15_0_arm64.whl → kernelforge-0.1.17/wheelhouse/kernelforge-0.1.17-cp311-cp311-macosx_15_0_arm64.whl +0 -0
- kernelforge-0.1.16/wheelhouse/kernelforge-0.1.16-cp312-cp312-macosx_15_0_arm64.whl → kernelforge-0.1.17/wheelhouse/kernelforge-0.1.17-cp312-cp312-macosx_15_0_arm64.whl +0 -0
- kernelforge-0.1.16/wheelhouse/kernelforge-0.1.16-cp313-cp313-macosx_15_0_arm64.whl → kernelforge-0.1.17/wheelhouse/kernelforge-0.1.17-cp313-cp313-macosx_15_0_arm64.whl +0 -0
- kernelforge-0.1.17/wheelhouse/kernelforge-0.1.17-cp314-cp314-macosx_15_0_arm64.whl +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/.clang-format +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/.clang-tidy +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/.gitignore +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/.pre-commit-config.yaml +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/CMakeLists.txt +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/LICENSE +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/Makefile +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/README.md +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/environments/environment-dev-macos.yaml +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/environments/environment-dev.yaml +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/examples/desc_hess-gauss.ipynb +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/examples/desc_hess.ipynb +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/examples/ethanol.sdf +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/examples/fchl_example.ipynb +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/examples/fchl_hess.ipynb +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/examples/qm7_example.ipynb +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/examples/regression_ethanol-Copy1.ipynb +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/examples/regression_forces.ipynb +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/examples/sgdml.ipynb +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/pytest.ini +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/python/kernelforge/__init__.py +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/python/kernelforge/cli.py +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/aligned_alloc64.hpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/bindings.cpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/bindings_cholesky.cpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/bindings_fchl19.cpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/bindings_kernels.cpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/cholesky.cpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/cholesky.hpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/constants.hpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/fchl19_representation.cpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/fchl19_representation.hpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/invdist.cpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/invdist.hpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/invdist_bindings.cpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/kernels.cpp +0 -0
- {kernelforge-0.1.16 → kernelforge-0.1.17}/src/kernels.hpp +0 -0
|
@@ -37,7 +37,7 @@ jobs:
|
|
|
37
37
|
CMAKE_PREFIX_PATH: /opt/homebrew/opt/libomp
|
|
38
38
|
run: |
|
|
39
39
|
uv sync --dev --all-extras
|
|
40
|
-
uv pip install scikit-build-core pybind11
|
|
40
|
+
uv pip install scikit-build-core pybind11 setuptools-scm
|
|
41
41
|
CMAKE_ARGS="-DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang \
|
|
42
42
|
-DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++" \
|
|
43
43
|
uv pip install -e .[test] --no-build-isolation
|
|
@@ -49,7 +49,7 @@ jobs:
|
|
|
49
49
|
OPENBLAS_NUM_THREADS: "1"
|
|
50
50
|
run: |
|
|
51
51
|
uv sync --dev --all-extras
|
|
52
|
-
uv pip install scikit-build-core pybind11
|
|
52
|
+
uv pip install scikit-build-core pybind11 setuptools-scm
|
|
53
53
|
uv pip install -e .[test] --no-build-isolation
|
|
54
54
|
|
|
55
55
|
|
|
@@ -2,30 +2,31 @@ name: Code Quality
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
5
|
-
branches: [
|
|
5
|
+
branches: [master]
|
|
6
6
|
pull_request:
|
|
7
|
-
branches: [
|
|
7
|
+
branches: [master]
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
8
12
|
|
|
9
13
|
jobs:
|
|
10
14
|
code-quality:
|
|
11
15
|
runs-on: ubuntu-latest
|
|
12
|
-
strategy:
|
|
13
|
-
matrix:
|
|
14
|
-
python-version: ["3.11", "3.12", "3.13", "3.14"]
|
|
15
16
|
|
|
16
17
|
steps:
|
|
17
18
|
- uses: actions/checkout@v4
|
|
18
19
|
|
|
19
|
-
- name: Set up
|
|
20
|
+
- name: Set up uv
|
|
21
|
+
uses: astral-sh/setup-uv@v7
|
|
22
|
+
|
|
23
|
+
- name: Set up Python
|
|
20
24
|
uses: actions/setup-python@v5
|
|
21
25
|
with:
|
|
22
|
-
python-version:
|
|
26
|
+
python-version: "3.12"
|
|
23
27
|
|
|
24
|
-
- name: Install
|
|
25
|
-
run:
|
|
26
|
-
python -m pip install --upgrade pip
|
|
27
|
-
pip install black isort ruff mypy
|
|
28
|
-
pip install numpy pytest
|
|
28
|
+
- name: Install code quality tools
|
|
29
|
+
run: uv pip install --system black isort ruff mypy numpy pytest
|
|
29
30
|
|
|
30
31
|
- name: Check formatting with Black
|
|
31
32
|
run: black --check python/ tests/
|
|
@@ -32,12 +32,12 @@ jobs:
|
|
|
32
32
|
run: brew install gcc libomp
|
|
33
33
|
|
|
34
34
|
- name: Install cibuildwheel
|
|
35
|
-
run: python -m pip install cibuildwheel==
|
|
35
|
+
run: python -m pip install cibuildwheel==3.3.1
|
|
36
36
|
|
|
37
37
|
- name: Build wheels
|
|
38
38
|
env:
|
|
39
39
|
CIBW_BUILD: "cp310-* cp311-* cp312-* cp313-* cp314-*"
|
|
40
|
-
CIBW_SKIP: "pp* *-musllinux_* cp*-manylinux_i686"
|
|
40
|
+
CIBW_SKIP: "pp* *-musllinux_* cp*-manylinux_i686 cp31?t-*"
|
|
41
41
|
CIBW_TEST_COMMAND: "pytest -q {project}/tests -k 'not slow' -x"
|
|
42
42
|
CIBW_TEST_EXTRAS: "test"
|
|
43
43
|
CIBW_ENVIRONMENT: >
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: kernelforge
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.17
|
|
4
4
|
Summary: Optimized Kernels for ML
|
|
5
5
|
Author: Anders Christensen
|
|
6
6
|
License: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/andersx/kernelforge
|
|
8
8
|
Project-URL: Issues, https://github.com/andersx/kernelforge/issues
|
|
9
|
-
Requires-Python: >=3.
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
10
|
Requires-Dist: numpy>=2.00
|
|
11
11
|
Provides-Extra: test
|
|
12
12
|
Requires-Dist: pytest>=8; extra == "test"
|
|
@@ -9,7 +9,7 @@ description = "Optimized Kernels for ML"
|
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = {text = "MIT"}
|
|
11
11
|
authors = [{name = "Anders Christensen"}]
|
|
12
|
-
requires-python = ">=3.
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
13
|
dependencies = [
|
|
14
14
|
"numpy>=2.00",
|
|
15
15
|
]
|
|
@@ -45,7 +45,7 @@ CMAKE_VERBOSE_MAKEFILE = "ON"
|
|
|
45
45
|
CMAKE_BUILD_TYPE = "Release"
|
|
46
46
|
|
|
47
47
|
[tool.uv.extra-build-dependencies]
|
|
48
|
-
kernelforge = ["scikit_build_core"]
|
|
48
|
+
kernelforge = ["scikit_build_core", "setuptools-scm>=8.0"]
|
|
49
49
|
|
|
50
50
|
[tool.setuptools_scm]
|
|
51
51
|
# Use git tags with 'v' prefix (e.g., v0.1.14)
|
|
@@ -56,75 +56,20 @@ fallback_version = "0.0.0.dev0"
|
|
|
56
56
|
|
|
57
57
|
[tool.black]
|
|
58
58
|
line-length = 100
|
|
59
|
-
target-version = ["py311", "py312"] # Black doesn't support py313/py314 yet
|
|
60
|
-
exclude = '''
|
|
61
|
-
/(
|
|
62
|
-
\.git
|
|
63
|
-
| \.venv
|
|
64
|
-
| _build
|
|
65
|
-
| build
|
|
66
|
-
| dist
|
|
67
|
-
)/
|
|
68
|
-
'''
|
|
69
59
|
|
|
70
60
|
[tool.isort]
|
|
71
61
|
profile = "black"
|
|
72
62
|
line_length = 100
|
|
73
|
-
multi_line_output = 3
|
|
74
|
-
include_trailing_comma = true
|
|
75
|
-
force_grid_wrap = 0
|
|
76
|
-
use_parentheses = true
|
|
77
|
-
ensure_newline_before_comments = true
|
|
78
|
-
skip_gitignore = true
|
|
79
63
|
|
|
80
64
|
[tool.ruff]
|
|
81
65
|
line-length = 100
|
|
82
|
-
target-version = "py311"
|
|
83
|
-
exclude = [
|
|
84
|
-
".git",
|
|
85
|
-
".venv",
|
|
86
|
-
"__pycache__",
|
|
87
|
-
"build",
|
|
88
|
-
"dist",
|
|
89
|
-
]
|
|
90
|
-
|
|
91
|
-
[tool.ruff.lint]
|
|
92
|
-
select = [
|
|
93
|
-
"E", # pycodestyle errors
|
|
94
|
-
"W", # pycodestyle warnings
|
|
95
|
-
"F", # pyflakes
|
|
96
|
-
"N", # pep8-naming
|
|
97
|
-
"UP", # pyupgrade
|
|
98
|
-
"B", # flake8-bugbear
|
|
99
|
-
"C4", # flake8-comprehensions
|
|
100
|
-
"PTH", # flake8-use-pathlib
|
|
101
|
-
]
|
|
102
|
-
ignore = [
|
|
103
|
-
"E501", # line too long (handled by black)
|
|
104
|
-
"B008", # do not perform function calls in argument defaults
|
|
105
|
-
"PTH123", # use pathlib for open (not always needed)
|
|
106
|
-
]
|
|
107
66
|
|
|
108
67
|
[tool.ruff.lint.per-file-ignores]
|
|
109
|
-
"tests/*" = ["
|
|
110
|
-
"python/kernelforge/cli.py" = ["N806", "F841"
|
|
68
|
+
"tests/*" = ["N803", "N806"]
|
|
69
|
+
"python/kernelforge/cli.py" = ["N806", "F841"]
|
|
70
|
+
"python/kernelforge/*.pyi" = ["N802", "N803", "N806"]
|
|
111
71
|
|
|
112
72
|
[tool.mypy]
|
|
113
73
|
python_version = "3.11"
|
|
114
|
-
warn_return_any = true
|
|
115
|
-
warn_unused_configs = true
|
|
116
74
|
disallow_untyped_defs = true
|
|
117
75
|
check_untyped_defs = true
|
|
118
|
-
warn_redundant_casts = true
|
|
119
|
-
warn_unused_ignores = true
|
|
120
|
-
warn_no_return = true
|
|
121
|
-
strict_optional = true
|
|
122
|
-
no_implicit_optional = true
|
|
123
|
-
|
|
124
|
-
[[tool.mypy.overrides]]
|
|
125
|
-
module = ["numpy.*", "pytest.*", "typer.*", "psutil.*", "cpuinfo.*"]
|
|
126
|
-
ignore_missing_imports = true
|
|
127
|
-
|
|
128
|
-
[[tool.mypy.overrides]]
|
|
129
|
-
module = "kernelforge.*"
|
|
130
|
-
ignore_errors = true
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Type stubs for _cholesky C++ extension module."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from numpy.typing import NDArray
|
|
5
|
+
|
|
6
|
+
def solve_cholesky(
|
|
7
|
+
K: NDArray[np.float64], y: NDArray[np.float64], regularize: float = 0.0
|
|
8
|
+
) -> NDArray[np.float64]: ...
|
|
9
|
+
def solve_cholesky_rfp_L(
|
|
10
|
+
K_arf: NDArray[np.float64],
|
|
11
|
+
y: NDArray[np.float64],
|
|
12
|
+
regularize: float = 0.0,
|
|
13
|
+
uplo: str = "U",
|
|
14
|
+
transr: str = "N",
|
|
15
|
+
) -> NDArray[np.float64]: ...
|
|
16
|
+
def full_to_rfp(
|
|
17
|
+
A: NDArray[np.float64], uplo: str = "U", transr: str = "N"
|
|
18
|
+
) -> NDArray[np.float64]: ...
|
|
19
|
+
def rfp_to_full(
|
|
20
|
+
ARF: NDArray[np.float64], n: int, uplo: str = "U", transr: str = "N"
|
|
21
|
+
) -> NDArray[np.float64]: ...
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Type stubs for _fchl19 C++ extension module."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from numpy.typing import NDArray
|
|
5
|
+
|
|
6
|
+
def compute_rep_size(nelements: int, nbasis2: int, nbasis3: int, nabasis: int) -> int: ...
|
|
7
|
+
def generate_fchl_acsf(
|
|
8
|
+
coords: NDArray[np.float64],
|
|
9
|
+
nuclear_z: NDArray[np.int32],
|
|
10
|
+
elements: list[int] = [1, 6, 7, 8, 16],
|
|
11
|
+
nRs2: int = 24,
|
|
12
|
+
nRs3: int = 20,
|
|
13
|
+
nFourier: int = 1,
|
|
14
|
+
eta2: float = 0.32,
|
|
15
|
+
eta3: float = 2.7,
|
|
16
|
+
zeta: float = ...,
|
|
17
|
+
rcut: float = 8.0,
|
|
18
|
+
acut: float = 8.0,
|
|
19
|
+
two_body_decay: float = 1.8,
|
|
20
|
+
three_body_decay: float = 0.57,
|
|
21
|
+
three_body_weight: float = 13.4,
|
|
22
|
+
) -> NDArray[np.float64]: ...
|
|
23
|
+
def generate_fchl_acsf_and_gradients(
|
|
24
|
+
coords: NDArray[np.float64],
|
|
25
|
+
nuclear_z: NDArray[np.int32],
|
|
26
|
+
elements: list[int] = [1, 6, 7, 8, 16],
|
|
27
|
+
nRs2: int = 24,
|
|
28
|
+
nRs3: int = 20,
|
|
29
|
+
nFourier: int = 1,
|
|
30
|
+
eta2: float = 0.32,
|
|
31
|
+
eta3: float = 2.7,
|
|
32
|
+
zeta: float = ...,
|
|
33
|
+
rcut: float = 8.0,
|
|
34
|
+
acut: float = 8.0,
|
|
35
|
+
two_body_decay: float = 1.8,
|
|
36
|
+
three_body_decay: float = 0.57,
|
|
37
|
+
three_body_weight: float = 13.4,
|
|
38
|
+
) -> tuple[NDArray[np.float64], NDArray[np.float64]]: ...
|
|
39
|
+
def flocal_kernel_symm(
|
|
40
|
+
X: NDArray[np.float64], Q: NDArray[np.int32], N: NDArray[np.int32], sigma: float
|
|
41
|
+
) -> NDArray[np.float64]: ...
|
|
42
|
+
def flocal_kernel_symm_rfp(
|
|
43
|
+
X: NDArray[np.float64], Q: NDArray[np.int32], N: NDArray[np.int32], sigma: float
|
|
44
|
+
) -> NDArray[np.float64]: ...
|
|
45
|
+
def flocal_kernel(
|
|
46
|
+
X1: NDArray[np.float64],
|
|
47
|
+
X2: NDArray[np.float64],
|
|
48
|
+
Q1: NDArray[np.int32],
|
|
49
|
+
Q2: NDArray[np.int32],
|
|
50
|
+
N1: NDArray[np.int32],
|
|
51
|
+
N2: NDArray[np.int32],
|
|
52
|
+
sigma: float,
|
|
53
|
+
) -> NDArray[np.float64]: ...
|
|
54
|
+
def fgdml_kernel_symm(
|
|
55
|
+
X: NDArray[np.float64],
|
|
56
|
+
dX: NDArray[np.float64],
|
|
57
|
+
Q: NDArray[np.int32],
|
|
58
|
+
N: NDArray[np.int32],
|
|
59
|
+
sigma: float,
|
|
60
|
+
) -> NDArray[np.float64]: ...
|
|
61
|
+
def fgdml_kernel(
|
|
62
|
+
X1: NDArray[np.float64],
|
|
63
|
+
X2: NDArray[np.float64],
|
|
64
|
+
dX1: NDArray[np.float64],
|
|
65
|
+
dX2: NDArray[np.float64],
|
|
66
|
+
Q1: NDArray[np.int32],
|
|
67
|
+
Q2: NDArray[np.int32],
|
|
68
|
+
N1: NDArray[np.int32],
|
|
69
|
+
N2: NDArray[np.int32],
|
|
70
|
+
sigma: float,
|
|
71
|
+
) -> NDArray[np.float64]: ...
|
|
72
|
+
def fatomic_local_gradient_kernel(
|
|
73
|
+
x1: NDArray[np.float64],
|
|
74
|
+
x2: NDArray[np.float64],
|
|
75
|
+
dX2: NDArray[np.float64],
|
|
76
|
+
q1: NDArray[np.int32],
|
|
77
|
+
q2: NDArray[np.int32],
|
|
78
|
+
n1: NDArray[np.int32],
|
|
79
|
+
n2: NDArray[np.int32],
|
|
80
|
+
sigma: float,
|
|
81
|
+
) -> NDArray[np.float64]: ...
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Type stubs for _invdist C++ extension module."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from numpy.typing import NDArray
|
|
5
|
+
|
|
6
|
+
def num_pairs(N: int) -> int: ...
|
|
7
|
+
def inverse_distance_upper(R: NDArray[np.float64]) -> NDArray[np.float64]: ...
|
|
8
|
+
def inverse_distance_upper_and_jacobian(
|
|
9
|
+
R: NDArray[np.float64], eps: float = 0.0
|
|
10
|
+
) -> tuple[NDArray[np.float64], NDArray[np.float64]]: ...
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Type stubs for _kernels C++ extension module."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from numpy.typing import NDArray
|
|
5
|
+
|
|
6
|
+
def kernel_symm(X: NDArray[np.float64], alpha: float) -> NDArray[np.float64]: ...
|
|
7
|
+
def kernel_asymm(
|
|
8
|
+
X1: NDArray[np.float64], X2: NDArray[np.float64], alpha: float
|
|
9
|
+
) -> NDArray[np.float64]: ...
|
|
10
|
+
def gaussian_jacobian_batch(
|
|
11
|
+
X1: NDArray[np.float64],
|
|
12
|
+
dX1: NDArray[np.float64],
|
|
13
|
+
X2: NDArray[np.float64],
|
|
14
|
+
sigma: float,
|
|
15
|
+
) -> NDArray[np.float64]: ...
|
|
16
|
+
def rbf_hessian_full_tiled_gemm(
|
|
17
|
+
X1: NDArray[np.float64],
|
|
18
|
+
dX1: NDArray[np.float64],
|
|
19
|
+
X2: NDArray[np.float64],
|
|
20
|
+
dX2: NDArray[np.float64],
|
|
21
|
+
sigma: float,
|
|
22
|
+
tile_B: int | None = None,
|
|
23
|
+
) -> NDArray[np.float64]: ...
|
|
24
|
+
def rbf_hessian_full_tiled_gemm_sym(
|
|
25
|
+
X: NDArray[np.float64],
|
|
26
|
+
dX: NDArray[np.float64],
|
|
27
|
+
sigma: float,
|
|
28
|
+
tile_B: int | None = None,
|
|
29
|
+
) -> NDArray[np.float64]: ...
|
|
File without changes
|
|
@@ -4,7 +4,7 @@ import pytest
|
|
|
4
4
|
from kernelforge import _cholesky
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
def test_small_system():
|
|
7
|
+
def test_small_system() -> None:
|
|
8
8
|
K = np.array([[4.0, 2.0, 0.6], [2.0, 5.0, 1.5], [0.6, 1.5, 3.0]], dtype=np.float64)
|
|
9
9
|
y = np.array([1.0, 2.0, 3.0], dtype=np.float64)
|
|
10
10
|
|
|
@@ -18,7 +18,7 @@ def test_small_system():
|
|
|
18
18
|
np.testing.assert_allclose(y, [1.0, 2.0, 3.0])
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
def test_identity_matrix():
|
|
21
|
+
def test_identity_matrix() -> None:
|
|
22
22
|
n = 5
|
|
23
23
|
K = np.eye(n, dtype=np.float64)
|
|
24
24
|
y = np.arange(1, n + 1, dtype=np.float64)
|
|
@@ -27,7 +27,7 @@ def test_identity_matrix():
|
|
|
27
27
|
np.testing.assert_allclose(alpha, y)
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
def test_random_pd_matrix():
|
|
30
|
+
def test_random_pd_matrix() -> None:
|
|
31
31
|
rng = np.random.default_rng(42)
|
|
32
32
|
A = rng.standard_normal((6, 6))
|
|
33
33
|
K = A.T @ A + np.eye(6) * 1e-6 # make SPD
|
|
@@ -38,14 +38,14 @@ def test_random_pd_matrix():
|
|
|
38
38
|
np.testing.assert_allclose((A.T @ A + np.eye(6) * 1e-6) @ alpha, y, rtol=1e-10, atol=1e-12)
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
def test_non_square_matrix():
|
|
41
|
+
def test_non_square_matrix() -> None:
|
|
42
42
|
with pytest.raises(RuntimeError):
|
|
43
43
|
K = np.ones((3, 2), dtype=np.float64)
|
|
44
44
|
y = np.ones(3, dtype=np.float64)
|
|
45
45
|
_cholesky.solve_cholesky(K, y)
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
def test_mismatched_size():
|
|
48
|
+
def test_mismatched_size() -> None:
|
|
49
49
|
with pytest.raises(RuntimeError):
|
|
50
50
|
K = np.eye(3, dtype=np.float64)
|
|
51
51
|
y = np.ones(4, dtype=np.float64)
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import numpy as np
|
|
2
|
-
import pytest
|
|
3
2
|
|
|
4
3
|
from kernelforge import _fchl19 as _fchl
|
|
5
4
|
from kernelforge._fchl19 import generate_fchl_acsf, generate_fchl_acsf_and_gradients
|
|
6
5
|
|
|
7
6
|
|
|
8
|
-
def _call_generate(coords, nuclear_z, **kwargs):
|
|
7
|
+
def _call_generate(coords, nuclear_z, **kwargs): # type: ignore
|
|
9
8
|
"""
|
|
10
9
|
Wrapper to call the extension using named args, handling either arg order
|
|
11
10
|
(coords first or nuclear_z first) depending on how it was compiled.
|
|
@@ -18,21 +17,21 @@ def _call_generate(coords, nuclear_z, **kwargs):
|
|
|
18
17
|
params.update(kwargs)
|
|
19
18
|
try:
|
|
20
19
|
# Our binding signature: (coords, nuclear_z, ...)
|
|
21
|
-
return fn(**params)
|
|
20
|
+
return fn(**params) # type: ignore[arg-type]
|
|
22
21
|
except TypeError:
|
|
23
22
|
# Fallback if someone compiled as (nuclear_z, coords, ...)
|
|
24
23
|
params2 = dict(params)
|
|
25
24
|
params2["coords"], params2["nuclear_z"] = params["nuclear_z"], params["coords"]
|
|
26
|
-
return fn(**params2)
|
|
25
|
+
return fn(**params2) # type: ignore[arg-type]
|
|
27
26
|
|
|
28
27
|
|
|
29
|
-
def _descr_size(n_elements, nRs2, nRs3, nFourier):
|
|
28
|
+
def _descr_size(n_elements, nRs2, nRs3, nFourier): # type: ignore
|
|
30
29
|
# Matches the code in the binding:
|
|
31
30
|
# rep_size = n_elements*nRs2 + (n_elements*(n_elements+1)) * nRs3 * nFourier
|
|
32
31
|
return n_elements * nRs2 + (n_elements * (n_elements + 1)) * nRs3 * nFourier
|
|
33
32
|
|
|
34
33
|
|
|
35
|
-
def test_shape_with_defaults_and_explicit_rep_size():
|
|
34
|
+
def test_shape_with_defaults_and_explicit_rep_size() -> None:
|
|
36
35
|
# H-O-H linear-ish toy geometry
|
|
37
36
|
coords = np.array(
|
|
38
37
|
[[-0.9572, 0.0, 0.0], [0.0000, 0.0, 0.0], [0.9572, 0.0, 0.0]], dtype=np.float64
|
|
@@ -50,7 +49,7 @@ def test_shape_with_defaults_and_explicit_rep_size():
|
|
|
50
49
|
assert rep.shape == (coords.shape[0], expected_rep_size)
|
|
51
50
|
|
|
52
51
|
|
|
53
|
-
def test_shape_with_explicit_basis_sizes_and_elements():
|
|
52
|
+
def test_shape_with_explicit_basis_sizes_and_elements() -> None:
|
|
54
53
|
coords = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [2.0, 0.0, 0.0]], dtype=np.float64)
|
|
55
54
|
Z = np.array([6, 1, 1], dtype=np.int32) # CHH
|
|
56
55
|
|
|
@@ -77,7 +76,7 @@ def test_shape_with_explicit_basis_sizes_and_elements():
|
|
|
77
76
|
assert rep.shape == (coords.shape[0], expected_rep_size)
|
|
78
77
|
|
|
79
78
|
|
|
80
|
-
def test_translation_invariance():
|
|
79
|
+
def test_translation_invariance() -> None:
|
|
81
80
|
coords = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]], dtype=np.float64)
|
|
82
81
|
Z = np.array([1, 1], dtype=np.int32)
|
|
83
82
|
|
|
@@ -119,7 +118,7 @@ def test_translation_invariance():
|
|
|
119
118
|
np.testing.assert_allclose(rep1, rep2, rtol=1e-10, atol=1e-12)
|
|
120
119
|
|
|
121
120
|
|
|
122
|
-
def test_three_body_zeroing_block_when_weight_zero():
|
|
121
|
+
def test_three_body_zeroing_block_when_weight_zero() -> None:
|
|
123
122
|
# Geometry with angles so 3-body term would be nonzero when enabled
|
|
124
123
|
coords = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.5, 0.8, 0.0]], dtype=np.float64)
|
|
125
124
|
Z = np.array([1, 1, 1], dtype=np.int32)
|
|
@@ -169,13 +168,13 @@ def test_three_body_zeroing_block_when_weight_zero():
|
|
|
169
168
|
assert np.linalg.norm(rep_pos[:, two_body_size:]) > 0.0
|
|
170
169
|
|
|
171
170
|
|
|
172
|
-
def test_defaults_match_manual_linspace_construction():
|
|
173
|
-
# Ensure the binding
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
def test_defaults_match_manual_linspace_construction() -> None:
|
|
172
|
+
# Ensure the binding's internal linspace matches what we'd build in Python
|
|
173
|
+
# TODO: Implement test
|
|
174
|
+
pass
|
|
176
175
|
|
|
177
176
|
|
|
178
|
-
def test_rep_matches_between_functions():
|
|
177
|
+
def test_rep_matches_between_functions() -> None:
|
|
179
178
|
# small, simple triatomic
|
|
180
179
|
coords = np.array(
|
|
181
180
|
[[-0.9572, 0.0, 0.0], [0.0000, 0.0, 0.0], [0.9572, 0.0, 0.0]], dtype=np.float64
|
|
@@ -198,8 +197,8 @@ def test_rep_matches_between_functions():
|
|
|
198
197
|
three_body_weight=13.4,
|
|
199
198
|
)
|
|
200
199
|
|
|
201
|
-
rep_only = generate_fchl_acsf(coords, Z, **kw)
|
|
202
|
-
rep_both, grad = generate_fchl_acsf_and_gradients(coords, Z, **kw)
|
|
200
|
+
rep_only = generate_fchl_acsf(coords, Z, **kw) # type: ignore[arg-type]
|
|
201
|
+
rep_both, grad = generate_fchl_acsf_and_gradients(coords, Z, **kw) # type: ignore[arg-type]
|
|
203
202
|
|
|
204
203
|
assert rep_only.shape == rep_both.shape
|
|
205
204
|
np.testing.assert_allclose(rep_only, rep_both, rtol=1e-12, atol=1e-14)
|
|
@@ -209,7 +208,7 @@ def test_rep_matches_between_functions():
|
|
|
209
208
|
assert grad.shape == (n, rep_size, n * 3)
|
|
210
209
|
|
|
211
210
|
|
|
212
|
-
def test_analytic_grad_matches_finite_difference():
|
|
211
|
+
def test_analytic_grad_matches_finite_difference() -> None:
|
|
213
212
|
# small CH2-like geometry (asymmetric to avoid accidental cancellations)
|
|
214
213
|
coords = np.array(
|
|
215
214
|
[[0.00, 0.00, 0.00], [1.10, 0.00, 0.00], [-0.20, 0.95, 0.15]], # C # H # H
|
|
@@ -232,7 +231,7 @@ def test_analytic_grad_matches_finite_difference():
|
|
|
232
231
|
three_body_weight=2.5,
|
|
233
232
|
)
|
|
234
233
|
|
|
235
|
-
rep, grad = generate_fchl_acsf_and_gradients(coords, Z, **kw)
|
|
234
|
+
rep, grad = generate_fchl_acsf_and_gradients(coords, Z, **kw) # type: ignore[arg-type]
|
|
236
235
|
n, rep_size = rep.shape
|
|
237
236
|
|
|
238
237
|
# central finite-difference using the rep-only function
|
|
@@ -246,8 +245,8 @@ def test_analytic_grad_matches_finite_difference():
|
|
|
246
245
|
cm = coords.copy()
|
|
247
246
|
cp[a, d] += h
|
|
248
247
|
cm[a, d] -= h
|
|
249
|
-
rep_p = generate_fchl_acsf(cp, Z, **kw)
|
|
250
|
-
rep_m = generate_fchl_acsf(cm, Z, **kw)
|
|
248
|
+
rep_p = generate_fchl_acsf(cp, Z, **kw) # type: ignore[arg-type]
|
|
249
|
+
rep_m = generate_fchl_acsf(cm, Z, **kw) # type: ignore[arg-type]
|
|
251
250
|
fd_grad[:, :, a * 3 + d] = (rep_p - rep_m) / (2.0 * h)
|
|
252
251
|
|
|
253
252
|
# Compare analytic vs FD. Use slightly looser tolerances than for exact equality.
|
|
@@ -255,7 +254,7 @@ def test_analytic_grad_matches_finite_difference():
|
|
|
255
254
|
np.testing.assert_allclose(grad, fd_grad, rtol=5e-6, atol=5e-8)
|
|
256
255
|
|
|
257
256
|
|
|
258
|
-
def test_translation_invariance_and_zero_grad_under_uniform_shift():
|
|
257
|
+
def test_translation_invariance_and_zero_grad_under_uniform_shift() -> None:
|
|
259
258
|
# two atoms; translation of all atoms should not change rep,
|
|
260
259
|
# and gradient wrt a *uniform* shift of all atoms should sum to ~0
|
|
261
260
|
coords = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]], dtype=np.float64)
|
|
@@ -276,10 +275,10 @@ def test_translation_invariance_and_zero_grad_under_uniform_shift():
|
|
|
276
275
|
three_body_weight=1.0,
|
|
277
276
|
)
|
|
278
277
|
|
|
279
|
-
rep1, grad1 = generate_fchl_acsf_and_gradients(coords, Z, **kw)
|
|
278
|
+
rep1, grad1 = generate_fchl_acsf_and_gradients(coords, Z, **kw) # type: ignore[arg-type]
|
|
280
279
|
|
|
281
280
|
shift = np.array([+3.2, -1.1, +0.7])
|
|
282
|
-
rep2, grad2 = generate_fchl_acsf_and_gradients(coords + shift, Z, **kw)
|
|
281
|
+
rep2, grad2 = generate_fchl_acsf_and_gradients(coords + shift, Z, **kw) # type: ignore[arg-type]
|
|
283
282
|
|
|
284
283
|
np.testing.assert_allclose(rep1, rep2, rtol=1e-12, atol=1e-14)
|
|
285
284
|
|
|
@@ -5,7 +5,7 @@ import pytest
|
|
|
5
5
|
import kernelforge._fchl19 as fchl
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
def slow_ref_grad(x1, x2, dX2, q1, q2, n1, n2, sigma):
|
|
8
|
+
def slow_ref_grad(x1, x2, dX2, q1, q2, n1, n2, sigma): # type: ignore
|
|
9
9
|
"""
|
|
10
10
|
NumPy reference matching the Fortran logic:
|
|
11
11
|
For each a,j1 and b,j2 with matching labels, accumulate:
|
|
@@ -60,7 +60,7 @@ def slow_ref_grad(x1, x2, dX2, q1, q2, n1, n2, sigma):
|
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
@pytest.mark.parametrize("seed", [0, 1234])
|
|
63
|
-
def test_fatomic_local_gradient_kernel_matches_reference(seed):
|
|
63
|
+
def test_fatomic_local_gradient_kernel_matches_reference(seed) -> None: # type: ignore[no-untyped-def]
|
|
64
64
|
rng = np.random.default_rng(seed)
|
|
65
65
|
|
|
66
66
|
# modest sizes to keep test fast but non-trivial
|
|
@@ -96,7 +96,7 @@ def test_fatomic_local_gradient_kernel_matches_reference(seed):
|
|
|
96
96
|
np.testing.assert_allclose(K, K_ref, rtol=1e-10, atol=1e-10)
|
|
97
97
|
|
|
98
98
|
|
|
99
|
-
def test_no_matches_yields_zero_matrix():
|
|
99
|
+
def test_no_matches_yields_zero_matrix() -> None:
|
|
100
100
|
rng = np.random.default_rng(42)
|
|
101
101
|
nm1, nm2 = 2, 2
|
|
102
102
|
max_atoms1, max_atoms2 = 3, 3
|
|
@@ -118,7 +118,7 @@ def test_no_matches_yields_zero_matrix():
|
|
|
118
118
|
assert np.allclose(K, 0.0)
|
|
119
119
|
|
|
120
120
|
|
|
121
|
-
def test_empty_derivatives_returns_nm1_by_0():
|
|
121
|
+
def test_empty_derivatives_returns_nm1_by_0() -> None:
|
|
122
122
|
rng = np.random.default_rng(7)
|
|
123
123
|
nm1, nm2 = 3, 2
|
|
124
124
|
max_atoms1, max_atoms2 = 4, 3
|
|
@@ -140,7 +140,7 @@ def test_empty_derivatives_returns_nm1_by_0():
|
|
|
140
140
|
assert K.size == 0
|
|
141
141
|
|
|
142
142
|
|
|
143
|
-
def test_shape_errors_raise_valueerror():
|
|
143
|
+
def test_shape_errors_raise_valueerror() -> None:
|
|
144
144
|
rng = np.random.default_rng(9)
|
|
145
145
|
nm1, nm2 = 2, 2
|
|
146
146
|
max_atoms1, max_atoms2 = 3, 3
|
|
@@ -4,7 +4,7 @@ import pytest
|
|
|
4
4
|
from kernelforge import _kernels # the module name from the pybind shim
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
def ref_block(x1, J1, x2, J2, sigma):
|
|
7
|
+
def ref_block(x1, J1, x2, J2, sigma): # type: ignore
|
|
8
8
|
"""
|
|
9
9
|
Reference NumPy implementation for one (a,b) block:
|
|
10
10
|
H = (k/s^2) * J1^T J2 - (k/s^4) * (J1^T d) (J2^T d)^T
|
|
@@ -22,7 +22,7 @@ def ref_block(x1, J1, x2, J2, sigma):
|
|
|
22
22
|
return term1 - term2
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
def assemble_ref_full(X1, dX1, X2, dX2, sigma):
|
|
25
|
+
def assemble_ref_full(X1, dX1, X2, dX2, sigma): # type: ignore
|
|
26
26
|
"""
|
|
27
27
|
Assemble full ((N1*D1) x (N2*D2)) Hessian by looping in Python
|
|
28
28
|
and calling the closed-form block above.
|
|
@@ -52,7 +52,7 @@ def assemble_ref_full(X1, dX1, X2, dX2, sigma):
|
|
|
52
52
|
(1, 1, 6, 5, 5),
|
|
53
53
|
],
|
|
54
54
|
)
|
|
55
|
-
def test_shapes_and_values(N1, N2, M, D1, D2):
|
|
55
|
+
def test_shapes_and_values(N1, N2, M, D1, D2) -> None: # type: ignore[no-untyped-def]
|
|
56
56
|
rng = np.random.default_rng(0)
|
|
57
57
|
X1 = rng.normal(size=(N1, M))
|
|
58
58
|
X2 = rng.normal(size=(N2, M))
|
|
@@ -69,7 +69,7 @@ def test_shapes_and_values(N1, N2, M, D1, D2):
|
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
@pytest.mark.parametrize("tile_B", [1, 2, 4, 7, 0]) # 0 => auto
|
|
72
|
-
def test_various_tile_sizes(tile_B):
|
|
72
|
+
def test_various_tile_sizes(tile_B) -> None: # type: ignore[no-untyped-def]
|
|
73
73
|
rng = np.random.default_rng(1)
|
|
74
74
|
N1, N2, M, D1, D2 = 2, 5, 8, 3, 4
|
|
75
75
|
X1 = rng.normal(size=(N1, M))
|
|
@@ -88,7 +88,7 @@ def test_various_tile_sizes(tile_B):
|
|
|
88
88
|
np.testing.assert_allclose(H, H_ref, rtol=1e-12, atol=1e-12)
|
|
89
89
|
|
|
90
90
|
|
|
91
|
-
def test_bad_sigma_raises():
|
|
91
|
+
def test_bad_sigma_raises() -> None:
|
|
92
92
|
rng = np.random.default_rng(2)
|
|
93
93
|
X1 = rng.normal(size=(1, 3))
|
|
94
94
|
X2 = rng.normal(size=(1, 3))
|
|
@@ -101,7 +101,7 @@ def test_bad_sigma_raises():
|
|
|
101
101
|
_ = _kernels.rbf_hessian_full_tiled_gemm(X1, dX1, X2, dX2, -1.0)
|
|
102
102
|
|
|
103
103
|
|
|
104
|
-
def test_shape_mismatch_raises():
|
|
104
|
+
def test_shape_mismatch_raises() -> None:
|
|
105
105
|
rng = np.random.default_rng(3)
|
|
106
106
|
X1 = rng.normal(size=(2, 4))
|
|
107
107
|
X2 = rng.normal(size=(3, 4))
|
|
@@ -6,12 +6,12 @@ import pytest
|
|
|
6
6
|
from kernelforge import _invdist as invdist
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
def _strict_upper_pairs(N):
|
|
9
|
+
def _strict_upper_pairs(N): # type: ignore
|
|
10
10
|
"""[(0,1), (0,2), ..., (N-2,N-1)]"""
|
|
11
11
|
return [(i, j) for i in range(N) for j in range(i + 1, N)]
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
def test_shapes_and_ordering_and_sparsity():
|
|
14
|
+
def test_shapes_and_ordering_and_sparsity() -> None:
|
|
15
15
|
rng = np.random.default_rng(42)
|
|
16
16
|
N = 5
|
|
17
17
|
# well-separated random coords to avoid tiny distances
|
|
@@ -39,7 +39,7 @@ def test_shapes_and_ordering_and_sparsity():
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
@pytest.mark.parametrize("N", [4, 5])
|
|
42
|
-
def test_jacobian_central_difference(N):
|
|
42
|
+
def test_jacobian_central_difference(N) -> None: # type: ignore[no-untyped-def]
|
|
43
43
|
rng = np.random.default_rng(123)
|
|
44
44
|
# Spread atoms to avoid small r; linear ramp helps conditioning
|
|
45
45
|
base = np.arange(N)[:, None] * np.array([1.5, 0.7, -0.6])
|
|
@@ -74,7 +74,7 @@ def test_jacobian_central_difference(N):
|
|
|
74
74
|
np.testing.assert_allclose(ana_col, num_col, rtol=rtol, atol=atol)
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
def test_eps_stability_no_nan_inf():
|
|
77
|
+
def test_eps_stability_no_nan_inf() -> None:
|
|
78
78
|
rng = np.random.default_rng(7)
|
|
79
79
|
N = 4
|
|
80
80
|
R = rng.normal(size=(N, 3)) * 1e-9 # nearly coincident (stress eps path)
|
|
@@ -5,11 +5,11 @@ import pytest
|
|
|
5
5
|
from kernelforge import _kernels
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
def _strict_upper_pairs(N):
|
|
8
|
+
def _strict_upper_pairs(N): # type: ignore
|
|
9
9
|
return [(i, j) for i in range(N) for j in range(i + 1, N)]
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
def test_shapes_and_basic_values():
|
|
12
|
+
def test_shapes_and_basic_values() -> None:
|
|
13
13
|
rng = np.random.default_rng(0)
|
|
14
14
|
|
|
15
15
|
N1, N2 = 3, 4
|
|
@@ -30,7 +30,7 @@ def test_shapes_and_basic_values():
|
|
|
30
30
|
assert not np.allclose(K, 0.0)
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
def test_formula_matches_numpy_reference():
|
|
33
|
+
def test_formula_matches_numpy_reference() -> None:
|
|
34
34
|
rng = np.random.default_rng(1)
|
|
35
35
|
|
|
36
36
|
N1, N2 = 2, 3
|
|
@@ -64,7 +64,7 @@ def test_formula_matches_numpy_reference():
|
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
@pytest.mark.parametrize("N1,N2,M,N", [(1, 2, 5, 3), (2, 1, 6, 2)])
|
|
67
|
-
def test_finite_difference_linearized_feature_model(N1, N2, M, N):
|
|
67
|
+
def test_finite_difference_linearized_feature_model(N1, N2, M, N) -> None: # type: ignore[no-untyped-def]
|
|
68
68
|
"""
|
|
69
69
|
Finite-difference check using a *linearized* feature->coordinate model:
|
|
70
70
|
x1_a(r) = x1_a0 + J_a @ r
|
|
@@ -94,7 +94,7 @@ def test_finite_difference_linearized_feature_model(N1, N2, M, N):
|
|
|
94
94
|
x2 = X2[b]
|
|
95
95
|
|
|
96
96
|
# Define k_ab(r) with linearized feature model around r=0
|
|
97
|
-
def k_of_r(r_vec):
|
|
97
|
+
def k_of_r(r_vec): # type: ignore
|
|
98
98
|
x1_r = x1 + J @ r_vec # (M,)
|
|
99
99
|
diff = x1_r - x2
|
|
100
100
|
return np.exp(-0.5 * inv_s2 * float(diff @ diff))
|
|
@@ -117,7 +117,7 @@ def test_finite_difference_linearized_feature_model(N1, N2, M, N):
|
|
|
117
117
|
np.testing.assert_allclose(ana[coords_to_test], num[coords_to_test], rtol=rtol, atol=atol)
|
|
118
118
|
|
|
119
119
|
|
|
120
|
-
def test_bad_sigma_raises():
|
|
120
|
+
def test_bad_sigma_raises() -> None:
|
|
121
121
|
rng = np.random.default_rng(3)
|
|
122
122
|
|
|
123
123
|
N1, N2, M, D = 1, 1, 4, 6
|
|
@@ -132,7 +132,7 @@ def test_bad_sigma_raises():
|
|
|
132
132
|
_ = _kernels.gaussian_jacobian_batch(X1, dX1, X2, -1.0)
|
|
133
133
|
|
|
134
134
|
|
|
135
|
-
def test_input_shape_mismatch_errors():
|
|
135
|
+
def test_input_shape_mismatch_errors() -> None:
|
|
136
136
|
rng = np.random.default_rng(4)
|
|
137
137
|
|
|
138
138
|
N1, N2, M, D = 2, 2, 5, 9
|
|
@@ -4,7 +4,7 @@ import pytest
|
|
|
4
4
|
from kernelforge import _kernels # adjust if your module is just `import _kernels`
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
def test_kernel_symm_shape_and_symmetry():
|
|
7
|
+
def test_kernel_symm_shape_and_symmetry() -> None:
|
|
8
8
|
rng = np.random.default_rng(0)
|
|
9
9
|
n, d = 4, 2
|
|
10
10
|
X = rng.normal(size=(n, d))
|
|
@@ -16,7 +16,7 @@ def test_kernel_symm_shape_and_symmetry():
|
|
|
16
16
|
assert np.allclose(np.diag(K), 1.0)
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
def test_kernel_symm_against_numpy():
|
|
19
|
+
def test_kernel_symm_against_numpy() -> None:
|
|
20
20
|
rng = np.random.default_rng(1)
|
|
21
21
|
n, d = 4, 2
|
|
22
22
|
X = rng.normal(size=(n, d))
|
|
@@ -32,14 +32,11 @@ def test_kernel_symm_against_numpy():
|
|
|
32
32
|
dist2 = sq_norms[i] + sq_norms[j] - 2 * np.dot(X[i], X[j])
|
|
33
33
|
K_ref[i, j] = np.exp(alpha * dist2)
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
# print(K_ref)
|
|
37
|
-
# assert np.allclose(K, K_ref, rtol=1e-12, atol=1e-12)
|
|
38
|
-
i, j = np.tril_indices(K.shape[0])
|
|
35
|
+
i, j = np.tril_indices(K.shape[0]) # type: ignore[assignment]
|
|
39
36
|
assert np.allclose(K[i, j], K_ref[i, j])
|
|
40
37
|
|
|
41
38
|
|
|
42
|
-
def test_small_input():
|
|
39
|
+
def test_small_input() -> None:
|
|
43
40
|
X = np.array([[0.0], [1.0]])
|
|
44
41
|
alpha = -1.0
|
|
45
42
|
K = _kernels.kernel_symm(X, alpha)
|
|
@@ -49,7 +46,7 @@ def test_small_input():
|
|
|
49
46
|
assert K[1, 1] == pytest.approx(1.0)
|
|
50
47
|
|
|
51
48
|
|
|
52
|
-
def _ref_kernel_asymm(X1, X2, alpha):
|
|
49
|
+
def _ref_kernel_asymm(X1, X2, alpha): # type: ignore
|
|
53
50
|
"""Pure NumPy reference implementation."""
|
|
54
51
|
n1, d = X1.shape
|
|
55
52
|
n2, _ = X2.shape
|
|
@@ -63,7 +60,7 @@ def _ref_kernel_asymm(X1, X2, alpha):
|
|
|
63
60
|
return Kref
|
|
64
61
|
|
|
65
62
|
|
|
66
|
-
def test_kernel_asymm_shape_and_values():
|
|
63
|
+
def test_kernel_asymm_shape_and_values() -> None:
|
|
67
64
|
rng = np.random.default_rng(42)
|
|
68
65
|
n1, n2, d = 5, 7, 3
|
|
69
66
|
X1 = rng.normal(size=(n1, d))
|
|
@@ -75,12 +72,10 @@ def test_kernel_asymm_shape_and_values():
|
|
|
75
72
|
|
|
76
73
|
Kref = _ref_kernel_asymm(X1, X2, alpha)
|
|
77
74
|
|
|
78
|
-
print(K[:4, :4])
|
|
79
|
-
print(Kref[:4, :4])
|
|
80
75
|
np.testing.assert_allclose(K, Kref, rtol=1e-12, atol=1e-12)
|
|
81
76
|
|
|
82
77
|
|
|
83
|
-
def test_kernel_asymm_small_case():
|
|
78
|
+
def test_kernel_asymm_small_case() -> None:
|
|
84
79
|
X1 = np.array([[0.0], [1.0]]) # n1=2, d=1
|
|
85
80
|
X2 = np.array([[0.0], [2.0]]) # n2=2, d=1
|
|
86
81
|
alpha = -1.0
|
|
@@ -93,30 +88,3 @@ def test_kernel_asymm_small_case():
|
|
|
93
88
|
# X2[1]=2 vs X1[1]=1 -> 1, exp(-1)
|
|
94
89
|
Kref = np.array([[1.0, np.exp(-4.0)], [np.exp(-1.0), np.exp(-1.0)]])
|
|
95
90
|
np.testing.assert_allclose(K, Kref, rtol=1e-12, atol=1e-12)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
@pytest.mark.slow
|
|
99
|
-
def test_time_kernel_symm():
|
|
100
|
-
|
|
101
|
-
X = np.random.normal(size=(16000, 512))
|
|
102
|
-
alpha = -1.0 / X.shape[1]
|
|
103
|
-
|
|
104
|
-
import time
|
|
105
|
-
|
|
106
|
-
start = time.time()
|
|
107
|
-
K = _kernels.kernel_symm(X, alpha)
|
|
108
|
-
end = time.time()
|
|
109
|
-
print(f"Computed kernel_symm in {end - start:.3f} seconds.")
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
def test_time_kernel_asymm():
|
|
113
|
-
X1 = np.random.normal(size=(16000, 512))
|
|
114
|
-
X2 = np.random.normal(size=(16000, 512))
|
|
115
|
-
alpha = -1.0 / X1.shape[1]
|
|
116
|
-
|
|
117
|
-
import time
|
|
118
|
-
|
|
119
|
-
start = time.time()
|
|
120
|
-
K = _kernels.kernel_asymm(X1, X2, alpha)
|
|
121
|
-
end = time.time()
|
|
122
|
-
print(f"Computed kernel_asymm in {end - start:.3f} seconds.")
|
|
@@ -4,7 +4,7 @@ import pytest
|
|
|
4
4
|
from kernelforge import _cholesky
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
def _sym_from_triangle(A, uplo):
|
|
7
|
+
def _sym_from_triangle(A, uplo): # type: ignore
|
|
8
8
|
"""Build a symmetric matrix from only one triangle of A (ignores the other)."""
|
|
9
9
|
if uplo == "U":
|
|
10
10
|
T = np.triu(A)
|
|
@@ -17,7 +17,7 @@ def _sym_from_triangle(A, uplo):
|
|
|
17
17
|
@pytest.mark.parametrize("n", [1, 2, 3, 5, 8, 17, 32])
|
|
18
18
|
@pytest.mark.parametrize("uplo", ["U", "L"])
|
|
19
19
|
@pytest.mark.parametrize("transr", ["N", "T"])
|
|
20
|
-
def test_roundtrip_symmetric(n, uplo, transr, seed=0):
|
|
20
|
+
def test_roundtrip_symmetric(n, uplo, transr, seed=0) -> None: # type: ignore[no-untyped-def]
|
|
21
21
|
rng = np.random.default_rng(seed)
|
|
22
22
|
M = rng.standard_normal((n, n))
|
|
23
23
|
A = (M + M.T) * 0.5 # symmetric
|
|
@@ -49,7 +49,7 @@ def test_roundtrip_symmetric(n, uplo, transr, seed=0):
|
|
|
49
49
|
@pytest.mark.parametrize("n", [3, 7])
|
|
50
50
|
@pytest.mark.parametrize("uplo", ["U", "L"])
|
|
51
51
|
@pytest.mark.parametrize("transr", ["N", "T"])
|
|
52
|
-
def test_nonsymmetric_triangle_semantics(n, uplo, transr, seed=123):
|
|
52
|
+
def test_nonsymmetric_triangle_semantics(n, uplo, transr, seed=123) -> None: # type: ignore[no-untyped-def]
|
|
53
53
|
"""Round-trip uses only one triangle. For a non-symmetric input,
|
|
54
54
|
the returned matrix's specified triangle should match that triangle of the input.
|
|
55
55
|
"""
|
|
@@ -72,7 +72,7 @@ def test_nonsymmetric_triangle_semantics(n, uplo, transr, seed=123):
|
|
|
72
72
|
np.testing.assert_allclose(Bs, expected, rtol=1e-13, atol=1e-13)
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
def test_bad_length_raises():
|
|
75
|
+
def test_bad_length_raises() -> None:
|
|
76
76
|
n = 5
|
|
77
77
|
good = np.zeros(n * (n + 1) // 2, dtype=np.float64)
|
|
78
78
|
bad = np.zeros(good.size + 1, dtype=np.float64)
|
|
@@ -85,7 +85,7 @@ def test_bad_length_raises():
|
|
|
85
85
|
_ = _cholesky.rfp_to_full(bad, n, uplo="U", transr="N")
|
|
86
86
|
|
|
87
87
|
|
|
88
|
-
def test_c_contiguity_and_dtype():
|
|
88
|
+
def test_c_contiguity_and_dtype() -> None:
|
|
89
89
|
n = 6
|
|
90
90
|
A = np.arange(n * n, dtype=np.float64).reshape(n, n) # C-order by default
|
|
91
91
|
arf = _cholesky.full_to_rfp(A, uplo="U", transr="N")
|
|
Binary file
|
|
index c57517e..715adcf 100644
|
|
|
Binary file
|
|
index be15f27..708a349 100644
|
|
|
Binary file
|
|
index e29fe54..828caaa 100644
|
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|