Skip to content

Commit 711536b

Browse files
Merge pull request #16 from SylvainCorlay/xtensor-master
Update xtensor-python to reflect semantic changes in xtensor
2 parents 36b91f4 + 925bd65 commit 711536b

File tree

4 files changed

+61
-26
lines changed

4 files changed

+61
-26
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.2.0 pytest numpy pybind11==1.8.1 -c conda-forge
27+
- conda install xtensor==0.2.2 pytest numpy pybind11==1.8.1 -c conda-forge
2828
- xcopy /S %APPVEYOR_BUILD_FOLDER%\include %MINICONDA%\include
2929

3030
build_script:

.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.2.0 pytest numpy pybind11==1.8.1 -c conda-forge
62+
- conda install xtensor==0.2.2 pytest numpy pybind11==1.8.1 -c conda-forge
6363
- cp -r $TRAVIS_BUILD_DIR/include/* $HOME/miniconda/include/
6464

6565
script:

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ The Python bindings for `xtensor` are based on the [pybind11](https://github.com
2222
conda install -c conda-forge xtensor-python
2323
```
2424

25+
### Dependences on `xtensor` and `pybind11`
26+
27+
`xtensor-python` depends on the `xtensor` and `pybind11` libraries
28+
29+
| `xtensor-python` | `xtensor` | `pybind11` |
30+
|-------------------|------------|-------------|
31+
| master | master | ^1.8.1 |
32+
| 0.2.0 | ^0.2.1 | ^1.8.1 |
33+
| 0.1.0 | ^0.1.1 | ^1.8.1 |
34+
35+
These dependencies are automatically resolved when using the conda package manager.
36+
2537
## Usage
2638

2739
### Example 1: Use an algorithm of the C++ library on a numpy array inplace.

include/xtensor-python/pyarray.hpp

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,17 @@ namespace xt
8181
using size_type = std::size_t;
8282
using difference_type = std::ptrdiff_t;
8383

84-
using stepper = xstepper<self_type>;
85-
using const_stepper = xstepper<const self_type>;
86-
87-
using iterator = xiterator<stepper>;
88-
using const_iterator = xiterator<const_stepper>;
89-
9084
using storage_iterator = T*;
9185
using const_storage_iterator = const T*;
9286

9387
using shape_type = std::vector<size_type>;
9488
using strides_type = std::vector<size_type>;
9589
using backstrides_type = pyarray_backstrides<self_type>;
90+
91+
using stepper = xstepper<self_type>;
92+
using const_stepper = xstepper<const self_type>;
93+
using iterator = xiterator<stepper, shape_type>;
94+
using const_iterator = xiterator<const_stepper, shape_type>;
9695

9796
using closure_type = const self_type&;
9897

@@ -153,13 +152,18 @@ namespace xt
153152
const_iterator cbegin() const;
154153
const_iterator cend() const;
155154

156-
iterator xbegin(const shape_type& shape);
157-
iterator xend(const shape_type& shape);
158-
159-
const_iterator xbegin(const shape_type& shape) const;
160-
const_iterator xend(const shape_type& shape) const;
161-
const_iterator cxbegin(const shape_type& shape) const;
162-
const_iterator cxend(const shape_type& shape) const;
155+
template <class S>
156+
xiterator<stepper, S> xbegin(const S& shape);
157+
template <class S>
158+
xiterator<stepper, S> xend(const S& shape);
159+
template <class S>
160+
xiterator<const_stepper, S> xbegin(const S& shape) const;
161+
template <class S>
162+
xiterator<const_stepper, S> xend(const S& shape) const;
163+
template <class S>
164+
xiterator<const_stepper, S> cxbegin(const S& shape) const;
165+
template <class S>
166+
xiterator<const_stepper, S> cxend(const S& shape) const;
163167

164168
stepper stepper_begin(const shape_type& shape);
165169
stepper stepper_end(const shape_type& shape);
@@ -169,9 +173,10 @@ namespace xt
169173

170174
storage_iterator storage_begin();
171175
storage_iterator storage_end();
172-
173176
const_storage_iterator storage_begin() const;
174177
const_storage_iterator storage_end() const;
178+
const_storage_iterator storage_cbegin() const;
179+
const_storage_iterator storage_cend() const;
175180

176181
template <class E>
177182
pyarray(const xexpression<E>& e);
@@ -427,37 +432,43 @@ namespace xt
427432
}
428433

429434
template <class T, int ExtraFlags>
430-
inline auto pyarray<T, ExtraFlags>::xbegin(const shape_type& shape) -> iterator
435+
template <class S>
436+
inline auto pyarray<T, ExtraFlags>::xbegin(const S& shape) -> xiterator<stepper, S>
431437
{
432-
return iterator(stepper_begin(shape), shape);
438+
return xiterator<stepper, S>(stepper_begin(shape), shape);
433439
}
434440

435441
template <class T, int ExtraFlags>
436-
inline auto pyarray<T, ExtraFlags>::xend(const shape_type& shape) -> iterator
442+
template <class S>
443+
inline auto pyarray<T, ExtraFlags>::xend(const S& shape) -> xiterator<stepper, S>
437444
{
438-
return iterator(stepper_end(shape), shape);
445+
return xiterator<stepper, S>(stepper_end(shape), shape);
439446
}
440447

441448
template <class T, int ExtraFlags>
442-
inline auto pyarray<T, ExtraFlags>::xbegin(const shape_type& shape) const -> const_iterator
449+
template <class S>
450+
inline auto pyarray<T, ExtraFlags>::xbegin(const S& shape) const -> xiterator<const_stepper, S>
443451
{
444-
return const_iterator(stepper_begin(shape), shape);
452+
return xiterator<const_stepper, S>(stepper_begin(shape), shape);
445453
}
446454

447455
template <class T, int ExtraFlags>
448-
inline auto pyarray<T, ExtraFlags>::xend(const shape_type& shape) const -> const_iterator
456+
template <class S>
457+
inline auto pyarray<T, ExtraFlags>::xend(const S& shape) const -> xiterator<const_stepper, S>
449458
{
450-
return const_iterator(stepper_end(shape), shape);
459+
return xiterator<const_stepper, S>(stepper_end(shape), shape);
451460
}
452461

453462
template <class T, int ExtraFlags>
454-
inline auto pyarray<T, ExtraFlags>::cxbegin(const shape_type& shape) const -> const_iterator
463+
template <class S>
464+
inline auto pyarray<T, ExtraFlags>::cxbegin(const S& shape) const -> xiterator<const_stepper, S>
455465
{
456466
return xbegin(shape);
457467
}
458468

459469
template <class T, int ExtraFlags>
460-
inline auto pyarray<T, ExtraFlags>::cxend(const shape_type& shape) const -> const_iterator
470+
template <class S>
471+
inline auto pyarray<T, ExtraFlags>::cxend(const S& shape) const -> xiterator<const_stepper, S>
461472
{
462473
return xend(shape);
463474
}
@@ -514,6 +525,18 @@ namespace xt
514525
return storage_begin() + pybind_array::size();
515526
}
516527

528+
template <class T, int ExtraFlags>
529+
inline auto pyarray<T, ExtraFlags>::storage_cbegin() const -> const_storage_iterator
530+
{
531+
return reinterpret_cast<const_storage_iterator>(pybind11::backport::array_proxy(m_ptr)->data);
532+
}
533+
534+
template <class T, int ExtraFlags>
535+
inline auto pyarray<T, ExtraFlags>::storage_cend() const -> const_storage_iterator
536+
{
537+
return storage_begin() + pybind_array::size();
538+
}
539+
517540
template <class T, int ExtraFlags>
518541
template <class E>
519542
inline pyarray<T, ExtraFlags>::pyarray(const xexpression<E>& e)

0 commit comments

Comments
 (0)