Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
IndexedViewMethods.inc
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2017 Gael Guennebaud <[email protected]>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#if !defined(EIGEN_PARSED_BY_DOXYGEN)
11
12public:
13// SFINAE dummy types
14
15template <typename RowIndices, typename ColIndices>
16using EnableOverload = std::enable_if_t<
17 internal::valid_indexed_view_overload<RowIndices, ColIndices>::value && internal::is_lvalue<Derived>::value, bool>;
18
19template <typename RowIndices, typename ColIndices>
20using EnableConstOverload =
21 std::enable_if_t<internal::valid_indexed_view_overload<RowIndices, ColIndices>::value, bool>;
22
23template <typename Indices>
24using EnableVectorOverload =
25 std::enable_if_t<!internal::is_valid_index_type<Indices>::value && internal::is_lvalue<Derived>::value, bool>;
26
27template <typename Indices>
28using EnableConstVectorOverload = std::enable_if_t<!internal::is_valid_index_type<Indices>::value, bool>;
29
30public:
31// Public API for 2D matrices/arrays
32
33// non-const versions
34
35 template <typename RowIndices, typename ColIndices>
36 using IndexedViewType = typename internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::ReturnType;
37
38 template <typename RowIndices, typename ColIndices, EnableOverload<RowIndices, ColIndices> = true>
39 IndexedViewType<RowIndices, ColIndices> operator()(const RowIndices& rowIndices, const ColIndices& colIndices) {
40 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), rowIndices, colIndices);
41 }
42
43template <typename RowType, size_t RowSize, typename ColIndices, typename RowIndices = Array<RowType, RowSize, 1>,
44 EnableOverload<RowIndices, ColIndices> = true>
45IndexedViewType<RowIndices, ColIndices> operator()(const RowType (&rowIndices)[RowSize], const ColIndices& colIndices) {
46 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), RowIndices{rowIndices},
47 colIndices);
48}
49
50template <typename RowIndices, typename ColType, size_t ColSize, typename ColIndices = Array<ColType, ColSize, 1>,
51 EnableOverload<RowIndices, ColIndices> = true>
52IndexedViewType<RowIndices, ColIndices> operator()(const RowIndices& rowIndices, const ColType (&colIndices)[ColSize]) {
53 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), rowIndices,
54 ColIndices{colIndices});
55}
56
57template <typename RowType, size_t RowSize, typename ColType, size_t ColSize,
58 typename RowIndices = Array<RowType, RowSize, 1>, typename ColIndices = Array<ColType, ColSize, 1>,
59 EnableOverload<RowIndices, ColIndices> = true>
60IndexedViewType<RowIndices, ColIndices> operator()(const RowType (&rowIndices)[RowSize],
61 const ColType (&colIndices)[ColSize]) {
62 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), RowIndices{rowIndices},
63 ColIndices{colIndices});
64}
65
66// const versions
67
68template <typename RowIndices, typename ColIndices>
69using ConstIndexedViewType = typename internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::ConstReturnType;
70
71template <typename RowIndices, typename ColIndices, EnableConstOverload<RowIndices, ColIndices> = true>
72ConstIndexedViewType<RowIndices, ColIndices> operator()(const RowIndices& rowIndices,
73 const ColIndices& colIndices) const {
74 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), rowIndices, colIndices);
75}
76
77template <typename RowType, size_t RowSize, typename ColIndices, typename RowIndices = Array<RowType, RowSize, 1>,
78 EnableConstOverload<RowIndices, ColIndices> = true>
79ConstIndexedViewType<RowIndices, ColIndices> operator()(const RowType (&rowIndices)[RowSize],
80 const ColIndices& colIndices) const {
81 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), RowIndices{rowIndices},
82 colIndices);
83}
84
85template <typename RowIndices, typename ColType, size_t ColSize, typename ColIndices = Array<ColType, ColSize, 1>,
86 EnableConstOverload<RowIndices, ColIndices> = true>
87ConstIndexedViewType<RowIndices, ColIndices> operator()(const RowIndices& rowIndices,
88 const ColType (&colIndices)[ColSize]) const {
89 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), rowIndices,
90 ColIndices{colIndices});
91}
92
93template <typename RowType, size_t RowSize, typename ColType, size_t ColSize,
94 typename RowIndices = Array<RowType, RowSize, 1>, typename ColIndices = Array<ColType, ColSize, 1>,
95 EnableConstOverload<RowIndices, ColIndices> = true>
96ConstIndexedViewType<RowIndices, ColIndices> operator()(const RowType (&rowIndices)[RowSize],
97 const ColType (&colIndices)[ColSize]) const {
98 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), RowIndices{rowIndices},
99 ColIndices{colIndices});
100}
101
102// Public API for 1D vectors/arrays
103
104// non-const versions
105
106template <typename Indices>
107using VectorIndexedViewType = typename internal::VectorIndexedViewSelector<Derived, Indices>::ReturnType;
108
109template <typename Indices, EnableVectorOverload<Indices> = true>
110VectorIndexedViewType<Indices> operator()(const Indices& indices) {
111 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
112 return internal::VectorIndexedViewSelector<Derived, Indices>::run(derived(), indices);
113}
114
115template <typename IndexType, size_t Size, typename Indices = Array<IndexType, Size, 1>,
116 EnableVectorOverload<Indices> = true>
117VectorIndexedViewType<Indices> operator()(const IndexType (&indices)[Size]) {
118 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
119 return internal::VectorIndexedViewSelector<Derived, Indices>::run(derived(), Indices{indices});
120}
121
122// const versions
123
124template <typename Indices>
125using ConstVectorIndexedViewType = typename internal::VectorIndexedViewSelector<Derived, Indices>::ConstReturnType;
126
127template <typename Indices, EnableConstVectorOverload<Indices> = true>
128ConstVectorIndexedViewType<Indices> operator()(const Indices& indices) const {
129 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
130 return internal::VectorIndexedViewSelector<Derived, Indices>::run(derived(), indices);
131}
132
133template <typename IndexType, size_t Size, typename Indices = Array<IndexType, Size, 1>,
134 EnableConstVectorOverload<Indices> = true>
135ConstVectorIndexedViewType<Indices> operator()(const IndexType (&indices)[Size]) const {
136 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
137 return internal::VectorIndexedViewSelector<Derived, Indices>::run(derived(), Indices{indices});
138}
139
140#else // EIGEN_PARSED_BY_DOXYGEN
141
182template <typename RowIndices, typename ColIndices>
183IndexedView_or_Block operator()(const RowIndices& rowIndices, const ColIndices& colIndices);
184
189template <typename Indices>
190IndexedView_or_VectorBlock operator()(const Indices& indices);
191
192#endif // EIGEN_PARSED_BY_DOXYGEN