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

Use time.time instead of time.clock in gensim/models/hdpmodel.py #2730

Merged
merged 2 commits into from
Jan 23, 2020
Merged
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
11 changes: 9 additions & 2 deletions gensim/models/hdpmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,10 @@ def update(self, corpus):
"""
save_freq = max(1, int(10000 / self.chunksize)) # save every 10k docs, roughly
chunks_processed = 0
start_time = time.clock()
try:
start_time = time.time()
except AttributeError:
start_time = time.clock()
tarohi24 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's with the clock()? Just use time.time(), it's there always. No need for such try: except.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. Looks like my merge was premature. @tarohi24 Are you able to make another PR to patch this up? If not, then I will take care of it.

Copy link
Contributor Author

@tarohi24 tarohi24 Jan 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK! I'll fix it.


while True:
for chunk in utils.grouper(corpus, self.chunksize):
Expand Down Expand Up @@ -508,12 +511,16 @@ def update_finished(self, start_time, chunks_processed, docs_processed):
If True - model is updated, False otherwise.

"""
try:
start_time = time.time()
except AttributeError:
start_time = time.clock()
return (
# chunk limit reached
(self.max_chunks and chunks_processed == self.max_chunks)

# time limit reached
or (self.max_time and time.clock() - start_time > self.max_time)
or (self.max_time and start_time - start_time > self.max_time)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start_time - start_time makes no sense (and the above AttributeError-complicated fallback to .clock() seems fishy too, especially since the deprecation of .clock() is exactly the reason for this PR). But, I have a different fix incoming in #2715.


# no limits and whole corpus has been processed once
or (not self.max_chunks and not self.max_time and docs_processed >= self.m_D))
Expand Down