Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
welschma committed Dec 22, 2020
1 parent 7ea0a2b commit 40df6be
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions templatefitter/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
from numba import jit, vectorize, float64, float32


__all__ = ["cov2corr", "corr2cov", "xlogyx", "get_systematic_cov_mat",
"array_split_into"]
__all__ = [
"cov2corr",
"corr2cov",
"xlogyx",
"get_systematic_cov_mat",
"array_split_into",
]


def cov2corr(cov):
Expand Down Expand Up @@ -77,19 +82,23 @@ def id_to_index(names, param_id):


# @jit(nopython=True, cache=True)
@vectorize([float32(float32, float32),
float64(float64, float64)])
@vectorize([float32(float32, float32), float64(float64, float64)])
def xlogyx(x, y):
"""Compute :math:`x*log(y/x)`to a good precision when :math:`y~x`.
The xlogyx function is taken from https://github.com/scikit-hep/probfit/blob/master/probfit/_libstat.pyx.
"""
# result = np.where(x < y, x * np.log1p((y - x) / x), -x * np.log1p((x - y) / y))
if x < 1e-100:
return 0.
elif x<y:
return x*np.log1p((y-x)/x)

if np.isnan(x):
return 0.0

elif x < 1e-100:
return 0.0

elif x < y:
return x * np.log1p((y - x) / x)
else:
return -x*np.log1p((x-y)/y)
return -x * np.log1p((x - y) / y)
# result = np.zeros_like(x)
#
# for i in range(x.shape[0]):
Expand Down

0 comments on commit 40df6be

Please sign in to comment.