def test_shrink_and_sort(frame=None):
if not frame:
frame = DATA + '/vectors/glove12-840B.h5'
vectors = load_any_embeddings(frame)
n, k = 10, 20
shrank = shrink_and_sort(vectors, n, k)
# Check the size of the frame
ok_(shrank.shape == (n, k))
# Check if the frame is l2 normalized
lengths = np.sqrt(np.sum(np.power(shrank, 2), axis='columns'))
ok_(all(isclose(length, 1.0, rel_tol=1e-04) for length in lengths))
# Check if the index is sorted
ok_(shrank.index.is_monotonic_increasing)
评论列表
文章目录