Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

nitpick_ignore_regex = [
["py:class", r"optype.*"],
["py:class", r"onp.*"],
]

sphinxconfig_missing_reference_aliases = {
Expand Down
15 changes: 12 additions & 3 deletions pytools/convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
from __future__ import annotations

import numbers
from typing import TYPE_CHECKING, Any

import numpy as np
from typing_extensions import override


# {{{ eoc estimation --------------------------------------------------------------
if TYPE_CHECKING:
import optype.numpy as onp


# {{{ eoc estimation

def estimate_order_of_convergence(abscissae, errors):
r"""Assuming that abscissae and errors are connected by a law of the form
Expand Down Expand Up @@ -48,7 +53,11 @@ class EOCRecorder:
def __init__(self) -> None:
self.history: list[tuple[float, float]] = []

def add_data_point(self, abscissa: float, error: float) -> None:
def add_data_point(
self,
abscissa: float | np.floating[Any] | onp.Array0D[np.floating[Any]],
error: float | np.floating[Any] | onp.Array0D[np.floating[Any]]
) -> None:
if not (isinstance(abscissa, numbers.Number)
or (isinstance(abscissa, np.ndarray) and abscissa.shape == ())):
raise TypeError(
Expand All @@ -58,7 +67,7 @@ def add_data_point(self, abscissa: float, error: float) -> None:
or (isinstance(error, np.ndarray) and error.shape == ())):
raise TypeError(f"'error' is not a scalar: '{type(error).__name__}'")

self.history.append((abscissa, error))
self.history.append((float(abscissa), float(error)))

def estimate_order_of_convergence(self,
gliding_mean: int | None = None,
Expand Down
Loading