From da7717a84244bc10dfa40ade9e7d8fe87fb49af9 Mon Sep 17 00:00:00 2001 From: Giordon Stark Date: Sun, 28 Aug 2022 21:56:58 -0700 Subject: [PATCH 1/3] add configuration for rendering docs --- docs/conf.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/conf.py b/docs/conf.py index 81e5f1a4f1..2c3b74e884 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -141,6 +141,38 @@ def setup(app): 'tensorflow_probability', ] + +_type_aliases_inverted = { + 'pyhf.typing': [ + 'PathOrStr', + 'ParameterBase', + 'Parameter', + 'Measurement', + 'ModifierBase', + 'NormSys', + 'NormFactor', + 'HistoSys', + 'StatError', + 'ShapeSys', + 'ShapeFactor', + 'LumiSys', + 'Modifier', + 'Sample', + 'Channel', + 'Observation', + 'Workspace', + 'Literal', + ], + 'numpy.typing': ['ArrayLike', 'DTypeLike', 'NBitBase', 'NDArray'], +} +autodoc_type_aliases = { + item: f'{k}.{item}' for k, v in _type_aliases_inverted.items() for item in v +} + +autodoc_typehints_format = 'fully-qualified' + +print(autodoc_type_aliases) + # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path From 882fbaf82a597d5ef3ae37d49fa45af7b6a550c8 Mon Sep 17 00:00:00 2001 From: Giordon Stark Date: Sun, 28 Aug 2022 21:57:46 -0700 Subject: [PATCH 2/3] found a typo in how we wrote out the dtype signature type --- src/pyhf/tensor/numpy_backend.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/pyhf/tensor/numpy_backend.py b/src/pyhf/tensor/numpy_backend.py index 1e623d0147..ea00a3b78f 100644 --- a/src/pyhf/tensor/numpy_backend.py +++ b/src/pyhf/tensor/numpy_backend.py @@ -15,7 +15,7 @@ T = TypeVar("T", bound=NBitBase) Tensor = Union["NDArray[np.number[T]]", "NDArray[np.bool_]"] - +FloatIntOrBool = Literal["float", "int", "bool"] log = logging.getLogger(__name__) @@ -53,7 +53,7 @@ def __init__(self, **kwargs: dict[str, str]): self.name = 'numpy' self.precision = kwargs.get('precision', '64b') self.dtypemap: Mapping[ - Literal['float', 'int', 'bool'], + FloatIntOrBool, DTypeLike, # Type[np.floating[T]] | Type[np.integer[T]] | Type[np.bool_], ] = { 'float': np.float64 if self.precision == '64b' else np.float32, @@ -206,7 +206,7 @@ def isfinite(self, tensor: Tensor[T]) -> NDArray[np.bool_]: return np.isfinite(tensor) def astensor( - self, tensor_in: ArrayLike, dtype: Literal['float'] = 'float' + self, tensor_in: ArrayLike, dtype: FloatIntOrBool = 'float' ) -> ArrayLike: """ Convert to a NumPy array. @@ -247,9 +247,7 @@ def product(self, tensor_in: Tensor[T], axis: Shape | None = None) -> ArrayLike: def abs(self, tensor: Tensor[T]) -> ArrayLike: return np.abs(tensor) - def ones( - self, shape: Shape, dtype: Literal["float", "int", "bool"] = "float" - ) -> ArrayLike: + def ones(self, shape: Shape, dtype: FloatIntOrBool = "float") -> ArrayLike: try: dtype_obj = self.dtypemap[dtype] except KeyError: @@ -261,9 +259,7 @@ def ones( return np.ones(shape, dtype=dtype_obj) - def zeros( - self, shape: Shape, dtype: Literal["float", "int", "bool"] = "float" - ) -> ArrayLike: + def zeros(self, shape: Shape, dtype: FloatIntOrBool = "float") -> ArrayLike: try: dtype_obj = self.dtypemap[dtype] except KeyError: From bfc64d0a0a91234cf2f51fe36aa40c6e0c5a2b07 Mon Sep 17 00:00:00 2001 From: Giordon Stark Date: Sun, 28 Aug 2022 22:01:38 -0700 Subject: [PATCH 3/3] drop print --- docs/conf.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 2c3b74e884..276d85a52b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -171,8 +171,6 @@ def setup(app): autodoc_typehints_format = 'fully-qualified' -print(autodoc_type_aliases) - # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path