-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Remove unnecessary creations of lists at all #2261
Conversation
0e36ad5
to
2a03366
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful! This set of changes fits very well with Gensim mission and philosophy, thank you.
I remember some constructs have a problem with empty generator, but accept empty list. This is a corner case we have to be the most careful, with these changes. I hope the tests cover it well.
gensim/models/ldamodel.py
Outdated
@@ -567,15 +567,18 @@ def init_dir_prior(self, prior, name): | |||
if isinstance(prior, six.string_types): | |||
if prior == 'symmetric': | |||
logger.info("using symmetric %s at %s", name, 1.0 / self.num_topics) | |||
init_prior = np.asarray([1.0 / self.num_topics for i in xrange(prior_shape)], dtype=self.dtype) | |||
init_prior = np.fromiter((1.0 / self.num_topics for i in xrange(prior_shape)), | |||
dtype=self.dtype, count=prior_shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hanging indent please, here and elsewhere.
We avoid vertical indent because it leads to inconsistent visual indenting (like here), especially when the lines are edited in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -674,7 +674,6 @@ def online_sanity(self, model): | |||
terro.append(l) | |||
else: | |||
others.append(l) | |||
self.assertTrue(all(['terrorism' not in l for l in others])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that this line does not check anything worthwhile. By code it is clear that this check is always true. It's not critical for me, so I return this line back.
ping @horpto, please fix @piskvorky comments and I'll merge current PR (don't forget to merge fresh |
- hanged indent - return assertTrue line - fix bug in _get_average_score in python2 - a bit refactor bm25
2a03366
to
14339f2
Compare
@@ -567,15 +567,18 @@ def init_dir_prior(self, prior, name): | |||
if isinstance(prior, six.string_types): | |||
if prior == 'symmetric': | |||
logger.info("using symmetric %s at %s", name, 1.0 / self.num_topics) | |||
init_prior = np.asarray([1.0 / self.num_topics for i in xrange(prior_shape)], dtype=self.dtype) | |||
init_prior = np.fromiter((1.0 / self.num_topics for i in xrange(prior_shape)), | |||
dtype=self.dtype, count=prior_shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still vertical indent.
In gensim, we use hanging indent always, consistently: https://www.python.org/dev/peps/pep-0008/#indentation
No description provided.