DNDSR 0.2.1
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
_generate_AdjPairTracked_bind.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""Generate AdjPairTracked pybind11 instantiation .cpp files and forward header.
3
4Each .cpp file instantiates pybind11_AdjPairTracked_define for one
5(row_size, row_max, align) triple. The forward header declares all
6define functions so the module entry point can call them.
7
8Follows the same pattern as DNDS/ArrayDOF_inst/_generate_explicit_inst.py.
9
10Usage:
11 python _generate_AdjPairTracked_bind.py
12"""
13
14import os
15import textwrap
16
17# (row_size, row_max, align)
18# Python class names are generated at compile time by the
19# pybind11_AdjPairTracked_name<rs, rm, al>() helper.
20INSTANTIATIONS = [
21 (-2, -2, -1024), # tAdjPair (NonUniformSize)
22 (2, 2, -1024), # tAdj2Pair
23 (1, 1, -1024), # tAdj1Pair
24]
25
26# Map special rowsize/align values to the same short tags used by
27# RowSize_To_PySnippet / Align_To_PySnippet in Defines.hpp.
28_RS_MAP = {-2: "I", -1: "D"}
29_AL_MAP = {-1024: "N"}
30
31
32def _tag(rs, rm, al):
33 r = _RS_MAP.get(rs, str(rs))
34 m = _RS_MAP.get(rm, str(rm))
35 a = _AL_MAP.get(al, str(al))
36 return f"{r}_{m}_{a}"
37
38
39CPP_TEMPLATE = textwrap.dedent("""\
40 // Auto-generated by _generate_AdjPairTracked_bind.py — do not edit.
41 #include "../AdjPairTracked_bind.hpp"
42
43 void pybind11_AdjPairTracked_{tag}_define(py::module_ &m)
44 {{
45 DNDS::Geom::pybind11_AdjPairTracked_define<{rs}, {rm}, {al}>(m);
46 }}
47""")
48
49FWD_HEADER_HEAD = textwrap.dedent("""\
50 // Auto-generated by _generate_AdjPairTracked_bind.py — do not edit.
51 #pragma once
52 #include <pybind11/pybind11.h>
53 namespace py = pybind11;
54
55""")
56
57DIR = os.path.dirname(os.path.abspath(__file__))
58
59
60def main():
61 for rs, rm, al in INSTANTIATIONS:
62 tag = _tag(rs, rm, al)
63 cpp = CPP_TEMPLATE.format(tag=tag, rs=rs, rm=rm, al=al)
64 path = os.path.join(DIR, f"AdjPairTracked_bind_{tag}.cpp")
65 with open(path, "w") as f:
66 f.write(cpp)
67 print(f" wrote {path}")
68
69 header = FWD_HEADER_HEAD
70 for rs, rm, al in INSTANTIATIONS:
71 tag = _tag(rs, rm, al)
72 header += f"void pybind11_AdjPairTracked_{tag}_define(py::module_ &m);\n"
73
74 fwd_path = os.path.join(DIR, "AdjPairTracked_bind_fwd.hpp")
75 with open(fwd_path, "w") as f:
76 f.write(header)
77 print(f" wrote {fwd_path}")
78
79
80if __name__ == "__main__":
81 main()