11 CSE_results = cse(expr, numbered_symbols(
"helper_"), optimizations=
'basic')
13 for helper
in CSE_results[0]:
14 if isinstance(helper[1], MatrixSymbol):
16 'const auto ' + str(helper[0]) +
'[' + str(helper[1].rows * helper[1].cols) +
'];')
17 lines.append(ccode(helper[1], helper[0]))
19 lines.append(
'const auto ' + ccode(helper[1], helper[0]))
21 for i, result
in enumerate(CSE_results[1]):
22 lines.append(ccode(result,
"result_%d" % i))
23 return '\n'.join(lines)
92def C99_print_tensor(expr, result_name="result"):
95 subs, result = cse(expr, numbered_symbols(
96 "helper_"), optimizations=
'basic')
101 lines.append(f
"const double {ccode(v, k)}")
103 result_shape = np.array(result).shape
104 if len(result_shape) == 2:
105 for i
in range(result_shape[0]):
106 for j
in range(result_shape[1]):
107 s = ccode(result[i, j], f
"{result_name}[{i}, {j}]")
109 elif len(result_shape) == 4:
110 for i
in range(result_shape[0]):
111 for j
in range(result_shape[1]):
112 for k
in range(result_shape[2]):
113 for l
in range(result_shape[3]):
114 s = ccode(result[i, j, k, l],
115 f
"{result_name}[{i * result_shape[1] + j}, {k * result_shape[3] + l}]")
118 return "\n".join(lines)