def test_size_empty(self): # Check size of descriptor set created with no descriptor list. ds = DescriptorSet() self.assertEqual(ds.size(), 0) # len() should also function and return the same thing self.assertEqual(len(ds), 0)
def test_size_multiple(self): # Check that size accurately report number of descriptors constructed # with. d_list = [ Descriptor(), ] ds = DescriptorSet(d_list) self.assertEqual(ds.size(), 1) self.assertEqual(len(ds), 1)
def test_size_multiple(self): # Check that size accurately report number of descriptors constructed # with. d_list = [ new_descriptor(), ] ds = DescriptorSet(d_list) self.assertEqual(ds.size(), 1) self.assertEqual(len(ds), 1)
def test_new_with_descriptors(self): # Try creating a descriptor set with multiple descriptors as input. descriptor_list = [ new_descriptor(1), new_descriptor(1), new_descriptor(1), ] ds = DescriptorSet(descriptor_list)
def convert_descriptor_set_in(datum_ptr): """ Convert a datum pointer to a vital DescriptorSet instance. :param datum_ptr: Sprokit datum pointer :return: Vital DescriptorSet instance :rtype: DescriptorSet """ _VCL = find_vital_library.find_vital_type_converter_library() func = _VCL['vital_descriptor_set_from_datum'] func.argtypes = [ctypes.py_object] func.restype = DescriptorSet.c_ptr_type() ds_handle = func(datum_ptr) return DescriptorSet(from_cptr=ds_handle)
def test_get_descriptors_multiple(self): # Test getting descriptors given to the set in its constructor. d_list = [ Descriptor(1), Descriptor(2), Descriptor(3), ] d_list[0][:] = [0] d_list[1][:] = [1, 2] d_list[2][:] = [3, 4, 5] ds = DescriptorSet(d_list) ds_descriptors = ds.descriptors() self.assertEqual(len(ds), 3) self.assertEqual(len(ds_descriptors), 3) numpy.testing.assert_array_equal(ds_descriptors[0], d_list[0]) numpy.testing.assert_array_equal(ds_descriptors[1], d_list[1]) numpy.testing.assert_array_equal(ds_descriptors[2], d_list[2])
def test_get_descriptors_multiple(self): # Test getting descriptors given to the set in its constructor. d_list = [ new_descriptor(1), new_descriptor(2), new_descriptor(3), ] d_list[0][:] = [0] d_list[1][:] = [1, 2] d_list[2][:] = [3, 4, 5] ds = DescriptorSet(d_list) ds_descriptors = ds.descriptors() self.assertEqual(len(ds), 3) self.assertEqual(len(ds_descriptors), 3) numpy.testing.assert_array_equal(ds_descriptors[0], d_list[0]) numpy.testing.assert_array_equal(ds_descriptors[1], d_list[1]) numpy.testing.assert_array_equal(ds_descriptors[2], d_list[2])
def convert_descriptor_set_out(py_descriptor_set): """ Convert a vital python DescriptorSet instance to a datum as a PyCapsule. :param py_descriptor_set: The vital DescriptorSet instance to convert. :type py_descriptor_set: DescriptorSet :return: Datum pointer. """ _VCL = find_vital_library.find_vital_type_converter_library() func = _VCL['vital_descriptor_set_to_datum'] func.argtypes = [DescriptorSet.c_ptr_type()] func.restype = ctypes.py_object return func(py_descriptor_set)
def _step(self): # # Grab input values from ports using traits. # # Vector of UIDs for vector of descriptors in descriptor_set. # #: :type: list[str] string_tuple = self.grab_input_using_trait('string_vector') descriptors = self.smqtk_descriptor_index.get_many_descriptors( string_tuple) vital_descriptors = [] for desc in descriptors: vector = desc.vector() vital_desc = new_descriptor(len(vector), "d") vital_desc[:] = vector vital_descriptors.append(vital_desc) vital_descriptor_set = DescriptorSet(vital_descriptors) self.push_to_port_using_trait('descriptor_set', vital_descriptor_set) self._base_step()
def test_get_descriptors_empty(self): # Try getting descriptor list from a set constructed with no # descriptors. ds = DescriptorSet() r_list = ds.descriptors() self.assertEqual(len(r_list), 0)
def test_new_empty(self): # Create an empty descriptor set, checking that no errors occur. DescriptorSet()