Skip to content

Commit

Permalink
mypy passing finally ...
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdi committed Nov 21, 2023
1 parent 8a164c4 commit 828aa30
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ContinuousTesting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
run: |
ruff check --output-format=github pyssp --verbose
- name: Static Type Check
run: |
mypy pyssp --explicit-package-bases
- name: Test
run: |
pytest
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Direct impelementation of statistical digital signal processing algorithms from

The book represents algorithms as:

1. set of instructions (pseudo-code)
1. matlab code
1. described in English in the textbook body
1. set of instructions (pseudo-code) annotated in Tables.
1. matlab code annotated in Figures.
1. described in words in the body of the text.

## Chapters

Expand All @@ -24,10 +24,10 @@ The book represents algorithms as:

- add proper reference to the book
- lint markdown readme
- Finalize test cases for all codes
- finalize test cases for all codes
- python documentation generator
- mypy static type checking
- Release package scripts
- release package scripts
- stub files?
- VS code add-ons
- use matlab-equivalent psuedo-inverse ("X \ R") operation to match the book
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

[tool.mypy]
mypy_path = "pyssp"
ignore_missing_imports = true
#plugins = "numpy.typing.mypy_plugin"
2 changes: 1 addition & 1 deletion pyssp/levinson.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def rtoa(r) -> tuple[np.ndarray, np.ndarray]:
gamma = -np.transpose(r[1:1 + j,]) @ np.flipud(a) / epsilon
an = np.concatenate((a, np.zeros((1, 1)))).reshape(-1, 1)
anT = np.conjugate(np.flipud(a))
a = an + gamma * np.concatenate(([0], anT.ravel())).reshape(-1, 1)
a = an + gamma * np.concatenate((np.zeros(1), anT.ravel())).reshape(-1, 1)
epsilon = epsilon * (1 - np.abs(gamma)**2)
print(f"{gamma=},\n{a=},\n{epsilon=}\n")
return a, epsilon
Expand Down
15 changes: 8 additions & 7 deletions pyssp/modeling.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Chapter 4 modeling algorithm implementations."""

from numpy.linalg import inv
import numpy as np
import scipy as sp

from .state import convm
from state import convm


def pade(x, p, q):

Check failure on line 10 in pyssp/modeling.py

View workflow job for this annotation

GitHub Actions / build

Ruff (I001)

pyssp/modeling.py:3:1: I001 Import block is un-sorted or un-formatted
Expand All @@ -20,7 +21,7 @@ def pade(x, p, q):
# Linear difference matrix spanning the number of zeros
Xq = X[q + 1:q + p + 1, 1:p + 1].copy()
print(Xq.shape)
a = np.linalg.solve(-Xq, X[q + 1: q + p + 1, 0])
a = linalg.solve(-Xq, X[q + 1: q + p + 1, 0])

Check failure on line 24 in pyssp/modeling.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F821)

pyssp/modeling.py:24:9: F821 Undefined name `linalg`
# a(0) normalized to 1
a = np.concatenate((np.ones(1), a)).reshape(-1, 1)
b = X[:q + 1, :p + 1] @ a
Expand Down Expand Up @@ -59,7 +60,7 @@ def prony(x, p, q):
Xq1 = X[q + 1:N + p, 0].copy()
Xq_H = Xq.conjugate().transpose()
rx = Xq_H @ Xq1
Xinv = np.linalg.inv(Xq_H @ Xq)
Xinv = linalg.inv(Xq_H @ Xq)

Check failure on line 63 in pyssp/modeling.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F821)

pyssp/modeling.py:63:12: F821 Undefined name `linalg`
a = -Xinv @ rx
print(a.shape)
# a(0) normalized to 1
Expand Down Expand Up @@ -93,7 +94,7 @@ def shanks(x, p, q):
gx = G0_H @ x0
# the factorization does not guarantee nonsingularity!
# resulting matrix is positive *semi*-definite
Ginv = np.linalg.inv(G0_H @ G0)
Ginv = linalg.inv(G0_H @ G0)

Check failure on line 97 in pyssp/modeling.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F821)

pyssp/modeling.py:97:12: F821 Undefined name `linalg`
print(f"{x.shape=}")
print(f"{Ginv.shape=}")
b = Ginv @ gx
Expand All @@ -117,7 +118,7 @@ def spike(g, n0, n):
G_H = np.transpose(G.conjugate())

print(f"{G_H.shape=}, {G.shape=}")
Ginv = np.linalg.inv(G_H @ G)
Ginv = linalg.inv(G_H @ G)

Check failure on line 121 in pyssp/modeling.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F821)

pyssp/modeling.py:121:12: F821 Undefined name `linalg`
h = Ginv @ G_H @ d

return h
Expand All @@ -141,7 +142,7 @@ def acm(x, p) -> tuple[np.ndarray, np.ndarray]:
Xq = X[:N + p - 1, :p].copy()
rx = X[1:N + p, 0].copy()
Xq_H = Xq.copy().conjugate().transpose()
Xinv = np.linalg.inv(Xq_H @ Xq)
Xinv = inv(Xq_H @ Xq)
a1 = -Xinv @ Xq_H @ rx
a = np.concatenate((np.ones(1), a1)).reshape(-1, 1)
err = np.abs(X[:N + p, 0].T @ X @ a)
Expand All @@ -161,7 +162,7 @@ def covm(x, p):
cx = X[p:N, 0].copy()
Xq_H = Xq.copy().conjugate().transpose()
print(f"{Xq=}")
Xinv = np.linalg.inv(Xq_H @ Xq)
Xinv = linalg.inv(Xq_H @ Xq)

Check failure on line 165 in pyssp/modeling.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F821)

pyssp/modeling.py:165:12: F821 Undefined name `linalg`
a1 = -Xinv @ Xq_H @ cx
a = np.concatenate((np.ones(1), a1)).reshape(-1, 1)
err = np.abs(cx.transpose() @ X[p:N,] @ a)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ matplotlib
ruff
pytest
pytest-cov
mypy
mypy

0 comments on commit 828aa30

Please sign in to comment.