10000 Merge pull request #194 from JohanMabille/xtensor_020 · robertodr/xtensor-python@a8b72e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit a8b72e3

Browse files
authored
Merge pull request xtensor-stack#194 from JohanMabille/xtensor_020
Upgraded to xtensor 0.20.0
2 parents 1a0ee4c + a9f5a83 commit a8b72e3

File tree

8 files changed

+65
-5
lines changed

8 files changed

+65
-5
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ install:
2222
- conda update -q conda
2323
- conda info -a
2424
- conda install gtest cmake -c conda-forge
25-
- conda install pytest numpy pybind11==2.2.1 xtensor==0.19.2 -c conda-forge
25+
- conda install pytest numpy pybind11==2.2.1 xtensor==0.20.0 -c conda-forge
2626< 10000 code class="diff-text syntax-highlighted-line">
- "set PYTHONHOME=%MINICONDA%"
2727
- cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\Library -D BUILD_TESTS=ON -D PYTHON_EXECUTABLE=%MINICONDA%\\python.exe .
2828
- nmake test_xtensor_python

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ install:
147147
else
148148
conda install pybind11==${PYBIND11_VERSION} -c conda-forge
149149
fi
150-
- conda install xtensor==0.19.2 -c conda-forge
150+
- conda install xtensor==0.20.0 -c conda-forge
151151
- cmake -D DOWNLOAD_GTEST=ON -D CMAKE_INSTALL_PREFIX=$HOME/miniconda -D PYTHON_EXECUTABLE=$PY_EXE .
152152
- make -j2 test_xtensor_python
153153
- make install

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ from the `docs` subdirectory.
195195

196196
| `xtensor-python` | `xtensor` | `pybind11` |
197197
|------------------|-----------|------------------|
198-
| master | ^0.19.0 | ~2.2.1 |
198+
| master | ^0.20.0 | ~2.2.1 |
199199
| 0.22.x | ^0.19.0 | ~2.2.1 |
200200
| 0.21.x | ^0.18.0 | ~2.2.1 |
201201
| 0.20.x | ^0.17.0 | ~2.2.1 |

include/xtensor-python/pyarray.hpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ namespace xt
264264

265265
using const_iterator = pybackstrides_iterator<self_type>;
266266
using iterator = const_iterator;
267+
using reverse_iterator = std::reverse_iterator<iterator>;
268+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
267269

268270
pyarray_backstrides() = default;
269271
pyarray_backstrides(const array_type& a);
@@ -281,6 +283,11 @@ namespace xt
281283
const_iterator cbegin() const;
282284
const_iterator cend() const;
283285

286+
const_reverse_iterator rbegin() const;
287+
const_reverse_iterator rend() const;
288+
const_reverse_iterator crbegin() const;
289+
const_reverse_iterator crend() const;
290+
284291
private:
285292

286293
const array_type* p_a;
@@ -472,6 +479,30 @@ namespace xt
472479
return const_iterator(this, size());
473480
}
474481

482+
template <class A>
483+
inline auto pyarray_backstrides<A>::rbegin() const -> const_reverse_iterator
484+
{
485+
return crbegin();
486+
}
487+
488+
template <class A>
489+
inline auto pyarray_backstrides<A>::rend() const -> const_reverse_iterator
490+
{
491+
return crend();
492+
}
493+
494+
template <class A>
495+
inline auto pyarray_backstrides<A>::crbegin() const -> const_reverse_iterator
496+
{
497+
return const_reverse_iterator(end());
498+
}
499+
500+
template <class A>
501+
inline auto pyarray_backstrides<A>::crend() const -> const_reverse_iterator
502+
{
503+
return const_reverse_iterator(begin());
504+
}
505+
475506
/**************************
476507
* pyarray implementation *
477508
**************************/
@@ -760,7 +791,7 @@ namespace xt
760791
m_strides = inner_strides_type(reinterpret_cast<difference_type*>(PyArray_STRIDES(this->python_array())),
761792
static_cast<size_type>(PyArray_NDIM(this->python_array())));
762793

763-
if (L != layout_type::dynamic && !do_strides_match(m_shape, m_strides, L))
794+
if (L != layout_type::dynamic && !do_strides_match(m_shape, m_strides, L, 1))
764795
{
765796
throw std::runtime_error("NumPy: passing container with bad strides for layout (is it a view?).");
766797
}

include/xtensor-python/pytensor.hpp

Lines changed: 1 addition & 1 deletion

Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ namespace xt
460460
[](auto v) { return v / sizeof(T); });
461461
adapt_strides(m_shape, m_strides, m_backstrides);
462462
463-
if (L != layout_type::dynamic && !do_strides_match(m_shape, m_strides, L))
463+
if (L != layout_type::dynamic && !do_strides_match(m_shape, m_strides, L, 1))
464464
{
465465
throw std::runtime_error("NumPy: passing container with bad strides for layout (is it a view?).");
466466
}

test/test_pyarray.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ namespace xt
1919
{
2020
using container_type = std::vector<npy_intp>;
2121

22+
template <class T>
23+
using ndarray = pyarray<T, xt::layout_type::row_major>;
24+
25+
void test1 (ndarray<int>const& x)
26+
{
27+
ndarray<int> y = x;
28+
ndarray<int> z = xt::zeros<int>({10});
29+
}
30+
31+
double compute(ndarray<double> const& xs)
32+
{
33+
auto v = xt::view (xs, 0, xt::all());
34+
return v(0);
35+
}
36+
2237
TEST(pyarray, initializer_constructor)
2338
{
2439
pyarray<int> t

test_python/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ void col_major_array(xt::pyarray<double, xt::layout_type::column_major>& arg)
181181
}
182182
}
183183

184+
template <class T>
185+
using ndarray = xt::pyarray<T, xt::layout_type::row_major>;
186+
187+
void test_rm(ndarray<int>const& x)
188+
{
189+
ndarray<int> y = x;
190+
ndarray<int> z = xt::zeros<int>({10});
191+
}
192+
184193
PYBIND11_MODULE(xtensor_python_test, m)
185194
{
186195
xt::import_numpy();
@@ -206,6 +215,8 @@ PYBIND11_MODULE(xtensor_python_test, m)
206215
return a.shape() == b.shape();
207216
});
208217

218+
m.def("test_rm", test_rm);
219+
209220
m.def("int_overload", int_overload<uint8_t>);
210221
m.def("int_overload", int_overload<int8_t>);
211222
m.def("int_overload", int_overload<uint16_t>);

test_python/test_pyarray.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
class XtensorTest(TestCase):
2525

26+
def test_rm(self):
27+
xt.test_rm(np.array([10], dtype=int))
28+
2629
def test_example1(self):
2730
self.assertEqual(4, xt.example1([4, 5, 6]))
2831

0 commit comments

Comments
 (0)
0