Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions include/xtensor-python/pycontainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ namespace xt
void reshape(S&& shape, layout_type layout = base_type::static_layout);

layout_type layout() const;
bool is_contiguous() const noexcept;

using base_type::operator();
using base_type::operator[];
Expand Down Expand Up @@ -442,6 +443,27 @@ namespace xt
}
}

/**
* Return whether or not the container uses contiguous buffer
* @return Boolean for contiguous buffer
*/
template <class D>
inline bool pycontainer<D>::is_contiguous() const noexcept
{
if (PyArray_CHKFLAGS(python_array(), NPY_ARRAY_C_CONTIGUOUS))
{
return 1 == this->strides().back();

@yungyuc yungyuc Oct 9, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this->strides() cannot be empty, and the element cannot be 0.

}
else if (PyArray_CHKFLAGS(python_array(), NPY_ARRAY_F_CONTIGUOUS))
{
return 1 == this->strides().front();
}
else
{
return false;
}
}

/**
* Import the numpy Python module.
*/
Expand Down