| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -136,8 +136,7 @@ See :any:`numpy indexing <numpy:arrays.indexing>` page. | |||
| 136 | 136 | +====================================================================+====================================================================+ | |
| 137 | 137 | | ``a[3, 2]`` | ``a(3, 2)`` | | |
| 138 | 138 | +--------------------------------------------------------------------+--------------------------------------------------------------------+ | |
| 139 | - | :any:`a.flat[4] <numpy.ndarray.flat>` || ``a[4]`` | | ||
| 140 | - | || ``a(4)`` | | ||
| 139 | + | :any:`a.flat[4] <numpy.ndarray.flat>` | ``a.flat(4)`` | | ||
| 141 | 140 | +--------------------------------------------------------------------+--------------------------------------------------------------------+ | |
| 142 | 141 | | ``a[3]`` || ``xt::view(a, 3, xt::all())`` | | |
| 143 | 142 | | || ``xt::row(a, 3)`` | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,7 +125,7 @@ namespace xt | |||
| 125 | 125 | /************************************ | |
| 126 | 126 | * xconst_accessible implementation * | |
| 127 | 127 | ************************************/ | |
| 128 | - | ||
| 128 | + | ||
| 129 | 129 | /** | |
| 130 | 130 | * Returns the size of the expression. | |
| 131 | 131 | */ | |
@@ -211,7 +211,7 @@ namespace xt | |||
| 211 | 211 | normalize_periodic(derived_cast().shape(), args...); | |
| 212 | 212 | return derived_cast()(static_cast<size_type>(args)...); | |
| 213 | 213 | } | |
| 214 | - | ||
| 214 | + | ||
| 215 | 215 | /** | |
| 216 | 216 | * Returns ``true`` only if the the specified position is a valid entry in the expression. | |
| 217 | 217 | * @param args a list of indices specifying the position in the expression. | |
@@ -246,7 +246,7 @@ namespace xt | |||
| 246 | 246 | template <class D> | |
| 247 | 247 | template <class... Args> | |
| 248 | 248 | inline auto xaccessible<D>::at(Args... args) -> reference | |
| 249 | - { | ||
| 249 | + { | ||
| 250 | 250 | check_access(derived_cast().shape(), static_cast<size_type>(args)...); | |
| 251 | 251 | return derived_cast().operator()(args...); | |
| 252 | 252 | } | |
@@ -293,7 +293,6 @@ namespace xt | |||
| 293 | 293 | return derived_cast()(static_cast<size_type>(args)...); | |
| 294 | 294 | } | |
| 295 | 295 | ||
| 296 | - | ||
| 297 | 296 | template <class D> | |
| 298 | 297 | inline auto xaccessible<D>::derived_cast() noexcept -> derived_type& | |
| 299 | 298 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -174,6 +174,9 @@ namespace xt | |||
| 174 | 174 | reference data_element(size_type i); | |
| 175 | 175 | const_reference data_element(size_type i) const; | |
| 176 | 176 | ||
| 177 | + reference flat(size_type i); | ||
| 178 | + const_reference flat(size_type i) const; | ||
| 179 | + | ||
| 177 | 180 | template <class requested_type> | |
| 178 | 181 | using simd_return_type = xt_simd::simd_return_type<value_type, requested_type>; | |
| 179 | 182 | ||
@@ -643,6 +646,18 @@ namespace xt | |||
| 643 | 646 | return storage()[i]; | |
| 644 | 647 | } | |
| 645 | 648 | ||
| 649 | + template <class D> | ||
| 650 | + inline auto xcontainer<D>::flat(size_type i) -> reference | ||
| 651 | + { | ||
| 652 | + return storage()[i]; | ||
| 653 | + } | ||
| 654 | + | ||
| 655 | + template <class D> | ||
| 656 | + inline auto xcontainer<D>::flat(size_type i) const -> const_reference | ||
| 657 | + { | ||
| 658 | + return storage()[i]; | ||
| 659 | + } | ||
| 660 | + | ||
| 646 | 661 | /*************** | |
| 647 | 662 | * stepper api * | |
| 648 | 663 | ***************/ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -181,6 +181,9 @@ namespace xt | |||
| 181 | 181 | template <class... Args> | |
| 182 | 182 | const_reference unchecked(Args... args) const; | |
| 183 | 183 | ||
| 184 | + reference flat(size_type index); | ||
| 185 | + const_reference flat(size_type index) const; | ||
| 186 | + | ||
| 184 | 187 | using base_type::operator[]; | |
| 185 | 188 | using base_type::at; | |
| 186 | 189 | using base_type::periodic; | |
@@ -450,6 +453,18 @@ namespace xt | |||
| 450 | 453 | return base_type::storage()[static_cast<size_type>(offset)]; | |
| 451 | 454 | } | |
| 452 | 455 | ||
| 456 | + template <class CT, class S, layout_type L, class FST> | ||
| 457 | + inline auto xdynamic_view<CT, S, L, FST>::flat(size_type i) -> reference | ||
| 458 | + { | ||
| 459 | + return base_type::storage()[data_offset() + i]; | ||
| 460 | + } | ||
| 461 | + | ||
| 462 | + template <class CT, class S, layout_type L, class FST> | ||
| 463 | + inline auto xdynamic_view<CT, S, L, FST>::flat(size_type i) const -> const_reference | ||
| 464 | + { | ||
| 465 | + return base_type::storage()[data_offset() + i]; | ||
| 466 | + } | ||
| 467 | + | ||
| 453 | 468 | template <class CT, class S, layout_type L, class FST> | |
| 454 | 469 | template <class It> | |
| 455 | 470 | inline auto xdynamic_view<CT, S, L, FST>::element(It first, It last) -> reference | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -307,6 +307,8 @@ namespace xt | |||
| 307 | 307 | ||
| 308 | 308 | const_reference data_element(size_type i) const; | |
| 309 | 309 | ||
| 310 | + const_reference flat(size_type i) const; | ||
| 311 | + | ||
| 310 | 312 | template <class UT = self_type, class = typename std::enable_if<UT::only_scalar::value>::type> | |
| 311 | 313 | operator value_type() const; | |
| 312 | 314 | ||
@@ -583,6 +585,20 @@ namespace xt | |||
| 583 | 585 | return access_impl(std::make_index_sequence<sizeof...(CT)>(), static_cast<size_type>(args)...); | |
| 584 | 586 | } | |
| 585 | 587 | ||
| 588 | + /** | ||
| 589 | + * @name Data | ||
| 590 | + */ | ||
| 591 | + /** | ||
| 592 | + * Returns a constant reference to the element at the specified position of the underlying | ||
| 593 | + * contiguous storage of the function. | ||
| 594 | + * @param index index to underlying flat storage. | ||
| 595 | + */ | ||
| 596 | + template <class F, class... CT> | ||
| 597 | + inline auto xfunction<F, CT...>::flat(size_type index) const -> const_reference | ||
| 598 | + { | ||
| 599 | + return data_element_impl(std::make_index_sequence<sizeof...(CT)>(), index); | ||
| 600 | + } | ||
| 601 | + | ||
| 586 | 602 | /** | |
| 587 | 603 | * Returns a constant reference to the element at the specified position in the expression. | |
| 588 | 604 | * @param args a list of indices specifying the position in the expression. Indices | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -178,6 +178,7 @@ namespace xt | |||
| 178 | 178 | using accessible_base::at; | |
| 179 | 179 | using accessible_base::operator[]; | |
| 180 | 180 | using accessible_base::periodic; | |
| 181 | + | ||
| 181 | 182 | using accessible_base::in_bounds; | |
| 182 | 183 | ||
| 183 | 184 | xexpression_type& expression() noexcept; | |
@@ -203,6 +204,20 @@ namespace xt | |||
| 203 | 204 | return m_functor(m_e.data_element(i)); | |
| 204 | 205 | } | |
| 205 | 206 | ||
| 207 | + template <class FCT = functor_type> | ||
| 208 | + auto flat(size_type i) | ||
| 209 | + -> decltype(std::declval<FCT>()(std::declval<undecay_expression>().flat(i))) | ||
| 210 | + { | ||
| 211 | + return m_functor(m_e.flat(i)); | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + template <class FCT = functor_type> | ||
| 215 | + auto flat(size_type i) const | ||
| 216 | + -> decltype(std::declval<FCT>()(std::declval<const undecay_expression>().flat(i))) | ||
| 217 | + { | ||
| 218 | + return m_functor(m_e.flat(i)); | ||
| 219 | + } | ||
| 220 | + | ||
| 206 | 221 | // The following functions are defined inline because otherwise signatures | |
| 207 | 222 | // don't match on GCC. | |
| 208 | 223 | template <class align, class requested_type = typename xexpression_type::value_type, | |
@@ -732,15 +747,15 @@ namespace xt | |||
| 732 | 747 | * | |
| 733 | 748 | * @warning This method is meant for performance, for expressions with a dynamic | |
| 734 | 749 | * number of dimensions (i.e. not known at compile time). Since it may have | |
| 735 | - * undefined behavior (see parameters), operator() should be prefered whenever | ||
| 750 | + * undefined behavior (see parameters), operator() should be preferred whenever | ||
| 736 | 751 | * it is possible. | |
| 737 | 752 | * @warning This method is NOT compatible with broadcasting, meaning the following | |
| 738 | 753 | * code has undefined behavior: | |
| 739 | 754 | * \code{.cpp} | |
| 740 | 755 | * xt::xarray<double> a = {{0, 1}, {2, 3}}; | |
| 741 | 756 | * xt::xarray<double> b = {0, 1}; | |
| 742 | 757 | * auto fd = a + b; | |
| 743 | - * double res = fd.uncheked(0, 1); | ||
| 758 | + * double res = fd.unchecked(0, 1); | ||
| 744 | 759 | * \endcode | |
| 745 | 760 | */ | |
| 746 | 761 | template <class D> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,7 +37,7 @@ namespace xt | |||
| 37 | 37 | ||
| 38 | 38 | template <class CTD, class CTM> | |
| 39 | 39 | struct xcontainer_inner_types<xmasked_view<CTD, CTM>> | |
| 40 | - { | ||
| 40 | + { | ||
| 41 | 41 | using data_type = std::decay_t<CTD>; | |
| 42 | 42 | using mask_type = std::decay_t<CTM>; | |
| 43 | 43 | using base_value_type = typename data_type::value_type; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -177,6 +177,9 @@ namespace xt | |||
| 177 | 177 | template <class... Args> | |
| 178 | 178 | const_reference periodic(Args... args) const; | |
| 179 | 179 | ||
| 180 | + reference flat(size_type args); | ||
| 181 | + const_reference flat(size_type args) const; | ||
| 182 | + | ||
| 180 | 183 | template <class It> | |
| 181 | 184 | reference element(It first, It last); | |
| 182 | 185 | template <class It> | |
@@ -659,6 +662,28 @@ namespace xt | |||
| 659 | 662 | return const_reference(value().periodic(args...), has_value().periodic(args...)); | |
| 660 | 663 | } | |
| 661 | 664 | ||
| 665 | + /** | ||
| 666 | + * Returns a reference to the element at the specified position | ||
| 667 | + * of the underlying storage in the optional assembly. | ||
| 668 | + * @param index index to underlying flat storage. | ||
| 669 | + */ | ||
| 670 | + template <class D> | ||
| 671 | + inline auto xoptional_assembly_base<D>::flat(size_type i) -> reference | ||
| 672 | + { | ||
| 673 | + return reference(value().flat(i), has_value().flat(i)); | ||
| 674 | + } | ||
| 675 | + | ||
| 676 | + /** | ||
| 677 | + * Returns a constant reference to the element at the specified position | ||
| 678 | + * of the underlying storage in the optional assembly. | ||
| 679 | + * @param index index to underlying flat storage. | ||
| 680 | + */ | ||
| 681 | + template <class D> | ||
| 682 | + inline auto xoptional_assembly_base<D>::flat(size_type i) const -> const_reference | ||
| 683 | + { | ||
| 684 | + return const_reference(value().flat(i), has_value().flat(i)); | ||
| 685 | + } | ||
| 686 | + | ||
| 662 | 687 | /** | |
| 663 | 688 | * Returns a reference to the element at the specified position in the optional assembly. | |
| 664 | 689 | * @param first iterator starting the sequence of indices | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -281,6 +281,9 @@ namespace xt | |||
| 281 | 281 | reference data_element(size_type i) noexcept; | |
| 282 | 282 | const_reference data_element(size_type i) const noexcept; | |
| 283 | 283 | ||
| 284 | + reference flat(size_type i) noexcept; | ||
| 285 | + const_reference flat(size_type i) const noexcept; | ||
| 286 | + | ||
| 284 | 287 | template <class align, class simd = simd_value_type> | |
| 285 | 288 | void store_simd(size_type i, const simd& e); | |
| 286 | 289 | template <class align, class requested_type = value_type, | |
@@ -932,6 +935,18 @@ namespace xt | |||
| 932 | 935 | return m_value; | |
| 933 | 936 | } | |
| 934 | 937 | ||
| 938 | + template <class CT> | ||
| 939 | + inline auto xscalar<CT>::flat(size_type) noexcept -> reference | ||
| 940 | + { | ||
| 941 | + return m_value; | ||
| 942 | + } | ||
| 943 | + | ||
| 944 | + template <class CT> | ||
| 945 | + inline auto xscalar<CT>::flat(size_type) const noexcept -> const_reference | ||
| 946 | + { | ||
| 947 | + return m_value; | ||
| 948 | + } | ||
| 949 | + | ||
| 935 | 950 | template <class CT> | |
| 936 | 951 | template <class align, class simd> | |
| 937 | 952 | inline void xscalar<CT>::store_simd(size_type, const simd& e) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -266,6 +266,9 @@ namespace xt | |||
| 266 | 266 | reference data_element(size_type i); | |
| 267 | 267 | const_reference data_element(size_type i) const; | |
| 268 | 268 | ||
| 269 | + reference flat(size_type i); | ||
| 270 | + const_reference flat(size_type i) const; | ||
| 271 | + | ||
| 269 | 272 | using container_iterator = std::conditional_t<is_const, | |
| 270 | 273 | typename storage_type::const_iterator, | |
| 271 | 274 | typename storage_type::iterator>; | |
@@ -457,6 +460,17 @@ namespace xt | |||
| 457 | 460 | return storage()[i]; | |
| 458 | 461 | } | |
| 459 | 462 | ||
| 463 | + template <class CT, class S, layout_type L, class FST> | ||
| 464 | + inline auto xstrided_view<CT, S, L, FST>::flat(size_type i) -> reference | ||
| 465 | + { | ||
| 466 | + return storage()[i]; | ||
| 467 | + } | ||
| 468 | + | ||
| 469 | + template <class CT, class S, layout_type L, class FST> | ||
| 470 | + inline auto xstrided_view<CT, S, L, FST>::flat(size_type i) const -> const_reference | ||
| 471 | + { | ||
| 472 | + return storage()[i]; | ||
| 473 | + } | ||
| 460 | 474 | ||
| 461 | 475 | template <class CT, class S, layout_type L, class FST> | |
| 462 | 476 | inline auto xstrided_view<CT, S, L, FST>::storage_begin() -> storage_iterator | |
| Back | FazBrowse Home | New Git URL |
0 commit comments