DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
ArrayAdjacency_bind.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "ArrayAdjacency.hpp"
4#include "../Array_bind.hpp"
5
6namespace DNDS
7{
8 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
10 {
11 return fmt::format("_{}_{}_{}",
12 RowSize_To_PySnippet(_row_size),
13 RowSize_To_PySnippet(_row_max),
14 Align_To_PySnippet(_align));
15 }
16
17 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
19 {
20 return "ArrayAdjacency" + pybind11_ArrayAdjacency_name_appends<_row_size, _row_max, _align>();
21 }
22
23 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
25 {
26 return "ArrayAdjacencyPair" + pybind11_ArrayAdjacency_name_appends<_row_size, _row_max, _align>();
27 }
28
29 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign> // ! shared ptr
31
32 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
34}
35
36namespace DNDS
37{
38 template <class TArray = ArrayAdjacency<1>>
39 auto pybind11_ArrayAdjacency_setitem(TArray &self, index index_, py::buffer row)
40 {
41 auto row_info = row.request(false);
42 DNDS_assert(row_info.item_type_is_equivalent_to<index>());
43 auto [count, row_style] = py_buffer_get_contigious_size(row_info);
44 DNDS_assert(self.RowSize(index_) == count);
45 auto row_start_ptr = reinterpret_cast<index *>(row_info.ptr);
46 std::copy(row_start_ptr, row_start_ptr + count, self.rowPtr(index_));
47 }
48
49 template <class TArray = ArrayAdjacency<1>>
50 auto pybind11_ArrayAdjacency_getitem(TArray &self, index index_)
51 {
52 AdjacencyRow row = self[index_];
53 return py::memoryview::from_buffer<index>(
54 row.begin(),
55 {row.size()},
56 {sizeof(index)},
57 false);
58 }
59}
60
61namespace DNDS
62{
63 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
64 tPy_ArrayAdjacency<_row_size, _row_max, _align>
66 {
67 auto ParArray_ = pybind11_ParArray_get_class<index, _row_size, _row_max, _align>(m);
68 return {m, pybind11_ArrayAdjacency_name<_row_size, _row_max, _align>().c_str(), ParArray_};
69 // std::cout << py::format_descriptor<Eigen::Matrix<double, 3, 3>>().format() << std::endl;
70 }
71
72 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
73 tPy_ArrayAdjacency<_row_size, _row_max, _align>
75 {
76 return {m.attr(pybind11_ArrayAdjacency_name<_row_size, _row_max, _align>().c_str())};
77 }
78
79 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
80 void pybind11_ArrayAdjacency_define(py::module_ &m)
81 {
82
83 using TArrayAdjacency = ArrayAdjacency<_row_size, _row_max, _align>;
84 auto ArrayAdjacency_ = pybind11_ArrayAdjacency_declare<_row_size, _row_max, _align>(m);
85
86 // // helper
87 // using TArrayAdjacency = ArrayAdjacency<1>;
88 // auto ArrayAdjacency_ = pybind11_ArrayAdjacency_declare<1>(m);
89 // // helper
90
91 ArrayAdjacency_
92 // we only bind the non-default ctor here
93 .def(py::init<const MPIInfo &>(), py::arg("nmpi"))
94 .def(py::init([](const std::string &name, const MPIInfo &nmpi)
95 { return make_ssp<TArrayAdjacency>(ObjName{name}, nmpi); }),
96 py::arg("name"), py::arg("nmpi"))
97 .def("setObjectName", &TArrayAdjacency::setObjectName, py::arg("name"))
98 .def("getObjectName", &TArrayAdjacency::getObjectName)
99 .def(
100 "__getitem__",
101 [](TArrayAdjacency &self, index index_)
102 {
103 return pybind11_ArrayAdjacency_getitem(self, index_);
104 },
105 py::keep_alive<0, 1>())
106 .def(
107 "__setitem__",
108 [](TArrayAdjacency &self, index index_, py::buffer row)
109 {
110 return pybind11_ArrayAdjacency_setitem(self, index_, row);
111 });
112 ArrayAdjacency_
113 .def("clone", [](TArrayAdjacency &self)
114 {
115 auto arr = std::make_shared<TArrayAdjacency>(self);
116 return arr; });
117
118 ArrayAdjacency_
119 .def("to_device", [](TArrayAdjacency &self, const std::string &backend)
120 { self.to_device(device_backend_name_to_enum(backend)); }, py::arg("backend"))
121 .def("to_host", &TArrayAdjacency::to_host);
122 }
123
124 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
126 {
127 if constexpr (_row_size == UnInitRowsize)
128 return;
129 else
130 return pybind11_ArrayAdjacency_define<_row_size, _row_max, _align>(m);
131 }
132}
133
134namespace DNDS
135{
136 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
137 tPy_ArrayAdjacencyPair<_row_size, _row_max, _align>
139 {
140 return {m, pybind11_ArrayAdjacencyPair_name<_row_size, _row_max, _align>().c_str()};
141 // std::cout << py::format_descriptor<Eigen::Matrix<double, 3, 3>>().format() << std::endl;
142 }
143
144 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
145 tPy_ArrayAdjacencyPair<_row_size, _row_max, _align>
147 {
148 return {m.attr(pybind11_ArrayAdjacencyPair_name<_row_size, _row_max, _align>().c_str())};
149 }
150
151 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
153 {
154
155 // using TArray = ParArray<T, _row_size, _row_max, _align>;
157 auto Pair_ = pybind11_ArrayAdjacencyPair_declare<_row_size, _row_max, _align>(m);
158
159 // // helper
160 // using TArray = ArrayAdjacency<_row_size, _row_max, _align>;
161 // using TPair = ArrayPair<ArrayAdjacency<1>>;
162 // auto Pair_ = pybind11_ArrayAdjacencyPair_declare<1>(m);
163 // // helper
164
165 pybind11_ArrayPairGenericBindBasics<TPair>(Pair_);
166
167 Pair_
168 .def("RowSize", [](const TPair &self, index i)
169 { return self.RowSize(i); }, py::arg("i"))
170 .def("RowSize", [](const TPair &self)
171 { return self.RowSize(); });
172 Pair_
173 .def(
174 "__getitem__",
175 [](TPair &self, index index_)
176 {
177 return self.runFunctionAppendedIndex(index_, [&](auto &ar, index iC) //* note the reference here!!!
178 { return pybind11_ArrayAdjacency_getitem(ar, iC); });
179 },
180 py::keep_alive<0, 1>())
181 .def(
182 "__setitem__",
183 [](TPair &self, index index_, py::buffer row)
184 {
185 return self.runFunctionAppendedIndex(index_, [&](auto &ar, index iC) //*note the auto&& reference here!!!
186 { return pybind11_ArrayAdjacency_setitem(ar, iC, row); });
187 });
188 }
189
190 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
192 {
193 if constexpr (_row_size == UnInitRowsize)
194 return;
195 else
196 return pybind11_ArrayAdjacencyPair_define<_row_size, _row_max, _align>(m);
197 }
198}
199
200namespace DNDS
201{
202 template <size_t N, std::array<int, N> const &Arr, size_t... Is>
203 void __pybind11_callBindArrayAdjacencys_rowsizes_sequence(py::module_ &m, std::index_sequence<Is...>)
204 {
205 (_pybind11_ArrayAdjacency_define_dispatch<Arr[Is]>(m), ...);
206 (_pybind11_ArrayAdjacencyPair_define_dispatch<Arr[Is]>(m), ...);
207 }
208
210 {
211 static constexpr auto seq = pybind11_arrayRowsizeInstantiationList;
213 seq.size(), seq>(m, std::make_index_sequence<seq.size()>{});
214 }
215
216 void pybind11_bind_ArrayAdjacency_All(py::module_ &m);
217}
Adjacency array (CSR-like index storage) built on ParArray.
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
Definition Errors.hpp:108
Non-owning span (pointer, size) into an ArrayAdjacency row.
DNDS_DEVICE_CALLABLE index_T * begin()
Mesh-connectivity array: ParArray<index> whose operator[] yields an AdjacencyRow typed view.
the host side operators are provided as implemented
void pybind11_ArrayAdjacencyPair_define(py::module_ &m)
void _pybind11_ArrayAdjacency_define_dispatch(py::module_ &m)
py::classh< T > py_class_ssp
void pybind11_bind_ArrayAdjacency_All(py::module_ &m)
std::tuple< ssize_t, char > py_buffer_get_contigious_size(const py::buffer_info &info)
void __pybind11_callBindArrayAdjacencys_rowsizes_sequence(py::module_ &m, std::index_sequence< Is... >)
DeviceBackend device_backend_name_to_enum(std::string_view s)
Inverse of device_backend_name. Returns Unknown for unrecognised names.
tPy_ArrayAdjacencyPair< _row_size, _row_max, _align > pybind11_ArrayAdjacencyPair_declare(py::module_ &m)
void _pybind11_ArrayAdjacencyPair_define_dispatch(py::module_ &m)
std::string RowSize_To_PySnippet(rowsize rs)
Encode a rowsize constant as a short Python-binding snippet: "<number>" for fixed,...
Definition Defines.hpp:294
tPy_ArrayAdjacency< _row_size, _row_max, _align > pybind11_ArrayAdjacency_get_class(py::module_ &m)
py_class_ssp< ArrayAdjacencyPair< _row_size, _row_max, _align > > tPy_ArrayAdjacencyPair
std::string pybind11_ArrayAdjacency_name()
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
Definition Defines.hpp:107
auto pybind11_ArrayAdjacency_getitem(TArray &self, index index_)
py_class_ssp< ArrayAdjacency< _row_size, _row_max, _align > > tPy_ArrayAdjacency
std::string pybind11_ArrayAdjacencyPair_name()
tPy_ArrayAdjacency< _row_size, _row_max, _align > pybind11_ArrayAdjacency_declare(py::module_ &m)
void pybind11_callBindArrayAdjacencys_rowsizes(py::module_ &m)
std::string pybind11_ArrayAdjacency_name_appends()
std::string Align_To_PySnippet(rowsize al)
Encode an alignment value as a Python-binding snippet: "N" for NoAlign, the number otherwise.
Definition Defines.hpp:310
auto pybind11_ArrayAdjacency_setitem(TArray &self, index index_, py::buffer row)
void pybind11_ArrayAdjacency_define(py::module_ &m)
tPy_ArrayAdjacencyPair< _row_size, _row_max, _align > pybind11_ArrayAdjacencyPair_get_class(py::module_ &m)
DNDS_CONSTANT const rowsize UnInitRowsize
Sentinel "not initialised" rowsize value (= INT32_MIN).
Definition Defines.hpp:179
Convenience bundle of a father, son, and attached ArrayTransformer.
Lightweight bundle of an MPI communicator and the calling rank's coordinates.
Definition MPI.hpp:215
Tag type for naming objects created via make_ssp.
Definition Defines.hpp:249