| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 96cf95d commit 89c1026
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -328,6 +328,7 @@ namespace xt | |||
| 328 | 328 | using const_reference = typename base_type::const_reference; | |
| 329 | 329 | using pointer = typename base_type::pointer; | |
| 330 | 330 | using size_type = typename base_type::size_type; | |
| 331 | + using difference_type = typename base_type::difference_type; | ||
| 331 | 332 | using shape_type = typename base_type::shape_type; | |
| 332 | 333 | using strides_type = typename base_type::strides_type; | |
| 333 | 334 | using backstrides_type = typename base_type::backstrides_type; | |
@@ -745,7 +746,7 @@ namespace xt | |||
| 745 | 746 | { | |
| 746 | 747 | m_shape = inner_shape_type(reinterpret_cast<size_type*>(PyArray_SHAPE(this->python_array())), | |
| 747 | 748 | static_cast<size_type>(PyArray_NDIM(this->python_array()))); | |
| 748 | - m_strides = inner_strides_type(reinterpret_cast<size_type*>(PyArray_STRIDES(this->python_array())), | ||
| 749 | + m_strides = inner_strides_type(reinterpret_cast<difference_type*>(PyArray_STRIDES(this->python_array())), | ||
| 749 | 750 | static_cast<size_type>(PyArray_NDIM(this->python_array()))); | |
| 750 | 751 | ||
| 751 | 752 | if (L != layout_type::dynamic && !do_strides_match(m_shape, m_strides, L)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,7 @@ namespace xt | |||
| 27 | 27 | { | |
| 28 | 28 | public: | |
| 29 | 29 | ||
| 30 | - using value_type = std::size_t; | ||
| 30 | + using value_type = std::ptrdiff_t; | ||
| 31 | 31 | using const_reference = value_type; | |
| 32 | 32 | using const_pointer = const value_type*; | |
| 33 | 33 | using size_type = std::size_t; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ | |||
| 11 | 11 | #include "xtensor-python/pyarray.hpp" | |
| 12 | 12 | ||
| 13 | 13 | #include "xtensor/xarray.hpp" | |
| 14 | + #include "xtensor/xview.hpp" | ||
| 14 | 15 | ||
| 15 | 16 | #include "test_common.hpp" | |
| 16 | 17 | ||
@@ -241,4 +242,11 @@ namespace xt | |||
| 241 | 242 | EXPECT_TRUE(std::equal(sc2.begin(), sc2.end(), a.shape().begin()) && a.shape().size() == 1); | |
| 242 | 243 | EXPECT_EQ(ptr, a.data()); | |
| 243 | 244 | } | |
| 245 | + | ||
| 246 | + TEST(pyarray, view) | ||
| 247 | + { | ||
| 248 | + xt::pyarray<int> arr = xt::zeros<int>({ 10 }); | ||
| 249 | + auto v = xt::view(arr, xt::all()); | ||
| 250 | + EXPECT_EQ(v(0), 0.); | ||
| 251 | + } | ||
| 244 | 252 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ | |||
| 11 | 11 | #include "xtensor-python/pytensor.hpp" | |
| 12 | 12 | ||
| 13 | 13 | #include "xtensor/xtensor.hpp" | |
| 14 | + #include "xtensor/xview.hpp" | ||
| 14 | 15 | ||
| 15 | 16 | #include "test_common.hpp" | |
| 16 | 17 | ||
@@ -231,4 +232,11 @@ namespace xt | |||
| 231 | 232 | // and the second element is `0`. | |
| 232 | 233 | EXPECT_THROW(a.reshape({6, 5}), std::runtime_error); | |
| 233 | 234 | } | |
| 235 | + | ||
| 236 | + TEST(pytensor, view) | ||
| 237 | + { | ||
| 238 | + xt::pytensor<int, 1> arr = xt::zeros<int>({ 10 }); | ||
| 239 | + auto v = xt::view(arr, xt::all()); | ||
| 240 | + EXPECT_EQ(v(0), 0.); | ||
| 241 | + } | ||
| 234 | 242 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments