FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

switch to row_major default by wolfv · Pull Request #195 · xtensor-stack/xtensor-python · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .hpp  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
22 changes: 20 additions & 2 deletions docs/source/array_tensor.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

The full license is in the file LICENSE, distributed with this software.

Arrays and tensors
==================
Arrays, Tensors and NumPy Views
===============================

``xtensor-python`` provides two container types wrapping numpy arrays: ``pyarray`` and ``pytensor``. They are the counterparts
to ``xarray`` and ``xtensor`` containers.
Expand All @@ -25,3 +25,21 @@ Like ``xtensor``, ``pytensor`` has a static stack-allocated shape. This means th
the shape of the ``pytensor`` upon creation. As a consequence, reshapes are not reflected across languages. However, this drawback
is offset by a more effective computation of shape and broadcast.

NumPy views
-----------

If you are trying to call a xtensor function with a NumPy view, you might read the following:
"passing container with wrong strides for static layout". This means, that the *static layout*
of the pytensor does not match the layout of the NumPy array (or view) that you are using to
call the function.

One fix for this is to choose the ``dynamic`` layout for your pyarray or pytensor:

.. code::

void my_function(xt::pyarray<double, xt::layout_type::dynamic> input)

When choosing the dynamic layout, you can pass any NumPy container (with Fortran order, or
an arbitrary view).
Note that iterators on a pyarray with dynamic layout are generally slower!

8 changes: 4 additions & 4 deletions include/xtensor-python/pyarray.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace xt
{
template <class T, layout_type L = layout_type::dynamic>
template <class T, layout_type L = layout_type::row_major>
class pyarray;
}

Expand Down Expand Up @@ -682,7 +682,7 @@ namespace xt

if (!tmp)
{
throw std::runtime_error("NumPy: unable to create ndarray");
throw std::runtime_error("pyarray: unable to create ndarray");
}

this->m_ptr = tmp.release().ptr();
Expand Down Expand Up @@ -771,7 +771,7 @@ namespace xt

if (!tmp)
{
throw std::runtime_error("NumPy: unable to create ndarray");
throw std::runtime_error("pyarray: unable to create ndarray");
}

this->m_ptr = tmp.release().ptr();
Expand All @@ -793,7 +793,7 @@ namespace xt

if (L != layout_type::dynamic && !do_strides_match(m_shape, m_strides, L, 1))
{
throw std::runtime_error("NumPy: passing container with bad strides for layout (is it a view?).");
throw std::runtime_error("pyarray: passing container with wrong strides for static layout. If you are trying to pass a view, set the pytensor layout template parameter to `layout_type::dynamic`, or `layout_type::column_major` for col major.");
}

m_backstrides = backstrides_type(*this);
Expand Down
8 changes: 4 additions & 4 deletions include/xtensor-python/pytensor.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace xt
{
template <class T, std::size_t N, layout_type L = layout_type::dynamic>
template <class T, std::size_t N, layout_type L = layout_type::row_major>
class pytensor;
}

Expand Down Expand Up @@ -431,7 +431,7 @@ namespace xt

if (!tmp)
{
throw std::runtime_error("NumPy: unable to create ndarray");
throw std::runtime_error("pytensor: unable to create ndarray");
}

this->m_ptr = tmp.release().ptr();
Expand All @@ -452,7 +452,7 @@ namespace xt

if (PyArray_NDIM(this->python_array()) != N)
{
throw std::runtime_error("NumPy: ndarray has incorrect number of dimensions");
throw std::runtime_error("pytensor: ndarray has incorrect number of dimensions");
}

std::copy(PyArray_DIMS(this->python_array()), PyArray_DIMS(this->python_array()) + N, m_shape.begin());
Expand All @@ -462,7 +462,7 @@ namespace xt

if (L != layout_type::dynamic && !do_strides_match(m_shape, m_strides, L, 1))
{
throw std::runtime_error("NumPy: passing container with bad strides for layout (is it a view?).");
throw std::runtime_error("pytensor: passing container with wrong strides for static layout. If you are trying to pass a view, set the pytensor layout template parameter to `layout_type::dynamic`, or `layout_type::column_major` for col major.");
}

m_storage = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())),
Expand Down

Back | FazBrowse Home | New Git URL