Skip to content

Commit

Permalink
Add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesWilde committed Dec 14, 2024
1 parent af8a5f7 commit 753b434
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/numpy/ndarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ bool is_c_contiguous(std::vector<Py_intptr_t> const & shape,
{
// 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;
for (std::vector<Py_intptr_t>::const_reverse_iterator i = shape.rbegin(); i != shape.rend(); ++i, ++j)
Expand All @@ -61,6 +63,8 @@ bool is_f_contiguous(std::vector<Py_intptr_t> const & shape,
{
// 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;
for (std::vector<Py_intptr_t>::const_iterator i = shape.begin(); i != shape.end(); ++i, ++j)
Expand All @@ -76,6 +80,7 @@ bool is_aligned(std::vector<Py_intptr_t> const & strides,
{
// An itemsize less than 0 is not useful - default to non-aligned.
if (0 > itemsize) return false;
// Check all strides to be aligned to itemsize.
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 753b434

Please sign in to comment.