Template array constructor (#582)
diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h
index 50eb682..af0f5ae 100644
--- a/include/pybind11/numpy.h
+++ b/include/pybind11/numpy.h
@@ -337,8 +337,9 @@
array() : array(0, static_cast<const double *>(nullptr)) {}
- array(const pybind11::dtype &dt, const std::vector<size_t> &shape,
- const std::vector<size_t> &strides, const void *ptr = nullptr,
+ template <typename Shape, typename Strides>
+ array(const pybind11::dtype &dt, const Shape &shape,
+ const Strides &strides, const void *ptr = nullptr,
handle base = handle()) {
auto& api = detail::npy_api::get();
auto ndim = shape.size();
@@ -536,7 +537,7 @@
throw std::runtime_error("array is not writeable");
}
- static std::vector<size_t> default_strides(const std::vector<size_t>& shape, size_t itemsize) {
+ template <typename Shape> static std::vector<size_t> default_strides(const Shape& shape, size_t itemsize) {
auto ndim = shape.size();
std::vector<size_t> strides(ndim);
if (ndim) {