Skip to content

Commit bee8827

Browse files
SylvainCorlaywjakob
authored andcommitted
Template array constructor (#582)
1 parent a76ed42 commit bee8827

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

include/pybind11/numpy.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,9 @@ class array : public buffer {
337337

338338
array() : array(0, static_cast<const double *>(nullptr)) {}
339339

340-
array(const pybind11::dtype &dt, const std::vector<size_t> &shape,
341-
const std::vector<size_t> &strides, const void *ptr = nullptr,
340+
template <typename Shape, typename Strides>
341+
array(const pybind11::dtype &dt, const Shape &shape,
342+
const Strides &strides, const void *ptr = nullptr,
342343
handle base = handle()) {
343344
auto& api = detail::npy_api::get();
344345
auto ndim = shape.size();
@@ -536,7 +537,7 @@ class array : public buffer {
536537
throw std::runtime_error("array is not writeable");
537538
}
538539

539-
static std::vector<size_t> default_strides(const std::vector<size_t>& shape, size_t itemsize) {
540+
template <typename Shape> static std::vector<size_t> default_strides(const Shape& shape, size_t itemsize) {
540541
auto ndim = shape.size();
541542
std::vector<size_t> strides(ndim);
542543
if (ndim) {

0 commit comments

Comments
 (0)