Skip to content
Closed
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
3 changes: 2 additions & 1 deletion src/pyhf/cli/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from pyhf.infer import hypotest
from pyhf.infer import mle
from pyhf.workspace import Workspace
from pyhf import get_backend, set_backend, optimize
from pyhf.tensor.manager import get_backend, set_backend
from pyhf import optimize

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/pyhf/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def paramset_to_rootnames(paramset):
paramset (:obj:`pyhf.paramsets.paramset`): The parameter set.

Returns:
:obj:`List[str]` or :obj:`str`: The generated parameter names
:obj:`list[str]` or :obj:`str`: The generated parameter names
(for the non-scalar/scalar case) respectively.

Example:
Expand Down
2 changes: 1 addition & 1 deletion src/pyhf/infer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Inference for Statistical Models."""

from pyhf.infer import utils
from pyhf import get_backend
from pyhf.tensor.manager import get_backend
from pyhf import exceptions


Expand Down
2 changes: 1 addition & 1 deletion src/pyhf/infer/calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

from pyhf.infer.mle import fixed_poi_fit
from pyhf import get_backend
from pyhf.tensor.manager import get_backend
from pyhf.infer import utils
import tqdm

Expand Down
2 changes: 1 addition & 1 deletion src/pyhf/infer/intervals/upper_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from scipy.optimize import toms748

from pyhf import get_backend
from pyhf.tensor.manager import get_backend
from pyhf.infer import hypotest

__all__ = ["linear_grid_scan", "toms748_scan", "upper_limit"]
Expand Down
2 changes: 1 addition & 1 deletion src/pyhf/infer/mle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Module for Maximum Likelihood Estimation."""

from pyhf import get_backend
from pyhf.tensor.manager import get_backend
from pyhf.exceptions import UnspecifiedPOI

__all__ = ["fit", "fixed_poi_fit", "twice_nll"]
Expand Down
2 changes: 1 addition & 1 deletion src/pyhf/infer/test_statistics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyhf import get_backend
from pyhf.tensor.manager import get_backend
from pyhf.infer.mle import fixed_poi_fit, fit
from pyhf.exceptions import UnspecifiedPOI

Expand Down
3 changes: 2 additions & 1 deletion src/pyhf/modifiers/lumi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from pyhf import get_backend, events
from pyhf.tensor.manager import get_backend
from pyhf import events
from pyhf.parameters import ParamViewer

log = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion src/pyhf/modifiers/normfactor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from pyhf import get_backend, events
from pyhf.tensor.manager import get_backend
from pyhf import events
from pyhf.parameters import ParamViewer

log = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion src/pyhf/modifiers/normsys.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from pyhf import get_backend, events
from pyhf.tensor.manager import get_backend
from pyhf import events
from pyhf import interpolators
from pyhf.parameters import ParamViewer

Expand Down
5 changes: 3 additions & 2 deletions src/pyhf/modifiers/staterror.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
from typing import List

import pyhf
from pyhf import events
Expand All @@ -10,7 +11,7 @@
log = logging.getLogger(__name__)


def required_parset(sigmas, fixed: List[bool]):
def required_parset(sigmas, fixed: list[bool]):
n_parameters = len(sigmas)
return {
'paramset_type': 'constrained_by_normal',
Expand Down
2 changes: 1 addition & 1 deletion src/pyhf/optimize/opt_jax.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""JAX Backend Function Shim."""

from pyhf import get_backend
from pyhf.tensor.manager import get_backend
from pyhf.tensor.common import _TensorViewer
import jax
import logging
Expand Down
2 changes: 1 addition & 1 deletion src/pyhf/optimize/opt_numpy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Numpy Backend Function Shim."""

from pyhf import get_backend
from pyhf.tensor.manager import get_backend
from pyhf import exceptions


Expand Down
4 changes: 1 addition & 3 deletions src/pyhf/parameters/paramsets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

import pyhf

__all__ = [
Expand Down Expand Up @@ -29,7 +27,7 @@ def __init__(self, **kwargs):
)

@property
def suggested_fixed(self) -> List[bool]:
def suggested_fixed(self) -> list[bool]:
if isinstance(self._suggested_fixed, bool):
return [self._suggested_fixed] * self.n_parameters
return self._suggested_fixed
Expand Down
4 changes: 2 additions & 2 deletions src/pyhf/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import copy
import logging
from typing import List, Union
from typing import Union

import pyhf.parameters
import pyhf
Expand Down Expand Up @@ -406,7 +406,7 @@ def param_set(self, name):
"""
return self.par_map[name]['paramset']

def suggested_fixed(self) -> List[bool]:
def suggested_fixed(self) -> list[bool]:
"""
Identify the fixed parameters in the model.

Expand Down
2 changes: 1 addition & 1 deletion src/pyhf/probability.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""The probability density function module."""

from pyhf import get_backend
from pyhf.tensor.manager import get_backend

__all__ = ["Independent", "Normal", "Poisson", "Simultaneous"]

Expand Down
5 changes: 2 additions & 3 deletions src/pyhf/readxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
IO,
Callable,
Iterable,
List,
MutableMapping,
MutableSequence,
Sequence,
Expand Down Expand Up @@ -99,7 +98,7 @@ def extract_error(hist: uproot.behaviors.TH1.TH1) -> list[float]:
"""

variance = hist.variances() if hist.weighted else hist.to_numpy()[0]
return cast(List[float], np.sqrt(variance).tolist())
return cast(list[float], np.sqrt(variance).tolist())


def import_root_histogram(
Expand Down Expand Up @@ -222,7 +221,7 @@ def process_sample(
modtag.attrib.get('HistoPath', ''),
modtag.attrib['HistoName'],
)
staterr = np.multiply(extstat, data).tolist()
staterr = cast(list[float], np.multiply(extstat, data).tolist())
if not staterr:
raise RuntimeError('cannot determine stat error.')
modifier_staterror: StatError = {
Expand Down
21 changes: 17 additions & 4 deletions src/pyhf/tensor/numpy_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
from __future__ import annotations

import logging
from typing import TYPE_CHECKING, Callable, Generic, Mapping, Sequence, TypeVar, Union
from typing import (
Any,
TYPE_CHECKING,
Callable,
Generic,
Mapping,
Sequence,
TypeVar,
Union,
)

import numpy as np

Expand Down Expand Up @@ -205,9 +214,12 @@ def conditional(
"""
return true_callable() if predicate else false_callable()

def tolist(self, tensor_in: Tensor[T] | list[T]) -> list[T]:
def tolist(
self, tensor_in: Tensor[T] | list[T]
) -> int | float | complex | list[T] | list[Any]:
try:
return tensor_in.tolist() # type: ignore[union-attr,no-any-return]
result = tensor_in.tolist() # type: ignore[union-attr]
return cast(Union[int, float, complex, list[T], list[Any]], result)
except AttributeError:
if isinstance(tensor_in, list):
return tensor_in
Expand Down Expand Up @@ -654,4 +666,5 @@ def transpose(self, tensor_in: Tensor[T]) -> ArrayLike:

.. versionadded:: 0.7.0
"""
return tensor_in.transpose()
result = tensor_in.transpose()
return cast(ArrayLike, result)
Loading