Skip to content
Prev Previous commit
Next Next commit
Change size type to boost::python::ssize_t - as did numpy with versio…
…n 2.0 and in accordance with PEP 353.
  • Loading branch information
JohannesWilde committed Dec 14, 2024
commit 1105d37dcc7fe97272d65eec831a260307777c6e
12 changes: 6 additions & 6 deletions src/numpy/ndarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ int bitflag_to_numpy(ndarray::bitflag f)

bool is_c_contiguous(std::vector<Py_intptr_t> const & shape,
std::vector<Py_intptr_t> const & strides,
int const itemsize)
boost::python::ssize_t const itemsize)
{
// An itemsize less than 0 is not useful - default to non-contiguity.
if (0 > itemsize) return false;
// Check the strides (stride[n]) match the accumulated shapes as per C-style,
// i.e. starting from rightmost C-index (itemsize * prod_{i in [n, N)} shape[i]).
std::vector<Py_intptr_t>::const_reverse_iterator j = strides.rbegin();
int total = itemsize;
boost::python::ssize_t total = itemsize;
for (std::vector<Py_intptr_t>::const_reverse_iterator i = shape.rbegin(); i != shape.rend(); ++i, ++j)
{
if (total != *j) return false;
Expand All @@ -59,14 +59,14 @@ bool is_c_contiguous(std::vector<Py_intptr_t> const & shape,

bool is_f_contiguous(std::vector<Py_intptr_t> const & shape,
std::vector<Py_intptr_t> const & strides,
int const itemsize)
boost::python::ssize_t const itemsize)
{
// An itemsize less than 0 is not useful - default to non-contiguity.
if (0 > itemsize) return false;
// Check the strides (stride[n]) match the accumulated shapes as per Fortran-style,
// i.e. starting from leftmost C-index (itemsize * prod_{i in [0, n]} shape[i]).
std::vector<Py_intptr_t>::const_iterator j = strides.begin();
int total = itemsize;
boost::python::ssize_t total = itemsize;
for (std::vector<Py_intptr_t>::const_iterator i = shape.begin(); i != shape.end(); ++i, ++j)
{
if (total != *j) return false;
Expand All @@ -76,7 +76,7 @@ bool is_f_contiguous(std::vector<Py_intptr_t> const & shape,
}

bool is_aligned(std::vector<Py_intptr_t> const & strides,
int const itemsize)
boost::python::ssize_t const itemsize)
{
// An itemsize less than 0 is not useful - default to non-aligned.
if (0 > itemsize) return false;
Expand Down Expand Up @@ -128,7 +128,7 @@ ndarray from_data_impl(void * data,
PyErr_SetString(PyExc_ValueError, "Length of shape and strides arrays do not match.");
python::throw_error_already_set();
}
int const itemsize = dt.get_itemsize();
boost::python::ssize_t const itemsize = dt.get_itemsize();
int flags = 0;
if (writeable) flags |= NPY_ARRAY_WRITEABLE;
if (is_c_contiguous(shape, strides, itemsize)) flags |= NPY_ARRAY_C_CONTIGUOUS;
Expand Down