Example #1
0
    def test_get_value(self):
        m = numpy.ndarray((3, 3))
        # [[ 0 1 2 ]               [[ 0 2 4 ]
        #  [ 3 4 5 ]  -> should ->  [ 2 4 6 ]
        #  [ 6 7 8 ]]               [ 4 6 8 ]]
        m.reshape((9, ))[:] = range(9)

        c = Covariance(3, c_type=ctypes.c_double, init_scalar_or_matrix=m)
        # Test matrix upper triangle locations
        nose.tools.assert_equal(c[0, 0], 0)
        nose.tools.assert_equal(c[0, 1], 2)
        nose.tools.assert_equal(c[0, 2], 4)
        nose.tools.assert_equal(c[1, 1], 4)
        nose.tools.assert_equal(c[1, 2], 6)
        nose.tools.assert_equal(c[2, 2], 8)
        nose.tools.assert_equal(c[0, 1], c[1, 0])
        nose.tools.assert_equal(c[0, 2], c[2, 0])
        nose.tools.assert_equal(c[1, 2], c[2, 1])

        c = Covariance(3, c_type=ctypes.c_float, init_scalar_or_matrix=m)
        # Test matrix upper triangle locations
        nose.tools.assert_equal(c[0, 0], 0)
        nose.tools.assert_equal(c[0, 1], 2)
        nose.tools.assert_equal(c[0, 2], 4)
        nose.tools.assert_equal(c[1, 1], 4)
        nose.tools.assert_equal(c[1, 2], 6)
        nose.tools.assert_equal(c[2, 2], 8)
        nose.tools.assert_equal(c[0, 1], c[1, 0])
        nose.tools.assert_equal(c[0, 2], c[2, 0])
        nose.tools.assert_equal(c[1, 2], c[2, 1])
Example #2
0
    def test_get_value(self):
        m = numpy.ndarray((3, 3))
        # [[ 0 1 2 ]               [[ 0 2 4 ]
        #  [ 3 4 5 ]  -> should ->  [ 2 4 6 ]
        #  [ 6 7 8 ]]               [ 4 6 8 ]]
        m.reshape((9,))[:] = list(range(9))

        c = Covariance.from_matrix(3, c_type='d', init=m)
        # Test matrix upper triangle locations
        nose.tools.assert_equal(c[0,0], 0)
        nose.tools.assert_equal(c[0,1], 2)
        nose.tools.assert_equal(c[0,2], 4)
        nose.tools.assert_equal(c[1,1], 4)
        nose.tools.assert_equal(c[1,2], 6)
        nose.tools.assert_equal(c[2,2], 8)
        nose.tools.assert_equal(c[0,1], c[1,0])
        nose.tools.assert_equal(c[0,2], c[2,0])
        nose.tools.assert_equal(c[1,2], c[2,1])

        c = Covariance.from_matrix(3, c_type='f', init=m)
        # Test matrix upper triangle locations
        nose.tools.assert_equal(c[0,0], 0)
        nose.tools.assert_equal(c[0,1], 2)
        nose.tools.assert_equal(c[0,2], 4)
        nose.tools.assert_equal(c[1,1], 4)
        nose.tools.assert_equal(c[1,2], 6)
        nose.tools.assert_equal(c[2,2], 8)
        nose.tools.assert_equal(c[0,1], c[1,0])
        nose.tools.assert_equal(c[0,2], c[2,0])
        nose.tools.assert_equal(c[1,2], c[2,1])
Example #3
0
    def test_get_value(self):
        m = numpy.ndarray((3, 3))
        # [[ 0 1 2 ]               [[ 0 2 4 ]
        #  [ 3 4 5 ]  -> should ->  [ 2 4 6 ]
        #  [ 6 7 8 ]]               [ 4 6 8 ]]
        m.reshape((9, ))[:] = list(range(9))

        c = Covariance.from_matrix(3, c_type='d', init=m)
        # Test matrix upper triangle locations
        nose.tools.assert_equal(c[0, 0], 0)
        nose.tools.assert_equal(c[0, 1], 2)
        nose.tools.assert_equal(c[0, 2], 4)
        nose.tools.assert_equal(c[1, 1], 4)
        nose.tools.assert_equal(c[1, 2], 6)
        nose.tools.assert_equal(c[2, 2], 8)
        nose.tools.assert_equal(c[0, 1], c[1, 0])
        nose.tools.assert_equal(c[0, 2], c[2, 0])
        nose.tools.assert_equal(c[1, 2], c[2, 1])

        c = Covariance.from_matrix(3, c_type='f', init=m)
        # Test matrix upper triangle locations
        nose.tools.assert_equal(c[0, 0], 0)
        nose.tools.assert_equal(c[0, 1], 2)
        nose.tools.assert_equal(c[0, 2], 4)
        nose.tools.assert_equal(c[1, 1], 4)
        nose.tools.assert_equal(c[1, 2], 6)
        nose.tools.assert_equal(c[2, 2], 8)
        nose.tools.assert_equal(c[0, 1], c[1, 0])
        nose.tools.assert_equal(c[0, 2], c[2, 0])
        nose.tools.assert_equal(c[1, 2], c[2, 1])
Example #4
0
 def covariance(self):
     cptr = self._call_cfunc(
         "vital_feature_covar",
         [self.C_TYPE_PTR],
         [self],
         Covariance.c_ptr_type(2, ctypes.c_double),
     )
     return Covariance(2, ctypes.c_double, from_cptr=cptr)
Example #5
0
    def test_set_oob(self):
        # 2x2 covariance mat
        c = Covariance(c_type=ctypes.c_float)
        c[0, 0] = 1  # Valid set
        nose.tools.assert_raises(IndexError, c.__setitem__, (0, 2), 1)

        c = Covariance(c_type=ctypes.c_double)
        c[0, 0] = 1  # Valid set
        nose.tools.assert_raises(IndexError, c.__setitem__, (0, 2), 1)
Example #6
0
    def test_get_oob(self):
        # 2x2 covariance mat
        c = Covariance(c_type=ctypes.c_double)
        _ = c[0, 0]  # Valid access
        nose.tools.assert_raises(IndexError, c.__getitem__, (0, 2))

        c = Covariance(c_type=ctypes.c_float)
        _ = c[0, 0]  # Valid access
        nose.tools.assert_raises(IndexError, c.__getitem__, (0, 2))
Example #7
0
    def test_get_oob(self):
        # 2x2 covariance mat
        c = Covariance.new_covar(c_type='d')
        _ = c[0, 0]  # Valid access
        nose.tools.assert_raises(IndexError, c.__getitem__, (0, 2))

        c = Covariance.new_covar(c_type='f')
        _ = c[0, 0]  # Valid access
        nose.tools.assert_raises(IndexError, c.__getitem__, (0, 2))
Example #8
0
    def test_set_oob(self):
        # 2x2 covariance mat
        c = Covariance.new_covar(c_type='f')
        c[0, 0] = 1  # Valid set
        nose.tools.assert_raises(IndexError, c.__setitem__, (0, 2), 1)

        c = Covariance.new_covar(c_type='d')
        c[0, 0] = 1  # Valid set
        nose.tools.assert_raises(IndexError, c.__setitem__, (0, 2), 1)
Example #9
0
 def test_new_identity(self):
     # Valid dimensions and types
     c = Covariance.new_covar(2, 'd')
     print('constructed matrix:\n', c.to_matrix())
     c = Covariance.new_covar(3, 'd')
     print('constructed matrix:\n', c.to_matrix())
     c = Covariance.new_covar(2, 'f')
     print('constructed matrix:\n', c.to_matrix())
     c = Covariance.new_covar(3, 'f')
     print('constructed matrix:\n', c.to_matrix())
Example #10
0
 def test_new_identity(self):
     # Valid dimensions and types
     c = Covariance.new_covar(2, 'd')
     print('constructed matrix:\n', c.to_matrix())
     c = Covariance.new_covar(3, 'd')
     print('constructed matrix:\n', c.to_matrix())
     c = Covariance.new_covar(2, 'f')
     print('constructed matrix:\n', c.to_matrix())
     c = Covariance.new_covar(3, 'f')
     print('constructed matrix:\n', c.to_matrix())
Example #11
0
 def covariance(self):
     """
     :return: a copy of this camera's center covariance
     :rtype: Covariance
     """
     cam_covar = self.VITAL_LIB['vital_camera_center_covar']
     cam_covar.argtypes = [self.c_ptr_type(), VitalErrorHandle.c_ptr_type()]
     cam_covar.restype = Covariance.c_ptr_type(3)
     with VitalErrorHandle() as eh:
         c_ptr = cam_covar(self, eh)
     return Covariance(3, from_cptr=c_ptr)
Example #12
0
    def test_set(self):
        m = numpy.ndarray((3, 3))
        # [[ 0 1 2 ]                      [[ 0 2 4 ]
        #  [ 3 4 5 ]  -> should become ->  [ 2 4 6 ]
        #  [ 6 7 8 ]]                      [ 4 6 8 ]]
        m.reshape((9, ))[:] = list(range(9))
        c = Covariance.from_matrix(3, c_type='d', init=m)

        # modify some locations
        c[0, 1] = 1
        c[2, 2] = 3

        nose.tools.assert_equal(c[0, 0], 0)
        nose.tools.assert_equal(c[0, 1], 1)
        nose.tools.assert_equal(c[0, 2], 4)
        nose.tools.assert_equal(c[1, 1], 4)
        nose.tools.assert_equal(c[1, 2], 6)
        nose.tools.assert_equal(c[2, 2], 3)
        nose.tools.assert_equal(c[0, 1], c[1, 0])
        nose.tools.assert_equal(c[0, 2], c[2, 0])
        nose.tools.assert_equal(c[1, 2], c[2, 1])

        # Set in upper triangle and see it reflect in lower
        c[0, 2] = 10.1
        nose.tools.assert_equal(c[2, 0], 10.1)

        # Change something in lower triangle and see it reflected in upper
        c[2, 1] = 20.2
        nose.tools.assert_equal(c[1, 2], 20.2)

        # FLOAT
        c = Covariance.from_matrix(3, c_type='f', init=m)

        # modify some locations
        c[0, 1] = 1
        c[2, 2] = 3

        nose.tools.assert_equal(c[0, 0], 0)
        nose.tools.assert_equal(c[0, 1], 1)
        nose.tools.assert_equal(c[0, 2], 4)
        nose.tools.assert_equal(c[1, 1], 4)
        nose.tools.assert_equal(c[1, 2], 6)
        nose.tools.assert_equal(c[2, 2], 3)
        nose.tools.assert_equal(c[0, 1], c[1, 0])
        nose.tools.assert_equal(c[0, 2], c[2, 0])
        nose.tools.assert_equal(c[1, 2], c[2, 1])

        # Set in upper triangle and see it reflect in lower
        c[0, 2] = 10.1
        nose.tools.assert_almost_equal(c[2, 0], 10.1, 6)

        # Change something in lower triangle and see it reflected in upper
        c[2, 1] = 20.2
        nose.tools.assert_almost_equal(c[1, 2], 20.2, 5)
Example #13
0
 def covariance(self, c):
     """
     Set new landmark covariance
     :type c: vital.types.Covariance
     """
     expected_covar_type = Covariance.c_ptr_type(3, self._datatype)
     # Convert covariance to correct type if necessary
     if c.C_TYPE_PTR != expected_covar_type:
         c = Covariance(3, self._datatype, c.to_matrix())
     self._call_cfunc('vital_landmark_{}_set_covar'.format(self._tchar),
                      [self.C_TYPE_PTR, expected_covar_type], [self, c])
Example #14
0
 def covariance(self, covar):
     if not isinstance(covar, Covariance):
         # Try an make a covariance out of whatever was provided
         covar = Covariance(2, self._datatype, covar)
     print "Setting covar:", covar
     self._call_cfunc(
         "vital_feature_{}_set_covar".format(self._tchar),
         [self.C_TYPE_PTR,
          Covariance.c_ptr_type(2, self._datatype)],
         [self, covar],
     )
Example #15
0
    def test_set(self):
        m = numpy.ndarray((3, 3))
        # [[ 0 1 2 ]                      [[ 0 2 4 ]
        #  [ 3 4 5 ]  -> should become ->  [ 2 4 6 ]
        #  [ 6 7 8 ]]                      [ 4 6 8 ]]
        m.reshape((9,))[:] = list(range(9))
        c = Covariance.from_matrix(3, c_type='d', init=m)

        # modify some locations
        c[0,1] = 1
        c[2,2] = 3

        nose.tools.assert_equal(c[0,0], 0)
        nose.tools.assert_equal(c[0,1], 1)
        nose.tools.assert_equal(c[0,2], 4)
        nose.tools.assert_equal(c[1,1], 4)
        nose.tools.assert_equal(c[1,2], 6)
        nose.tools.assert_equal(c[2,2], 3)
        nose.tools.assert_equal(c[0,1], c[1,0])
        nose.tools.assert_equal(c[0,2], c[2,0])
        nose.tools.assert_equal(c[1,2], c[2,1])

        # Set in upper triangle and see it reflect in lower
        c[0, 2] = 10.1
        nose.tools.assert_equal(c[2, 0], 10.1)

        # Change something in lower triangle and see it reflected in upper
        c[2, 1] = 20.2
        nose.tools.assert_equal(c[1, 2], 20.2)

        # FLOAT
        c = Covariance.from_matrix(3, c_type='f', init=m)

        # modify some locations
        c[0,1] = 1
        c[2,2] = 3

        nose.tools.assert_equal(c[0,0], 0)
        nose.tools.assert_equal(c[0,1], 1)
        nose.tools.assert_equal(c[0,2], 4)
        nose.tools.assert_equal(c[1,1], 4)
        nose.tools.assert_equal(c[1,2], 6)
        nose.tools.assert_equal(c[2,2], 3)
        nose.tools.assert_equal(c[0,1], c[1,0])
        nose.tools.assert_equal(c[0,2], c[2,0])
        nose.tools.assert_equal(c[1,2], c[2,1])

        # Set in upper triangle and see it reflect in lower
        c[0, 2] = 10.1
        nose.tools.assert_almost_equal(c[2, 0], 10.1, 6)

        # Change something in lower triangle and see it reflected in upper
        c[2, 1] = 20.2
        nose.tools.assert_almost_equal(c[1, 2], 20.2, 5)
Example #16
0
 def covariance(self, covar):
     if self._datatype is None:
         raise VitalNoTypeInfoException(
             "Type info required but not present")
     if not isinstance(covar, Covariance):
         # Try an make a covariance out of whatever was provided
         covar = Covariance(2, self._datatype, covar)
     print "Setting covar:", covar
     self._call_cfunc(
         "vital_feature_{}_set_covar".format(self._tchar),
         [self.C_TYPE_PTR,
          Covariance.c_ptr_type(2, self._datatype)],
         [self, covar],
     )
Example #17
0
 def covariance(self):
     cptr = self._call_cfunc(
         "vital_feature_covar",
         [self.C_TYPE_PTR],
         Covariance.c_ptr_type(2, ctypes.c_double),
         self
     )
     return Covariance(2, ctypes.c_double, from_cptr=cptr)
Example #18
0
    def test_covariance(self):
        for ct in self.C_TYPES:
            print(ct)
            l = Landmark(c_type=ct)

            # check default
            nose.tools.assert_equal(l.covariance, Covariance(3))

            # set type-aligned covariance
            c = Covariance(3, ct, 7)
            l.covariance = c
            nose.tools.assert_equal(l.covariance, c)

            # set no-necessarily-aligned covariance
            c = Covariance(3, init_scalar_or_matrix=7)
            l.covariance = c
            nose.tools.assert_equal(l.covariance, c)
Example #19
0
    def test_set_oob(self):
        # 2x2 covariance mat
        c = Covariance.new_covar(c_type='f')
        c[0, 0] = 1  # Valid set
        nose.tools.assert_raises(
            IndexError,
            c.__setitem__,
            (0, 2), 1
        )

        c = Covariance.new_covar(c_type='d')
        c[0, 0] = 1  # Valid set
        nose.tools.assert_raises(
            IndexError,
            c.__setitem__,
            (0, 2), 1
        )
Example #20
0
    def test_get_oob(self):
        # 2x2 covariance mat
        c = Covariance.new_covar(c_type='d')
        _ = c[0, 0]  # Valid access
        nose.tools.assert_raises(
            IndexError,
            c.__getitem__,
            (0, 2)
        )

        c = Covariance.new_covar(c_type='f')
        _ = c[0, 0]  # Valid access
        nose.tools.assert_raises(
            IndexError,
            c.__getitem__,
            (0, 2)
        )
Example #21
0
 def test_new_identity(self):
     # Valid dimensions and types
     c = Covariance(2, ctypes.c_double)
     print 'constructed matrix:\n', c.to_matrix()
     c = Covariance(3, ctypes.c_double)
     print 'constructed matrix:\n', c.to_matrix()
     c = Covariance(2, ctypes.c_float)
     print 'constructed matrix:\n', c.to_matrix()
     c = Covariance(3, ctypes.c_float)
     print 'constructed matrix:\n', c.to_matrix()
Example #22
0
 def covariance(self, covar):
     if not isinstance(covar, Covariance):
         # Try an make a covariance out of whatever was provided
         covar = Covariance(2, self._datatype, covar)
     print "Setting covar:", covar
     self._call_cfunc(
         "vital_feature_{}_set_covar".format(self._tchar),
         [self.C_TYPE_PTR, Covariance.c_ptr_type(2, self._datatype)],
         None,
         self, covar
     )
Example #23
0
    def test_covariance(self):
        for ct in self.ctypeS:
            print(ct)
            l = Landmark(ctype=ct)

            # check default
            #nose.tools.assert_equal(l.covariance, Covariance.new_covar(3))

            # set type-aligned covariance
            c = Covariance.new_covar(3, ct, 7)
            l.covariance = c
Example #24
0
 def covariance(self):
     """
     :return: a copy of this camera's center covariance
     :rtype: Covariance
     """
     cam_covar = self.VITAL_LIB['vital_camera_center_covar']
     cam_covar.argtypes = [self.c_ptr_type(), VitalErrorHandle.c_ptr_type()]
     cam_covar.restype = Covariance.c_ptr_type(3)
     with VitalErrorHandle() as eh:
         c_ptr = cam_covar(self, eh)
     return Covariance(3, from_cptr=c_ptr)
Example #25
0
    def test_new_matrix(self):
        a = EigenArray(2, 2, type='d')
        m = a.get_matrix()
        m[:] = 1.
        c = Covariance.from_matrix(2, 'd', m)
        m_out = c.to_matrix()
        print('input matrix:\n', m)
        print('output matrix:\n', m_out)
        numpy.testing.assert_array_equal(m_out, m)

        # Type casting should be handled
        a = EigenArray(2, 2, type='f')
        m = a.get_matrix()
        m[:] = 1.
        c = Covariance.from_matrix(2, 'd', m)
        m_out = c.to_matrix()
        print('input matrix:\n', m)
        print('output matrix:\n', m_out)
        numpy.testing.assert_array_equal(m_out, m)

        # Any other numpy array of the correct shape should be acceptable
        m = numpy.ndarray((2, 2))
        m[:] = 3.
        c = Covariance.from_matrix(2, 'f', init=m)
        m_out = c.to_matrix()
        print('input matrix:\n', m)
        print('output matrix:\n', m_out)
        numpy.testing.assert_array_equal(m_out, m)

        # Diagonally congruent values should be averages when initializing with
        # matrix
        m = numpy.eye(3, dtype=numpy.double)
        m[0,2] = 2.
        m_expected = m.copy()
        m_expected[0,2] = 1.
        m_expected[2,0] = 1.
        c = Covariance.from_matrix(3, init=m)
        m_out = c.to_matrix()
        print('input matrix:\n', m)
        print('output matrix:\n', m_out)
        numpy.testing.assert_array_equal(m_out, m_expected)
Example #26
0
    def test_new_matrix(self):
        a = EigenArray(2, 2, type='d')
        m = a.get_matrix()
        m[:] = 1.
        c = Covariance.from_matrix(2, 'd', m)
        m_out = c.to_matrix()
        print('input matrix:\n', m)
        print('output matrix:\n', m_out)
        numpy.testing.assert_array_equal(m_out, m)

        # Type casting should be handled
        a = EigenArray(2, 2, type='f')
        m = a.get_matrix()
        m[:] = 1.
        c = Covariance.from_matrix(2, 'd', m)
        m_out = c.to_matrix()
        print('input matrix:\n', m)
        print('output matrix:\n', m_out)
        numpy.testing.assert_array_equal(m_out, m)

        # Any other numpy array of the correct shape should be acceptable
        m = numpy.ndarray((2, 2))
        m[:] = 3.
        c = Covariance.from_matrix(2, 'f', init=m)
        m_out = c.to_matrix()
        print('input matrix:\n', m)
        print('output matrix:\n', m_out)
        numpy.testing.assert_array_equal(m_out, m)

        # Diagonally congruent values should be averages when initializing with
        # matrix
        m = numpy.eye(3, dtype=numpy.double)
        m[0, 2] = 2.
        m_expected = m.copy()
        m_expected[0, 2] = 1.
        m_expected[2, 0] = 1.
        c = Covariance.from_matrix(3, init=m)
        m_out = c.to_matrix()
        print('input matrix:\n', m)
        print('output matrix:\n', m_out)
        numpy.testing.assert_array_equal(m_out, m_expected)
Example #27
0
 def covariance(self, covar):
     if self._datatype is None:
         raise VitalNoTypeInfoException("Type info required but not present")
     if not isinstance(covar, Covariance):
         # Try an make a covariance out of whatever was provided
         covar = Covariance(2, self._datatype, covar)
     print "Setting covar:", covar
     self._call_cfunc(
         "vital_feature_{}_set_covar".format(self._tchar),
         [self.C_TYPE_PTR, Covariance.c_ptr_type(2, self._datatype)],
         [self, covar],
     )
Example #28
0
    def test_set_covar(self):
        f = Feature(ctype='d')
        #nose.tools.assert_equal(f.covariance, Covariance.new_covar())

        expected = [[1, 2], [3, 4]]
        c = Covariance.from_matrix(2, 'd', expected)
        f.covariance = c
        #nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
        #nose.tools.assert_equal(f.covariance, c)

        # And for floats...
        f = Feature(ctype='f')
        #nose.tools.assert_equal(f.covariance, Covariance())

        expected = [[1, 2], [3, 4]]
        c = Covariance.from_matrix(2, 'f', expected)
        f.covariance = c
        #nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
Example #29
0
    def test_set_covar(self):
        f = Feature(ctype=ctypes.c_double)
        nose.tools.assert_equal(f.covariance, Covariance())

        expected = [[1, 2], [3, 4]]
        c = Covariance(2, ctypes.c_double, expected)
        f.covariance = c
        nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
        nose.tools.assert_equal(f.covariance, c)

        # And for floats...
        f = Feature(ctype=ctypes.c_float)
        nose.tools.assert_equal(f.covariance, Covariance())

        expected = [[1, 2], [3, 4]]
        c = Covariance(2, ctypes.c_float, expected)
        f.covariance = c
        nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
        nose.tools.assert_equal(f.covariance, c)
Example #30
0
    def test_set_covar(self):
        f = Feature(ctype='d')
        #nose.tools.assert_equal(f.covariance, Covariance.new_covar())

        expected = [[1, 2],
                    [3, 4]]
        c = Covariance.from_matrix(2, 'd', expected)
        f.covariance = c
        #nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
        #nose.tools.assert_equal(f.covariance, c)

        # And for floats...
        f = Feature(ctype='f')
        #nose.tools.assert_equal(f.covariance, Covariance())

        expected = [[1, 2],
                    [3, 4]]
        c = Covariance.from_matrix(2, 'f', expected)
        f.covariance = c
        #nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
Example #31
0
    def test_from_cptr(self):
        # Create a new covariance from C function and create new python instance
        # from that pointer
        c_new_func = VitalObject.VITAL_LIB['vital_covariance_3d_new']
        c_new_func.argtypes = [VitalErrorHandle.C_TYPE_PTR]
        c_new_func.restype = Covariance.c_ptr_type(3, ctypes.c_double)
        with VitalErrorHandle() as eh:
            c_ptr = c_new_func(eh)

        c = Covariance(N=3, c_type=ctypes.c_double, from_cptr=c_ptr)
        nose.tools.assert_is(c.C_TYPE_PTR,
                             Covariance.c_ptr_type(3, ctypes.c_double))
        numpy.testing.assert_array_equal(c.to_matrix(), numpy.eye(3))

        c_new_func = VitalObject.VITAL_LIB['vital_covariance_3f_new']
        c_new_func.argtypes = [VitalErrorHandle.C_TYPE_PTR]
        c_new_func.restype = Covariance.c_ptr_type(3, ctypes.c_float)
        with VitalErrorHandle() as eh:
            c_ptr = c_new_func(eh)

        c = Covariance(N=3, c_type=ctypes.c_float, from_cptr=c_ptr)
        nose.tools.assert_is(c.C_TYPE_PTR,
                             Covariance.c_ptr_type(3, ctypes.c_float))
        numpy.testing.assert_array_equal(c.to_matrix(), numpy.eye(3))
Example #32
0
    def test_new_scalar(self):
        c = Covariance.new_covar(2, 'd', 2.)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance.new_covar(3, 'd', 2.)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance.new_covar(2, 'f', 2.)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance.new_covar(3, 'f', 2.)
        print('constructed matrix:\n', c.to_matrix())

        c = Covariance.new_covar(2, 'd', 14.675)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance.new_covar(3, 'd', 14.675)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance.new_covar(2, 'f', 14.675)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance.new_covar(3, 'f', 14.675)
        print('constructed matrix:\n', c.to_matrix())
Example #33
0
    def test_new_scalar(self):
        c = Covariance.new_covar(2, 'd', 2.)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance.new_covar(3, 'd', 2.)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance.new_covar(2, 'f', 2.)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance.new_covar(3, 'f', 2.)
        print('constructed matrix:\n', c.to_matrix())

        c = Covariance.new_covar(2, 'd', 14.675)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance.new_covar(3, 'd', 14.675)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance.new_covar(2, 'f', 14.675)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance.new_covar(3, 'f', 14.675)
        print('constructed matrix:\n', c.to_matrix())
Example #34
0
    def test_new_matrix(self):
        m = EigenArray(2, 2, dtype=numpy.double)
        m[:] = 1.
        c = Covariance(2, ctypes.c_double, m)
        m_out = c.to_matrix()
        print 'input matrix:\n', m
        print 'output matrix:\n', m_out
        numpy.testing.assert_array_equal(m_out, m)

        # Type casting should be handled
        m = EigenArray(2, 2, dtype=numpy.float32)
        m[:] = 1.
        c = Covariance(2, ctypes.c_double, m)
        m_out = c.to_matrix()
        print 'input matrix:\n', m
        print 'output matrix:\n', m_out
        numpy.testing.assert_array_equal(m_out, m)

        # Any other numpy array of the correct shape should be acceptable
        m = numpy.ndarray((2, 2))
        m[:] = 3.
        c = Covariance(2, ctypes.c_float, init_scalar_or_matrix=m)
        m_out = c.to_matrix()
        print 'input matrix:\n', m
        print 'output matrix:\n', m_out
        numpy.testing.assert_array_equal(m_out, m)

        # Diagonally congruent values should be averages when initializing with
        # matrix
        m = numpy.eye(3, dtype=numpy.double)
        m[0,2] = 2.
        m_expected = m.copy()
        m_expected[0,2] = 1.
        m_expected[2,0] = 1.
        c = Covariance(3, init_scalar_or_matrix=m)
        m_out = c.to_matrix()
        print 'input matrix:\n', m
        print 'output matrix:\n', m_out
        numpy.testing.assert_array_equal(m_out, m_expected)
Example #35
0
    def test_from_cptr(self):
        # Create a new covariance from C function and create new python instance
        # from that pointer
        c_new_func = VitalObject.VITAL_LIB['vital_covariance_3d_new']
        c_new_func.argtypes = [VitalErrorHandle.C_TYPE_PTR]
        c_new_func.restype = Covariance.c_ptr_type(3, ctypes.c_double)
        with VitalErrorHandle() as eh:
            c_ptr = c_new_func(eh)

        c = Covariance(N=3, c_type=ctypes.c_double, from_cptr=c_ptr)
        nose.tools.assert_is(c.C_TYPE_PTR, Covariance.c_ptr_type(3, ctypes.c_double))
        numpy.testing.assert_array_equal(c.to_matrix(), numpy.eye(3))


        c_new_func = VitalObject.VITAL_LIB['vital_covariance_3f_new']
        c_new_func.argtypes = [VitalErrorHandle.C_TYPE_PTR]
        c_new_func.restype = Covariance.c_ptr_type(3, ctypes.c_float)
        with VitalErrorHandle() as eh:
            c_ptr = c_new_func(eh)

        c = Covariance(N=3, c_type=ctypes.c_float, from_cptr=c_ptr)
        nose.tools.assert_is(c.C_TYPE_PTR,Covariance.c_ptr_type(3, ctypes.c_float))
        numpy.testing.assert_array_equal(c.to_matrix(), numpy.eye(3))
Example #36
0
    def test_equal(self):
        for ct in self.C_TYPES:
            print(ct)

            l = Landmark(c_type=ct)
            l2 = Landmark(c_type=ct)
            nose.tools.assert_equal(l, l2)

            l = Landmark([1, 1, 1], 42.2, c_type=ct)
            l2 = Landmark([1, 1, 1], 42.2, c_type=ct)
            nose.tools.assert_equal(l, l2)

            norm = [0, 0.5, 0.5]
            covar = Covariance(3, init_scalar_or_matrix=3)
            color = RGBColor(2, 1, 5)
            obs = 43

            l.normal = l2.normal = norm
            l.covariance = l2.covariance = covar
            l.color = l2.color = color
            l.observations = l2.observations = obs
            nose.tools.assert_equal(l, l2)
Example #37
0
    def test_new_scalar(self):
        c = Covariance(2, ctypes.c_double, 2.)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance(3, ctypes.c_double, 2.)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance(2, ctypes.c_float, 2.)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance(3, ctypes.c_float, 2.)
        print('constructed matrix:\n', c.to_matrix())

        c = Covariance(2, ctypes.c_double, 14.675)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance(3, ctypes.c_double, 14.675)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance(2, ctypes.c_float, 14.675)
        print('constructed matrix:\n', c.to_matrix())
        c = Covariance(3, ctypes.c_float, 14.675)
        print('constructed matrix:\n', c.to_matrix())
Example #38
0
 def test_new_identity(self):
     # Valid dimensions and types
     c = Covariance(2, ctypes.c_double)
     print('constructed matrix:\n', c.to_matrix())
     c = Covariance(3, ctypes.c_double)
     print('constructed matrix:\n', c.to_matrix())
     c = Covariance(2, ctypes.c_float)
     print('constructed matrix:\n', c.to_matrix())
     c = Covariance(3, ctypes.c_float)
     print('constructed matrix:\n', c.to_matrix())
Example #39
0
 def test_get_covar(self):
     dflt_covar = Covariance.new_covar(2)
     f = Feature()
Example #40
0
 def test_get_covar(self):
     dflt_covar = Covariance.new_covar(2)
     f = Feature()
Example #41
0
    def test_new_matrix(self):
        m = EigenArray(2, 2, dtype=numpy.double)
        m[:] = 1.
        c = Covariance(2, ctypes.c_double, m)
        m_out = c.to_matrix()
        print('input matrix:\n', m)
        print('output matrix:\n', m_out)
        numpy.testing.assert_array_equal(m_out, m)

        # Type casting should be handled
        m = EigenArray(2, 2, dtype=numpy.float32)
        m[:] = 1.
        c = Covariance(2, ctypes.c_double, m)
        m_out = c.to_matrix()
        print('input matrix:\n', m)
        print('output matrix:\n', m_out)
        numpy.testing.assert_array_equal(m_out, m)

        # Any other numpy array of the correct shape should be acceptable
        m = numpy.ndarray((2, 2))
        m[:] = 3.
        c = Covariance(2, ctypes.c_float, init_scalar_or_matrix=m)
        m_out = c.to_matrix()
        print('input matrix:\n', m)
        print('output matrix:\n', m_out)
        numpy.testing.assert_array_equal(m_out, m)

        # Diagonally congruent values should be averages when initializing with
        # matrix
        m = numpy.eye(3, dtype=numpy.double)
        m[0, 2] = 2.
        m_expected = m.copy()
        m_expected[0, 2] = 1.
        m_expected[2, 0] = 1.
        c = Covariance(3, init_scalar_or_matrix=m)
        m_out = c.to_matrix()
        print('input matrix:\n', m)
        print('output matrix:\n', m_out)
        numpy.testing.assert_array_equal(m_out, m_expected)
Example #42
0
 def covariance(self):
     cptr = self._call_cfunc('vital_landmark_covariance', [self.C_TYPE_PTR],
                             [self], Covariance.c_ptr_type(3))
     return Covariance(3, from_cptr=cptr)
Example #43
0
 def test_get_covar(self):
     dflt_covar = Covariance(2)
     f = Feature()
     nose.tools.assert_equal(f.covariance, dflt_covar)
Example #44
0
    def test_new_scalar(self):
        c = Covariance(2, ctypes.c_double, 2.)
        print 'constructed matrix:\n', c.to_matrix()
        c = Covariance(3, ctypes.c_double, 2.)
        print 'constructed matrix:\n', c.to_matrix()
        c = Covariance(2, ctypes.c_float, 2.)
        print 'constructed matrix:\n', c.to_matrix()
        c = Covariance(3, ctypes.c_float, 2.)
        print 'constructed matrix:\n', c.to_matrix()

        c = Covariance(2, ctypes.c_double, 14.675)
        print 'constructed matrix:\n', c.to_matrix()
        c = Covariance(3, ctypes.c_double, 14.675)
        print 'constructed matrix:\n', c.to_matrix()
        c = Covariance(2, ctypes.c_float, 14.675)
        print 'constructed matrix:\n', c.to_matrix()
        c = Covariance(3, ctypes.c_float, 14.675)
        print 'constructed matrix:\n', c.to_matrix()