9 CSE_results = cse(expr, numbered_symbols(
"helper_"), optimizations=
'basic')
11 for helper
in CSE_results[0]:
12 if isinstance(helper[1], MatrixSymbol):
14 'const auto ' + str(helper[0]) +
'[' + str(helper[1].rows * helper[1].cols) +
'];')
15 lines.append(ccode(helper[1], helper[0]))
17 lines.append(
'const auto ' + ccode(helper[1], helper[0]))
19 for i, result
in enumerate(CSE_results[1]):
20 lines.append(ccode(result,
"result_%d" % i))
21 return '\n'.join(lines)
24def C99_print_tensor(expr, result_name="result"):
27 subs, result = cse(expr, numbered_symbols(
28 "helper_"), optimizations=
'basic')
33 lines.append(f
"const double {ccode(v, k)}")
35 result_shape = np.array(result).shape
36 if len(result_shape) == 2:
37 for i
in range(result_shape[0]):
38 for j
in range(result_shape[1]):
39 s = ccode(result[i, j], f
"{result_name}[{i}, {j}]")
41 elif len(result_shape) == 4:
42 for i
in range(result_shape[0]):
43 for j
in range(result_shape[1]):
44 for k
in range(result_shape[2]):
45 for l
in range(result_shape[3]):
46 s = ccode(result[i, j, k, l],
47 f
"{result_name}[{i * result_shape[1] + j}, {k * result_shape[3] + l}]")
50 return "\n".join(lines)