Skip to content

Commit

Permalink
TST: GHA Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
has2k1 committed Jul 18, 2023
1 parent b47f8b0 commit 99e46f3
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions mizani/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,51 @@ def precision(x: FloatArrayLike | float) -> float:
return min(1, res)


def precision_test(x: FloatArrayLike | float) -> float:
"""
Examples
--------
>>> precision_test([0.08, 0.09])
0.009999999999999995
-2.0
-2.0
0.001
[80. 90.]
[80. 90.]
[0. 0.]
[ True True]
True
0.01
"""
x = np.asarray(x)
x = x[~(np.isnan(x) | np.isinf(x))]

if len(x) <= 1:
return 1

smallest_diff = np.diff(np.sort(x))[0]
if smallest_diff < np.sqrt(EPSILON): # pragma: nocover
return 1
else:
res = 10 ** int(np.floor(np.log10(smallest_diff)) - 1)
has_extra_zeros = (np.round(x / res) % 10 == 0).all()
print(smallest_diff)
print(np.log10(smallest_diff))
print(np.floor(np.log10(smallest_diff)))
print(res)
print(x / res)
print(np.round(x / res))
print(np.round(x / res) % 10)
print((np.round(x / res) % 10 == 0))
print(has_extra_zeros)
if has_extra_zeros:
res *= 10

# 1 comes first so that min(1, 1.0) returns an integer
return min(1, res)


def same_log10_order_of_magnitude(x, delta=0.1):
"""
Return true if range is approximately in same order of magnitude
Expand Down

0 comments on commit 99e46f3

Please sign in to comment.