Eigen  5.0.1
 
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 <gael.guennebaud@inria.fr>
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// SPDX-License-Identifier: MPL-2.0
10
11#if !defined(EIGEN_PARSED_BY_DOXYGEN)
12
13public:
14// SFINAE dummy types
15
16template <typename RowIndices, typename ColIndices>
17using EnableOverload = std::enable_if_t<
18 internal::valid_indexed_view_overload<RowIndices, ColIndices>::value && internal::is_lvalue<Derived>::value, bool>;
19
20template <typename RowIndices, typename ColIndices>
21using EnableConstOverload =
22 std::enable_if_t<internal::valid_indexed_view_overload<RowIndices, ColIndices>::value, bool>;
23
24template <typename Indices>
25using EnableVectorOverload =
26 std::enable_if_t<!internal::is_valid_index_type<Indices>::value && internal::is_lvalue<Derived>::value, bool>;
27
28template <typename Indices>
29using EnableConstVectorOverload = std::enable_if_t<!internal::is_valid_index_type<Indices>::value, bool>;
30
31public:
32// Public API for 2D matrices/arrays
33
34// non-const versions
35
36 template <typename RowIndices, typename ColIndices>
37 using IndexedViewType = typename internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::ReturnType;
38
39 template <typename RowIndices, typename ColIndices, EnableOverload<RowIndices, ColIndices> = true>
40 IndexedViewType<RowIndices, ColIndices> operator()(const RowIndices& rowIndices, const ColIndices& colIndices) {
41 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), rowIndices, colIndices);
42 }
43
44template <typename RowType, size_t RowSize, typename ColIndices, typename RowIndices = Array<RowType, RowSize, 1>,
45 EnableOverload<RowIndices, ColIndices> = true>
46IndexedViewType<RowIndices, ColIndices> operator()(const RowType (&rowIndices)[RowSize], const ColIndices& colIndices) {
47 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), RowIndices{rowIndices},
48 colIndices);
49}
50
51template <typename RowIndices, typename ColType, size_t ColSize, typename ColIndices = Array<ColType, ColSize, 1>,
52 EnableOverload<RowIndices, ColIndices> = true>
53IndexedViewType<RowIndices, ColIndices> operator()(const RowIndices& rowIndices, const ColType (&colIndices)[ColSize]) {
54 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), rowIndices,
55 ColIndices{colIndices});
56}
57
58template <typename RowType, size_t RowSize, typename ColType, size_t ColSize,
59 typename RowIndices = Array<RowType, RowSize, 1>, typename ColIndices = Array<ColType, ColSize, 1>,
60 EnableOverload<RowIndices, ColIndices> = true>
61IndexedViewType<RowIndices, ColIndices> operator()(const RowType (&rowIndices)[RowSize],
62 const ColType (&colIndices)[ColSize]) {
63 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), RowIndices{rowIndices},
64 ColIndices{colIndices});
65}
66
67// const versions
68
69template <typename RowIndices, typename ColIndices>
70using ConstIndexedViewType = typename internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::ConstReturnType;
71
72template <typename RowIndices, typename ColIndices, EnableConstOverload<RowIndices, ColIndices> = true>
73ConstIndexedViewType<RowIndices, ColIndices> operator()(const RowIndices& rowIndices,
74 const ColIndices& colIndices) const {
75 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), rowIndices, colIndices);
76}
77
78template <typename RowType, size_t RowSize, typename ColIndices, typename RowIndices = Array<RowType, RowSize, 1>,
79 EnableConstOverload<RowIndices, ColIndices> = true>
80ConstIndexedViewType<RowIndices, ColIndices> operator()(const RowType (&rowIndices)[RowSize],
81 const ColIndices& colIndices) const {
82 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), RowIndices{rowIndices},
83 colIndices);
84}
85
86template <typename RowIndices, typename ColType, size_t ColSize, typename ColIndices = Array<ColType, ColSize, 1>,
87 EnableConstOverload<RowIndices, ColIndices> = true>
88ConstIndexedViewType<RowIndices, ColIndices> operator()(const RowIndices& rowIndices,
89 const ColType (&colIndices)[ColSize]) const {
90 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), rowIndices,
91 ColIndices{colIndices});
92}
93
94template <typename RowType, size_t RowSize, typename ColType, size_t ColSize,
95 typename RowIndices = Array<RowType, RowSize, 1>, typename ColIndices = Array<ColType, ColSize, 1>,
96 EnableConstOverload<RowIndices, ColIndices> = true>
97ConstIndexedViewType<RowIndices, ColIndices> operator()(const RowType (&rowIndices)[RowSize],
98 const ColType (&colIndices)[ColSize]) const {
99 return internal::IndexedViewSelector<Derived, RowIndices, ColIndices>::run(derived(), RowIndices{rowIndices},
100 ColIndices{colIndices});
101}
102
103// Public API for 1D vectors/arrays
104
105// non-const versions
106
107template <typename Indices>
108using VectorIndexedViewType = typename internal::VectorIndexedViewSelector<Derived, Indices>::ReturnType;
109
110template <typename Indices, EnableVectorOverload<Indices> = true>
111VectorIndexedViewType<Indices> operator()(const Indices& indices) {
112 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
113 return internal::VectorIndexedViewSelector<Derived, Indices>::run(derived(), indices);
114}
115
116template <typename IndexType, size_t Size, typename Indices = Array<IndexType, Size, 1>,
117 EnableVectorOverload<Indices> = true>
118VectorIndexedViewType<Indices> operator()(const IndexType (&indices)[Size]) {
119 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
120 return internal::VectorIndexedViewSelector<Derived, Indices>::run(derived(), Indices{indices});
121}
122
123// const versions
124
125template <typename Indices>
126using ConstVectorIndexedViewType = typename internal::VectorIndexedViewSelector<Derived, Indices>::ConstReturnType;
127
128template <typename Indices, EnableConstVectorOverload<Indices> = true>
129ConstVectorIndexedViewType<Indices> operator()(const Indices& indices) const {
130 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
131 return internal::VectorIndexedViewSelector<Derived, Indices>::run(derived(), indices);
132}
133
134template <typename IndexType, size_t Size, typename Indices = Array<IndexType, Size, 1>,
135 EnableConstVectorOverload<Indices> = true>
136ConstVectorIndexedViewType<Indices> operator()(const IndexType (&indices)[Size]) const {
137 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
138 return internal::VectorIndexedViewSelector<Derived, Indices>::run(derived(), Indices{indices});
139}
140
141#else // EIGEN_PARSED_BY_DOXYGEN
142
183template <typename RowIndices, typename ColIndices>
184IndexedView_or_Block operator()(const RowIndices& rowIndices, const ColIndices& colIndices);
185
190template <typename Indices>
191IndexedView_or_VectorBlock operator()(const Indices& indices);
192
193#endif // EIGEN_PARSED_BY_DOXYGEN