本文整理汇总了Python中smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex._table方法的典型用法代码示例。如果您正苦于以下问题:Python MemoryDescriptorIndex._table方法的具体用法?Python MemoryDescriptorIndex._table怎么用?Python MemoryDescriptorIndex._table使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex
的用法示例。
在下文中一共展示了MemoryDescriptorIndex._table方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cache_table_empty_table
# 需要导入模块: from smqtk.representation.descriptor_index.memory import MemoryDescriptorIndex [as 别名]
# 或者: from smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex import _table [as 别名]
def test_cache_table_empty_table(self):
inst = MemoryDescriptorIndex(DataMemoryElement(), -1)
inst._table = {}
expected_table_pickle_bytes = pickle.dumps(inst._table, -1)
inst.cache_table()
self.assertIsNotNone(inst.cache_element)
self.assertEqual(inst.cache_element.get_bytes(),
expected_table_pickle_bytes)
示例2: test_remove_from_index_shared_hashes_partial
# 需要导入模块: from smqtk.representation.descriptor_index.memory import MemoryDescriptorIndex [as 别名]
# 或者: from smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex import _table [as 别名]
def test_remove_from_index_shared_hashes_partial(self):
"""
Test that only some hashes are removed from the hash index, but not
others when those hashes still refer to other descriptors.
"""
# Simulate initial state with some descriptor hashed to one value and
# other descriptors hashed to another.
# Vectors of length 1 for easy dummy hashing prediction.
descriptors = [
DescriptorMemoryElement('t', 0).set_vector([0]),
DescriptorMemoryElement('t', 1).set_vector([1]),
DescriptorMemoryElement('t', 2).set_vector([2]),
DescriptorMemoryElement('t', 3).set_vector([3]),
DescriptorMemoryElement('t', 4).set_vector([4]),
]
# Dummy hash function to do the simulated thing
hash_func = DummyHashFunctor()
hash_func.get_hash = mock.Mock(
# Vectors of even sum hash to 0, odd to 1.
side_effect=lambda vec: [vec.sum() % 2]
)
d_set = MemoryDescriptorIndex()
d_set._table = {
0: descriptors[0],
1: descriptors[1],
2: descriptors[2],
3: descriptors[3],
4: descriptors[4],
}
hash2uid_kvs = MemoryKeyValueStore()
hash2uid_kvs._table = {
0: {0, 2, 4},
1: {1, 3},
}
idx = LSHNearestNeighborIndex(hash_func, d_set, hash2uid_kvs)
idx.hash_index = mock.Mock(spec=HashIndex)
idx.remove_from_index([1, 2, 3])
# Check that only one hash vector was passed to hash_index's removal
# method (deque of hash-code vectors).
idx.hash_index.remove_from_index.assert_called_once_with(
collections.deque([
[1],
])
)
self.assertDictEqual(d_set._table, {
0: descriptors[0],
4: descriptors[4],
})
self.assertDictEqual(hash2uid_kvs._table, {0: {0, 4}})
示例3: test_cache_table_no_cache
# 需要导入模块: from smqtk.representation.descriptor_index.memory import MemoryDescriptorIndex [as 别名]
# 或者: from smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex import _table [as 别名]
def test_cache_table_no_cache(self):
inst = MemoryDescriptorIndex()
inst._table = {}
inst.cache_table() # should basically do nothing
self.assertIsNone(inst.cache_element)