| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2d42039 commit 1d53250
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -374,7 +374,7 @@ namespace xt | |||
| 374 | 374 | inner_shape_type m_shape; | |
| 375 | 375 | inner_strides_type m_strides; | |
| 376 | 376 | mutable inner_backstrides_type m_backstrides; | |
| 377 | - storage_type m_data; | ||
| 377 | + storage_type m_storage; | ||
| 378 | 378 | ||
| 379 | 379 | void init_array(const shape_type& shape, const strides_type& strides); | |
| 380 | 380 | void init_from_python(); | |
@@ -477,7 +477,7 @@ namespace xt | |||
| 477 | 477 | shape_type shape = xtl::make_sequence<shape_type>(0, size_type(1)); | |
| 478 | 478 | strides_type strides = xtl::make_sequence<strides_type>(0, size_type(0)); | |
| 479 | 479 | init_array(shape, strides); | |
| 480 | - m_data[0] = T(); | ||
| 480 | + m_storage[0] = T(); | ||
| 481 | 481 | } | |
| 482 | 482 | ||
| 483 | 483 | /** | |
@@ -488,47 +488,47 @@ namespace xt | |||
| 488 | 488 | : base_type() | |
| 489 | 489 | { | |
| 490 | 490 | base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | |
| 491 | - nested_copy(m_data.begin(), t); | ||
| 491 | + nested_copy(m_storage.begin(), t); | ||
| 492 | 492 | } | |
| 493 | 493 | ||
| 494 | 494 | template <class T> | |
| 495 | 495 | inline pyarray<T>::pyarray(nested_initializer_list_t<T, 1> t) | |
| 496 | 496 | : base_type() | |
| 497 | 497 | { | |
| 498 | 498 | base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | |
| 499 | - nested_copy(m_data.begin(), t); | ||
| 499 | + nested_copy(m_storage.begin(), t); | ||
| 500 | 500 | } | |
| 501 | 501 | ||
| 502 | 502 | template <class T> | |
| 503 | 503 | inline pyarray<T>::pyarray(nested_initializer_list_t<T, 2> t) | |
| 504 | 504 | : base_type() | |
| 505 | 505 | { | |
| 506 | 506 | base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | |
| 507 | - nested_copy(m_data.begin(), t); | ||
| 507 | + nested_copy(m_storage.begin(), t); | ||
| 508 | 508 | } | |
| 509 | 509 | ||
| 510 | 510 | template <class T> | |
| 511 | 511 | inline pyarray<T>::pyarray(nested_initializer_list_t<T, 3> t) | |
| 512 | 512 | : base_type() | |
| 513 | 513 | { | |
| 514 | 514 | base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | |
| 515 | - nested_copy(m_data.begin(), t); | ||
| 515 | + nested_copy(m_storage.begin(), t); | ||
| 516 | 516 | } | |
| 517 | 517 | ||
| 518 | 518 | template <class T> | |
| 519 | 519 | inline pyarray<T>::pyarray(nested_initializer_list_t<T, 4> t) | |
| 520 | 520 | : base_type() | |
| 521 | 521 | { | |
| 522 | 522 | base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | |
| 523 | - nested_copy(m_data.begin(), t); | ||
| 523 | + nested_copy(m_storage.begin(), t); | ||
| 524 | 524 | } | |
| 525 | 525 | ||
| 526 | 526 | template <class T> | |
| 527 | 527 | inline pyarray<T>::pyarray(nested_initializer_list_t<T, 5> t) | |
| 528 | 528 | : base_type() | |
| 529 | 529 | { | |
| 530 | 530 | base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | |
| 531 | - nested_copy(m_data.begin(), t); | ||
| 531 | + nested_copy(m_storage.begin(), t); | ||
| 532 | 532 | } | |
| 533 | 533 | ||
| 534 | 534 | template <class T> | |
@@ -581,7 +581,7 @@ namespace xt | |||
| 581 | 581 | strides_type strides(shape.size()); | |
| 582 | 582 | compute_strides(shape, l, strides); | |
| 583 | 583 | init_array(shape, strides); | |
| 584 | - std::fill(m_data.begin(), m_data.end(), value); | ||
| 584 | + std::fill(m_storage.begin(), m_storage.end(), value); | ||
| 585 | 585 | } | |
| 586 | 586 | ||
| 587 | 587 | /** | |
@@ -596,7 +596,7 @@ namespace xt | |||
| 596 | 596 | : base_type() | |
| 597 | 597 | { | |
| 598 | 598 | init_array(shape, strides); | |
| 599 | - std::fill(m_data.begin(), m_data.end(), value); | ||
| 599 | + std::fill(m_storage.begin(), m_storage.end(), value); | ||
| 600 | 600 | } | |
| 601 | 601 | ||
| 602 | 602 | /** | |
@@ -730,8 +730,8 @@ namespace xt | |||
| 730 | 730 | m_strides = inner_strides_type(reinterpret_cast<size_type*>(PyArray_STRIDES(this->python_array())), | |
| 731 | 731 | static_cast<size_type>(PyArray_NDIM(this->python_array()))); | |
| 732 | 732 | m_backstrides = backstrides_type(*this); | |
| 733 | - m_data = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), | ||
| 734 | - this->get_min_stride() * static_cast<size_type>(PyArray_SIZE(this->python_array()))); | ||
| 733 | + m_storage = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), | ||
| 734 | + this->get_min_stride() * static_cast<size_type>(PyArray_SIZE(this->python_array()))); | ||
| 735 | 735 | } | |
| 736 | 736 | ||
| 737 | 737 | template <class T> | |
@@ -759,13 +759,13 @@ namespace xt | |||
| 759 | 759 | template <class T> | |
| 760 | 760 | inline auto pyarray<T>::storage_impl() noexcept -> storage_type& | |
| 761 | 761 | { | |
| 762 | - return m_data; | ||
| 762 | + return m_storage; | ||
| 763 | 763 | } | |
| 764 | 764 | ||
| 765 | 765 | template <class T> | |
| 766 | 766 | inline auto pyarray<T>::storage_impl() const noexcept -> const storage_type& | |
| 767 | 767 | { | |
| 768 | - return m_data; | ||
| 768 | + return m_storage; | ||
| 769 | 769 | } | |
| 770 | 770 | } | |
| 771 | 771 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -358,11 +358,17 @@ namespace xt | |||
| 358 | 358 | inline layout_type pycontainer<D>::layout() const | |
| 359 | 359 | { | |
| 360 | 360 | if (PyArray_CHKFLAGS(python_array(), NPY_ARRAY_C_CONTIGUOUS)) | |
| 361 | + { | ||
| 361 | 362 | return layout_type::row_major; | |
| 363 | + } | ||
| 362 | 364 | else if (PyArray_CHKFLAGS(python_array(), NPY_ARRAY_F_CONTIGUOUS)) | |
| 365 | + { | ||
| 363 | 366 | return layout_type::column_major; | |
| 367 | + } | ||
| 364 | 368 | else | |
| 369 | + { | ||
| 365 | 370 | return layout_type::dynamic; | |
| 371 | + } | ||
| 366 | 372 | } | |
| 367 | 373 | ||
| 368 | 374 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -191,7 +191,7 @@ namespace xt | |||
| 191 | 191 | inner_shape_type m_shape; | |
| 192 | 192 | inner_strides_type m_strides; | |
| 193 | 193 | inner_backstrides_type m_backstrides; | |
| 194 | - storage_type m_data; | ||
| 194 | + storage_type m_storage; | ||
| 195 | 195 | ||
| 196 | 196 | void init_tensor(const shape_type& shape, const strides_type& strides); | |
| 197 | 197 | void init_from_python(); | |
@@ -228,7 +228,7 @@ namespace xt | |||
| 228 | 228 | m_shape = xtl::make_sequence<shape_type>(N, size_type(1)); | |
| 229 | 229 | m_strides = xtl::make_sequence<strides_type>(N, size_type(0)); | |
| 230 | 230 | init_tensor(m_shape, m_strides); | |
| 231 | - m_data[0] = T(); | ||
| 231 | + m_storage[0] = T(); | ||
| 232 | 232 | } | |
| 233 | 233 | ||
| 234 | 234 | /** | |
@@ -239,7 +239,7 @@ namespace xt | |||
| 239 | 239 | : base_type() | |
| 240 | 240 | { | |
| 241 | 241 | base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | |
| 242 | - nested_copy(m_data.begin(), t); | ||
| 242 | + nested_copy(m_storage.begin(), t); | ||
| 243 | 243 | } | |
| 244 | 244 | ||
| 245 | 245 | template <class T, std::size_t N> | |
@@ -290,7 +290,7 @@ namespace xt | |||
| 290 | 290 | { | |
| 291 | 291 | compute_strides(shape, l, m_strides); | |
| 292 | 292 | init_tensor(shape, m_strides); | |
| 293 | - std::fill(m_data.begin(), m_data.end(), value); | ||
| 293 | + std::fill(m_storage.begin(), m_storage.end(), value); | ||
| 294 | 294 | } | |
| 295 | 295 | ||
| 296 | 296 | /** | |
@@ -306,7 +306,7 @@ namespace xt | |||
| 306 | 306 | const_reference value) | |
| 307 | 307 | { | |
| 308 | 308 | init_tensor(shape, strides); | |
| 309 | - std::fill(m_data.begin(), m_data.end(), value); | ||
| 309 | + std::fill(m_storage.begin(), m_storage.end(), value); | ||
| 310 | 310 | } | |
| 311 | 311 | ||
| 312 | 312 | /** | |
@@ -417,8 +417,8 @@ namespace xt | |||
| 417 | 417 | m_shape = shape; | |
| 418 | 418 | m_strides = strides; | |
| 419 | 419 | adapt_strides(m_shape, m_strides, m_backstrides); | |
| 420 | - m_data = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), | ||
| 421 | - static_cast<size_type>(PyArray_SIZE(this->python_array()))); | ||
| 420 | + m_storage = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), | ||
| 421 | + static_cast<size_type>(PyArray_SIZE(this->python_array()))); | ||
| 422 | 422 | } | |
| 423 | 423 | ||
| 424 | 424 | template <class T, std::size_t N> | |
@@ -433,8 +433,8 @@ namespace xt | |||
| 433 | 433 | std::transform(PyArray_STRIDES(this->python_array()), PyArray_STRIDES(this->python_array()) + N, m_strides.begin(), | |
| 434 | 434 | [](auto v) { return v / sizeof(T); }); | |
| 435 | 435 | adapt_strides(m_shape, m_strides, m_backstrides); | |
| 436 | - m_data = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), | ||
| 437 | - this->get_min_stride() * static_cast<size_type>(PyArray_SIZE(this->python_array()))); | ||
| 436 | + m_storage = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), | ||
| 437 | + this->get_min_stride() * static_cast<size_type>(PyArray_SIZE(this->python_array()))); | ||
| 438 | 438 | } | |
| 439 | 439 | ||
| 440 | 440 | template <class T, std::size_t N> | |
@@ -476,13 +476,13 @@ namespace xt | |||
| 476 | 476 | template <class T, std::size_t N> | |
| 477 | 477 | inline auto pytensor<T, N>::storage_impl() noexcept -> storage_type& | |
| 478 | 478 | { | |
| 479 | - return m_data; | ||
| 479 | + return m_storage; | ||
| 480 | 480 | } | |
| 481 | 481 | ||
| 482 | 482 | template <class T, std::size_t N> | |
| 483 | 483 | inline auto pytensor<T, N>::storage_impl() const noexcept -> const storage_type& | |
| 484 | 484 | { | |
| 485 | - return m_data; | ||
| 485 | + return m_storage; | ||
| 486 | 486 | } | |
| 487 | 487 | } | |
| 488 | 488 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,10 @@ | |||
| 15 | 15 | #ifndef XTENSOR_TYPE_CASTER_HPP | |
| 16 | 16 | #define XTENSOR_TYPE_CASTER_HPP | |
| 17 | 17 | ||
| 18 | + #include <cstddef> | ||
| 19 | + #include <algorithm> | ||
| 20 | + #include <vector> | ||
| 21 | + | ||
| 18 | 22 | #include "xtensor/xtensor.hpp" | |
| 19 | 23 | ||
| 20 | 24 | #include <pybind11/numpy.h> | |
@@ -24,17 +28,20 @@ namespace pybind11 | |||
| 24 | 28 | { | |
| 25 | 29 | namespace detail | |
| 26 | 30 | { | |
| 27 | - // Casts an xtensor (or xarray) type to numpy array. If given a base, the numpy array references the src data, | ||
| 28 | - // otherwise it'll make a copy. writeable lets you turn off the writeable flag for the array. | ||
| 31 | + // Casts an xtensor (or xarray) type to numpy array.If given a base, | ||
| 32 | + // the numpy array references the src data, otherwise it'll make a copy. | ||
| 33 | + // The writeable attributes lets you specify writeable flag for the array. | ||
| 29 | 34 | template <typename Type> | |
| 30 | - handle xtensor_array_cast(Type const& src, handle base = handle(), bool writeable = true) | ||
| 35 | + handle xtensor_array_cast(const Type& src, handle base = handle(), bool writeable = true) | ||
| 31 | 36 | { | |
| 32 | 37 | // TODO: make use of xt::pyarray instead of array. | |
| 33 | - std::vector<size_t> python_strides(src.strides().size()); | ||
| 34 | - std::transform(src.strides().begin(), src.strides().end(), python_strides.begin(), | ||
| 35 | - [](auto v) { return sizeof(typename Type::value_type) * v; }); | ||
| 38 | + std::vector<std::size_t> python_strides(src.strides().size()); | ||
| 39 | + std::transform(src.strides().begin(), src.strides().end(), | ||
| 40 | + python_strides.begin(), [](auto v) { | ||
| 41 | + return sizeof(typename Type::value_type) * v; | ||
| 42 | + }); | ||
| 36 | 43 | ||
| 37 | - std::vector<size_t> python_shape(src.shape().size()); | ||
| 44 | + std::vector<std::size_t> python_shape(src.shape().size()); | ||
| 38 | 45 | std::copy(src.shape().begin(), src.shape().end(), python_shape.begin()); | |
| 39 | 46 | ||
| 40 | 47 | array a(python_shape, python_strides, src.begin(), base); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments