aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/many_temporaries/matrix_product2.py
blob: 7baeb09b13177bb22e786c47341de79abcaf1975 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
m=4
n=5
p=6
number_type='double'
with open('matrix_product2.c', 'w') as cfile:
    cfile.write(f'void matrix_product({number_type} c[{m}][{p}], const {number_type} a[{m}][{n}], const {number_type} b[{n}][{p}]) {{\n')
    for i in range(m):
        for j in range(n):
            for k in range(p):
                cfile.write(f'  const {number_type} p_{i}_{j}_{k} = a[{i}][{j}] * b[{j}][{k}];\n')
    for i in range(m):
        for k in range(p):
            cfile.write(f'  const {number_type} r_{i}_{k} = ')
            for j in range(n):
                if j>0:
                    cfile.write(' + ')
                cfile.write(f'p_{i}_{j}_{k}')
            cfile.write(';\n')
    for i in range(m):
        for k in range(p):
            cfile.write(f'  c[{i}][{k}] = r_{i}_{k};\n')
    
    cfile.write('}\n')