Skip to content

Commit feef3f3

Browse files
committed
Remove iterator pair constructors
They can be handled via any_container arguments via {begin, end}, and not having them cuts down the number of constructors required.
1 parent ad75327 commit feef3f3

File tree

3 files changed

+3
-30
lines changed

3 files changed

+3
-30
lines changed

include/pybind11/buffer_info.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,12 @@ struct buffer_info {
3535
size *= shape[i];
3636
}
3737

38-
39-
template <typename ShapeIt, typename StridesIt,
40-
typename = detail::enable_if_t<detail::is_input_iterator<ShapeIt>::value && detail::is_input_iterator<StridesIt>::value>>
41-
buffer_info(void *ptr, size_t itemsize, const std::string &format, size_t ndim,
42-
ShapeIt shape_first, ShapeIt shape_last, StridesIt strides_first, StridesIt strides_last)
43-
: buffer_info(ptr, itemsize, format, ndim, {shape_first, shape_last}, {strides_first, strides_last}) { }
44-
4538
buffer_info(void *ptr, size_t itemsize, const std::string &format, size_t size)
4639
: buffer_info(ptr, itemsize, format, 1, { size }, { itemsize }) { }
4740

4841
explicit buffer_info(Py_buffer *view, bool ownview_in = true)
4942
: buffer_info(view->buf, (size_t) view->itemsize, view->format, (size_t) view->ndim,
50-
view->shape, view->shape + view->ndim, view->strides, view->strides + view->ndim) {
43+
{view->shape, view->shape + view->ndim}, {view->strides, view->strides + view->ndim}) {
5144
ownview = ownview_in;
5245
}
5346

include/pybind11/numpy.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -496,26 +496,13 @@ class array : public buffer {
496496
m_ptr = tmp.release().ptr();
497497
}
498498

499-
template <typename ShapeIt, typename StridesIt,
500-
typename = detail::enable_if_t<detail::is_input_iterator<ShapeIt>::value && detail::is_input_iterator<StridesIt>::value>>
501-
array(const pybind11::dtype &dt, ShapeIt shape_first, ShapeIt shape_last, StridesIt strides_first, StridesIt strides_last,
502-
const void *ptr = nullptr, handle base = handle())
503-
: array(dt, {shape_first, shape_last}, {strides_first, strides_last}, ptr, base) { }
504-
505499
array(const pybind11::dtype &dt, ShapeContainer shape, const void *ptr = nullptr, handle base = handle())
506500
: array(dt, std::move(shape), {}, ptr, base) { }
507501

508502
array(const pybind11::dtype &dt, size_t count, const void *ptr = nullptr,
509503
handle base = handle())
510504
: array(dt, ShapeContainer{{ count }}, ptr, base) { }
511505

512-
template <typename T, typename ShapeIt, typename StridesIt,
513-
typename = detail::enable_if_t<detail::is_input_iterator<ShapeIt>::value && detail::is_input_iterator<StridesIt>::value>>
514-
array(ShapeIt shape_first, ShapeIt shape_last, StridesIt strides_first, StridesIt strides_last,
515-
const T *ptr = nullptr, handle base = handle())
516-
: array(pybind11::dtype::of<T>(), ShapeContainer(std::move(shape_first), std::move(shape_last)),
517-
StrideContainer(std::move(strides_first), std::move(strides_last)), ptr, base) { }
518-
519506
template <typename T>
520507
array(ShapeContainer shape, StridesContainer strides, const T *ptr, handle base = handle())
521508
: array(pybind11::dtype::of<T>(), std::move(shape), std::move(strides), ptr, base) { }
@@ -747,13 +734,6 @@ template <typename T, int ExtraFlags = array::forcecast> class array_t : public
747734
array_t(ShapeContainer shape, StridesContainer strides, const T *ptr = nullptr, handle base = handle())
748735
: array(std::move(shape), std::move(strides), ptr, base) { }
749736

750-
template <typename ShapeIt, typename StridesIt,
751-
typename = detail::enable_if_t<detail::is_input_iterator<ShapeIt>::value && detail::is_input_iterator<StridesIt>::value>>
752-
array_t(ShapeIt shape_first, ShapeIt shape_last, StridesIt strides_first, StridesIt strides_last,
753-
const T *ptr = nullptr, handle base = handle())
754-
: array(ShapeContainer(std::move(shape_first), std::move(shape_last)),
755-
StridesContainer(std::move(strides_first), std::move(strides_last)), ptr, base) { }
756-
757737
explicit array_t(ShapeContainer shape, const T *ptr = nullptr, handle base = handle())
758738
: array(std::move(shape), ptr, base) { }
759739

tests/test_numpy_array.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ test_initializer numpy_array([](py::module &m) {
118118
sm.def("wrap", [](py::array a) {
119119
return py::array(
120120
a.dtype(),
121-
a.shape(), a.shape() + a.ndim(),
122-
a.strides(), a.strides() + a.ndim(),
121+
{a.shape(), a.shape() + a.ndim()},
122+
{a.strides(), a.strides() + a.ndim()},
123123
a.data(),
124124
a
125125
);

0 commit comments

Comments
 (0)