Example #1
0
    def test_ts_feat_desc(self):
        t = Track()

        f0 = Feature(mag=0)
        d0 = Descriptor(4)
        d0[:] = 0
        t.append(TrackState(0, f0, d0))

        f1 = Feature(mag=1)
        d1 = Descriptor(4)
        d1[:] = 1
        t.append(TrackState(1, f1, d1))

        nose.tools.assert_equal(t.size, 2)
        nose.tools.assert_equal(len(t), 2)
        ts0 = t.find_state(0)
        nose.tools.assert_equal(ts0.feature, f0)
        numpy.testing.assert_equal(ts0.descriptor, d0)

        ts1 = t.find_state(1)
        nose.tools.assert_equal(ts1.feature, f1)
        numpy.testing.assert_equal(ts1.descriptor, d1)

        # Delete local descriptor references, get track states and check
        # descriptor values manually
        del f0, f1, d0, d1, ts0, ts1
        # Now, only the track-state in C++ has feature/descriptor references
        numpy.testing.assert_equal(t.find_state(0).descriptor, [0, 0, 0, 0])
        numpy.testing.assert_equal(t.find_state(1).descriptor, [1, 1, 1, 1])
Example #2
0
    def descriptors(self):
        """
        Get the set of descriptor instances contained in this set as a tuple.

        :return: A tuple of the contained descriptor instances.
        :rtype: tuple[Descriptor]
        """
        out_d_array = ctypes.POINTER(Descriptor.c_ptr_type())()
        out_d_array_size = ctypes.c_size_t()

        self._call_cfunc(
            'vital_descriptor_set_get_descriptors',
            [
                self.C_TYPE_PTR,
                ctypes.POINTER(ctypes.POINTER(Descriptor.c_ptr_type())),
                ctypes.POINTER(ctypes.c_size_t)
            ],
            [self,
             ctypes.byref(out_d_array),
             ctypes.byref(out_d_array_size)],
        )

        d_list = []
        for i in range(out_d_array_size.value):
            cptr = Descriptor.c_ptr_type()(out_d_array[i].contents)
            d_list.append(Descriptor(from_cptr=cptr))
        free_void_ptr(out_d_array)

        return d_list
Example #3
0
 def test_new(self):
     # Attempt construction using a bunch of random, non-zero integers
     random.seed(0)
     for i in xrange(100):
         n = random.randint(1, 4096)
         Descriptor(n, ctypes.c_double)
         Descriptor(n, ctypes.c_float)
Example #4
0
 def test_new(self):
     # Attempt construction using a bunch of random, non-zero integers
     random.seed(0)
     for i in range(100):
         n = random.randint(1, 4096)
         Descriptor(n, 'd')
         Descriptor(n, 'f')
Example #5
0
    def test_desc(self):
        # Some random initialized descriptor
        d = Descriptor()
        d[:] = 1
        nose.tools.assert_equal(d.sum(), d.size)

        ts = TrackState(0, descriptor=d)
        numpy.testing.assert_equal(d, ts.descriptor)
Example #6
0
 def test_tobytearray(self):
     # Expect 0-valued descriptor to have 0-valued byte array of the
     # appropriate size
     d = Descriptor(64)
     d[:] = 0
     b = d.tobytearray()
     nose.tools.assert_equal(b.size, d.nbytes)
     nose.tools.assert_equal(b.sum(), 0)
Example #7
0
 def test_tobytearray(self):
     # Expect 0-valued descriptor to have 0-valued byte array of the
     # appropriate size
     d = Descriptor(64)
     d[:] = 0
     b = d.tobytearray()
     nose.tools.assert_equal(len(b), d.nbytes)
     nose.tools.assert_equal(sum(b), 0)
Example #8
0
 def descriptor(self):
     d_ptr = self._call_cfunc("vital_track_state_descriptor",
                              [self.C_TYPE_PTR], [self],
                              Descriptor.c_ptr_type())
     if d_ptr:
         return Descriptor(from_cptr=d_ptr)
     else:
         return None
 def test_new_with_descriptors(self):
     # Try creating a descriptor set with multiple descriptors as input.
     descriptor_list = [
         Descriptor(1),
         Descriptor(1),
         Descriptor(1),
     ]
     ds = DescriptorSet(descriptor_list)
Example #10
0
    def test_new(self):
        # Attempt construction using a bunch of random, non-zero integers
        random.seed(0)
        for i in xrange(100):
            n = random.randint(1, 4096)
            Descriptor(n, ctypes.c_double)
            Descriptor(n, ctypes.c_float)

        nose.tools.assert_raises(ctypes.ArgumentError, Descriptor, 42.3)
Example #11
0
    def test_num_bytes(self):
        # While not calling the C function, it should still be a correct value
        random.seed(0)
        for i in range(100):
            n = random.randint(1, 4096)
            print(n, end=' ')

            nose.tools.assert_equal(Descriptor(n, 'd').nbytes, 8 * n)
            nose.tools.assert_equal(Descriptor(n, 'f').nbytes, 4 * n)
Example #12
0
    def test_raw_data(self):
        d = Descriptor(64)
        d[:] = 1
        nose.tools.assert_equal(d.sum(), 64)

        # Check that slicing the array data yields an array with the same
        # values.
        d2 = d[:]
        numpy.testing.assert_equal(d.todoublearray(), d2)
Example #13
0
    def test_raw_data(self):
        d = Descriptor(64)
        d[:] = 1
        nose.tools.assert_equal(d.sum(), 64)

        # Check that slicing the array data yields an array with the same
        # values.
        d2 = d[:]
        numpy.testing.assert_equal(d.todoublearray(), d2)
Example #14
0
    def test_raw_data(self):
        d = Descriptor(64)
        d[:] = 1
        nose.tools.assert_equal(d.sum(), 64)

        d2 = d[:]
        numpy.testing.assert_almost_equal(d, d2)

        d2[:] = 2
        numpy.testing.assert_almost_equal(d, d2)
Example #15
0
    def test_raw_data(self):
        d = Descriptor(64)
        d[:] = 1
        nose.tools.assert_equal(d.sum(), 64)

        d2 = d[:]
        numpy.testing.assert_almost_equal(d, d2)

        d2[:] = 2
        numpy.testing.assert_almost_equal(d, d2)
Example #16
0
    def test_num_bytes(self):
        # While not calling the C function, it should still be a correct value
        random.seed(0)
        for i in xrange(100):
            n = random.randint(1, 4096)
            print n,

            nose.tools.assert_equal(
                Descriptor(n, ctypes.c_double).nbytes,
                ctypes.sizeof(ctypes.c_double) * n)
            nose.tools.assert_equal(
                Descriptor(n, ctypes.c_float).nbytes,
                ctypes.sizeof(ctypes.c_float) * n)
Example #17
0
    def test_raw_data(self):
        d = Descriptor(64)
        d[:] = 1
        nose.tools.assert_equal(d.sum(), 64)

        # Check that slicing the array data yields an array with the same
        # values.
        d2 = d[:]
        numpy.testing.assert_almost_equal(d, d2)

        # Check that modifying the sliced array shared the same data as the
        # parent descriptor.
        d2[:] = 2
        numpy.testing.assert_almost_equal(d, d2)
Example #18
0
    def _new(self, descriptor_list):
        """
        Create a new descriptor set instance from a list of descriptor elements.

        :param descriptor_list: List of child descriptor instance handles.
        :type descriptor_list: list[Descriptor]

        """
        if descriptor_list is None:
            descriptor_list = []
        c_descriptor_array = (Descriptor.c_ptr_type() * len(descriptor_list))(
            *(d.c_pointer for d in descriptor_list))
        return self._call_cfunc(
            'vital_descriptor_set_new',
            [ctypes.POINTER(Descriptor.c_ptr_type()), ctypes.c_size_t],
            [c_descriptor_array, len(descriptor_list)], self.C_TYPE_PTR)
 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)
Example #20
0
    def test_data_type_failure(self):
        d_d = Descriptor(128, ctypes.c_double)
        d_d[:] = 1
        nose.tools.assert_equal(d_d.sum(), 128)
        nose.tools.assert_raises(
            VitalDynamicCastException,
            Descriptor,
            from_cptr=d_d.c_pointer, ctype=ctypes.c_float
        )

        d_f = Descriptor(128, ctypes.c_float)
        d_f[:] = 1
        nose.tools.assert_equal(d_f.sum(), 128)
        nose.tools.assert_raises(
            VitalDynamicCastException,
            Descriptor,
            from_cptr=d_f.c_pointer, ctype=ctypes.c_double
        )
    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])
Example #22
0
    def test_new_ts(self):
        TrackState(0)
        TrackState(23456)

        # With feat, desc, feat/desc
        f = Feature()
        d = Descriptor()
        TrackState(0, feature=f)
        TrackState(0, descriptor=d)
        TrackState(0, f, d)

        # Only integers
        nose.tools.assert_raises(ctypes.ArgumentError, TrackState, 1.2)
        nose.tools.assert_raises(ctypes.ArgumentError, TrackState, 'foo')
Example #23
0
    def _new(self, frame, feature, descriptor):
        """
        :param feature: Optional Feature instance associated with this state.
        :type feature: vital.types.Feature

        :param descriptor: Optional Descriptor instance associated with this
            state.
        :type descriptor: vital.types.Descriptor
        """
        return self._call_cfunc(
            "vital_feature_track_state_new",
            [ctypes.c_int64, Feature.c_ptr_type(), Descriptor.c_ptr_type()],
            [frame, feature, descriptor],
            self.C_TYPE_PTR
        )
Example #24
0
    def test_data_type_failure(self):
        d_d = Descriptor(128, ctypes.c_double)
        d_d[:] = 1
        nose.tools.assert_equal(d_d.sum(), 128)
        nose.tools.assert_raises(VitalDynamicCastException,
                                 Descriptor,
                                 from_cptr=d_d.c_pointer,
                                 ctype=ctypes.c_float)

        d_f = Descriptor(128, ctypes.c_float)
        d_f[:] = 1
        nose.tools.assert_equal(d_f.sum(), 128)
        nose.tools.assert_raises(VitalDynamicCastException,
                                 Descriptor,
                                 from_cptr=d_f.c_pointer,
                                 ctype=ctypes.c_double)
Example #25
0
 def test_size(self):
     random.seed(0)
     for i in xrange(100):
         n = random.randint(1, 4096)
         nose.tools.assert_equal(Descriptor(n).size, n)
Example #26
0
 def test_size(self):
     # Check that we can check the size of the descriptor array.
     random.seed(0)
     for i in xrange(100):
         n = random.randint(1, 4096)
         nose.tools.assert_equal(Descriptor(n).size, n)