diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 36077ec04..7108e06c4 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -1110,6 +1110,20 @@ public: + byte_offset(ssize_t(index)...) / itemsize()); } + // const-reference to element at a given index without bounds checking + template + const T &operator()(Ix... index) const { + return *(static_cast(array::data()) + + byte_offset(ssize_t(index)...) / itemsize()); + } + + // mutable reference to element at a given index without bounds checking + template + T &operator()(Ix... index) { + return *(static_cast(array::mutable_data()) + + byte_offset(ssize_t(index)...) / itemsize()); + } + /** * Returns a proxy object that provides access to the array's data without bounds or * dimensionality checking. Will throw if the array is missing the `writeable` flag. Use with