20 auto ndim = shape.size();
21 std::vector<ssize_t>
strides(ndim, itemsize);
23 for (
size_t i = ndim - 1;
i > 0; --
i) {
24 strides[
i - 1] = strides[
i] * shape[
i];
31 inline std::vector<ssize_t>
f_strides(
const std::vector<ssize_t> &shape,
ssize_t itemsize) {
32 auto ndim = shape.size();
33 std::vector<ssize_t>
strides(ndim, itemsize);
34 for (
size_t i = 1;
i < ndim; ++
i) {
35 strides[
i] = strides[
i - 1] * shape[
i - 1];
59 const std::string &format,
61 detail::any_container<ssize_t> shape_in,
62 detail::any_container<ssize_t> strides_in,
63 bool readonly =
false)
64 : ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim),
65 shape(
std::
move(shape_in)), strides(
std::
move(strides_in)), readonly(readonly) {
66 if (ndim != (
ssize_t) shape.size() || ndim != (
ssize_t) strides.size()) {
67 pybind11_fail(
"buffer_info: ndim doesn't match shape and/or strides length");
69 for (
size_t i = 0;
i < (
size_t) ndim; ++
i) {
76 detail::any_container<ssize_t> shape_in,
77 detail::any_container<ssize_t> strides_in,
78 bool readonly =
false)
83 static_cast<
ssize_t>(shape_in->size()),
90 const std::string &format,
92 bool readonly =
false)
110 {view->shape, view->shape + view->ndim},
115 ? std::vector<ssize_t>(
view->strides,
view->strides +
view->ndim)
117 (
view->readonly != 0)) {
131 itemsize = rhs.itemsize;
133 format = std::move(rhs.format);
135 shape = std::move(rhs.shape);
136 strides = std::move(rhs.strides);
139 readonly = rhs.readonly;
159 const std::string &format,
161 detail::any_container<ssize_t> &&shape_in,
162 detail::any_container<ssize_t> &&strides_in,
165 ptr, itemsize, format, ndim,
std::
move(shape_in),
std::
move(strides_in), readonly) {}
173 template <
typename T,
typename SFINAE =
void>
180 template <
typename T>
185 || ((
sizeof(
T) ==
sizeof(
long))
187 || ((
sizeof(
T) ==
sizeof(
size_t))
buffer_info & operator=(buffer_info &&rhs) noexcept
buffer_info(buffer_info &&other) noexcept
std::vector< ssize_t > strides
static bool compare(const buffer_info &b)
buffer_info(private_ctr_tag, void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim, detail::any_container< ssize_t > &&shape_in, detail::any_container< ssize_t > &&strides_in, bool readonly)
#define PYBIND11_NAMESPACE
PyExc_RuntimeError [[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
static bool compare(const buffer_info &b)
std::vector< ssize_t > c_strides(const std::vector< ssize_t > &shape, ssize_t itemsize)
buffer_info(T *ptr, detail::any_container< ssize_t > shape_in, detail::any_container< ssize_t > strides_in, bool readonly=false)
EIGEN_ALWAYS_INLINE DSizes< IndexType, NumDims > strides(const DSizes< IndexType, NumDims > &dimensions)
Eigen::Triplet< double > T
buffer_info(Py_buffer *view, bool ownview=true)
std::vector< ssize_t > f_strides(const std::vector< ssize_t > &shape, ssize_t itemsize)
std::vector< ssize_t > shape
void swap(GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &a, GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &b)
buffer_info(const T *ptr, ssize_t size, bool readonly=true)
buffer_info & operator=(const buffer_info &)=delete
buffer_info(T *ptr, ssize_t size, bool readonly=false)
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
Information record describing a Python buffer object.
buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t size, bool readonly=false)
buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim, detail::any_container< ssize_t > shape_in, detail::any_container< ssize_t > strides_in, bool readonly=false)
#define PYBIND11_NAMESPACE_END(name)
#define PYBIND11_NAMESPACE_BEGIN(name)