def test_serialize_and_parse(self): blob = self.ordered_sparse_topic_hist.serialize_to_string() sparse_topic_hist = OrderedSparseTopicHistogram(self.num_topics) sparse_topic_hist.parse_from_string(blob) self.assertEqual(sparse_topic_hist.size(), self.ordered_sparse_topic_hist.size()) self.assertEqual(str(sparse_topic_hist), str(self.ordered_sparse_topic_hist))
def _load_word_topic_hist(self, filename): logging.info('Loading word_topic_hist matrix N(w|z).') self.word_topic_hist.clear() fp = open(filename, "rb") record_reader = RecordReader(fp) while True: blob = record_reader.read() if blob == None: break word_topic_hist_pb = WordTopicHistogramPB() word_topic_hist_pb.ParseFromString(blob) ordered_sparse_topic_hist = \ OrderedSparseTopicHistogram(self.num_topics) ordered_sparse_topic_hist.parse_from_string( word_topic_hist_pb.sparse_topic_hist.SerializeToString()) self.word_topic_hist[word_topic_hist_pb.word] = \ ordered_sparse_topic_hist fp.close() return (len(self.word_topic_hist) > 0)