@@ -171,16 +171,13 @@ TEST_SUBMODULE(buffers, m) {
171
171
class FortranMatrix : public Matrix {
172
172
public:
173
173
FortranMatrix (py::ssize_t rows, py::ssize_t cols) : Matrix(cols, rows) {
174
- print_created (this , std::to_string (rows) + " x" + std::to_string (cols) + " Fortran matrix" );
174
+ print_created (this ,
175
+ std::to_string (rows) + " x" + std::to_string (cols) + " Fortran matrix" );
175
176
}
176
177
177
- float operator ()(py::ssize_t i, py::ssize_t j) const {
178
- return Matrix::operator ()(j, i);
179
- }
178
+ float operator ()(py::ssize_t i, py::ssize_t j) const { return Matrix::operator ()(j, i); }
180
179
181
- float &operator ()(py::ssize_t i, py::ssize_t j) {
182
- return Matrix::operator ()(j, i);
183
- }
180
+ float &operator ()(py::ssize_t i, py::ssize_t j) { return Matrix::operator ()(j, i); }
184
181
185
182
using Matrix::data;
186
183
@@ -210,30 +207,33 @@ TEST_SUBMODULE(buffers, m) {
210
207
})
211
208
// / Provide buffer access
212
209
.def_buffer ([](FortranMatrix &m) -> py::buffer_info {
213
- return py::buffer_info (
214
- m.data (), /* Pointer to buffer */
215
- {m.rows (), m.cols ()}, /* Buffer dimensions */
216
- /* Strides (in bytes) for each index */
217
- {sizeof (float ), sizeof (float ) * size_t (m.rows ())});
210
+ return py::buffer_info (m.data (), /* Pointer to buffer */
211
+ {m.rows (), m.cols ()}, /* Buffer dimensions */
212
+ /* Strides (in bytes) for each index */
213
+ {sizeof (float ), sizeof (float ) * size_t (m.rows ())});
218
214
});
219
215
220
216
// A matrix that uses a discontiguous underlying memory block.
221
217
class DiscontiguousMatrix : public Matrix {
222
218
public:
223
- DiscontiguousMatrix (py::ssize_t rows, py::ssize_t cols,
224
- py::ssize_t row_factor, py::ssize_t col_factor)
225
- : Matrix(rows * row_factor, cols * col_factor),
226
- m_row_factor (row_factor), m_col_factor(col_factor)
227
- {
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) {
228
225
print_created (this ,
229
- std::to_string (rows) + " (*" + std::to_string (row_factor) + " )x" +
230
- std::to_string (cols) + " (*" + std::to_string (col_factor) + " ) matrix" );
226
+ std::to_string (rows) + " (*" + std::to_string (row_factor) + " )x"
227
+ + std::to_string (cols) + " (*" + std::to_string (col_factor)
228
+ + " ) matrix" );
231
229
}
232
230
233
231
~DiscontiguousMatrix () {
234
232
print_destroyed (this ,
235
- std::to_string (rows () / m_row_factor) + " (*" + std::to_string (m_row_factor) + " )x" +
236
- std::to_string (cols () / m_col_factor) + " (*" + std::to_string (m_col_factor) + " ) matrix" );
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
237
}
238
238
239
239
float operator ()(py::ssize_t i, py::ssize_t j) const {
@@ -278,12 +278,12 @@ TEST_SUBMODULE(buffers, m) {
278
278
})
279
279
// / Provide buffer access
280
280
.def_buffer ([](DiscontiguousMatrix &m) -> py::buffer_info {
281
- return py::buffer_info (
282
- m. data (), /* Pointer to buffer */
283
- {m. rows (), m. cols ()}, /* Buffer dimensions */
284
- /* Strides (in bytes) for each index */
285
- { size_t (m. col_factor ()) * sizeof ( float ) * size_t (m. cols ()) * size_t (m.row_factor ()),
286
- size_t (m.col_factor ()) * sizeof (float )});
281
+ return py::buffer_info (m. data (), /* Pointer to buffer */
282
+ {m. rows (), m. cols ()}, /* Buffer dimensions */
283
+ /* Strides (in bytes) for each index */
284
+ { size_t (m. col_factor ()) * sizeof ( float ) * size_t (m. cols ())
285
+ * size_t (m.row_factor ()),
286
+ size_t (m.col_factor ()) * sizeof (float )});
287
287
});
288
288
289
289
class BrokenMatrix : public Matrix {
0 commit comments