Skip to content

Commit 59b1aad

Browse files
style: pre-commit fixes
1 parent c24aabb commit 59b1aad

File tree

3 files changed

+40
-34
lines changed

3 files changed

+40
-34
lines changed

include/pybind11/detail/class.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int fla
602602
return -1;
603603
}
604604

605-
// Fill in all the information, and then downgrade as requested by the caller, or raise an error if that's not possible.
605+
// Fill in all the information, and then downgrade as requested by the caller, or raise an
606+
// error if that's not possible.
606607
view->obj = obj;
607608
view->internal = info;
608609
view->buf = info->ptr;
@@ -624,14 +625,16 @@ extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int fla
624625
if (!PyBuffer_IsContiguous(view, 'C')) {
625626
std::memset(view, 0, sizeof(Py_buffer));
626627
delete info;
627-
set_error(PyExc_BufferError, "C-contiguous buffer requested for discontiguous storage");
628+
set_error(PyExc_BufferError,
629+
"C-contiguous buffer requested for discontiguous storage");
628630
return -1;
629631
}
630632
} else if ((flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS) {
631633
if (!PyBuffer_IsContiguous(view, 'F')) {
632634
std::memset(view, 0, sizeof(Py_buffer));
633635
delete info;
634-
set_error(PyExc_BufferError, "Fortran-contiguous buffer requested for discontiguous storage");
636+
set_error(PyExc_BufferError,
637+
"Fortran-contiguous buffer requested for discontiguous storage");
635638
return -1;
636639
}
637640
} else if ((flags & PyBUF_ANY_CONTIGUOUS) == PyBUF_ANY_CONTIGUOUS) {
@@ -642,13 +645,14 @@ extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int fla
642645
return -1;
643646
}
644647

645-
// If no strides are requested, the buffer must be C-contiguous.
646-
// https://docs.python.org/3/c-api/buffer.html#contiguity-requests
648+
// If no strides are requested, the buffer must be C-contiguous.
649+
// https://docs.python.org/3/c-api/buffer.html#contiguity-requests
647650
} else if ((flags & PyBUF_STRIDES) != PyBUF_STRIDES) {
648651
if (!PyBuffer_IsContiguous(view, 'C')) {
649652
std::memset(view, 0, sizeof(Py_buffer));
650653
delete info;
651-
set_error(PyExc_BufferError, "C-contiguous buffer requested for discontiguous storage");
654+
set_error(PyExc_BufferError,
655+
"C-contiguous buffer requested for discontiguous storage");
652656
return -1;
653657
}
654658

tests/test_buffers.cpp

+27-27
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,13 @@ TEST_SUBMODULE(buffers, m) {
171171
class FortranMatrix : public Matrix {
172172
public:
173173
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");
175176
}
176177

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); }
180179

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); }
184181

185182
using Matrix::data;
186183

@@ -210,30 +207,33 @@ TEST_SUBMODULE(buffers, m) {
210207
})
211208
/// Provide buffer access
212209
.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())});
218214
});
219215

220216
// A matrix that uses a discontiguous underlying memory block.
221217
class DiscontiguousMatrix : public Matrix {
222218
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) {
228225
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");
231229
}
232230

233231
~DiscontiguousMatrix() {
234232
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");
237237
}
238238

239239
float operator()(py::ssize_t i, py::ssize_t j) const {
@@ -278,12 +278,12 @@ TEST_SUBMODULE(buffers, m) {
278278
})
279279
/// Provide buffer access
280280
.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)});
287287
});
288288

289289
class BrokenMatrix : public Matrix {

tests/test_buffers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ def test_to_pybuffer():
310310
def test_to_pybuffer_contiguity():
311311
def check_strides(mat):
312312
# The full block is memset to 0, so fill it with non-zero in real spots.
313-
expected = np.arange(1, mat.rows() * mat.cols() + 1).reshape((mat.rows(), mat.cols()))
313+
expected = np.arange(1, mat.rows() * mat.cols() + 1).reshape(
314+
(mat.rows(), mat.cols())
315+
)
314316
for i in range(mat.rows()):
315317
for j in range(mat.cols()):
316318
mat[i, j] = expected[i, j]

0 commit comments

Comments
 (0)