Beispiel #1
0
 def test_center_initialized(self):
     expected_c = EigenArray(3)
     expected_c.get_matrix()[:] = [[1], [2], [3]]
     cam = Camera(expected_c)
     numpy.testing.assert_array_equal(
         numpy.array([cam.center]).T, expected_c.get_matrix())
     numpy.testing.assert_array_equal(cam.center, [1, 2, 3])
Beispiel #2
0
    def test_mutability(self):
        a = EigenArray(2, 3)
        d = a.get_matrix()  # The data pointer
        for i in range(2):
            for j in range(3):
                d[i][j] = 0
        numpy.testing.assert_array_equal(a.get_matrix(),
                                         [[0, 0, 0], [0, 0, 0]])

        d[:] = 1
        numpy.testing.assert_array_equal(a.get_matrix(),
                                         [[1, 1, 1], [1, 1, 1]])

        d[1, 0] = 2
        numpy.testing.assert_array_equal(a.get_matrix(),
                                         [[1, 1, 1], [2, 1, 1]])

        d[:, 2] = 3
        numpy.testing.assert_array_equal(a.get_matrix(),
                                         [[1, 1, 3], [2, 1, 3]])

        d += 1
        numpy.testing.assert_array_equal(a.get_matrix(),
                                         [[2, 2, 4], [3, 2, 4]])

        b = d * 0
        numpy.testing.assert_array_equal(a.get_matrix(),
                                         [[2, 2, 4], [3, 2, 4]])
        numpy.testing.assert_array_equal(b, [[0, 0, 0], [0, 0, 0]])
Beispiel #3
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)
Beispiel #4
0
    def test_order_transform(self):
        a = EigenArray(2, 3)
        d = a.get_matrix()  # The data pointer
        # column-major 2x3 matrix [[ 1 2 3 ]  (Eigen format)
        #                          [ 4 5 6 ]]
        d[0][0] = 1
        d[0][1] = 2
        d[0][2] = 3
        d[1][0] = 4
        d[1][1] = 5
        d[1][2] = 6

        numpy.testing.assert_array_equal(a.get_matrix(),
                                         [[1., 2., 3.], [4., 5., 6.]])

        ntools.assert_equal(a.get_matrix()[0, 0], 1)
        ntools.assert_equal(a.get_matrix()[0, 1], 2)
        ntools.assert_equal(a.get_matrix()[0, 2], 3)
        ntools.assert_equal(a.get_matrix()[1, 0], 4)
        ntools.assert_equal(a.get_matrix()[1, 1], 5)
        ntools.assert_equal(a.get_matrix()[1, 2], 6)
Beispiel #5
0
    def test_from_array(self):
        # from list
        expected_list = [[0.4, 0], [1, 1.123], [2.253, 4.768124]]
        ea = EigenArray.from_array(expected_list)
        em = ea.get_matrix()
        numpy.testing.assert_array_equal(em, expected_list)

        # from ndarray
        expected_ndar = numpy.array(expected_list)
        ea = EigenArray.from_array(expected_ndar)
        em = ea.get_matrix()
        numpy.testing.assert_array_equal(em, expected_ndar)

        # from EigenArray, which should return the input object
        ea = EigenArray(3, 2)
        em = ea.get_matrix()
        em[:] = expected_list
        ea2 = EigenArray.from_array(em)
        em2 = ea2.get_matrix()
        numpy.testing.assert_array_equal(em2, em)