MCPcopy Create free account
hub / github.com/pybind/pybind11 / DiscontiguousMatrix

Class DiscontiguousMatrix

tests/test_buffers.cpp:217–257  ·  view source on GitHub ↗

A matrix that uses a discontiguous underlying memory block.

Source from the content-addressed store, hash-verified

215
216 // A matrix that uses a discontiguous underlying memory block.
217 class DiscontiguousMatrix : public Matrix {
218 public:
219 DiscontiguousMatrix(py::ssize_t rows,
220 py::ssize_t cols,
221 py::ssize_t row_factor,
222 py::ssize_t col_factor)
223 : Matrix(rows * row_factor, cols * col_factor), m_row_factor(row_factor),
224 m_col_factor(col_factor) {
225 print_created(this,
226 std::to_string(rows) + "(*" + std::to_string(row_factor) + ")x"
227 + std::to_string(cols) + "(*" + std::to_string(col_factor)
228 + ") matrix");
229 }
230 DiscontiguousMatrix(const DiscontiguousMatrix &) = delete;
231 ~DiscontiguousMatrix() {
232 print_destroyed(this,
233 std::to_string(rows() / m_row_factor) + "(*"
234 + std::to_string(m_row_factor) + ")x"
235 + std::to_string(cols() / m_col_factor) + "(*"
236 + std::to_string(m_col_factor) + ") matrix");
237 }
238
239 float operator()(py::ssize_t i, py::ssize_t j) const {
240 return Matrix::operator()(i * m_row_factor, j * m_col_factor);
241 }
242
243 float &operator()(py::ssize_t i, py::ssize_t j) {
244 return Matrix::operator()(i * m_row_factor, j * m_col_factor);
245 }
246
247 using Matrix::data;
248
249 py::ssize_t rows() const { return Matrix::rows() / m_row_factor; }
250 py::ssize_t cols() const { return Matrix::cols() / m_col_factor; }
251 py::ssize_t row_factor() const { return m_row_factor; }
252 py::ssize_t col_factor() const { return m_col_factor; }
253
254 private:
255 py::ssize_t m_row_factor;
256 py::ssize_t m_col_factor;
257 };
258 py::class_<DiscontiguousMatrix, Matrix>(m, "DiscontiguousMatrix", py::buffer_protocol())
259 .def(py::init<py::ssize_t, py::ssize_t, py::ssize_t, py::ssize_t>())
260

Callers

nothing calls this directly

Calls 1

operator()Function · 0.50

Tested by

no test coverage detected