wuzp
Wrong Unit? Zero Points! Compile-time checks for units, coordinate systems and points vs. vectors.
Loading...
Searching...
No Matches
TypeMatrix.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <cstddef>
5#include <tuple>
6#include <utility>
7
10#include "wuzp/core/traits.hpp"
11
12namespace wuzp {
13
14template <size_t ColsV_, typename Tuple, typename IndexSequence>
16template <size_t ColsV_, typename... Ts, size_t... RowIs>
17struct ToRowsImpl<ColsV_, std::tuple<Ts...>, std::index_sequence<RowIs...>> {
18 using type =
19 typename Cat<typename std::tuple<typename GetSubset<RowIs * ColsV_, RowIs * ColsV_ + ColsV_, 1, std::tuple<Ts...>>::type>...>::type;
20};
21
22template <size_t ColsV_, typename... Ts>
23using ToRows = ToRowsImpl<ColsV_, std::tuple<Ts...>, std::make_index_sequence<sizeof...(Ts) / ColsV_>>;
24
25template <size_t ColsV_, typename Tuple, typename IndexSequence>
27template <size_t ColsV_, typename... Ts, size_t... ColIs>
28struct ToColsImpl<ColsV_, std::tuple<Ts...>, std::index_sequence<ColIs...>> {
29 using type = typename Cat<typename std::tuple<typename GetSubset<ColIs, sizeof...(Ts), ColsV_, std::tuple<Ts...>>::type>...>::type;
30};
31
32template <size_t ColsV_, typename... Ts>
33using ToCols = ToColsImpl<ColsV_, std::tuple<Ts...>, std::make_index_sequence<ColsV_>>;
34
35template <typename Lhs, typename Rhs, typename IndexSequence>
37template <typename... TsLhs, typename... TsRhs, size_t... Is>
38struct AddTwoTuplesImpl<std::tuple<TsLhs...>, std::tuple<TsRhs...>, std::index_sequence<Is...>> {
39 using type = std::tuple<typename Sum<typename std::tuple_element<Is, std::tuple<TsLhs...>>::type,
40 typename std::tuple_element<Is, std::tuple<TsRhs...>>::type>::type...>;
41};
42
43template <typename Lhs, typename Rhs>
45template <typename... TsLhs, typename... TsRhs>
46struct AddTwoTuples<std::tuple<TsLhs...>, std::tuple<TsRhs...>> {
47 static_assert(sizeof...(TsLhs) == sizeof...(TsRhs), "Tuple sizes do not match.");
48 using type = typename AddTwoTuplesImpl<std::tuple<TsLhs...>, std::tuple<TsRhs...>, std::make_index_sequence<sizeof...(TsLhs)>>::type;
49};
50
51template <typename Lhs, typename Rhs, typename IndexSequence>
53template <typename... TsLhs, typename... TsRhs, size_t... Is>
54struct SubtractTwoTuplesImpl<std::tuple<TsLhs...>, std::tuple<TsRhs...>, std::index_sequence<Is...>> {
55 using type = std::tuple<typename Difference<typename std::tuple_element<Is, std::tuple<TsLhs...>>::type,
56 typename std::tuple_element<Is, std::tuple<TsRhs...>>::type>::type...>;
57};
58
59template <typename Lhs, typename Rhs>
61template <typename... TsLhs, typename... TsRhs>
62struct SubtractTwoTuples<std::tuple<TsLhs...>, std::tuple<TsRhs...>> {
63 static_assert(sizeof...(TsLhs) == sizeof...(TsRhs), "Tuple sizes do not match.");
64 using type = typename SubtractTwoTuplesImpl<std::tuple<TsLhs...>, std::tuple<TsRhs...>, std::make_index_sequence<sizeof...(TsLhs)>>::type;
65};
66
67template <typename Lhs, typename Rhs, typename IndexSequence>
69template <typename... TsLhs, typename... TsRhs, size_t... Is>
70struct MultiplyTwoTuplesImpl<std::tuple<TsLhs...>, std::tuple<TsRhs...>, std::index_sequence<Is...>> {
71 using type = std::tuple<typename Product<typename std::tuple_element<Is, std::tuple<TsLhs...>>::type,
72 typename std::tuple_element<Is, std::tuple<TsRhs...>>::type>::type...>;
73};
74
75template <typename Lhs, typename Rhs>
77template <typename... TsLhs, typename... TsRhs>
78struct MultiplyTwoTuples<std::tuple<TsLhs...>, std::tuple<TsRhs...>> {
79 static_assert(sizeof...(TsLhs) == sizeof...(TsRhs), "Tuple sizes do not match.");
80 using type = typename MultiplyTwoTuplesImpl<std::tuple<TsLhs...>, std::tuple<TsRhs...>, std::make_index_sequence<sizeof...(TsLhs)>>::type;
81};
82
83template <typename Lhs, typename Rhs, typename IndexSequence>
85template <typename... TsLhs, typename... TsRhs, size_t... Is>
86struct ContractTwoTuplesImpl<std::tuple<TsLhs...>, std::tuple<TsRhs...>, std::index_sequence<Is...>> {
87 using type = typename Sum<typename Product<typename std::tuple_element<Is, std::tuple<TsLhs...>>::type,
88 typename std::tuple_element<Is, std::tuple<TsRhs...>>::type>::type...>::type;
89};
90
91template <typename Lhs, typename Rhs>
93template <typename... TsLhs, typename... TsRhs>
94struct ContractTwoTuples<std::tuple<TsLhs...>, std::tuple<TsRhs...>> {
95 using type = typename ContractTwoTuplesImpl<std::tuple<TsLhs...>, std::tuple<TsRhs...>, std::make_index_sequence<sizeof...(TsLhs)>>::type;
96};
97
98template <typename Lhs, typename Rhs, typename IndexSequence>
100template <typename... TuplesLhs, typename... TuplesRhs, size_t... Is>
101struct ContractTuples<std::tuple<TuplesLhs...>, std::tuple<TuplesRhs...>, std::index_sequence<Is...>> {
102 using type = std::tuple<
103 typename ContractTwoTuples<typename std::tuple_element<Is / sizeof...(TuplesRhs), std::tuple<TuplesLhs...>>::type,
104 typename std::tuple_element<Is % sizeof...(TuplesRhs), std::tuple<TuplesRhs...>>::type>::type...>;
105};
106
109template <typename MatrixSizeT_, typename Types>
111template <int RowsV_, int ColsV_, typename... Types>
112struct TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, std::tuple<Types...>> {
113 static_assert(sizeof...(Types) == RowsV_ * ColsV_, "Number of types does not match matrix size.");
114};
115
116template <int RowsV_, int ColsV_, typename Type0, typename... Types>
118 static_assert(sizeof...(Types) + 1 == RowsV_ * ColsV_, "Number of types does not match matrix size.");
119 using type = TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, std::tuple<Type0, Types...>>;
120};
121template <int RowsV_, int ColsV_, typename TypeT_>
125
126template <int RowsV_, int ColsV_, typename Types>
127struct IsHomogeneous<TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, Types>> {
128 static constexpr bool value = IsHomogeneous<Types>::value;
129};
130
131template <int RowsV_, int ColsV_, typename Types>
132struct GetTypes<TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, Types>> {
133 using type = Types;
134};
135
136template <int RowsV_, int ColsV_, typename Types>
137struct GetType<TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, Types>> {
138 static_assert(IsHomogeneous<TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, Types>>::value, "Types are heterogeneous.");
139 using type = typename std::tuple_element<0, typename GetTypes<TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, Types>>::type>::type;
140};
141
142template <typename Types>
143struct Dimension<TypeMatrixImpl<MatrixSize<1, 1>, Types>> {
144 static constexpr int value = 0;
145};
146template <int RowsV_, typename Types>
147struct Dimension<TypeMatrixImpl<MatrixSize<RowsV_, 1>, Types>> {
148 static constexpr int value = 1;
149};
150template <int ColsV_, typename Types>
151struct Dimension<TypeMatrixImpl<MatrixSize<1, ColsV_>, Types>> {
152 static constexpr int value = 1;
153};
154template <int RowsV_, int ColsV_, typename Types>
155struct Dimension<TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, Types>> {
156 static constexpr int value = 2;
157};
158
159template <int RowsV_, int ColsV_, typename Types>
160struct Rows<TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, Types>> {
161 static constexpr int value = RowsV_;
162};
163
164template <int RowsV_, int ColsV_, typename Types>
165struct Cols<TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, Types>> {
166 static constexpr int value = ColsV_;
167};
168
169template <int RowsV_, int ColsV_, typename... Types, int ElementRowIdV_, int ElementColIdV_>
170struct Element<TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, std::tuple<Types...>>, ElementRowIdV_, ElementColIdV_> {
171 static_assert(internal::RequireElementInRange<MatrixSize<RowsV_, ColsV_>, ElementRowIdV_, ElementColIdV_>::value);
172 using type = typename std::tuple_element<std::size_t{ElementRowIdV_ * ColsV_ + ElementColIdV_}, std::tuple<Types...>>::type;
173};
174
175template <int ColsV_, int BlockRowIdV_, int BlockColIdV_, int BlockRowsV_, int BlockColsV_, typename Tuple, typename IndexSequence>
177template <int ColsV_, int BlockRowIdV_, int BlockColIdV_, int BlockRowsV_, int BlockColsV_, typename... Ts, size_t... BlockRowIs>
178struct BlockImpl<ColsV_, BlockRowIdV_, BlockColIdV_, BlockRowsV_, BlockColsV_, std::tuple<Ts...>, std::index_sequence<BlockRowIs...>> {
179 using type = typename Cat<
180 typename GetSubset<(BlockRowIdV_ + BlockRowIs) * ColsV_ + BlockColIdV_,
181 (BlockRowIdV_ + BlockRowIs) * ColsV_ + BlockColIdV_ + BlockColsV_, 1, std::tuple<Ts...>>::type...>::type;
182};
183
184template <int RowsV_, int ColsV_, typename... Types, int BlockRowIdV_, int BlockColIdV_, int BlockRowsV_, int BlockColsV_>
185struct Block<TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, std::tuple<Types...>>, BlockRowIdV_, BlockColIdV_, BlockRowsV_, BlockColsV_> {
186 static_assert(BlockRowIdV_ >= 0 && BlockColIdV_ >= 0, "Block top left corner is out of range.");
187 static_assert(BlockRowIdV_ + BlockRowsV_ <= RowsV_ && BlockColIdV_ + BlockColsV_ <= ColsV_, "Block bottom right corner is out of range.");
189 typename BlockImpl<ColsV_, BlockRowIdV_, BlockColIdV_, BlockRowsV_, BlockColsV_, std::tuple<Types...>,
190 std::make_index_sequence<std::size_t{BlockRowsV_}>>::type>;
191};
192
193template <int RowsLhsV_, int ColsLhsV_, typename... TypesLhs, int RowsRhsV_, int ColsRhsV_, typename... TypesRhs>
194struct Sum<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>,
195 TypeMatrixImpl<MatrixSize<RowsRhsV_, ColsRhsV_>, std::tuple<TypesRhs...>>> {
196 static_assert(RowsLhsV_ == RowsRhsV_, "Matrix sizes do not match.");
197 static_assert(ColsLhsV_ == ColsRhsV_, "Matrix sizes do not match.");
198 using type =
199 TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsRhsV_>, typename AddTwoTuples<std::tuple<TypesLhs...>, std::tuple<TypesRhs...>>::type>;
200};
201
202template <int RowsLhsV_, int ColsLhsV_, typename... TypesLhs, int RowsRhsV_, int ColsRhsV_, typename... TypesRhs>
203struct Difference<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>,
204 TypeMatrixImpl<MatrixSize<RowsRhsV_, ColsRhsV_>, std::tuple<TypesRhs...>>> {
205 static_assert(RowsLhsV_ == RowsRhsV_, "Matrix sizes do not match.");
206 static_assert(ColsLhsV_ == ColsRhsV_, "Matrix sizes do not match.");
207 using type =
208 TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsRhsV_>, typename SubtractTwoTuples<std::tuple<TypesLhs...>, std::tuple<TypesRhs...>>::type>;
209};
210
211// Product of type matrix and type.
212template <int RowsLhsV_, int ColsLhsV_, typename... TypesLhs, typename TypeRhs>
213struct Product<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>, TypeRhs> {
214 using type = TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<typename Product<TypesLhs, TypeRhs>::type...>>;
215};
216// Product of type and type matrix.
217template <typename TypeLhs, int RowsRhsV_, int ColsRhsV_, typename... TypesRhs>
218struct Product<TypeLhs, TypeMatrixImpl<MatrixSize<RowsRhsV_, ColsRhsV_>, std::tuple<TypesRhs...>>> {
219 using type = typename Product<TypeMatrixImpl<MatrixSize<RowsRhsV_, ColsRhsV_>, std::tuple<TypesRhs...>>, TypeLhs>::type;
220};
221// Product of two type matrices. The right one is a 1x1 matrix, the left one can be a 1x1 matrix as well.
222template <int RowsLhsV_, int ColsLhsV_, typename... TypesLhs, typename TypeRhs>
223struct Product<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>,
224 TypeMatrixImpl<MatrixSize<1, 1>, std::tuple<TypeRhs>>> {
225 using type = typename Product<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>, TypeRhs>::type;
226};
227// Product of two type matrices. The left one is a 1x1 matrix, the right one is not.
228template <typename TypeLhs, int RowsRhsV_, int ColsRhsV_, typename Type0Rhs, typename Type1Rhs, typename... TypesRhs>
229struct Product<TypeMatrixImpl<MatrixSize<1, 1>, std::tuple<TypeLhs>>,
230 TypeMatrixImpl<MatrixSize<RowsRhsV_, ColsRhsV_>, std::tuple<Type0Rhs, Type1Rhs, TypesRhs...>>> {
231 using type =
232 typename Product<TypeLhs, TypeMatrixImpl<MatrixSize<RowsRhsV_, ColsRhsV_>, std::tuple<Type0Rhs, Type1Rhs, TypesRhs...>>>::type;
233};
234// Product of two type matrices. None of them is a 1x1 matrix.
235template <int RowsLhsV_, int ColsLhsV_, typename Type0Lhs, typename Type1Lhs, typename... TypesLhs, int RowsRhsV_, int ColsRhsV_,
236 typename Type0Rhs, typename Type1Rhs, typename... TypesRhs>
237struct Product<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<Type0Lhs, Type1Lhs, TypesLhs...>>,
238 TypeMatrixImpl<MatrixSize<RowsRhsV_, ColsRhsV_>, std::tuple<Type0Rhs, Type1Rhs, TypesRhs...>>> {
239 static_assert(RowsLhsV_ == RowsRhsV_, "Matrix sizes do not match.");
240 static_assert(ColsLhsV_ == ColsRhsV_, "Matrix sizes do not match.");
241 using type =
242 TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, typename MultiplyTwoTuples<std::tuple<Type0Lhs, Type1Lhs, TypesLhs...>,
243 std::tuple<Type0Rhs, Type1Rhs, TypesRhs...>>::type>;
244};
245
246template <int RowsLhsV_, int ColsLhsV_, typename... TypesLhs, int RowsRhsV_, int ColsRhsV_, typename... TypesRhs>
247struct InnerProduct<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>,
248 TypeMatrixImpl<MatrixSize<RowsRhsV_, ColsRhsV_>, std::tuple<TypesRhs...>>> {
249 static_assert(ColsLhsV_ == RowsRhsV_, "Matrix sizes do not match.");
251 typename ContractTuples<typename ToRows<std::size_t{ColsLhsV_}, TypesLhs...>::type,
252 typename ToCols<std::size_t{ColsRhsV_}, TypesRhs...>::type,
253 std::make_index_sequence<std::size_t{RowsLhsV_ * ColsRhsV_}>>::type>;
254};
255
256template <int N, typename T>
258 template <typename... Args>
259 using type = typename CreateHomogeneousTupleImpl<N - 1, T>::template type<T, Args...>;
260};
261
262template <typename T>
264 template <typename... Args>
265 using type = std::tuple<Args...>;
266};
267
268template <int N, typename T>
272
273template <int RowsLhsV_, int ColsLhsV_, typename... TypesLhs, int RowsRhsV_, int ColsRhsV_, typename... TypesRhs>
274struct OuterProduct<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>,
275 TypeMatrixImpl<MatrixSize<RowsRhsV_, ColsRhsV_>, std::tuple<TypesRhs...>>> {
276 static_assert(std::min(RowsLhsV_, RowsRhsV_) <= 1,
277 "Hypermatrices are not supported. At least one of the matrices must be a scalar or a vector.");
278 static_assert(std::min(ColsLhsV_, ColsRhsV_) <= 1,
279 "Hypermatrices are not supported. At least one of the matrices must be a scalar or a vector.");
281 MatrixSize<RowsLhsV_ + RowsRhsV_ - 1, ColsLhsV_ + ColsRhsV_ - 1>,
282 typename IfThenElse<
283 RowsLhsV_ == 1,
284 typename Cat<typename MultiplyTwoTuples<std::tuple<TypesLhs...>,
285 typename CreateHomogeneousTuple<sizeof...(TypesLhs), TypesRhs>::type>::type...>::type,
286 typename Cat<typename MultiplyTwoTuples<
287 std::tuple<TypesRhs...>, typename CreateHomogeneousTuple<sizeof...(TypesRhs), TypesLhs>::type>::type...>::type>::type>;
288};
289
290template <int RowsLhsV_, int ColsLhsV_, typename... TypesLhs, int RowsRhsV_, int ColsRhsV_, typename... TypesRhs>
291struct DotProduct<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>,
292 TypeMatrixImpl<MatrixSize<RowsRhsV_, ColsRhsV_>, std::tuple<TypesRhs...>>> {
293 static_assert(RowsLhsV_ == RowsRhsV_, "Matrix sizes do not match.");
294 static_assert(ColsLhsV_ == 1, "Dot product is only defined for vectors.");
295 static_assert(ColsRhsV_ == 1, "Dot product is only defined for vectors.");
296 using type = typename InnerProduct<typename Transpose<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>>::type,
298};
299
300template <int RowsLhsV_, int ColsLhsV_, typename... TypesLhs, int RowsRhsV_, int ColsRhsV_, typename... TypesRhs>
301struct CrossProduct<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>,
302 TypeMatrixImpl<MatrixSize<RowsRhsV_, ColsRhsV_>, std::tuple<TypesRhs...>>> {
303 static_assert(RowsLhsV_ == 3 && RowsRhsV_ == 3 && ColsLhsV_ == 1 && ColsRhsV_ == 1,
304 "Cross product is only defined for three-dimensional vectors.");
305 using type =
307 std::tuple<typename Difference<typename Product<std::tuple_element_t<1, std::tuple<TypesLhs...>>,
308 std::tuple_element_t<2, std::tuple<TypesRhs...>>>::type,
309 typename Product<std::tuple_element_t<2, std::tuple<TypesLhs...>>,
310 std::tuple_element_t<1, std::tuple<TypesRhs...>>>::type>::type,
311 typename Difference<typename Product<std::tuple_element_t<2, std::tuple<TypesLhs...>>,
312 std::tuple_element_t<0, std::tuple<TypesRhs...>>>::type,
313 typename Product<std::tuple_element_t<0, std::tuple<TypesLhs...>>,
314 std::tuple_element_t<2, std::tuple<TypesRhs...>>>::type>::type,
315 typename Difference<typename Product<std::tuple_element_t<0, std::tuple<TypesLhs...>>,
316 std::tuple_element_t<1, std::tuple<TypesRhs...>>>::type,
317 typename Product<std::tuple_element_t<1, std::tuple<TypesLhs...>>,
318 std::tuple_element_t<0, std::tuple<TypesRhs...>>>::type>::type>>;
319};
320
321// Division of a type matrix by a type.
322template <int RowsLhsV_, int ColsLhsV_, typename... TypesLhs, typename TypeRhs>
323struct Division<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>, TypeRhs> {
324 using type = TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<typename Division<TypesLhs, TypeRhs>::type...>>;
325};
326// Division of a type matrix by a 1x1 type matrix.
327template <int RowsLhsV_, int ColsLhsV_, typename... TypesLhs, typename TypeRhs>
328struct Division<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>,
329 TypeMatrixImpl<MatrixSize<1, 1>, std::tuple<TypeRhs>>> {
330 using type = typename Division<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>, TypeRhs>::type;
331};
332// Division of a type matrix by a type matrix.
333template <int RowsLhsV_, int ColsLhsV_, typename... TypesLhs, int RowsRhsV_, int ColsRhsV_, typename... TypesRhs>
334struct Division<TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<TypesLhs...>>,
335 TypeMatrixImpl<MatrixSize<RowsRhsV_, ColsRhsV_>, std::tuple<TypesRhs...>>> {
336 static_assert(RowsLhsV_ == RowsRhsV_, "Matrix sizes do not match.");
337 static_assert(ColsLhsV_ == ColsRhsV_, "Matrix sizes do not match.");
338 using type = TypeMatrixImpl<MatrixSize<RowsLhsV_, ColsLhsV_>, std::tuple<typename Division<TypesLhs, TypesRhs>::type...>>;
339};
340
342template <int RowsV_, int ColsV_, typename... Types>
343struct CwiseInverse<TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, std::tuple<Types...>>> {
344 using type = TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, std::tuple<typename Inverse<Types>::type...>>;
345};
346
348template <int RowsV_, int ColsV_, typename... Types, typename ExponentT_>
349struct Power<TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, std::tuple<Types...>>, ExponentT_> {
350 using type = TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, std::tuple<typename Power<Types, ExponentT_>::type...>>;
351};
352
353template <int RowsV_, int ColsV_, typename... Types>
354struct Transpose<TypeMatrixImpl<MatrixSize<RowsV_, ColsV_>, std::tuple<Types...>>> {
355 using type =
356 TypeMatrixImpl<MatrixSize<ColsV_, RowsV_>, typename ExtractAndApply<Cat, typename ToCols<std::size_t{ColsV_}, Types...>::type>::type>;
357};
358
359template <int SizeV_, typename ZeroType, typename OneType, typename IndexSequence>
361template <int SizeV_, typename ZeroType, typename OneType, size_t... Is>
362struct DiagonalTypeMatrixImpl<SizeV_, ZeroType, OneType, std::index_sequence<Is...>> {
363 using type =
364 TypeMatrixImpl<MatrixSize<SizeV_, SizeV_>, std::tuple<typename IfThenElse<Is % (SizeV_ + 1) != 0, ZeroType, OneType>::type...>>;
365};
366
367template <int SizeV_, typename ZeroType, typename OneType>
369 typename DiagonalTypeMatrixImpl<SizeV_, ZeroType, OneType, std::make_index_sequence<std::size_t{SizeV_ * SizeV_}>>::type;
370
377template <int RowsV_, int ColsV_, typename... Types>
378using TypeMatrix = typename CreateTypeMatrix<RowsV_, ColsV_, Types...>::type;
379
385template <int RowsV_, typename... Types>
386using TypeVector = typename CreateTypeMatrix<RowsV_, 1, Types...>::type;
387
392template <typename TypeT_>
394
395} // namespace wuzp
GetSubsetImpl< Start, End, Increment, Tuple, std::make_index_sequence< std::tuple_size< Tuple >::value > > GetSubset
Definition helpers.hpp:87
ToRowsImpl< ColsV_, std::tuple< Ts... >, std::make_index_sequence< sizeof...(Ts)/ColsV_ > > ToRows
decltype(std::tuple_cat(std::declval< std::array< T, std::size_t{Size}> >())) HomogeneousTuple
Definition helpers.hpp:24
typename CreateTypeMatrix< 1, 1, TypeT_ >::type TypeScalar
A scalar storing a type at compile-time.
typename DiagonalTypeMatrixImpl< SizeV_, ZeroType, OneType, std::make_index_sequence< std::size_t{SizeV_ *SizeV_}> >::type DiagonalTypeMatrix
typename CreateTypeMatrix< RowsV_, ColsV_, Types... >::type TypeMatrix
A matrix storing types at compile-time.
ToColsImpl< ColsV_, std::tuple< Ts... >, std::make_index_sequence< ColsV_ > > ToCols
typename CreateTypeMatrix< RowsV_, 1, Types... >::type TypeVector
A vector storing types at compile-time.
std::tuple< typename Sum< typename std::tuple_element< Is, std::tuple< TsLhs... > >::type, typename std::tuple_element< Is, std::tuple< TsRhs... > >::type >::type... > type
typename AddTwoTuplesImpl< std::tuple< TsLhs... >, std::tuple< TsRhs... >, std::make_index_sequence< sizeof...(TsLhs)> >::type type
typename Cat< typename GetSubset<(BlockRowIdV_+BlockRowIs) *ColsV_+BlockColIdV_,(BlockRowIdV_+BlockRowIs) *ColsV_+BlockColIdV_+BlockColsV_, 1, std::tuple< Ts... > >::type... >::type type
TypeMatrixImpl< MatrixSize< BlockRowsV_, BlockColsV_ >, typename BlockImpl< ColsV_, BlockRowIdV_, BlockColIdV_, BlockRowsV_, BlockColsV_, std::tuple< Types... >, std::make_index_sequence< std::size_t{BlockRowsV_}> >::type > type
std::tuple< typename ContractTwoTuples< typename std::tuple_element< Is/sizeof...(TuplesRhs), std::tuple< TuplesLhs... > >::type, typename std::tuple_element< Is % sizeof...(TuplesRhs), std::tuple< TuplesRhs... > >::type >::type... > type
typename Sum< typename Product< typename std::tuple_element< Is, std::tuple< TsLhs... > >::type, typename std::tuple_element< Is, std::tuple< TsRhs... > >::type >::type... >::type type
typename ContractTwoTuplesImpl< std::tuple< TsLhs... >, std::tuple< TsRhs... >, std::make_index_sequence< sizeof...(TsLhs)> >::type type
typename CreateHomogeneousTupleImpl< N - 1, T >::template type< T, Args... > type
typename CreateHomogeneousTupleImpl< N, T >::template type<> type
TypeMatrixImpl< MatrixSize< RowsV_, ColsV_ >, HomogeneousTuple< RowsV_ *ColsV_, TypeT_ > > type
TypeMatrixImpl< MatrixSize< RowsV_, ColsV_ >, std::tuple< Type0, Types... > > type
TypeMatrixImpl< MatrixSize< RowsLhsV_, ColsLhsV_ >, std::tuple< typename Difference< typename Product< std::tuple_element_t< 1, std::tuple< TypesLhs... > >, std::tuple_element_t< 2, std::tuple< TypesRhs... > > >::type, typename Product< std::tuple_element_t< 2, std::tuple< TypesLhs... > >, std::tuple_element_t< 1, std::tuple< TypesRhs... > > >::type >::type, typename Difference< typename Product< std::tuple_element_t< 2, std::tuple< TypesLhs... > >, std::tuple_element_t< 0, std::tuple< TypesRhs... > > >::type, typename Product< std::tuple_element_t< 0, std::tuple< TypesLhs... > >, std::tuple_element_t< 2, std::tuple< TypesRhs... > > >::type >::type, typename Difference< typename Product< std::tuple_element_t< 0, std::tuple< TypesLhs... > >, std::tuple_element_t< 1, std::tuple< TypesRhs... > > >::type, typename Product< std::tuple_element_t< 1, std::tuple< TypesLhs... > >, std::tuple_element_t< 0, std::tuple< TypesRhs... > > >::type >::type > > type
TypeMatrixImpl< MatrixSize< RowsV_, ColsV_ >, std::tuple< typename Inverse< Types >::type... > > type
The elementwise reciprocal of a matrix, like Eigen's ArrayBase::inverse() or cwiseInverse().
Definition traits.hpp:194
TypeMatrixImpl< MatrixSize< SizeV_, SizeV_ >, std::tuple< typename IfThenElse< Is %(SizeV_+1) !=0, ZeroType, OneType >::type... > > type
TypeMatrixImpl< MatrixSize< RowsLhsV_, ColsRhsV_ >, typename SubtractTwoTuples< std::tuple< TypesLhs... >, std::tuple< TypesRhs... > >::type > type
TypeMatrixImpl< MatrixSize< RowsLhsV_, ColsLhsV_ >, std::tuple< typename Division< TypesLhs, TypeRhs >::type... > > type
typename Division< TypeMatrixImpl< MatrixSize< RowsLhsV_, ColsLhsV_ >, std::tuple< TypesLhs... > >, TypeRhs >::type type
typename InnerProduct< typename Transpose< TypeMatrixImpl< MatrixSize< RowsLhsV_, ColsLhsV_ >, std::tuple< TypesLhs... > > >::type, TypeMatrixImpl< MatrixSize< RowsRhsV_, ColsRhsV_ >, std::tuple< TypesRhs... > > >::type type
typename std::tuple_element< std::size_t{ElementRowIdV_ *ColsV_+ElementColIdV_}, std::tuple< Types... > >::type type
typename std::tuple_element< 0, typename GetTypes< TypeMatrixImpl< MatrixSize< RowsV_, ColsV_ >, Types > >::type >::type type
Trait to select one type or another depending on a boolean. Note that both types must be defined even...
Definition helpers.hpp:51
TypeMatrixImpl< MatrixSize< RowsLhsV_, ColsRhsV_ >, typename ContractTuples< typename ToRows< std::size_t{ColsLhsV_}, TypesLhs... >::type, typename ToCols< std::size_t{ColsRhsV_}, TypesRhs... >::type, std::make_index_sequence< std::size_t{RowsLhsV_ *ColsRhsV_}> >::type > type
static constexpr bool value
Definition helpers.hpp:101
std::tuple< typename Product< typename std::tuple_element< Is, std::tuple< TsLhs... > >::type, typename std::tuple_element< Is, std::tuple< TsRhs... > >::type >::type... > type
typename MultiplyTwoTuplesImpl< std::tuple< TsLhs... >, std::tuple< TsRhs... >, std::make_index_sequence< sizeof...(TsLhs)> >::type type
TypeMatrixImpl< MatrixSize< RowsLhsV_+RowsRhsV_ - 1, ColsLhsV_+ColsRhsV_ - 1 >, typename IfThenElse< RowsLhsV_==1, typename Cat< typename MultiplyTwoTuples< std::tuple< TypesLhs... >, typename CreateHomogeneousTuple< sizeof...(TypesLhs), TypesRhs >::type >::type... >::type, typename Cat< typename MultiplyTwoTuples< std::tuple< TypesRhs... >, typename CreateHomogeneousTuple< sizeof...(TypesRhs), TypesLhs >::type >::type... >::type >::type > type
TypeMatrixImpl< MatrixSize< RowsV_, ColsV_ >, std::tuple< typename Power< Types, ExponentT_ >::type... > > type
typename Product< TypeMatrixImpl< MatrixSize< RowsRhsV_, ColsRhsV_ >, std::tuple< TypesRhs... > >, TypeLhs >::type type
typename Product< TypeLhs, TypeMatrixImpl< MatrixSize< RowsRhsV_, ColsRhsV_ >, std::tuple< Type0Rhs, Type1Rhs, TypesRhs... > > >::type type
typename Product< TypeMatrixImpl< MatrixSize< RowsLhsV_, ColsLhsV_ >, std::tuple< TypesLhs... > >, TypeRhs >::type type
TypeMatrixImpl< MatrixSize< RowsLhsV_, ColsLhsV_ >, std::tuple< typename Product< TypesLhs, TypeRhs >::type... > > type
TypeMatrixImpl< MatrixSize< RowsLhsV_, ColsLhsV_ >, typename MultiplyTwoTuples< std::tuple< Type0Lhs, Type1Lhs, TypesLhs... >, std::tuple< Type0Rhs, Type1Rhs, TypesRhs... > >::type > type
std::tuple< typename Difference< typename std::tuple_element< Is, std::tuple< TsLhs... > >::type, typename std::tuple_element< Is, std::tuple< TsRhs... > >::type >::type... > type
typename SubtractTwoTuplesImpl< std::tuple< TsLhs... >, std::tuple< TsRhs... >, std::make_index_sequence< sizeof...(TsLhs)> >::type type
TypeMatrixImpl< MatrixSize< RowsLhsV_, ColsRhsV_ >, typename AddTwoTuples< std::tuple< TypesLhs... >, std::tuple< TypesRhs... > >::type > type
typename Cat< typename std::tuple< typename GetSubset< ColIs, sizeof...(Ts), ColsV_, std::tuple< Ts... > >::type >... >::type type
typename Cat< typename std::tuple< typename GetSubset< RowIs *ColsV_, RowIs *ColsV_+ColsV_, 1, std::tuple< Ts... > >::type >... >::type type
TypeMatrixImpl< MatrixSize< ColsV_, RowsV_ >, typename ExtractAndApply< Cat, typename ToCols< std::size_t{ColsV_}, Types... >::type >::type > type
A matrix of the types in the std::tuple Types, row by row, of the size MatrixSizeT_,...