Skip to content
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

Fix crash in tqdm library #491

Open
wants to merge 3 commits into
base: develop/main
Choose a base branch
from
Open
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 Tests/requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pyyaml
numpy
pytest>=6.2.5
pandas
sqlalchemy
sqlalchemy
tqdm
42 changes: 41 additions & 1 deletion Tests/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,44 @@ def test_strides_from_shape():
strides = [itemsize] + list(shape[:-1])
for i in range(1, ndim):
strides[i] *= strides[i-1]
assert strides == [10, 5, 1]
assert strides == [10, 5, 1]


@pytest.mark.optimization(1)
def test_ema():
class EMA:
"""
From the tqdm library

Exponential moving average: smoothing to give progressively lower
weights to older values.
Parameters
----------
smoothing : float, optional
Smoothing factor in range [0, 1], [default: 0.3].
Increase to give more weight to recent values.
Ranges from 0 (yields old value) to 1 (yields new value).
"""
def __init__(self, smoothing=0.3):
self.alpha = smoothing
self.last = 0
self.calls = 0

def __call__(self, x=None):
"""
Parameters
----------
x : float
New value to include in EMA.
"""
beta = 1 - self.alpha
if x is not None:
self.last = self.alpha * x + beta * self.last
self.calls += 1
return self.last / (1 - beta ** self.calls) if self.calls else self.last

ema = EMA()
assert ema() == 0
assert round(ema(1)) == 1
assert round(ema()) == 1
assert round(ema(2), 1) == 1.6
7 changes: 7 additions & 0 deletions Tests/test_mines.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ def by(s):
return bytearray(map(ord, s))
b = by("Hello, world")
assert re.findall(br"\w+", b) == [by("Hello"), by("world")]


import tqdm

def test_tqdm():
for _ in tqdm.tqdm(range(10)):
pass