From 79dc7b4285ea274649a7a6d0295d8b2183fc84ce Mon Sep 17 00:00:00 2001 From: Bram Veenboer Date: Thu, 14 Aug 2025 11:05:31 +0200 Subject: [PATCH] Add dimension checks --- python/bindings.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/bindings.cpp b/python/bindings.cpp index 1988e98..ba63955 100644 --- a/python/bindings.cpp +++ b/python/bindings.cpp @@ -11,6 +11,10 @@ py::array_t compute_sin(const Backend &backend, py::array_t x) { ssize_t n = x.shape(0); + if (x.ndim() != 1) { + throw py::value_error("Input array must be 1-dimensional"); + } + const T *x_ptr = x.data(); py::array_t s(n); @@ -26,6 +30,10 @@ py::array_t compute_cos(const Backend &backend, py::array_t x) { ssize_t n = x.shape(0); + if (x.ndim() != 1) { + throw py::value_error("Input array must be 1-dimensional"); + } + const T *x_ptr = x.data(); py::array_t c(n); @@ -41,6 +49,10 @@ std::tuple, py::array_t> compute_sincos(const Backend &backend, py::array_t x) { ssize_t n = x.shape(0); + if (x.ndim() != 1) { + throw py::value_error("Input array must be 1-dimensional"); + } + const T *x_ptr = x.data(); py::array_t s(n);