def test_transpose(self): m = Matrix(3,2) m[0,0] = 0 m[1,0] = 2 m[2,0] = 4 m[0,1] = 1 m[1,1] = 3 m[2,1] = 5 mt = m.transpose( ) self.assertEqual(m[0,0] , 0) self.assertEqual(m[1,0] , 2) self.assertEqual(m[2,0] , 4) self.assertEqual(m[0,1] , 1) self.assertEqual(m[1,1] , 3) self.assertEqual(m[2,1] , 5) self.assertEqual( mt.rows() , m.columns()) self.assertEqual( mt.columns() , m.rows()) self.assertEqual(mt[0,0] , 0) self.assertEqual(mt[1,0] , 1) self.assertEqual(mt[0,1] , 2) self.assertEqual(mt[1,1] , 3) self.assertEqual(mt[0,2] , 4) self.assertEqual(mt[1,2] , 5) m.transpose( inplace = True ) self.assertEqual( m , mt )
def test_matmul(self): m1 = Matrix(3,3) m2 = Matrix(2,2) with self.assertRaises(ValueError): Matrix.matmul( m1 , m2 ) m = Matrix(3,2) m[0,0] = 0 m[1,0] = 2 m[2,0] = 4 m[0,1] = 1 m[1,1] = 3 m[2,1] = 5 mt = m.transpose( ) m2 = Matrix.matmul( m , mt ) self.assertEqual( m2[0,0] , 1 ) self.assertEqual( m2[1,1] , 13 ) self.assertEqual( m2[2,2] , 41 )