Skip to content

Commit

Permalink
Test type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
pushpankar committed Feb 5, 2018
1 parent 164cf63 commit 4d0661f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gensim/test/test_datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def load_model(self, datatype):

def test_high_precision(self):
kv = self.load_model(np.float64)
import pdb
pdb.set_trace()
self.assertAlmostEqual(kv['horse.n.01'][0], -0.0008546282343595379)
self.assertEqual(kv['horse.n.01'][0].dtype, np.float64)

Expand All @@ -38,6 +40,16 @@ def test_low_precision(self):
self.assertAlmostEqual(kv['horse.n.01'][0], -0.00085449)
self.assertEqual(kv['horse.n.01'][0].dtype, np.float16)

def test_type_conversion(self):
path = datapath('test.kv.txt')
binary_path = datapath('test.kv.bin')
model1 = KeyedVectors.load_word2vec_format(path, datatype=np.float16)
model1.save_word2vec_format(binary_path, binary=True)
model2 = KeyedVectors.load_word2vec_format(binary_path, datatype=np.float64, binary=True)
import pdb
pdb.set_trace()
self.assertAlmostEqual(model1["horse.n.01"][0], np.float16(model2["horse.n.01"][0]))


if __name__ == '__main__':
logging.root.setLevel(logging.WARNING)
Expand Down

0 comments on commit 4d0661f

Please sign in to comment.