| 9 | |
| 10 | |
| 11 | def generate_dummy_code_pybind11(nclasses=10): |
| 12 | decl = "" |
| 13 | bindings = "" |
| 14 | |
| 15 | for cl in range(nclasses): |
| 16 | decl += f"class cl{cl:03};\n" |
| 17 | decl += "\n" |
| 18 | |
| 19 | for cl in range(nclasses): |
| 20 | decl += f"class {cl:03} {{\n" |
| 21 | decl += "public:\n" |
| 22 | bindings += f' py::class_<cl{cl:03}>(m, "cl{cl:03}")\n' |
| 23 | for fn in range(nfns): |
| 24 | ret = random.randint(0, nclasses - 1) |
| 25 | params = [random.randint(0, nclasses - 1) for i in range(nargs)] |
| 26 | decl += f" cl{ret:03} *fn_{fn:03}(" |
| 27 | decl += ", ".join(f"cl{p:03} *" for p in params) |
| 28 | decl += ");\n" |
| 29 | bindings += f' .def("fn_{fn:03}", &cl{cl:03}::fn_{fn:03})\n' |
| 30 | decl += "};\n\n" |
| 31 | bindings += " ;\n" |
| 32 | |
| 33 | result = "#include <pybind11/pybind11.h>\n\n" |
| 34 | result += "namespace py = pybind11;\n\n" |
| 35 | result += decl + "\n" |
| 36 | result += "PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {\n" |
| 37 | result += bindings |
| 38 | result += "}" |
| 39 | return result |
| 40 | |
| 41 | |
| 42 | def generate_dummy_code_boost(nclasses=10): |