-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds some basic memmap support to the `diskannpy.vectors_…
…from_file` utility function. You can now return memory mapped np.array conformant view vs. requiring it beloaded fully into memory.
- Loading branch information
Showing
3 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT license. | ||
|
||
import unittest | ||
|
||
import numpy as np | ||
|
||
from fixtures import random_vectors, vectors_as_temp_file | ||
|
||
import diskannpy as dap | ||
|
||
|
||
class TestVectorsFromFile(unittest.TestCase): | ||
def test_in_mem(self): | ||
expected = random_vectors(10_000, 100, dtype=np.float32) | ||
with vectors_as_temp_file(expected) as vecs_file: | ||
actual = dap.vectors_from_file(vecs_file, dtype=np.float32) | ||
self.assertTrue(all(expected == actual)) | ||
|
||
def test_memmap(self): | ||
expected = random_vectors(10_000, 100, dtype=np.float32) | ||
with vectors_as_temp_file(expected) as vecs_file: | ||
actual = dap.vectors_from_file( | ||
vecs_file, | ||
dtype=np.float32, | ||
use_memmap=True | ||
) | ||
self.assertTrue(all(expected == actual)) | ||
actual = dap.vectors_from_file( | ||
vecs_file, | ||
dtype=np.float32, | ||
use_memap=True, | ||
mode="r+" | ||
) | ||
self.assertTrue(all(expected == actual)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |