4#include "../Array_bind.hpp"
11 return "ArrayEigenMatrixBatch";
16 return "ArrayEigenMatrixBatchPair";
29 using tReadMap = Eigen::Map<
30 const Eigen::Matrix<tElem, Eigen::Dynamic, Eigen::Dynamic, Eigen::DontAlign | Eigen::ColMajor>,
32 Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>>;
33 std::vector<tReadMap> mat_maps;
34 for (
const auto &
v : matList)
36 if (!py::isinstance<py::buffer>(
v))
37 throw std::runtime_error(
"All elements must be buffer-compatible objects.");
38 py::buffer buf =
v.cast<py::buffer>();
39 auto buf_info = buf.request(
false);
40 DNDS_assert(buf_info.item_type_is_equivalent_to<tElem>());
42 auto buf_start_ptr =
reinterpret_cast<tElem *
>(buf_info.ptr);
45 auto c_mat_map = tReadMap(
49 Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>(buf_info.strides[1] /
sizeof(tElem) , buf_info.strides[0] /
sizeof(tElem) ));
50 mat_maps.push_back(c_mat_map);
59 auto rowBatch = self[index_];
61 for (
int iMat = 0; iMat < rowBatch.Size(); iMat++)
63 auto mat = rowBatch[iMat];
65 py::memoryview::from_buffer<tElem>(
67 {mat.rows(), mat.cols()},
68 {sizeof(tElem) * mat.rowStride(), sizeof(tElem) * mat.colStride()},
78 auto mat = self(std::get<0>(index_), std::get<1>(index_));
79 return py::memoryview::from_buffer<tElem>(
81 {mat.rows(), mat.cols()},
82 {sizeof(tElem) * mat.rowStride(), sizeof(tElem) * mat.colStride()},
89 auto row_info = row.request(
false);
90 DNDS_assert(row_info.item_type_is_equivalent_to<tElem>());
91 auto mat = self(std::get<0>(index_), std::get<1>(index_));
96 auto row_start_ptr =
reinterpret_cast<tElem *
>(row_info.ptr);
98 auto row_mat_map = Eigen::Map<
99 const Eigen::Matrix<tElem, Eigen::Dynamic, Eigen::Dynamic, Eigen::DontAlign | Eigen::ColMajor>,
101 Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>>(
105 Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>(row_info.strides[1] /
sizeof(tElem) , row_info.strides[0] /
sizeof(tElem) ));
115 auto ParArray_ = pybind11_ParArray_get_class<real, NonUniformSize>(m);
131 ArrayEigenMatrixBatch_
133 .def(py::init<const MPIInfo &>(), py::arg(
"nmpi"))
136 [](TArrayEigenMatrixBatch &self,
index i)
138 return self.BatchSize(i);
142 "InitializeWriteRow",
143 [](TArrayEigenMatrixBatch &self,
index i,
const py::list &matList)
147 py::arg(
"i"), py::arg(
"matList"));
148 ArrayEigenMatrixBatch_
149 .def(
"clone", [](TArrayEigenMatrixBatch &self)
151 auto arr = std::make_shared<TArrayEigenMatrixBatch>(self);
153 ArrayEigenMatrixBatch_
156 [](TArrayEigenMatrixBatch &self,
index index_)
160 py::keep_alive<0, 1>())
163 [](TArrayEigenMatrixBatch &self, std::tuple<index, rowsize> index_)
167 py::keep_alive<0, 1>())
170 [](TArrayEigenMatrixBatch &self, std::tuple<index, rowsize> index_, py::buffer row)
175 ArrayEigenMatrixBatch_
176 .def(
"to_device", [](TArrayEigenMatrixBatch &self,
const std::string &backend)
178 .def(
"to_host", &TArrayEigenMatrixBatch::to_host);
202 pybind11_ArrayPairGenericBindBasics<TPair>(Pair_);
205 .def(
"RowSize", [](
const TPair &self,
index i)
206 {
return self.RowSize(i); }, py::arg(
"i"));
210 [](TPair &self,
index index_)
212 return self.runFunctionAppendedIndex(index_, [&](
auto &ar,
index iC)
215 py::keep_alive<0, 1>())
217 "InitializeWriteRow",
218 [](TPair &self,
index index_, py::buffer row)
220 return self.runFunctionAppendedIndex(index_, [&](
auto &ar,
index iC)
227 [](TPair &self, std::tuple<index, rowsize> index_)
229 return self.runFunctionAppendedIndex(std::get<0>(index_), [&](
auto &ar,
index iC)
232 py::keep_alive<0, 1>())
235 [](TPair &self, std::tuple<index, rowsize> index_, py::buffer row)
237 return 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 + ...
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)
py_class_ssp< ArrayEigenMatrixBatchPair > tPy_ArrayEigenMatrixBatchPair
py::classh< T > py_class_ssp
auto pybind11_ArrayEigenMatrixBatch_setitem(ArrayEigenMatrixBatch &self, std::tuple< index, rowsize > index_, py::buffer row)
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.
auto pybind11_ArrayEigenMatrixBatch_setitem_row(ArrayEigenMatrixBatch &self, index i, const py::list &matList)
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
tPy_ArrayEigenMatrixBatchPair pybind11_ArrayEigenMatrixBatchPair_get_class(py::module_ &m)
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