Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

switch to row_major default#195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
wolfv wants to merge1 commit intoxtensor-stack:master
base:master
Choose a base branch
Loading
fromwolfv:default_row_major
Open
Show file tree
Hide file tree
Changes fromall 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: 20 additions & 2 deletionsdocs/source/array_tensor.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,8 +4,8 @@

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

Arraysandtensors
==================
Arrays, TensorsandNumPy 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 deletionsinclude/xtensor-python/pyarray.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 withbad strides for layout (is ita view?).");
throw std::runtime_error("pyarray: passing container withwrong strides forstaticlayout. If you are trying to passa 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 deletionsinclude/xtensor-python/pytensor.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 withbad strides for layout (is ita view?).");
throw std::runtime_error("pytensor: passing container withwrong strides forstaticlayout. If you are trying to passa 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

[8]ページ先頭

©2009-2025 Movatter.jp