本文整理汇总了Python中smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex.remove_descriptor方法的典型用法代码示例。如果您正苦于以下问题:Python MemoryDescriptorIndex.remove_descriptor方法的具体用法?Python MemoryDescriptorIndex.remove_descriptor怎么用?Python MemoryDescriptorIndex.remove_descriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex
的用法示例。
在下文中一共展示了MemoryDescriptorIndex.remove_descriptor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_added_descriptor_table_caching
# 需要导入模块: from smqtk.representation.descriptor_index.memory import MemoryDescriptorIndex [as 别名]
# 或者: from smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex import remove_descriptor [as 别名]
def test_added_descriptor_table_caching(self):
cache_elem = DataMemoryElement(readonly=False)
descrs = [random_descriptor() for _ in range(3)]
expected_table = dict((r.uuid(), r) for r in descrs)
i = MemoryDescriptorIndex(cache_elem)
self.assertTrue(cache_elem.is_empty())
# Should add descriptors to table, caching to writable element.
i.add_many_descriptors(descrs)
self.assertFalse(cache_elem.is_empty())
self.assertEqual(pickle.loads(i.cache_element.get_bytes()),
expected_table)
# Changing the internal table (remove, add) it should reflect in
# cache
new_d = random_descriptor()
expected_table[new_d.uuid()] = new_d
i.add_descriptor(new_d)
self.assertEqual(pickle.loads(i.cache_element.get_bytes()),
expected_table)
rm_d = list(expected_table.values())[0]
del expected_table[rm_d.uuid()]
i.remove_descriptor(rm_d.uuid())
self.assertEqual(pickle.loads(i.cache_element.get_bytes()),
expected_table)
示例2: test_remove
# 需要导入模块: from smqtk.representation.descriptor_index.memory import MemoryDescriptorIndex [as 别名]
# 或者: from smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex import remove_descriptor [as 别名]
def test_remove(self):
i = MemoryDescriptorIndex()
descrs = [random_descriptor() for _ in xrange(100)]
i.add_many_descriptors(descrs)
ntools.assert_equal(len(i), 100)
ntools.assert_equal(list(i.iterdescriptors()), descrs)
# remove singles
i.remove_descriptor(descrs[0].uuid())
ntools.assert_equal(len(i), 99)
ntools.assert_equal(set(i.iterdescriptors()),
set(descrs[1:]))
# remove many
rm_d = descrs[slice(45, 80, 3)]
i.remove_many_descriptors((d.uuid() for d in rm_d))
ntools.assert_equal(len(i), 99 - len(rm_d))
ntools.assert_equal(set(i.iterdescriptors()),
set(descrs[1:]).difference(rm_d))
示例3: test_table_caching
# 需要导入模块: from smqtk.representation.descriptor_index.memory import MemoryDescriptorIndex [as 别名]
# 或者: from smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex import remove_descriptor [as 别名]
def test_table_caching(self):
fd, tmp_cache = tempfile.mkstemp()
os.close(fd)
os.remove(tmp_cache)
try:
i = MemoryDescriptorIndex(tmp_cache)
descrs = [random_descriptor() for _ in xrange(3)]
expected_cache = dict((r.uuid(), r) for r in descrs)
# cache should not exist yet
ntools.assert_false(os.path.isfile(tmp_cache))
# Should write file and should be a dictionary of 3
# elements
i.add_many_descriptors(descrs)
ntools.assert_true(os.path.isfile(tmp_cache))
with open(tmp_cache) as f:
ntools.assert_equal(cPickle.load(f),
expected_cache)
# Changing the internal table (remove, add) it should reflect in
# cache
new_d = random_descriptor()
i.add_descriptor(new_d)
expected_cache[new_d.uuid()] = new_d
with open(tmp_cache) as f:
ntools.assert_equal(cPickle.load(f),
expected_cache)
rm_d = expected_cache.values()[0]
i.remove_descriptor(rm_d.uuid())
del expected_cache[rm_d.uuid()]
with open(tmp_cache) as f:
ntools.assert_equal(cPickle.load(f),
expected_cache)
finally:
os.remove(tmp_cache)