Skip to content

Commit 6ec5e27

Browse files
committed
Make access unsafe
1 parent 5b5e3de commit 6ec5e27

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

include/pybind11/numpy.h

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -510,15 +510,17 @@ class array : public buffer {
510510
}
511511

512512
template<typename... Ix> size_t byte_offset(Ix... index) const {
513-
check_dimensions(index...);
514513
return byte_offset_unsafe(index...);
515514
}
516515

516+
PYBIND11_DEPRECATED("Use array<T>::byte_offset() instead")
517517
template<size_t dim = 0, typename... Ix> size_t byte_offset_unsafe(size_t i, Ix... index) const {
518518
return i * strides()[dim] + byte_offset_unsafe<dim + 1>(index...);
519519
}
520520

521-
template<size_t dim = 0> size_t byte_offset_unsafe() const { return 0; }
521+
template<size_t dim = 0> size_t byte_offset_unsafe() const {
522+
return 0;
523+
}
522524

523525
void check_writeable() const {
524526
if (!writeable())
@@ -537,21 +539,6 @@ class array : public buffer {
537539
return strides;
538540
}
539541

540-
template<typename... Ix> void check_dimensions(Ix... index) const {
541-
check_dimensions_impl(size_t(0), shape(), size_t(index)...);
542-
}
543-
544-
void check_dimensions_impl(size_t, const size_t*) const { }
545-
546-
template<typename... Ix> void check_dimensions_impl(size_t axis, const size_t* shape, size_t i, Ix... index) const {
547-
if (i >= *shape) {
548-
throw index_error(std::string("index ") + std::to_string(i) +
549-
" is out of bounds for axis " + std::to_string(axis) +
550-
" with size " + std::to_string(*shape));
551-
}
552-
check_dimensions_impl(axis + 1, shape + 1, index...);
553-
}
554-
555542
/// Create array from any object -- always returns a new reference
556543
static PyObject *raw_array(PyObject *ptr, int ExtraFlags = 0) {
557544
if (ptr == nullptr)

0 commit comments

Comments
 (0)