Пример #1
0
 def test_radd_(self):
     left1 = numpy.matrix([[1], [2], [3]])
     right1 = numpy.matrix([[5], [6], [7]])
     rmat1 = RMat(left1, right1)
     addend = numpy.matrix(numpy.ones((3, 3)))
     res = rmat1.__radd__(addend)
     check = rmat1.to_matrix() + numpy.matrix(numpy.ones((3, 3)))
     self.assertEqual(res.norm(), numpy.linalg.norm(check))
Пример #2
0
 def test_transpose(self):
     left_block = numpy.matrix([[1, 2, 3], [3, 2, 1], [2, 3, 1]])
     right_block = numpy.matrix([[2, 3, 4], [4, 3, 2], [3, 4, 2]])
     rmat = RMat(left_block, right_block)
     self.assertEqual(rmat.transpose(),
                      RMat(left_mat=right_block, right_mat=left_block))
     trans = rmat.transpose()
     full = rmat.to_matrix()
     self.assertTrue(numpy.array_equal(trans.to_matrix(), full.transpose()))
Пример #3
0
 def test_add(self):
     left1 = numpy.matrix([[1], [2], [3]])
     left2 = numpy.matrix([[2], [3], [4]])
     add_left = numpy.matrix([[1, 2], [2, 3], [3, 4]])
     right1 = numpy.matrix([[5], [6], [7]])
     right2 = numpy.matrix([[4], [5], [6]])
     add_right = numpy.matrix([[5, 4], [6, 5], [7, 6]])
     rmat1 = RMat(left1, right1)
     rmat2 = RMat(left2, right2)
     add_mat = RMat(add_left, add_right)
     res = rmat1 + rmat2
     self.assertEqual(res, add_mat)
     self.assertAlmostEqual(abs(rmat1 + rmat2), abs(rmat2 + rmat1), 6)
     self.assertRaises(ValueError, rmat1.__add__, numpy.ones((2, 4)))
     self.assertRaises(ValueError, rmat1.__add__, 1)
     res = rmat1 + numpy.matrix(numpy.ones((3, 3)))
     check = rmat1.to_matrix() + numpy.matrix(numpy.ones((3, 3)))
     self.assertEqual(res.norm(), numpy.linalg.norm(check))
     self.assertRaises(NotImplementedError, rmat1.__add__, 'bla')
     self.assertRaises(NotImplementedError, rmat1.__add__, numpy.ones(
         (3, 3)))
Пример #4
0
 def test_toMatrix(self):
     left = numpy.matrix([[1], [2], [3]])
     right = numpy.matrix([[2], [3], [4]])
     rmat = RMat(left, right, 1)
     check_mat = numpy.matrix([[2, 3, 4], [4, 6, 8], [6, 9, 12]])
     self.assertTrue(numpy.array_equal(rmat.to_matrix(), check_mat))