-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
268 additions
and
64 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
"argmax", | ||
"AVOGADROS", | ||
"dtype", | ||
"EATF", | ||
"fft", | ||
"fftfreq", | ||
"fftpack", | ||
|
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
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
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,14 +1,23 @@ | ||
"""Useful utilities (largely linalg for calculating polarizability model).""" | ||
|
||
import itertools | ||
from typing import Iterable | ||
|
||
import numpy as np | ||
from numpy.typing import NDArray | ||
from numpy.typing import NDArray, ArrayLike | ||
|
||
|
||
def find_duplicates(vectors: list[NDArray[np.float64]]) -> NDArray[np.float64] | None: | ||
def find_duplicates(vectors: Iterable[ArrayLike]) -> NDArray | None: | ||
"""Return duplicate vector in a list or None if no duplicates found.""" | ||
for vector_1, vector_2 in itertools.combinations(vectors, 2): | ||
if np.isclose(vector_1, vector_2): | ||
return vector_1 | ||
return None | ||
try: | ||
combinations = itertools.combinations(vectors, 2) | ||
except TypeError as exc: | ||
wrong_type = type(vectors).__name__ | ||
raise TypeError(f"vectors should be iterable, not {wrong_type}") from exc | ||
try: | ||
for vector_1, vector_2 in combinations: | ||
if np.isclose(vector_1, vector_2).all(): | ||
return np.array(vector_1) | ||
return None | ||
except TypeError as exc: | ||
raise TypeError("elements of vectors are not array_like") from exc |
Oops, something went wrong.