Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a bit numpy typing #40

Merged
merged 45 commits into from
Dec 4, 2024
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
3a44754
introduced quemb namespace
mcocdawc Nov 26, 2024
2c13894
updated docs with quemb namespace
mcocdawc Nov 26, 2024
19b5474
removed wrong __init__.py
mcocdawc Nov 26, 2024
7e5e2fd
updated mypy settings
mcocdawc Nov 26, 2024
fc3e5c0
add check for assumed failing function
mcocdawc Nov 26, 2024
beda895
improved docstring adder
mcocdawc Nov 26, 2024
3788b0b
small reformatting
mcocdawc Nov 26, 2024
d3869fe
fixed rdm test
mcocdawc Nov 26, 2024
f917b9f
changed molbe.BE.localize to be properly defined as method
mcocdawc Nov 26, 2024
b17b222
turned kbe localization into mixin
mcocdawc Nov 26, 2024
4adb13e
Revert "changed molbe.BE.localize to be properly defined as method"
mcocdawc Nov 26, 2024
a8fcf44
turned molBE localize into method via mixin
mcocdawc Nov 26, 2024
d6a615f
moved molbe.external to shared.external
mcocdawc Nov 26, 2024
5ab89e8
turned get_be_error_jacobian into free function
mcocdawc Nov 26, 2024
727e061
moved definition of molbe.optimize
mcocdawc Nov 26, 2024
f6198ce
added ISSUES and TODOs
mcocdawc Nov 26, 2024
187ffce
moved molbe RDM methods into the molbe class
mcocdawc Nov 26, 2024
c5a993e
moved kbe.BE.optimize into the class definition
mcocdawc Nov 26, 2024
00efcbf
no more imports in class definitions
mcocdawc Nov 26, 2024
0af761e
Replace dangerous double leading underscores with trailing ones
mcocdawc Nov 26, 2024
57ac99a
fixed indentation
mcocdawc Nov 27, 2024
359de78
fixed formatting
mcocdawc Nov 27, 2024
31456c0
added py.typed file to quemb
mcocdawc Nov 27, 2024
63f7d3c
added TODO
mcocdawc Nov 27, 2024
d6655aa
use approx cumulant in molbe octane rdm test
mcocdawc Nov 27, 2024
b344df1
added correct Optional specifier
mcocdawc Nov 27, 2024
fdf25eb
moved ncore_ from molbe.helper to shared.helper
mcocdawc Nov 27, 2024
ecdf2ad
Merge branch 'main' into fix_mypy
mcocdawc Nov 27, 2024
002477d
fixed imports
mcocdawc Nov 27, 2024
2b58871
added check for trailing whitespace to CI pipeline
mcocdawc Nov 27, 2024
f33dda2
check whitespace test on server side
mcocdawc Nov 27, 2024
574c014
play around with whitespace rules
mcocdawc Nov 27, 2024
ba74d58
fixed trailing newlines at EOF
mcocdawc Nov 27, 2024
93ba15b
changed docs/make.bat to UNIX format
mcocdawc Nov 27, 2024
62ee6fd
do the whitespace test earlier
mcocdawc Nov 27, 2024
966ea27
check the enforcement of whitespace rules
mcocdawc Nov 27, 2024
87b6c38
fixed trailing line at EOF of gitignore
mcocdawc Nov 27, 2024
43d6acb
recommit docs/make.bat with Windows newline chars
mcocdawc Nov 27, 2024
8129872
cleanly ignore windows file for whitespace check
mcocdawc Nov 27, 2024
3575c96
removed ISSUES and TODO files
mcocdawc Nov 27, 2024
99daeca
added a bit of functionality for numpy typing
mcocdawc Nov 27, 2024
d1ce094
Merge branch 'main' of github.com:troyvvgroup/quemb into add_a_bit_nu…
mcocdawc Dec 4, 2024
91a8a97
deleted .DS_Store
mcocdawc Dec 4, 2024
dab199c
added comment to explain reason for covariant type
mcocdawc Dec 4, 2024
1e4fbaf
trigger pipeline
mcocdawc Dec 4, 2024
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
27 changes: 27 additions & 0 deletions src/quemb/shared/typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Enable barebone typechecking for the shape of numpy arrays

Inspired by
https://stackoverflow.com/questions/75495212/type-hinting-numpy-arrays-and-batches

Note that most numpy functions return `ndarray[Any, Any]`
i.e. the type is mostly useful to document intent to the developer.
"""

from typing import Tuple, TypeVar

import numpy as np

# We want the dtype to behave covariant, i.e. if a
# Vector[float] is allowed, then the more specific
# Vector[float64] should also be allowed.
# Also see here:
# https://stackoverflow.com/questions/61568462/what-does-typevara-b-covariant-true-mean
T_dtype_co = TypeVar("T_dtype_co", bound=np.generic, covariant=True)

Vector = np.ndarray[Tuple[int], np.dtype[T_dtype_co]]
Matrix = np.ndarray[Tuple[int, int], np.dtype[T_dtype_co]]
Tensor3D = np.ndarray[Tuple[int, int, int], np.dtype[T_dtype_co]]
Tensor4D = np.ndarray[Tuple[int, int, int, int], np.dtype[T_dtype_co]]
Tensor5D = np.ndarray[Tuple[int, int, int, int, int], np.dtype[T_dtype_co]]
Tensor6D = np.ndarray[Tuple[int, int, int, int, int, int], np.dtype[T_dtype_co]]
Tensor = np.ndarray[Tuple[int, ...], np.dtype[T_dtype_co]]
Loading