/usr/include/xtensor/xfunctorview.hpp is in xtensor-dev 0.10.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 | /***************************************************************************
* Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XFUNCTORVIEW_HPP
#define XFUNCTORVIEW_HPP
#include <algorithm>
#include <array>
#include <cstddef>
#include <type_traits>
#include <utility>
#include "xtensor/xexpression.hpp"
#include "xtensor/xiterator.hpp"
#include "xtensor/xsemantic.hpp"
#include "xtensor/xutils.hpp"
#include "xtensor/xarray.hpp"
#include "xtensor/xtensor.hpp"
namespace xt
{
/****************************
* xfunctorview declaration *
****************************/
template <class F, class IT>
class xfunctor_iterator;
template <class F, class ST>
class xfunctor_stepper;
template <class F, class CT>
class xfunctorview;
/*******************************
* xfunctorview_temporary_type *
*******************************/
namespace detail
{
template <class F, class S, layout_type L>
struct functorview_temporary_type_impl
{
using type = xarray<typename F::value_type, L>;
};
template <class F, class T, std::size_t N, layout_type L>
struct functorview_temporary_type_impl<F, std::array<T, N>, L>
{
using type = xtensor<typename F::value_type, N, L>;
};
}
template <class F, class E>
struct xfunctorview_temporary_type
{
using type = typename detail::functorview_temporary_type_impl<F, typename E::shape_type, E::static_layout>::type;
};
template <class F, class CT>
struct xcontainer_inner_types<xfunctorview<F, CT>>
{
using xexpression_type = std::decay_t<CT>;
using temporary_type = typename xfunctorview_temporary_type<F, xexpression_type>::type;
};
#define DL DEFAULT_LAYOUT
/**
* @class xfunctorview
* @brief View of an xexpression .
*
* The xfunctorview class is an expression addressing its elements by applying a functor to the
* corresponding element of an underlying expression. Unlike e.g. xgenerator, an xfunctorview is
* an lvalue. It is used e.g. to access real and imaginary parts of complex expressions.
* expressions.
* xfunctorview is not meant to be used directly, but through helper functions such
* as \ref real or \ref imag.
*
* @tparam F the functor type to be applied to the elements of specified expression.
* @tparam CT the closure type of the \ref xexpression type underlying this view
*
* @sa real, imag
*/
template <class F, class CT>
class xfunctorview : public xview_semantic<xfunctorview<F, CT>>
{
public:
using self_type = xfunctorview<F, CT>;
using xexpression_type = std::decay_t<CT>;
using semantic_base = xview_semantic<self_type>;
using functor_type = typename std::decay_t<F>;
using value_type = typename functor_type::value_type;
using reference = typename functor_type::reference;
using const_reference = typename functor_type::const_reference;
using pointer = typename functor_type::pointer;
using const_pointer = typename functor_type::const_pointer;
using size_type = typename xexpression_type::size_type;
using difference_type = typename xexpression_type::difference_type;
using shape_type = typename xexpression_type::shape_type;
using stepper = xfunctor_stepper<functor_type, typename xexpression_type::stepper>;
using const_stepper = xfunctor_stepper<functor_type, typename xexpression_type::const_stepper>;
using iterator = xfunctor_iterator<functor_type, typename xexpression_type::iterator>;
using const_iterator = xfunctor_iterator<functor_type, typename xexpression_type::const_iterator>;
template <layout_type L>
using broadcast_iterator = xfunctor_iterator<functor_type, typename xexpression_type::template broadcast_iterator<L>>;
template <layout_type L>
using const_broadcast_iterator = xfunctor_iterator<functor_type, typename xexpression_type::template const_broadcast_iterator<L>>;
template <class S, layout_type L>
using shaped_xiterator = xfunctor_iterator<functor_type, xiterator<typename xexpression_type::stepper, S, L>>;
template <class S, layout_type L>
using const_shaped_xiterator = xfunctor_iterator<functor_type, xiterator<typename xexpression_type::const_stepper, S, L>>;
using reverse_iterator = xfunctor_iterator<functor_type, typename xexpression_type::reverse_iterator>;
using const_reverse_iterator = xfunctor_iterator<functor_type, typename xexpression_type::const_reverse_iterator>;
template <layout_type L>
using reverse_broadcast_iterator = xfunctor_iterator<functor_type, typename xexpression_type::template reverse_broadcast_iterator<L>>;
template <layout_type L>
using const_reverse_broadcast_iterator = xfunctor_iterator<functor_type, typename xexpression_type::template const_reverse_broadcast_iterator<L>>;
template <class S, layout_type L>
using reverse_shaped_xiterator = xfunctor_iterator<functor_type, typename xexpression_type::template reverse_shaped_xiterator<S, L>>;
template <class S, layout_type L>
using const_reverse_shaped_xiterator = xfunctor_iterator<functor_type, typename xexpression_type::template const_reverse_shaped_xiterator<S, L>>;
static constexpr layout_type static_layout = xexpression_type::static_layout;
static constexpr bool contiguous_layout = false;
xfunctorview(CT) noexcept;
template <class Func, class E>
xfunctorview(Func&&, E&&) noexcept;
template <class E>
self_type& operator=(const xexpression<E>& e);
template <class E>
disable_xexpression<E, self_type>& operator=(const E& e);
size_type size() const noexcept;
size_type dimension() const noexcept;
const shape_type& shape() const noexcept;
layout_type layout() const noexcept;
template <class... Args>
reference operator()(Args... args);
reference operator[](const xindex& index);
reference operator[](size_type i);
template <class IT>
reference element(IT first, IT last);
template <class... Args>
const_reference operator()(Args... args) const;
const_reference operator[](const xindex& index) const;
const_reference operator[](size_type i) const;
template <class IT>
const_reference element(IT first, IT last) const;
template <class S>
bool broadcast_shape(S& shape) const;
template <class S>
bool is_trivial_broadcast(const S& strides) const;
iterator begin() noexcept;
iterator end() noexcept;
const_iterator begin() const noexcept;
const_iterator end() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
template <layout_type L = DL>
broadcast_iterator<L> xbegin() noexcept;
template <layout_type L = DL>
broadcast_iterator<L> xend() noexcept;
template <layout_type L = DL>
const_broadcast_iterator<L> xbegin() const noexcept;
template <layout_type L = DL>
const_broadcast_iterator<L> xend() const noexcept;
template <layout_type L = DL>
const_broadcast_iterator<L> cxbegin() const noexcept;
template <layout_type L = DL>
const_broadcast_iterator<L> cxend() const noexcept;
template <class S, layout_type L = DL>
shaped_xiterator<S, L> xbegin(const S& shape) noexcept;
template <class S, layout_type L = DL>
shaped_xiterator<S, L> xend(const S& shape) noexcept;
template <class S, layout_type L = DL>
const_shaped_xiterator<S, L> xbegin(const S& shape) const noexcept;
template <class S, layout_type L = DL>
const_shaped_xiterator<S, L> xend(const S& shape) const noexcept;
template <class S, layout_type L = DL>
const_shaped_xiterator<S, L> cxbegin(const S& shape) const noexcept;
template <class S, layout_type L = DL>
const_shaped_xiterator<S, L> cxend(const S& shape) const noexcept;
reverse_iterator rbegin() noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rbegin() const noexcept;
const_reverse_iterator rend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
template <layout_type L = DL>
reverse_broadcast_iterator<L> xrbegin() noexcept;
template <layout_type L = DL>
reverse_broadcast_iterator<L> xrend() noexcept;
template <layout_type L = DL>
const_reverse_broadcast_iterator<L> xrbegin() const noexcept;
template <layout_type L = DL>
const_reverse_broadcast_iterator<L> xrend() const noexcept;
template <layout_type L = DL>
const_reverse_broadcast_iterator<L> cxrbegin() const noexcept;
template <layout_type L = DL>
const_reverse_broadcast_iterator<L> cxrend() const noexcept;
template <class S, layout_type L = DL>
reverse_shaped_xiterator<S, L> xrbegin(const S& shape) noexcept;
template <class S, layout_type L = DL>
reverse_shaped_xiterator<S, L> xrend(const S& shape) noexcept;
template <class S, layout_type L = DL>
const_reverse_shaped_xiterator<S, L> xrbegin(const S& shape) const noexcept;
template <class S, layout_type L = DL>
const_reverse_shaped_xiterator<S, L> xrend(const S& shape) const noexcept;
template <class S, layout_type L = DL>
const_reverse_shaped_xiterator<S, L> cxrbegin(const S& shape) const noexcept;
template <class S, layout_type L = DL>
const_reverse_shaped_xiterator<S, L> cxrend(const S& shape) const noexcept;
template <class S>
stepper stepper_begin(const S& shape) noexcept;
template <class S>
stepper stepper_end(const S& shape, layout_type l) noexcept;
template <class S>
const_stepper stepper_begin(const S& shape) const noexcept;
template <class S>
const_stepper stepper_end(const S& shape, layout_type l) const noexcept;
private:
CT m_e;
functor_type m_functor;
using temporary_type = typename xcontainer_inner_types<self_type>::temporary_type;
void assign_temporary_impl(temporary_type&& tmp);
friend class xview_semantic<xfunctorview<F, CT>>;
};
#undef DL
/*********************************
* xfunctor_iterator declaration *
*********************************/
template <class F, class IT>
class xfunctor_iterator
{
public:
using functor_type = std::decay_t<F>;
using value_type = typename functor_type::value_type;
using subiterator_traits = std::iterator_traits<IT>;
using reference = apply_cv_t<typename subiterator_traits::reference, value_type>;
using pointer = std::remove_reference_t<reference>*;
using difference_type = typename subiterator_traits::difference_type;
using iterator_category = typename subiterator_traits::iterator_category;
using self_type = xfunctor_iterator<F, IT>;
xfunctor_iterator(const IT&, const functor_type*);
self_type& operator++();
self_type operator++(int);
reference operator*() const;
pointer operator->() const;
bool equal(const xfunctor_iterator& rhs) const;
private:
IT m_it;
const functor_type* p_functor;
template <class F_, class IT_>
friend xfunctor_iterator<F_, IT_> operator+(xfunctor_iterator<F_, IT_>, xfunctor_iterator<F_, IT_>);
template <class F_, class IT_>
friend typename xfunctor_iterator<F_, IT_>::difference_type operator-(xfunctor_iterator<F_, IT_>, xfunctor_iterator<F_, IT_>);
};
template <class F, class IT>
bool operator==(const xfunctor_iterator<F, IT>& lhs,
const xfunctor_iterator<F, IT>& rhs);
template <class F, class IT>
bool operator!=(const xfunctor_iterator<F, IT>& lhs,
const xfunctor_iterator<F, IT>& rhs);
template <class F, class IT>
xfunctor_iterator<F, IT> operator+(xfunctor_iterator<F, IT> it1, xfunctor_iterator<F, IT> it2)
{
return xfunctor_iterator<F, IT>(it1.m_it + it2.m_it);
}
template <class F, class IT>
typename xfunctor_iterator<F, IT>::difference_type operator-(xfunctor_iterator<F, IT> it1, xfunctor_iterator<F, IT> it2)
{
return it1.m_it - it2.m_it;
}
/********************************
* xfunctor_stepper declaration *
********************************/
template <class F, class ST>
class xfunctor_stepper
{
public:
using functor_type = std::decay_t<F>;
using value_type = typename functor_type::value_type;
using reference = apply_cv_t<typename ST::reference, value_type>;
using pointer = std::remove_reference_t<reference>*;
using size_type = typename ST::size_type;
using difference_type = typename ST::difference_type;
xfunctor_stepper() = default;
xfunctor_stepper(const ST&, const functor_type*);
reference operator*() const;
void step(size_type dim, size_type n = 1);
void step_back(size_type dim, size_type n = 1);
void reset(size_type dim);
void reset_back(size_type dim);
void to_begin();
void to_end(layout_type);
bool equal(const xfunctor_stepper& rhs) const;
private:
ST m_stepper;
const functor_type* p_functor;
};
template <class F, class ST>
bool operator==(const xfunctor_stepper<F, ST>& lhs,
const xfunctor_stepper<F, ST>& rhs);
template <class F, class ST>
bool operator!=(const xfunctor_stepper<F, ST>& lhs,
const xfunctor_stepper<F, ST>& rhs);
/*******************************
* xfunctorview implementation *
*******************************/
/**
* @name Constructors
*/
//@{
/**
* Constructs an xfunctorview expression wrappering the specified \ref xexpression.
*
* @param e the underlying expression
*/
template <class F, class CT>
inline xfunctorview<F, CT>::xfunctorview(CT e) noexcept
: m_e(e), m_functor(functor_type())
{
}
/**
* Constructs an xfunctorview expression wrappering the specified \ref xexpression.
*
* @param func the functor to be applied to the elements of the underlying expression.
* @param e the underlying expression
*/
template <class F, class CT>
template <class Func, class E>
inline xfunctorview<F, CT>::xfunctorview(Func&& func, E&& e) noexcept
: m_e(std::forward<E>(e)), m_functor(std::forward<Func>(func))
{
}
//@}
/**
* @name Extended copy semantic
*/
//@{
/**
* The extended assignment operator.
*/
template <class F, class CT>
template <class E>
inline auto xfunctorview<F, CT>::operator=(const xexpression<E>& e) -> self_type&
{
bool cond = (e.derived_cast().shape().size() == dimension()) && std::equal(shape().begin(), shape().end(), e.derived_cast().shape().begin());
if (!cond)
{
semantic_base::operator=(broadcast(e.derived_cast(), shape()));
}
else
{
semantic_base::operator=(e);
}
return *this;
}
//@}
template <class F, class CT>
template <class E>
inline auto xfunctorview<F, CT>::operator=(const E& e) -> disable_xexpression<E, self_type>&
{
std::fill(begin(), end(), e);
return *this;
}
template <class F, class CT>
inline void xfunctorview<F, CT>::assign_temporary_impl(temporary_type&& tmp)
{
std::copy(tmp.cbegin(), tmp.cend(), xbegin());
}
/**
* @name Size and shape
*/
/**
* Returns the size of the expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::size() const noexcept -> size_type
{
return m_e.size();
}
/**
* Returns the number of dimensions of the expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::dimension() const noexcept -> size_type
{
return m_e.dimension();
}
/**
* Returns the shape of the expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::shape() const noexcept -> const shape_type&
{
return m_e.shape();
}
/**
* Returns the layout_type of the expression.
*/
template <class F, class CT>
inline layout_type xfunctorview<F, CT>::layout() const noexcept
{
return m_e.layout();
}
//@}
/**
* @name Data
*/
/**
* Returns a reference to the element at the specified position in the expression.
* @param args a list of indices specifying the position in the function. Indices
* must be unsigned integers, the number of indices should be equal or greater than
* the number of dimensions of the expression.
*/
template <class F, class CT>
template <class... Args>
inline auto xfunctorview<F, CT>::operator()(Args... args) -> reference
{
return m_functor(m_e(args...));
}
/**
* Returns a reference to the element at the specified position in the expression.
* @param index a sequence of indices specifying the position in the function. Indices
* must be unsigned integers, the number of indices in the sequence should be equal or greater
* than the number of dimensions of the container.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::operator[](const xindex& index) -> reference
{
return m_functor(m_e[index]);
}
template <class F, class CT>
inline auto xfunctorview<F, CT>::operator[](size_type i) -> reference
{
return operator()(i);
}
/**
* Returns a reference to the element at the specified position in the expression.
* @param first iterator starting the sequence of indices
* @param last iterator ending the sequence of indices
* The number of indices in the sequence should be equal to or greater
* than the number of dimensions of the function.
*/
template <class F, class CT>
template <class IT>
inline auto xfunctorview<F, CT>::element(IT first, IT last) -> reference
{
return m_functor(m_e.element(first, last));
}
/**
* Returns a constant reference to the element at the specified position in the expression.
* @param args a list of indices specifying the position in the function. Indices
* must be unsigned integers, the number of indices should be equal or greater than
* the number of dimensions of the expression.
*/
template <class F, class CT>
template <class... Args>
inline auto xfunctorview<F, CT>::operator()(Args... args) const -> const_reference
{
return m_functor(m_e(args...));
}
/**
* Returns a constant reference to the element at the specified position in the expression.
* @param index a sequence of indices specifying the position in the function. Indices
* must be unsigned integers, the number of indices in the sequence should be equal or greater
* than the number of dimensions of the container.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::operator[](const xindex& index) const -> const_reference
{
return m_functor(m_e[index]);
}
template <class F, class CT>
inline auto xfunctorview<F, CT>::operator[](size_type i) const -> const_reference
{
return operator()(i);
}
/**
* Returns a constant reference to the element at the specified position in the expression.
* @param first iterator starting the sequence of indices
* @param last iterator ending the sequence of indices
* The number of indices in the sequence should be equal to or greater
* than the number of dimensions of the function.
*/
template <class F, class CT>
template <class IT>
inline auto xfunctorview<F, CT>::element(IT first, IT last) const -> const_reference
{
return m_functor(m_e.element(first, last));
}
//@}
/**
* @name Broadcasting
*/
//@{
/**
* Broadcast the shape of the function to the specified parameter.
* @param shape the result shape
* @return a boolean indicating whether the broadcasting is trivial
*/
template <class F, class CT>
template <class S>
inline bool xfunctorview<F, CT>::broadcast_shape(S& shape) const
{
return m_e.broadcast_shape(shape);
}
/**
* Compares the specified strides with those of the container to see whether
* the broadcasting is trivial.
* @return a boolean indicating whether the broadcasting is trivial
*/
template <class F, class CT>
template <class S>
inline bool xfunctorview<F, CT>::is_trivial_broadcast(const S& strides) const
{
return m_e.is_trivial_broadcast(strides);
}
//@}
/**
* @name Iterators
*/
//@{
/**
* Returns an iterator to the first element of the expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::begin() noexcept -> iterator
{
return iterator(m_e.begin(), &m_functor);
}
/**
* Returns an iterator to the element following the last element
* of the expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::end() noexcept -> iterator
{
return iterator(m_e.end(), &m_functor);
}
/**
* Returns a constant iterator to the first element of the expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::begin() const noexcept -> const_iterator
{
return const_iterator(m_e.cbegin(), &m_functor);
}
/**
* Returns a constant iterator to the element following the last element
* of the expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::end() const noexcept -> const_iterator
{
return const_iterator(m_e.cend(), &m_functor);
}
/**
* Returns a constant iterator to the first element of the expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::cbegin() const noexcept -> const_iterator
{
return const_iterator(m_e.cbegin(), &m_functor);
}
/**
* Returns a constant iterator to the element following the last element
* of the expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::cend() const noexcept -> const_iterator
{
return const_iterator(m_e.cend(), &m_functor);
}
//@}
/**
* @name Broadcast iterators
*/
//@{
/**
* Returns an iterator to the first element of the expression.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <layout_type L>
inline auto xfunctorview<F, CT>::xbegin() noexcept -> broadcast_iterator<L>
{
return broadcast_iterator<L>(m_e.template xbegin<L>(), &m_functor);
}
/**
* Returns an iterator to the element following the last element
* of the expression.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <layout_type L>
inline auto xfunctorview<F, CT>::xend() noexcept -> broadcast_iterator<L>
{
return broadcast_iterator<L>(m_e.template xend<L>(), &m_functor);
}
/**
* Returns a constant iterator to the first element of the expression.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <layout_type L>
inline auto xfunctorview<F, CT>::xbegin() const noexcept -> const_broadcast_iterator<L>
{
return cxbegin<L>();
}
/**
* Returns a constant iterator to the element following the last element
* of the expression.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <layout_type L>
inline auto xfunctorview<F, CT>::xend() const noexcept -> const_broadcast_iterator<L>
{
return cxend<L>();
}
/**
* Returns a constant iterator to the first element of the expression.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <layout_type L>
inline auto xfunctorview<F, CT>::cxbegin() const noexcept -> const_broadcast_iterator<L>
{
return const_broadcast_iterator<L>(m_e.template cxbegin<L>(), &m_functor);
}
/**
* Returns a constant iterator to the element following the last element
* of the expression.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <layout_type L>
inline auto xfunctorview<F, CT>::cxend() const noexcept -> const_broadcast_iterator<L>
{
return const_broadcast_iterator<L>(m_e.template cxend<L>(), &m_functor);
}
/**
* Returns a constant iterator to the first element of the expression. The
* iteration is broadcasted to the specified shape.
* @param shape the shape used for broadcasting
* @tparam S type of the \c shape parameter.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <class S, layout_type L>
inline auto xfunctorview<F, CT>::xbegin(const S& shape) noexcept -> shaped_xiterator<S, L>
{
return shaped_xiterator<S, L>(m_e.template xbegin<S, L>(shape), &m_functor);
}
/**
* Returns a constant iterator to the element following the last element of the
* expression. The iteration is broadcasted to the specified shape.
* @param shape the shape used for broadcasting
* @tparam S type of the \c shape parameter.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <class S, layout_type L>
inline auto xfunctorview<F, CT>::xend(const S& shape) noexcept -> shaped_xiterator<S, L>
{
return shaped_xiterator<S, L>(m_e.template xend<S, L>(shape), &m_functor);
}
/**
* Returns a constant iterator to the first element of the expression. The
* iteration is broadcasted to the specified shape.
* @param shape the shape used for broadcasting
* @tparam S type of the \c shape parameter.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <class S, layout_type L>
inline auto xfunctorview<F, CT>::xbegin(const S& shape) const noexcept -> const_shaped_xiterator<S, L>
{
return cxbegin<S, L>(shape);
}
/**
* Returns a constant iterator to the element following the last element of the
* expression. The iteration is broadcasted to the specified shape.
* @param shape the shape used for broadcasting
* @tparam S type of the \c shape parameter.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <class S, layout_type L>
inline auto xfunctorview<F, CT>::xend(const S& shape) const noexcept -> const_shaped_xiterator<S, L>
{
return cxend<S, L>(shape);
}
/**
* Returns a constant iterator to the first element of the expression. The
* iteration is broadcasted to the specified shape.
* @param shape the shape used for broadcasting
* @tparam S type of the \c shape parameter.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <class S, layout_type L>
inline auto xfunctorview<F, CT>::cxbegin(const S& shape) const noexcept -> const_shaped_xiterator<S, L>
{
return const_shaped_xiterator<S, L>(m_e.template cxbegin<S, L>(shape), &m_functor);
}
/**
* Returns a constant iterator to the element following the last element of the
* expression. The iteration is broadcasted to the specified shape.
* @param shape the shape used for broadcasting
* @tparam S type of the \c shape parameter.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <class S, layout_type L>
inline auto xfunctorview<F, CT>::cxend(const S& shape) const noexcept -> const_shaped_xiterator<S, L>
{
return const_shaped_xiterator<S, L>(m_e.template cxend<S, L>(shape), &m_functor);
}
//@}
/**
* @name Reverse iterators
*/
//@{
/**
* Returns an iterator to the first element of the reversed expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::rbegin() noexcept -> reverse_iterator
{
return reverse_iterator(m_e.rbegin(), &m_functor);
}
/**
* Returns an iterator to the element following the last element
* of the reversed expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::rend() noexcept -> reverse_iterator
{
return reverse_iterator(m_e.rend(), &m_functor);
}
/**
* Returns a constant iterator to the first element of the reversed expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::rbegin() const noexcept -> const_reverse_iterator
{
return crbegin();
}
/**
* Returns a constant iterator to the element following the last element
* of the reversed expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::rend() const noexcept -> const_reverse_iterator
{
return crend();
}
/**
* Returns a constant iterator to the first element of the reversed expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::crbegin() const noexcept -> const_reverse_iterator
{
return const_reverse_iterator(m_e.crbegin(), &m_functor);
}
/**
* Returns a constant iterator to the element following the last element
* of the reversed expression.
*/
template <class F, class CT>
inline auto xfunctorview<F, CT>::crend() const noexcept -> const_reverse_iterator
{
return const_reverse_iterator(m_e.crend(), &m_functor);
}
//@}
/**
* @name Reverse broadcast iterators
*/
//@{
/**
* Returns an iterator to the first element of the reversed expression.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <layout_type L>
inline auto xfunctorview<F, CT>::xrbegin() noexcept -> reverse_broadcast_iterator<L>
{
return reverse_broadcast_iterator<L>(m_e.template xrbegin<L>(), &m_functor);
}
/**
* Returns an iterator to the element following the last element
* of the reversed expression.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <layout_type L>
inline auto xfunctorview<F, CT>::xrend() noexcept -> reverse_broadcast_iterator<L>
{
return reverse_broadcast_iterator<L>(m_e.template xrend<L>(), &m_functor);
}
/**
* Returns a constant iterator to the first element of the reversed expression.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <layout_type L>
inline auto xfunctorview<F, CT>::xrbegin() const noexcept -> const_reverse_broadcast_iterator<L>
{
return cxrbegin<L>();
}
/**
* Returns a constant iterator to the element following the last element
* of the reversed expression.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <layout_type L>
inline auto xfunctorview<F, CT>::xrend() const noexcept -> const_reverse_broadcast_iterator<L>
{
return cxrend<L>();
}
/**
* Returns a constant iterator to the first element of the reversed expression.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <layout_type L>
inline auto xfunctorview<F, CT>::cxrbegin() const noexcept -> const_reverse_broadcast_iterator<L>
{
return const_reverse_broadcast_iterator<L>(m_e.template cxrbegin<L>(), &m_functor);
}
/**
* Returns a constant iterator to the element following the last element
* of the reversed expression.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <layout_type L>
inline auto xfunctorview<F, CT>::cxrend() const noexcept -> const_reverse_broadcast_iterator<L>
{
return const_reverse_broadcast_iterator<L>(m_e.template cxrend<L>(), &m_functor);
}
/**
* Returns an iterator to the first element of the expression. The
* iteration is broadcasted to the specified shape.
* @param shape the shape used for broadcasting
* @tparam S type of the \c shape parameter.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <class S, layout_type L>
inline auto xfunctorview<F, CT>::xrbegin(const S& shape) noexcept -> reverse_shaped_xiterator<S, L>
{
return reverse_shaped_xiterator<S, L>(m_e.template xrbegin<S, L>(shape), &m_functor);
}
/**
* Returns an iterator to the element following the last element of the
* reversed expression. The iteration is broadcasted to the specified shape.
* @param shape the shape used for broadcasting
* @tparam S type of the \c shape parameter.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <class S, layout_type L>
inline auto xfunctorview<F, CT>::xrend(const S& shape) noexcept -> reverse_shaped_xiterator<S, L>
{
return reverse_shaped_xiterator<S, L>(m_e.template xrend<S, L>(shape), &m_functor);
}
/**
* Returns a constant iterator to the first element of the reversed expression.
* The iteration is broadcasted to the specified shape.
* @param shape the shape used for broadcasting
* @tparam S type of the \c shape parameter.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <class S, layout_type L>
inline auto xfunctorview<F, CT>::xrbegin(const S& shape) const noexcept -> const_reverse_shaped_xiterator<S, L>
{
return cxrbegin<S, L>(shape);
}
/**
* Returns a constant iterator to the element following the last element
* of the reversed expression.
* @param shape the shape used for broadcasting
* @tparam S type of the \c shape parameter.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <class S, layout_type L>
inline auto xfunctorview<F, CT>::xrend(const S& shape) const noexcept -> const_reverse_shaped_xiterator<S, L>
{
return cxrend<S, L>();
}
/**
* Returns a constant iterator to the first element of the reversed expression.
* The iteration is broadcasted to the specified shape.
* @param shape the shape used for broadcasting
* @tparam S type of the \c shape parameter.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <class S, layout_type L>
inline auto xfunctorview<F, CT>::cxrbegin(const S& shape) const noexcept -> const_reverse_shaped_xiterator<S, L>
{
return const_reverse_shaped_xiterator<S, L>(m_e.template cxrbegin<S, L>(), &m_functor);
}
/**
* Returns a constant iterator to the element following the last element
* of the reversed expression.
* @param shape the shape used for broadcasting
* @tparam S type of the \c shape parameter.
* @tparam L layout used for the traversal. Default value is \c DEFAULT_LAYOUT.
*/
template <class F, class CT>
template <class S, layout_type L>
inline auto xfunctorview<F, CT>::cxrend(const S& shape) const noexcept -> const_reverse_shaped_xiterator<S, L>
{
return const_reverse_shaped_xiterator<S, L>(m_e.template cxrend<S, L>(shape), &m_functor);
}
//@}
/***************
* stepper api *
***************/
template <class F, class CT>
template <class S>
inline auto xfunctorview<F, CT>::stepper_begin(const S& shape) noexcept -> stepper
{
return stepper(m_e.stepper_begin(shape), &m_functor);
}
template <class F, class CT>
template <class S>
inline auto xfunctorview<F, CT>::stepper_end(const S& shape, layout_type l) noexcept -> stepper
{
return stepper(m_e.stepper_end(shape, l), &m_functor);
}
template <class F, class CT>
template <class S>
inline auto xfunctorview<F, CT>::stepper_begin(const S& shape) const noexcept -> const_stepper
{
const xexpression_type& const_m_e = m_e;
return const_stepper(const_m_e.stepper_begin(shape), &m_functor);
}
template <class F, class CT>
template <class S>
inline auto xfunctorview<F, CT>::stepper_end(const S& shape, layout_type l) const noexcept -> const_stepper
{
const xexpression_type& const_m_e = m_e;
return const_stepper(const_m_e.stepper_end(shape, l), &m_functor);
}
/************************************
* xfunctor_iterator implementation *
************************************/
template <class F, class IT>
xfunctor_iterator<F, IT>::xfunctor_iterator(const IT& it, const functor_type* pf)
: m_it(it), p_functor(pf)
{
}
template <class F, class IT>
auto xfunctor_iterator<F, IT>::operator++() -> self_type&
{
++m_it;
return *this;
}
template <class F, class IT>
auto xfunctor_iterator<F, IT>::operator++(int) -> self_type
{
self_type tmp(*this);
++m_it;
return tmp;
}
template <class F, class IT>
auto xfunctor_iterator<F, IT>::operator*() const -> reference
{
return (*p_functor)(*m_it);
}
template <class F, class IT>
auto xfunctor_iterator<F, IT>::operator->() const -> pointer
{
return &((*p_functor)(*m_it));
}
template <class F, class IT>
auto xfunctor_iterator<F, IT>::equal(const xfunctor_iterator& rhs) const -> bool
{
return m_it == rhs.m_it;
}
template <class F, class IT>
bool operator==(const xfunctor_iterator<F, IT>& lhs,
const xfunctor_iterator<F, IT>& rhs)
{
return lhs.equal(rhs);
}
template <class F, class IT>
bool operator!=(const xfunctor_iterator<F, IT>& lhs,
const xfunctor_iterator<F, IT>& rhs)
{
return !lhs.equal(rhs);
}
/***********************************
* xfunctor_stepper implementation *
***********************************/
template <class F, class ST>
xfunctor_stepper<F, ST>::xfunctor_stepper(const ST& stepper, const functor_type* pf)
: m_stepper(stepper), p_functor(pf)
{
}
template <class F, class ST>
auto xfunctor_stepper<F, ST>::operator*() const -> reference
{
return (*p_functor)(*m_stepper);
}
template <class F, class ST>
void xfunctor_stepper<F, ST>::step(size_type dim, size_type n)
{
m_stepper.step(dim, n);
}
template <class F, class ST>
void xfunctor_stepper<F, ST>::step_back(size_type dim, size_type n)
{
m_stepper.step_back(dim, n);
}
template <class F, class ST>
void xfunctor_stepper<F, ST>::reset(size_type dim)
{
m_stepper.reset(dim);
}
template <class F, class ST>
void xfunctor_stepper<F, ST>::reset_back(size_type dim)
{
m_stepper.reset_back(dim);
}
template <class F, class ST>
void xfunctor_stepper<F, ST>::to_begin()
{
m_stepper.to_begin();
}
template <class F, class ST>
void xfunctor_stepper<F, ST>::to_end(layout_type l)
{
m_stepper.to_end(l);
}
template <class F, class ST>
auto xfunctor_stepper<F, ST>::equal(const xfunctor_stepper& rhs) const -> bool
{
return m_stepper == rhs.m_stepper;
}
template <class F, class ST>
bool operator==(const xfunctor_stepper<F, ST>& lhs,
const xfunctor_stepper<F, ST>& rhs)
{
return lhs.equal(rhs);
}
template <class F, class ST>
bool operator!=(const xfunctor_stepper<F, ST>& lhs,
const xfunctor_stepper<F, ST>& rhs)
{
return !lhs.equal(rhs);
}
}
#endif
|