Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions include/xtensor-python/pyarray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ namespace xt
void init_array(const shape_type& shape, const strides_type& strides);
void init_from_python();

const inner_shape_type& shape_impl() const;
const inner_strides_type& strides_impl() const;
const inner_backstrides_type& backstrides_impl() const;
const inner_shape_type& shape_impl() const noexcept;
const inner_strides_type& strides_impl() const noexcept;
const inner_backstrides_type& backstrides_impl() const noexcept;

container_type& data_impl();
const container_type& data_impl() const;
container_type& data_impl() noexcept;
const container_type& data_impl() const noexcept;

friend class xcontainer<pyarray<T>>;
};
Expand Down Expand Up @@ -383,19 +383,19 @@ namespace xt
}

template <class T>
inline auto pyarray<T>::shape_impl() const -> const inner_shape_type&
inline auto pyarray<T>::shape_impl() const noexcept -> const inner_shape_type&
{
return m_shape;
}

template <class T>
inline auto pyarray<T>::strides_impl() const -> const inner_strides_type&
inline auto pyarray<T>::strides_impl() const noexcept -> const inner_strides_type&
{
return m_strides;
}

template <class T>
inline auto pyarray<T>::backstrides_impl() const -> const inner_backstrides_type&
inline auto pyarray<T>::backstrides_impl() const noexcept -> const inner_backstrides_type&
{
// The pyarray object may be copied, invalidating m_backstrides. Building
// it each time it is needed avoids tricky bugs.
Expand All @@ -404,13 +404,13 @@ namespace xt
}

template <class T>
inline auto pyarray<T>::data_impl() -> container_type&
inline auto pyarray<T>::data_impl() noexcept -> container_type&
{
return m_data;
}

template <class T>
inline auto pyarray<T>::data_impl() const -> const container_type&
inline auto pyarray<T>::data_impl() const noexcept -> const container_type&
{
return m_data;
}
Expand Down
14 changes: 2 additions & 12 deletions include/xtensor-python/pytensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ namespace xt

void init_tensor(const shape_type& shape, const strides_type& strides);
void init_from_python();
void compute_backstrides();

inner_shape_type& shape_impl() noexcept;
const inner_shape_type& shape_impl() const noexcept;
Expand Down Expand Up @@ -281,7 +280,7 @@ namespace xt
this->m_ptr = tmp.release().ptr();
m_shape = shape;
m_strides = strides;
compute_backstrides();
adapt_strides(m_shape, m_strides, m_backstrides);
m_data = container_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())),
static_cast<size_type>(PyArray_SIZE(this->python_array())));
}
Expand All @@ -297,20 +296,11 @@ namespace xt
std::copy(PyArray_DIMS(this->python_array()), PyArray_DIMS(this->python_array()) + N, m_shape.begin());
std::transform(PyArray_STRIDES(this->python_array()), PyArray_STRIDES(this->python_array()) + N, m_strides.begin(),
[](auto v) { return v / sizeof(T); });
compute_backstrides();
adapt_strides(m_shape, m_strides, m_backstrides);
m_data = container_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())),
static_cast<size_type>(PyArray_SIZE(this->python_array())));
}

template <class T, std::size_t N>
inline void pytensor<T, N>::compute_backstrides()
{
for (size_type i = 0; i < m_shape.size(); ++i)
{
m_backstrides[i] = m_strides[i] * (m_shape[i] - 1);
}
}

template <class T, std::size_t N>
inline auto pytensor<T, N>::shape_impl() noexcept -> inner_shape_type&
{
Expand Down