Skip to content

Commit be9452a

Browse files
committed
Update to xtensor 0.7.0
1 parent a8cab8c commit be9452a

File tree

5 files changed

+14
-79
lines changed

5 files changed

+14
-79
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ install:
2424
- conda info -a
2525
- conda install pytest -c conda-forge
2626
- cd test
27-
- conda install xtensor==0.6.0 pytest numpy pybind11==2.0.1 -c conda-forge
27+
- conda install xtensor==0.7.1 pytest numpy pybind11==2.0.1 -c conda-forge
2828
- xcopy /S %APPVEYOR_BUILD_FOLDER%\include %MINICONDA%\include
2929

3030
build_script:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ docs/build/
4343
__pycache__
4444
build
4545
*.egg-info
46+
47+
# py.test
48+
.cache/

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ install:
5959
# Useful for debugging any issues with conda
6060
- conda info -a
6161
- cd test
62-
- conda install xtensor==0.6.0 pytest numpy pybind11==2.0.1 -c conda-forge
62+
- conda install xtensor==0.7.1 pytest numpy pybind11==2.0.1 -c conda-forge
6363
- cp -r $TRAVIS_BUILD_DIR/include/* $HOME/miniconda/include/
6464

6565
script:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ conda install -c conda-forge xtensor-python
2929

3030
| `xtensor-python` | `xtensor` | `pybind11` |
3131
|-------------------|------------|-------------|
32-
| master | 0.6.0 | ^2.0.0 |
32+
| master | 0.7.1 | ^2.0.0 |
3333
| 0.5.0 | 0.5.0 | ^2.0.0 |
3434
| 0.4.0 | 0.5.0 | ^2.0.0 |
3535
| 0.3.0 | ^0.4.1 | ^2.0.0 |

include/xtensor-python/pycontainer.hpp

Lines changed: 8 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#include "pybind11/pybind11.h"
1616
#include "pybind11/common.h"
1717
#include "pybind11/complex.h"
18-
// Because of layout, else xiterator and xtensor_forward are sufficient
18+
19+
// Because of layout, otherwise xiterator and xtensor_forward are sufficient
1920
#include "xtensor/xcontainer.hpp"
2021

2122
namespace xt
@@ -144,26 +145,11 @@ namespace xt
144145
pycontainer(pycontainer&&) = default;
145146
pycontainer& operator=(pycontainer&&) = default;
146147

147-
void fill_default_strides(const shape_type& shape,
148-
layout l,
149-
strides_type& strides);
150-
151148
static derived_type ensure(pybind11::handle h);
152149
static bool check_(pybind11::handle h);
153150
static PyObject* raw_array_t(PyObject* ptr);
154151

155152
PyArrayObject* python_array();
156-
157-
private:
158-
159-
template <size_t dim = 0>
160-
size_type data_offset(const inner_strides_type&) const;
161-
162-
template <size_t dim = 0, class... Args>
163-
size_type data_offset(const inner_strides_type& strides, size_type i, Args... args) const;
164-
165-
template <class It>
166-
size_type element_offset(const inner_strides_type& strides, It first, It last) const;
167153
};
168154

169155
namespace detail
@@ -241,36 +227,6 @@ namespace xt
241227
throw pybind11::error_already_set();
242228
}
243229

244-
template <class D>
245-
inline void pycontainer<D>::fill_default_strides(const shape_type& shape, layout l, strides_type& strides)
246-
{
247-
typename strides_type::value_type data_size = 1;
248-
if(l == layout::row_major)
249-
{
250-
for(size_type i = strides.size(); i != 0; --i)
251-
{
252-
strides[i - 1] = data_size;
253-
data_size = strides[i - 1] * shape[i - 1];
254-
if(shape[i - 1] == 1)
255-
{
256-
strides[i - 1] = 0;
257-
}
258-
}
259-
}
260-
else
261-
{
262-
for(size_type i = 0; i < strides.size(); ++i)
263-
{
264-
strides[i] = data_size;
265-
data_size = strides[i] * shape[i];
266-
if(shape[i] == 1)
267-
{
268-
strides[i] = 0;
269-
}
270-
}
271-
}
272-
}
273-
274230
template <class D>
275231
inline auto pycontainer<D>::ensure(pybind11::handle h) -> derived_type
276232
{
@@ -306,29 +262,6 @@ namespace xt
306262
return reinterpret_cast<PyArrayObject*>(this->m_ptr);
307263
}
308264

309-
template <class D>
310-
template <size_t dim>
311-
inline auto pycontainer<D>::data_offset(const inner_strides_type&) const -> size_type
312-
{
313-
return 0;
314-
}
315-
316-
template <class D>
317-
template <size_t dim, class... Args>
318-
inline auto pycontainer<D>::data_offset(const inner_strides_type& strides, size_type i, Args... args) const -> size_type
319-
{
320-
return i * strides[dim] + data_offset<dim + 1>(strides, args...);
321-
}
322-
323-
template <class D>
324-
template <class It>
325-
inline auto pycontainer<D>::element_offset(const inner_strides_type& strides, It, It last) const -> size_type
326-
{
327-
It first = last;
328-
first -= strides.size();
329-
return std::inner_product(strides.begin(), strides.end(), first, size_type(0));
330-
}
331-
332265
template <class D>
333266
inline auto pycontainer<D>::size() const -> size_type
334267
{
@@ -344,7 +277,7 @@ namespace xt
344277
template <class D>
345278
inline auto pycontainer<D>::shape() const -> const inner_shape_type&
346279
{
347-
return static_cast<const derived_type*>(this)-> shape_impl();
280+
return static_cast<const derived_type*>(this)->shape_impl();
348281
}
349282

350283
template <class D>
@@ -372,7 +305,7 @@ namespace xt
372305
inline void pycontainer<D>::reshape(const shape_type& shape, layout l)
373306
{
374307
strides_type strides(shape.size());
375-
fill_default_strides(shape, l, strides);
308+
compute_strides(shape, l, strides);
376309
reshape(shape, strides);
377310
}
378311

@@ -387,15 +320,15 @@ namespace xt
387320
template <class... Args>
388321
inline auto pycontainer<D>::operator()(Args... args) -> reference
389322
{
390-
size_type index = data_offset(strides(), static_cast<size_type>(args)...);
323+
size_type index = data_offset<size_type>(strides(), static_cast<size_type>(args)...);
391324
return data()[index];
392325
}
393326

394327
template <class D>
395328
template <class... Args>
396329
inline auto pycontainer<D>::operator()(Args... args) const -> const_reference
397330
{
398-
size_type index = data_offset(strides(), static_cast<size_type>(args)...);
331+
size_type index = data_offset<size_type>(strides(), static_cast<size_type>(args)...);
399332
return data()[index];
400333
}
401334

@@ -415,14 +348,14 @@ namespace xt
415348
template <class It>
416349
inline auto pycontainer<D>::element(It first, It last) -> reference
417350
{
418-
return data()[element_offset(strides(), first, last)];
351+
return data()[element_offset<size_type>(strides(), first, last)];
419352
}
420353

421354
template <class D>
422355
template <class It>
423356
inline auto pycontainer<D>::element(It first, It last) const -> const_reference
424357
{
425-
return data()[element_offset(strides(), first, last)];
358+
return data()[element_offset<size_type>(strides(), first, last)];
426359
}
427360

428361
template <class D>
@@ -602,7 +535,6 @@ namespace xt
602535
size_type offset = shape.size() - dimension();
603536
return const_stepper(static_cast<const derived_type*>(this), data().end(), offset);
604537
}
605-
606538
}
607539

608540
#endif

0 commit comments

Comments
 (0)