Skip to content

Use numbers module from stdlib as type #379

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

Merged
merged 1 commit into from
Oct 12, 2022
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
4 changes: 3 additions & 1 deletion adaptive/learner/average_learner.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from __future__ import annotations

from math import sqrt
from numbers import Integral as Int
from numbers import Real
from typing import Callable

import cloudpickle
import numpy as np

from adaptive.learner.base_learner import BaseLearner
from adaptive.notebook_integration import ensure_holoviews
from adaptive.types import Float, Int, Real
from adaptive.types import Float
from adaptive.utils import (
assign_defaults,
cache_latest,
Expand Down
7 changes: 4 additions & 3 deletions adaptive/learner/average_learner1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from collections import defaultdict
from copy import deepcopy
from math import hypot
from numbers import Integral as Int
from numbers import Real
from typing import Callable, DefaultDict, Iterable, List, Sequence, Tuple

import numpy as np
Expand All @@ -14,7 +16,6 @@

from adaptive.learner.learner1D import Learner1D, _get_intervals
from adaptive.notebook_integration import ensure_holoviews
from adaptive.types import Int, Real
from adaptive.utils import assign_defaults, partial_function_from_dataframe

try:
Expand Down Expand Up @@ -576,10 +577,10 @@ def tell_many_at_point(self, x: Real, seed_y_mapping: dict[int, Real]) -> None:
self._update_interpolated_loss_in_interval(*interval)
self._oldscale = deepcopy(self._scale)

def _get_data(self) -> dict[Real, Real]:
def _get_data(self) -> dict[Real, dict[Int, Real]]:
return self._data_samples

def _set_data(self, data: dict[Real, Real]) -> None:
def _set_data(self, data: dict[Real, dict[Int, Real]]) -> None:
if data:
for x, samples in data.items():
self.tell_many_at_point(x, samples)
Expand Down
4 changes: 3 additions & 1 deletion adaptive/learner/learner1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import itertools
import math
from copy import copy, deepcopy
from numbers import Integral as Int
from numbers import Real
from typing import Any, Callable, Dict, List, Sequence, Tuple, Union

import cloudpickle
Expand All @@ -15,7 +17,7 @@
from adaptive.learner.learnerND import volume
from adaptive.learner.triangulation import simplex_volume_in_embedding
from adaptive.notebook_integration import ensure_holoviews
from adaptive.types import Float, Int, Real
from adaptive.types import Float
from adaptive.utils import (
assign_defaults,
cache_latest,
Expand Down
2 changes: 1 addition & 1 deletion adaptive/learner/sequence_learner.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import annotations

from copy import copy
from numbers import Integral as Int
from typing import Any, Tuple

import cloudpickle
from sortedcontainers import SortedDict, SortedSet

from adaptive.learner.base_learner import BaseLearner
from adaptive.types import Int
from adaptive.utils import assign_defaults, partial_function_from_dataframe

try:
Expand Down
7 changes: 5 additions & 2 deletions adaptive/types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from numbers import Integral as Int
from numbers import Real
from typing import Union

import numpy as np
Expand All @@ -9,6 +11,7 @@
from typing_extensions import TypeAlias

Float: TypeAlias = Union[float, np.float_]
Int: TypeAlias = Union[int, np.int_]
Real: TypeAlias = Union[Float, Int]
Bool: TypeAlias = Union[bool, np.bool_]


__all__ = ["Float", "Bool", "Int", "Real"]