6#include "../Array_bind.hpp"
13 return "ArrayEigenMatrixBatch";
18 return "ArrayEigenMatrixBatchPair";
31 using tReadMap = Eigen::Map<
32 const Eigen::Matrix<tElem, Eigen::Dynamic, Eigen::Dynamic, Eigen::DontAlign | Eigen::ColMajor>,
34 Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>>;
35 std::vector<tReadMap> mat_maps;
36 for (
const auto &
v : matList)
38 if (!py::isinstance<py::buffer>(
v))
39 throw std::runtime_error(
"All elements must be buffer-compatible objects.");
40 auto buf =
v.cast<py::buffer>();
41 auto buf_info = buf.request(
false);
42 DNDS_assert(buf_info.item_type_is_equivalent_to<tElem>());
44 auto *buf_start_ptr =
reinterpret_cast<tElem *
>(buf_info.ptr);
47 auto c_mat_map = tReadMap(
51 Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>(buf_info.strides[1] /
sizeof(tElem) , buf_info.strides[0] /
sizeof(tElem) ));
52 mat_maps.push_back(c_mat_map);
61 auto rowBatch = self[index_];
63 for (
int iMat = 0; iMat < rowBatch.Size(); iMat++)
65 auto mat = rowBatch[iMat];
67 py::memoryview::from_buffer<tElem>(
69 {mat.rows(), mat.cols()},
70 {sizeof(tElem) * mat.rowStride(), sizeof(tElem) * mat.colStride()},
80 auto mat = self(std::get<0>(index_), std::get<1>(index_));
81 return py::memoryview::from_buffer<tElem>(
83 {mat.rows(), mat.cols()},
84 {sizeof(tElem) * mat.rowStride(), sizeof(tElem) * mat.colStride()},
91 auto row_info = row.request(
false);
92 DNDS_assert(row_info.item_type_is_equivalent_to<tElem>());
93 auto mat = self(std::get<0>(index_), std::get<1>(index_));
98 auto *row_start_ptr =
reinterpret_cast<tElem *
>(row_info.ptr);
100 auto row_mat_map = Eigen::Map<
101 const Eigen::Matrix<tElem, Eigen::Dynamic, Eigen::Dynamic, Eigen::DontAlign | Eigen::ColMajor>,
103 Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>>(
107 Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>(row_info.strides[1] /
sizeof(tElem) , row_info.strides[0] /
sizeof(tElem) ));
117 auto ParArray_ = pybind11_ParArray_get_class<real, NonUniformSize>(
m);
133 ArrayEigenMatrixBatch_
135 .def(py::init<const MPIInfo &>(), py::arg(
"nmpi"))
138 [](TArrayEigenMatrixBatch &self,
index i)
140 return self.BatchSize(
i);
144 "InitializeWriteRow",
145 [](TArrayEigenMatrixBatch &self,
index i,
const py::list &matList)
149 py::arg(
"i"), py::arg(
"matList"));
150 ArrayEigenMatrixBatch_
151 .def(
"clone", [](TArrayEigenMatrixBatch &self)
153 auto arr = std::make_shared<TArrayEigenMatrixBatch>(self);
155 ArrayEigenMatrixBatch_
158 [](TArrayEigenMatrixBatch &self,
index index_)
162 py::keep_alive<0, 1>())
165 [](TArrayEigenMatrixBatch &self, std::tuple<index, rowsize> index_)
169 py::keep_alive<0, 1>())
172 [](TArrayEigenMatrixBatch &self, std::tuple<index, rowsize> index_,
const py::buffer &row)
177 ArrayEigenMatrixBatch_
178 .def(
"to_device", [](TArrayEigenMatrixBatch &self,
const std::string &backend)
180 .def(
"to_host", &TArrayEigenMatrixBatch::to_host);
204 pybind11_ArrayPairGenericBindBasics<TPair>(Pair_);
207 .def(
"RowSize", [](
const TPair &self,
index i)
208 {
return self.RowSize(
i); }, py::arg(
"i"));
212 [](TPair &self,
index index_)
214 return self.runFunctionAppendedIndex(index_, [&](
auto &ar,
index iC)
217 py::keep_alive<0, 1>())
219 "InitializeWriteRow",
220 [](TPair &self,
index index_,
const py::buffer &row)
222 self.runFunctionAppendedIndex(index_, [&](
auto &ar,
index iC)
229 [](TPair &self, std::tuple<index, rowsize> index_)
231 return self.runFunctionAppendedIndex(std::get<0>(index_), [&](
auto &ar,
index iC)
234 py::keep_alive<0, 1>())
237 [](TPair &self, std::tuple<index, rowsize> index_,
const py::buffer &row)
239 self.runFunctionAppendedIndex(std::get<0>(index_), [&](
auto &ar,
index iC)
Batch of variable-sized Eigen matrices stored in CSR layout.
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
Eigen::Matrix< real, 3, 3 > m
CSR array storing a variable-sized batch of Eigen matrices per row.
void InitializeWriteRow(index i, const std::vector< t_matrices_elem > &matrices)
the host side operators are provided as implemented
void pybind11_ArrayEigenMatrixBatchPair_define(py::module_ &m)
void pybind11_ArrayEigenMatrixBatch_setitem_row(ArrayEigenMatrixBatch &self, index i, const py::list &matList)
py_class_ssp< ArrayEigenMatrixBatchPair > tPy_ArrayEigenMatrixBatchPair
py::classh< T > py_class_ssp
tPy_ArrayEigenMatrixBatchPair pybind11_ArrayEigenMatrixBatchPair_declare(py::module_ &m)
std::string pybind11_ArrayEigenMatrixBatch_name()
DeviceBackend device_backend_name_to_enum(std::string_view s)
Inverse of device_backend_name. Returns Unknown for unrecognised names.
tPy_ArrayEigenMatrixBatch pybind11_ArrayEigenMatrixBatch_declare(py::module_ &m)
py_class_ssp< ArrayEigenMatrixBatch > tPy_ArrayEigenMatrixBatch
tPy_ArrayEigenMatrixBatch pybind11_ArrayEigenMatrixBatch_get_class(py::module_ &m)
void pybind11_ArrayEigenMatrixBatch_define(py::module_ &m)
auto pybind11_ArrayEigenMatrixBatch_getitem(ArrayEigenMatrixBatch &self, std::tuple< index, rowsize > index_)
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
ArrayPair< ArrayEigenMatrixBatch > ArrayEigenMatrixBatchPair
ArrayPair alias for per-row variable-size Eigen matrix batches.
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
tPy_ArrayEigenMatrixBatchPair pybind11_ArrayEigenMatrixBatchPair_get_class(py::module_ &m)
void pybind11_ArrayEigenMatrixBatch_setitem(ArrayEigenMatrixBatch &self, std::tuple< index, rowsize > index_, const py::buffer &row)
std::string pybind11_ArrayEigenMatrixBatchPair_name()
auto pybind11_ArrayEigenMatrixBatch_getitem_row(ArrayEigenMatrixBatch &self, index index_)
void pybind11_bind_ArrayEigenMatrixBatch_All(py::module_ &m)
Eigen::Matrix< real, 5, 1 > v