def testMul_2x3(self): a = ComplexM(2,3, [ [(3,2) , (0,0) , (5,-6) ], [(1,0) , (4,2) , (0,1) ], ] ) b = ComplexM(3,2, [ [(5,0) , (2,-1)], [(0,0) , (4,5)], [(7,-4) , (2,7)], ] ) res = ComplexM(2,2, [ [(26,-52) , (60,24)], [(9,7) , (1,29)], ] ) self.assertEqual(a*b, res) self.assertNotEqual(b*a, a*b) self.assertIsNone(a.get_identity()) self.assertIsNone(b.get_identity()) self.assertIsNotNone(res.get_identity()) x = Complex(4,-3.5) self.assertEqual(x * (a*b), (x*a) * b) self.assertEqual(x * (a*b), a * (x*b)) self.assertEqual((a*b).transpose(), b.transpose() * a.transpose()) self.assertEqual((a*b).adjoint(), b.adjoint() * a.adjoint()) self.assertEqual((a*b).conjugate(), a.conjugate() * b.conjugate())
def testMul_3x3(self): a = ComplexM(3,3, [ [(3,2) , (0,0) , (5,-6) ], [(1,0) , (4,2) , (0,1) ], [(4,-1) , (0,0) , (4,0) ], ] ) b = ComplexM(3,3, [ [(5,0) , (2,-1) , (6,-4) ], [(0,0) , (4,5) , (2,0) ], [(7,-4) , (2,7) , (0,0) ], ] ) res = ComplexM(3,3, [ [(26,-52) , (60,24) , (26,0) ], [(9,7) , (1,29) , (14,0) ], [(48,-21) , (15,22) , (20,-22) ], ] ) self.assertEqual(a*b, res) self.assertNotEqual(b*a, a*b) ident = a.get_identity() self.assertEqual(a, a*ident) self.assertEqual(b, b*ident) x = Complex(2,-1) self.assertEqual(x * (a*b), (x*a) * b) self.assertEqual(x * (a*b), a * (x*b)) c = res self.assertEqual((a*b)*c, a*(b*c)) self.assertEqual(a*(b+c), (a*b)+(a*c)) self.assertEqual((a*b).transpose(), b.transpose() * a.transpose()) self.assertEqual((a*b).adjoint(), b.adjoint() * a.adjoint()) self.assertEqual((a*b).conjugate(), a.conjugate() * b.conjugate())