Skip to content

Commit 5521210

Browse files
committed
style: pre-commit applied
1 parent 36cae6f commit 5521210

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+7821
-5647
lines changed

include/pybind11/attr.h

Lines changed: 157 additions & 87 deletions
Large diffs are not rendered by default.

include/pybind11/buffer_info.h

Lines changed: 93 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,100 +15,141 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
1515

1616
/// Information record describing a Python buffer object
1717
struct buffer_info {
18-
void *ptr = nullptr; // Pointer to the underlying storage
19-
ssize_t itemsize = 0; // Size of individual items in bytes
20-
ssize_t size = 0; // Total number of entries
21-
std::string format; // For homogeneous buffers, this should be set to format_descriptor<T>::format()
22-
ssize_t ndim = 0; // Number of dimensions
23-
std::vector<ssize_t> shape; // Shape of the tensor (1 entry per dimension)
24-
std::vector<ssize_t> strides; // Number of bytes between adjacent entries (for each per dimension)
25-
bool readonly = false; // flag to indicate if the underlying storage may be written to
26-
27-
buffer_info() { }
28-
29-
buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim,
30-
detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in, bool readonly=false)
31-
: ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim),
32-
shape(std::move(shape_in)), strides(std::move(strides_in)), readonly(readonly) {
18+
void *ptr = nullptr; // Pointer to the underlying storage
19+
ssize_t itemsize = 0; // Size of individual items in bytes
20+
ssize_t size = 0; // Total number of entries
21+
std::string
22+
format; // For homogeneous buffers, this should be set to format_descriptor<T>::format()
23+
ssize_t ndim = 0; // Number of dimensions
24+
std::vector<ssize_t> shape; // Shape of the tensor (1 entry per dimension)
25+
std::vector<ssize_t>
26+
strides; // Number of bytes between adjacent entries (for each per dimension)
27+
bool readonly = false; // flag to indicate if the underlying storage may be written to
28+
29+
buffer_info() {}
30+
31+
buffer_info(void *ptr,
32+
ssize_t itemsize,
33+
const std::string &format,
34+
ssize_t ndim,
35+
detail::any_container<ssize_t> shape_in,
36+
detail::any_container<ssize_t> strides_in,
37+
bool readonly = false)
38+
: ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim),
39+
shape(std::move(shape_in)), strides(std::move(strides_in)), readonly(readonly) {
3340
if (ndim != (ssize_t) shape.size() || ndim != (ssize_t) strides.size())
3441
pybind11_fail("buffer_info: ndim doesn't match shape and/or strides length");
3542
for (size_t i = 0; i < (size_t) ndim; ++i)
3643
size *= shape[i];
3744
}
3845

3946
template <typename T>
40-
buffer_info(T *ptr, detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in, bool readonly=false)
41-
: buffer_info(private_ctr_tag(), ptr, sizeof(T), format_descriptor<T>::format(), static_cast<ssize_t>(shape_in->size()), std::move(shape_in), std::move(strides_in), readonly) { }
42-
43-
buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t size, bool readonly=false)
44-
: buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}, readonly) { }
47+
buffer_info(T *ptr,
48+
detail::any_container<ssize_t> shape_in,
49+
detail::any_container<ssize_t> strides_in,
50+
bool readonly = false)
51+
: buffer_info(private_ctr_tag(),
52+
ptr,
53+
sizeof(T),
54+
format_descriptor<T>::format(),
55+
static_cast<ssize_t>(shape_in->size()),
56+
std::move(shape_in),
57+
std::move(strides_in),
58+
readonly) {}
59+
60+
buffer_info(void *ptr,
61+
ssize_t itemsize,
62+
const std::string &format,
63+
ssize_t size,
64+
bool readonly = false)
65+
: buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}, readonly) {}
4566

4667
template <typename T>
47-
buffer_info(T *ptr, ssize_t size, bool readonly=false)
48-
: buffer_info(ptr, sizeof(T), format_descriptor<T>::format(), size, readonly) { }
68+
buffer_info(T *ptr, ssize_t size, bool readonly = false)
69+
: buffer_info(ptr, sizeof(T), format_descriptor<T>::format(), size, readonly) {}
4970

5071
template <typename T>
51-
buffer_info(const T *ptr, ssize_t size, bool readonly=true)
52-
: buffer_info(const_cast<T*>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) { }
72+
buffer_info(const T *ptr, ssize_t size, bool readonly = true)
73+
: buffer_info(
74+
const_cast<T *>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) {}
5375

5476
explicit buffer_info(Py_buffer *view, bool ownview = true)
55-
: buffer_info(view->buf, view->itemsize, view->format, view->ndim,
56-
{view->shape, view->shape + view->ndim}, {view->strides, view->strides + view->ndim}, view->readonly) {
57-
this->m_view = view;
77+
: buffer_info(view->buf,
78+
view->itemsize,
79+
view->format,
80+
view->ndim,
81+
{view->shape, view->shape + view->ndim},
82+
{view->strides, view->strides + view->ndim},
83+
view->readonly) {
84+
this->m_view = view;
5885
this->ownview = ownview;
5986
}
6087

6188
buffer_info(const buffer_info &) = delete;
62-
buffer_info& operator=(const buffer_info &) = delete;
89+
buffer_info &operator=(const buffer_info &) = delete;
6390

64-
buffer_info(buffer_info &&other) {
65-
(*this) = std::move(other);
66-
}
91+
buffer_info(buffer_info &&other) { (*this) = std::move(other); }
6792

68-
buffer_info& operator=(buffer_info &&rhs) {
69-
ptr = rhs.ptr;
93+
buffer_info &operator=(buffer_info &&rhs) {
94+
ptr = rhs.ptr;
7095
itemsize = rhs.itemsize;
71-
size = rhs.size;
72-
format = std::move(rhs.format);
73-
ndim = rhs.ndim;
74-
shape = std::move(rhs.shape);
75-
strides = std::move(rhs.strides);
96+
size = rhs.size;
97+
format = std::move(rhs.format);
98+
ndim = rhs.ndim;
99+
shape = std::move(rhs.shape);
100+
strides = std::move(rhs.strides);
76101
std::swap(m_view, rhs.m_view);
77102
std::swap(ownview, rhs.ownview);
78103
readonly = rhs.readonly;
79104
return *this;
80105
}
81106

82107
~buffer_info() {
83-
if (m_view && ownview) { PyBuffer_Release(m_view); delete m_view; }
108+
if (m_view && ownview) {
109+
PyBuffer_Release(m_view);
110+
delete m_view;
111+
}
84112
}
85113

86114
Py_buffer *view() const { return m_view; }
87115
Py_buffer *&view() { return m_view; }
88-
private:
89-
struct private_ctr_tag { };
90116

91-
buffer_info(private_ctr_tag, void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim,
92-
detail::any_container<ssize_t> &&shape_in, detail::any_container<ssize_t> &&strides_in, bool readonly)
93-
: buffer_info(ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) { }
117+
private:
118+
struct private_ctr_tag {};
119+
120+
buffer_info(private_ctr_tag,
121+
void *ptr,
122+
ssize_t itemsize,
123+
const std::string &format,
124+
ssize_t ndim,
125+
detail::any_container<ssize_t> &&shape_in,
126+
detail::any_container<ssize_t> &&strides_in,
127+
bool readonly)
128+
: buffer_info(
129+
ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) {}
94130

95131
Py_buffer *m_view = nullptr;
96-
bool ownview = false;
132+
bool ownview = false;
97133
};
98134

99135
PYBIND11_NAMESPACE_BEGIN(detail)
100136

101-
template <typename T, typename SFINAE = void> struct compare_buffer_info {
102-
static bool compare(const buffer_info& b) {
137+
template <typename T, typename SFINAE = void>
138+
struct compare_buffer_info {
139+
static bool compare(const buffer_info &b) {
103140
return b.format == format_descriptor<T>::format() && b.itemsize == (ssize_t) sizeof(T);
104141
}
105142
};
106143

107-
template <typename T> struct compare_buffer_info<T, detail::enable_if_t<std::is_integral<T>::value>> {
108-
static bool compare(const buffer_info& b) {
109-
return (size_t) b.itemsize == sizeof(T) && (b.format == format_descriptor<T>::value ||
110-
((sizeof(T) == sizeof(long)) && b.format == (std::is_unsigned<T>::value ? "L" : "l")) ||
111-
((sizeof(T) == sizeof(size_t)) && b.format == (std::is_unsigned<T>::value ? "N" : "n")));
144+
template <typename T>
145+
struct compare_buffer_info<T, detail::enable_if_t<std::is_integral<T>::value>> {
146+
static bool compare(const buffer_info &b) {
147+
return (size_t) b.itemsize == sizeof(T)
148+
&& (b.format == format_descriptor<T>::value
149+
|| ((sizeof(T) == sizeof(long))
150+
&& b.format == (std::is_unsigned<T>::value ? "L" : "l"))
151+
|| ((sizeof(T) == sizeof(size_t))
152+
&& b.format == (std::is_unsigned<T>::value ? "N" : "n")));
112153
}
113154
};
114155

0 commit comments

Comments
 (0)