1#!/usr/bin/python
2
3def gen(x, y):
4    origtype = "mat" + str(x)
5    trantype = "mat" + str(y)
6    if x != y:
7        origtype = origtype + "x" + str(y)
8        trantype = trantype + "x" + str(x)
9    print trantype + " transpose(" + origtype + " m)\n{"
10    print "    " + trantype + " t;"
11
12    # The obvious implementation of transpose
13    for i in range(x):
14        for j in range(y):
15            print "    t[" + str(j) + "][" + str(i) + "] =",
16            print "m[" + str(i) + "][" + str(j) + "];"
17    print "    return t;\n}"
18
19print "#version 120"
20gen(2,2)
21gen(2,3) # mat2x3 means 2 columns, 3 rows
22gen(2,4)
23gen(3,2)
24gen(3,3)
25gen(3,4)
26gen(4,2)
27gen(4,3)
28gen(4,4)
29