Skip to content

Commit

Permalink
Exempt negative itemsize from contiguity and alginment.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesWilde committed Dec 14, 2024
1 parent 4a0c096 commit af8a5f7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/numpy/ndarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ bool is_c_contiguous(std::vector<Py_intptr_t> const & shape,
std::vector<Py_intptr_t> const & strides,
int itemsize)
{
// An itemsize less than 0 is not useful - default to non-contiguity.
if (0 > itemsize) return false;
std::vector<Py_intptr_t>::const_reverse_iterator j = strides.rbegin();
int total = itemsize;
for (std::vector<Py_intptr_t>::const_reverse_iterator i = shape.rbegin(); i != shape.rend(); ++i, ++j)
Expand All @@ -57,6 +59,8 @@ bool is_f_contiguous(std::vector<Py_intptr_t> const & shape,
std::vector<Py_intptr_t> const & strides,
int itemsize)
{
// An itemsize less than 0 is not useful - default to non-contiguity.
if (0 > itemsize) return false;
std::vector<Py_intptr_t>::const_iterator j = strides.begin();
int total = itemsize;
for (std::vector<Py_intptr_t>::const_iterator i = shape.begin(); i != shape.end(); ++i, ++j)
Expand All @@ -70,6 +74,8 @@ bool is_f_contiguous(std::vector<Py_intptr_t> const & shape,
bool is_aligned(std::vector<Py_intptr_t> const & strides,
int itemsize)
{
// An itemsize less than 0 is not useful - default to non-aligned.
if (0 > itemsize) return false;
for (std::vector<Py_intptr_t>::const_iterator i = strides.begin(); i != strides.end(); ++i)
{
if (*i % itemsize) return false;
Expand Down

0 comments on commit af8a5f7

Please sign in to comment.