Skip to content

Commit acfe4b7

Browse files
Merge pull request xtensor-stack#63 from SylvainCorlay/adapt-strides
Remove compute-strides
2 parents daabb2d + caea90b commit acfe4b7

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

include/xtensor-python/pyarray.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ namespace xt
172172
void init_array(const shape_type& shape, const strides_type& strides);
173173
void init_from_python();
174174

175-
const inner_shape_type& shape_impl() const;
176-
const inner_strides_type& strides_impl() const;
177-
const inner_backstrides_type& backstrides_impl() const;
175+
const inner_shape_type& shape_impl() const noexcept;
176+
const inner_strides_type& strides_impl() const noexcept;
177+
const inner_backstrides_type& backstrides_impl() const noexcept;
178178

179-
container_type& data_impl();
180-
const container_type& data_impl() const;
179+
container_type& data_impl() noexcept;
180+
const container_type& data_impl() const noexcept;
181181

182182
friend class xcontainer<pyarray<T>>;
183183
};
@@ -383,19 +383,19 @@ namespace xt
383383
}
384384

385385
template <class T>
386-
inline auto pyarray<T>::shape_impl() const -> const inner_shape_type&
386+
inline auto pyarray<T>::shape_impl() const noexcept -> const inner_shape_type&
387387
{
388388
return m_shape;
389389
}
390390

391391
template <class T>
392-
inline auto pyarray<T>::strides_impl() const -> const inner_strides_type&
392+
inline auto pyarray<T>::strides_impl() const noexcept -> const inner_strides_type&
393393
{
394394
return m_strides;
395395
}
396396

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

406406
template <class T>
407-
inline auto pyarray<T>::data_impl() -> container_type&
407+
inline auto pyarray<T>::data_impl() noexcept -> container_type&
408408
{
409409
return m_data;
410410
}
411411

412412
template <class T>
413-
inline auto pyarray<T>::data_impl() const -> const container_type&
413+
inline auto pyarray<T>::data_impl() const noexcept -> const container_type&
414414
{
415415
return m_data;
416416
}

include/xtensor-python/pytensor.hpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ namespace xt
140140

141141
void init_tensor(const shape_type& shape, const strides_type& strides);
142142
void init_from_python();
143-
void compute_backstrides();
144143

145144
inner_shape_type& shape_impl() noexcept;
146145
const inner_shape_type& shape_impl() const noexcept;
@@ -281,7 +280,7 @@ namespace xt
281280
this->m_ptr = tmp.release().ptr();
282281
m_shape = shape;
283282
m_strides = strides;
284-
compute_backstrides();
283+
adapt_strides(m_shape, m_strides, m_backstrides);
285284
m_data = container_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())),
286285
static_cast<size_type>(PyArray_SIZE(this->python_array())));
287286
}
@@ -297,20 +296,11 @@ namespace xt
297296
std::copy(PyArray_DIMS(this->python_array()), PyArray_DIMS(this->python_array()) + N, m_shape.begin());
298297
std::transform(PyArray_STRIDES(this->python_array()), PyArray_STRIDES(this->python_array()) + N, m_strides.begin(),
299298
[](auto v) { return v / sizeof(T); });
300-
compute_backstrides();
299+
adapt_strides(m_shape, m_strides, m_backstrides);
301300
m_data = container_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())),
302301
static_cast<size_type>(PyArray_SIZE(this->python_array())));
303302
}
304303

305-
template <class T, std::size_t N>
306-
inline void pytensor<T, N>::compute_backstrides()
307-
{
308-
for (size_type i = 0; i < m_shape.size(); ++i)
309-
{
310-
m_backstrides[i] = m_strides[i] * (m_shape[i] - 1);
311-
}
312-
}
313-
314304
template <class T, std::size_t N>
315305
inline auto pytensor<T, N>::shape_impl() noexcept -> inner_shape_type&
316306
{

0 commit comments

Comments
 (0)