mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-22 23:33:02 +08:00
Add pep8-naming to pre-commit hooks and fixes incorrect naming conventions (#7062)
* ci(pre-commit): Add pep8-naming to `pre-commit` hooks (#7038) * refactor: Fix naming conventions (#7038) * Update arithmetic_analysis/lu_decomposition.py Co-authored-by: Christian Clauss <cclauss@me.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor(lu_decomposition): Replace `NDArray` with `ArrayLike` (#7038) * chore: Fix naming conventions in doctests (#7038) * fix: Temporarily disable project euler problem 104 (#7069) * chore: Fix naming conventions in doctests (#7038) Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -26,7 +26,7 @@ def is_hermitian(matrix: np.ndarray) -> bool:
|
||||
return np.array_equal(matrix, matrix.conjugate().T)
|
||||
|
||||
|
||||
def rayleigh_quotient(A: np.ndarray, v: np.ndarray) -> Any:
|
||||
def rayleigh_quotient(a: np.ndarray, v: np.ndarray) -> Any:
|
||||
"""
|
||||
Returns the Rayleigh quotient of a Hermitian matrix A and
|
||||
vector v.
|
||||
@ -45,20 +45,20 @@ def rayleigh_quotient(A: np.ndarray, v: np.ndarray) -> Any:
|
||||
array([[3.]])
|
||||
"""
|
||||
v_star = v.conjugate().T
|
||||
v_star_dot = v_star.dot(A)
|
||||
v_star_dot = v_star.dot(a)
|
||||
assert isinstance(v_star_dot, np.ndarray)
|
||||
return (v_star_dot.dot(v)) / (v_star.dot(v))
|
||||
|
||||
|
||||
def tests() -> None:
|
||||
A = np.array([[2, 2 + 1j, 4], [2 - 1j, 3, 1j], [4, -1j, 1]])
|
||||
a = np.array([[2, 2 + 1j, 4], [2 - 1j, 3, 1j], [4, -1j, 1]])
|
||||
v = np.array([[1], [2], [3]])
|
||||
assert is_hermitian(A), f"{A} is not hermitian."
|
||||
print(rayleigh_quotient(A, v))
|
||||
assert is_hermitian(a), f"{a} is not hermitian."
|
||||
print(rayleigh_quotient(a, v))
|
||||
|
||||
A = np.array([[1, 2, 4], [2, 3, -1], [4, -1, 1]])
|
||||
assert is_hermitian(A), f"{A} is not hermitian."
|
||||
assert rayleigh_quotient(A, v) == float(3)
|
||||
a = np.array([[1, 2, 4], [2, 3, -1], [4, -1, 1]])
|
||||
assert is_hermitian(a), f"{a} is not hermitian."
|
||||
assert rayleigh_quotient(a, v) == float(3)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user