| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b5aca15 commit f0ce20f
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -761,7 +761,7 @@ namespace xt | |||
| 761 | 761 | ||
| 762 | 762 | m_backstrides = backstrides_type(*this); | |
| 763 | 763 | m_storage = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), | |
| 764 | - this->get_min_stride() * static_cast<size_type>(PyArray_SIZE(this->python_array()))); | ||
| 764 | + this->get_buffer_size()); | ||
| 765 | 765 | } | |
| 766 | 766 | ||
| 767 | 767 | template <class T, layout_type L> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -122,7 +122,7 @@ namespace xt | |||
| 122 | 122 | const derived_type& derived_cast() const; | |
| 123 | 123 | ||
| 124 | 124 | PyArrayObject* python_array() const; | |
| 125 | - size_type get_min_stride() const; | ||
| 125 | + size_type get_buffer_size() const; | ||
| 126 | 126 | }; | |
| 127 | 127 | ||
| 128 | 128 | namespace detail | |
@@ -297,10 +297,15 @@ namespace xt | |||
| 297 | 297 | } | |
| 298 | 298 | ||
| 299 | 299 | template <class D> | |
| 300 | - inline auto pycontainer<D>::get_min_stride() const -> size_type | ||
| 300 | + inline auto pycontainer<D>::get_buffer_size() const -> size_type | ||
| 301 | 301 | { | |
| 302 | 302 | const size_type& (*min)(const size_type&, const size_type&) = std::min<size_type>; | |
| 303 | - return std::max(size_type(1), std::accumulate(this->strides().cbegin(), this->strides().cend(), std::numeric_limits<size_type>::max(), min)); | ||
| 303 | + size_type min_stride = this->strides().empty() ? size_type(1) : | ||
| 304 | + std::max(size_type(1), std::accumulate(this->strides().cbegin(), | ||
| 305 | + this->strides().cend(), | ||
| 306 | + std::numeric_limits<size_type>::max(), | ||
| 307 | + min)); | ||
| 308 | + return min_stride * static_cast<size_type>(PyArray_SIZE(this->python_array())); | ||
| 304 | 309 | } | |
| 305 | 310 | ||
| 306 | 311 | template <class D> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -463,7 +463,7 @@ namespace xt | |||
| 463 | 463 | } | |
| 464 | 464 | ||
| 465 | 465 | m_storage = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), | |
| 466 | - this->get_min_stride() * static_cast<size_type>(PyArray_SIZE(this->python_array()))); | ||
| 466 | + this->get_buffer_size()); | ||
| 467 | 467 | } | |
| 468 | 468 | ||
| 469 | 469 | template <class T, std::size_t N, layout_type L> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -249,4 +249,11 @@ namespace xt | |||
| 249 | 249 | auto v = xt::view(arr, xt::all()); | |
| 250 | 250 | EXPECT_EQ(v(0), 0.); | |
| 251 | 251 | } | |
| 252 | + | ||
| 253 | + TEST(pyarray, zerod_copy) | ||
| 254 | + { | ||
| 255 | + xt::pyarray<int> arr = 2; | ||
| 256 | + xt::pyarray<int> arr2(arr); | ||
| 257 | + EXPECT_EQ(arr(), arr2()); | ||
| 258 | + } | ||
| 252 | 259 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments