From d6fac09212e73a4db04682d7e48753269defc704 Mon Sep 17 00:00:00 2001 From: Mohit Rathore Date: Fri, 21 Oct 2016 03:08:26 +0530 Subject: [PATCH 1/3] Attempt basemodel tests to run on appveyor (#969) --- gensim/test/{test_basemodel.py => basetests.py} | 0 gensim/test/test_hdpmodel.py | 4 ++-- gensim/test/test_ldamodel.py | 4 ++-- gensim/test/test_lsimodel.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename gensim/test/{test_basemodel.py => basetests.py} (100%) diff --git a/gensim/test/test_basemodel.py b/gensim/test/basetests.py similarity index 100% rename from gensim/test/test_basemodel.py rename to gensim/test/basetests.py diff --git a/gensim/test/test_hdpmodel.py b/gensim/test/test_hdpmodel.py index 8c0495cb9a..2fb4fb8a80 100644 --- a/gensim/test/test_hdpmodel.py +++ b/gensim/test/test_hdpmodel.py @@ -22,7 +22,7 @@ from gensim.corpora import mmcorpus, Dictionary from gensim.models import hdpmodel from gensim import matutils -from gensim.test import test_basemodel +from gensim.test import basetests module_path = os.path.dirname(__file__) # needed because sample data files are located in the same folder @@ -48,7 +48,7 @@ def testfile(): return os.path.join(tempfile.gettempdir(), 'gensim_models.tst') -class TestHdpModel(unittest.TestCase, test_basemodel.TestBaseTopicModel): +class TestHdpModel(unittest.TestCase, basetests.TestBaseTopicModel): def setUp(self): self.corpus = mmcorpus.MmCorpus(datapath('testcorpus.mm')) self.class_ = hdpmodel.HdpModel diff --git a/gensim/test/test_ldamodel.py b/gensim/test/test_ldamodel.py index cc2cececc9..a96d96ae6f 100644 --- a/gensim/test/test_ldamodel.py +++ b/gensim/test/test_ldamodel.py @@ -23,7 +23,7 @@ from gensim.corpora import mmcorpus, Dictionary from gensim.models import ldamodel, ldamulticore from gensim import matutils -from gensim.test import test_basemodel +from gensim.test import basetests module_path = os.path.dirname(__file__) # needed because sample data files are located in the same folder @@ -55,7 +55,7 @@ def testRandomState(): assert(isinstance(ldamodel.get_random_state(testcase), numpy.random.RandomState)) -class TestLdaModel(unittest.TestCase, test_basemodel.TestBaseTopicModel): +class TestLdaModel(unittest.TestCase, basetests.TestBaseTopicModel): def setUp(self): self.corpus = mmcorpus.MmCorpus(datapath('testcorpus.mm')) self.class_ = ldamodel.LdaModel diff --git a/gensim/test/test_lsimodel.py b/gensim/test/test_lsimodel.py index ab86c18d4f..cb2052773c 100644 --- a/gensim/test/test_lsimodel.py +++ b/gensim/test/test_lsimodel.py @@ -22,7 +22,7 @@ from gensim.corpora import mmcorpus, Dictionary from gensim.models import lsimodel from gensim import matutils -from gensim.test import test_basemodel +from gensim.test import basetests module_path = os.path.dirname(__file__) # needed because sample data files are located in the same folder @@ -51,7 +51,7 @@ def testfile(): return os.path.join(tempfile.gettempdir(), 'gensim_models.tst') -class TestLsiModel(unittest.TestCase, test_basemodel.TestBaseTopicModel): +class TestLsiModel(unittest.TestCase, basetests.TestBaseTopicModel): def setUp(self): self.corpus = mmcorpus.MmCorpus(datapath('testcorpus.mm')) self.model = lsimodel.LsiModel(self.corpus, num_topics=2) From b5a2b58d57d3536a5622bb27bef80e68a1c3327a Mon Sep 17 00:00:00 2001 From: Mohit Rathore Date: Fri, 21 Oct 2016 03:09:03 +0530 Subject: [PATCH 2/3] Pyro annotations for lsi_worker (#968) @Pyro4.expose annotations for lsi_worker --- gensim/models/lsi_worker.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gensim/models/lsi_worker.py b/gensim/models/lsi_worker.py index ef54144328..b9de939962 100755 --- a/gensim/models/lsi_worker.py +++ b/gensim/models/lsi_worker.py @@ -39,7 +39,7 @@ class Worker(object): def __init__(self): self.model = None - + @Pyro4.expose def initialize(self, myid, dispatcher, **model_params): self.lock_update = threading.Lock() self.jobsdone = 0 # how many jobs has this worker completed? @@ -49,7 +49,7 @@ def initialize(self, myid, dispatcher, **model_params): logger.info("initializing worker #%s" % myid) self.model = lsimodel.LsiModel(**model_params) - + @Pyro4.expose @Pyro4.oneway def requestjob(self): """ @@ -81,7 +81,7 @@ def processjob(self, job): fname = os.path.join(tempfile.gettempdir(), 'lsi_worker.pkl') self.model.save(fname) - + @Pyro4.expose @utils.synchronous('lock_update') def getstate(self): logger.info("worker #%i returning its state after %s jobs" % @@ -90,7 +90,7 @@ def getstate(self): self.finished = True return self.model.projection - + @Pyro4.expose @utils.synchronous('lock_update') def reset(self): logger.info("resetting worker #%i" % self.myid) From 3b9bb59dac0d55a1cd6ca8f984cead38b9cb0860 Mon Sep 17 00:00:00 2001 From: Arif Ahmed Date: Fri, 21 Oct 2016 03:17:32 +0530 Subject: [PATCH 3/3] Rectify PR#950 to follow PEP8 (#966) --- gensim/matutils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gensim/matutils.py b/gensim/matutils.py index 6cc8c80133..4c92be4562 100644 --- a/gensim/matutils.py +++ b/gensim/matutils.py @@ -326,7 +326,7 @@ def ret_normalized_vec(vec, length): else: return list(vec) -def ret_log_normalize_vec(vec, axis = 1): +def ret_log_normalize_vec(vec, axis=1): log_max = 100.0 if len(vec.shape) == 1: max_val = numpy.max(vec) @@ -335,17 +335,17 @@ def ret_log_normalize_vec(vec, axis = 1): log_norm = numpy.log(tot) - log_shift vec = vec - log_norm else: - if axis == 1:#independently normalize each sample + if axis == 1: # independently normalize each sample max_val = numpy.max(vec, 1) log_shift = log_max - numpy.log(vec.shape[1] + 1.0) - max_val tot = numpy.sum(numpy.exp(vec + log_shift[:, numpy.newaxis]), 1) log_norm = numpy.log(tot) - log_shift vec = vec - log_norm[:, numpy.newaxis] - elif axis == 0:#normalize each feature + elif axis == 0: # normalize each feature k = ret_log_normalize_vec(vec.T) return (k[0].T, k[1]) else: - raise ValueError("'%d' is not a supported axis" % axis) + raise ValueError("'%s' is not a supported axis" % axis) return (vec, log_norm)