Eigen  5.0.1-dev+master
 
Loading...
Searching...
No Matches
ReshapedHelper.h
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#ifndef EIGEN_RESHAPED_HELPER_H
12#define EIGEN_RESHAPED_HELPER_H
13
14// IWYU pragma: private
15#include "../InternalHeaderCheck.h"
16
17namespace Eigen {
18
19enum AutoSize_t { AutoSize };
20const int AutoOrder = 2;
21
22namespace internal {
23
24template <typename SizeType, typename OtherSize, int TotalSize>
25struct get_compiletime_reshape_size : get_fixed_value<SizeType> {};
26
27template <typename SizeType>
28Index get_runtime_reshape_size(SizeType size, Index /*other*/, Index /*total*/) {
29 return internal::get_runtime_value(size);
30}
31
32template <typename OtherSize, int TotalSize>
33struct get_compiletime_reshape_size<AutoSize_t, OtherSize, TotalSize> {
34 enum {
35 other_size = get_fixed_value<OtherSize>::value,
36 // An empty reshape with a zero other size has no preferred size: choose 0 rather than dividing 0 by 0.
37 value = (TotalSize == Dynamic || other_size == Dynamic) ? Dynamic
38 : other_size == 0 ? 0
39 : TotalSize / other_size
40 };
41};
42
43inline Index get_runtime_reshape_size(AutoSize_t /*size*/, Index other, Index total) {
44 // total == 0 and other == 0: any size is consistent, choose 0. (total != 0 is rejected by Reshaped's size assertion.)
45 return other == 0 ? Index(0) : total / other;
46}
47
48constexpr int get_compiletime_reshape_order(int flags, int order) {
49 return order == AutoOrder ? flags & RowMajorBit : order;
50}
51
52} // namespace internal
53
54} // end namespace Eigen
55
56#endif // EIGEN_RESHAPED_HELPER_H
constexpr unsigned int RowMajorBit
Definition Constants.h:71