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 type annotations #244

Closed
wants to merge 21 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
50143e5
Add type-annotations to Runner
basnijholt Oct 12, 2022
6cf01d8
Add type-hints to adaptive/_version.py
basnijholt Oct 12, 2022
1786f80
Add type-hints to adaptive/learner/__init__.py
basnijholt Oct 12, 2022
9490093
Add type-hints to adaptive/learner/balancing_learner.py
basnijholt Oct 12, 2022
6b3209f
Add type-hints to adaptive/learner/base_learner.py
basnijholt Oct 12, 2022
8363aa6
Add type-hints to adaptive/learner/data_saver.py
basnijholt Oct 12, 2022
2b0497f
Add type-hints to adaptive/learner/integrator_coeffs.py
basnijholt Oct 12, 2022
c2b6cf3
Add type-hints to adaptive/learner/integrator_learner.py
basnijholt Oct 12, 2022
3293f60
Add type-hints to adaptive/learner/learner2D.py
basnijholt Oct 12, 2022
2b5e0d1
Add type-hints to adaptive/learner/learnerND.py
basnijholt Oct 12, 2022
08ddfb2
Add type-hints to adaptive/learner/sequence_learner.py
basnijholt Oct 12, 2022
5d8110f
Add type-hints to adaptive/learner/skopt_learner.py
basnijholt Oct 12, 2022
7fd0588
Add type-hints to adaptive/learner/triangulation.py
basnijholt Oct 12, 2022
2e0efc1
Add type-hints to adaptive/notebook_integration.py
basnijholt Oct 12, 2022
96e186f
Add type-hints to adaptive/tests/algorithm_4.py
basnijholt Oct 12, 2022
ec3649a
Add type-hints to adaptive/tests/test_average_learner1d.py
basnijholt Oct 12, 2022
54265bb
Add type-hints to adaptive/tests/test_learner1d.py
basnijholt Oct 12, 2022
9e52ecb
Add type-hints to adaptive/tests/test_learners.py
basnijholt Oct 12, 2022
b4ba66e
Add type-hints to adaptive/types.py
basnijholt Oct 12, 2022
3928c3d
Add type-hints to adaptive/utils.py
basnijholt Oct 12, 2022
95cc29b
Add type-hints to setup.py
basnijholt Oct 12, 2022
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
Prev Previous commit
Next Next commit
Add type-hints to adaptive/learner/integrator_coeffs.py
basnijholt committed Oct 12, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 2b0497f46f5f8fb6cc6e5c2d526933ff6de81d95
11 changes: 6 additions & 5 deletions adaptive/learner/integrator_coeffs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Based on an adaptive quadrature algorithm by Pedro Gonnet
from __future__ import annotations

from collections import defaultdict
from fractions import Fraction
@@ -8,7 +9,7 @@
import scipy.linalg


def legendre(n):
def legendre(n: int) -> list[list[Fraction]]:
"""Return the first n Legendre polynomials.

The polynomials have *standard* normalization, i.e.
@@ -29,7 +30,7 @@ def legendre(n):
return result


def newton(n):
def newton(n: int) -> np.ndarray:
"""Compute the monomial coefficients of the Newton polynomial over the
nodes of the n-point Clenshaw-Curtis quadrature rule.
"""
@@ -86,7 +87,7 @@ def newton(n):
return cf


def scalar_product(a, b):
def scalar_product(a: list[Fraction], b: list[Fraction]) -> Fraction:
"""Compute the polynomial scalar product int_-1^1 dx a(x) b(x).

The args must be sequences of polynomial coefficients. This
@@ -107,7 +108,7 @@ def scalar_product(a, b):
return 2 * sum(c[i] / (i + 1) for i in range(0, lc, 2))


def calc_bdef(ns):
def calc_bdef(ns: tuple[int, int, int, int]) -> list[np.ndarray]:
"""Calculate the decompositions of Newton polynomials (over the nodes
of the n-point Clenshaw-Curtis quadrature rule) in terms of
Legandre polynomials.
@@ -133,7 +134,7 @@ def calc_bdef(ns):
return result


def calc_V(x, n):
def calc_V(x: np.ndarray, n: int) -> np.ndarray:
V = [np.ones(x.shape), x.copy()]
for i in range(2, n):
V.append((2 * i - 1) / i * x * V[-1] - (i - 1) / i * V[-2])