diff options
author | Gael Guennebaud <g.gael@free.fr> | 2017-02-21 15:57:25 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2017-02-21 15:57:25 +0100 |
commit | 3d200257d73d99a1f37b1cb23ce52b80264ba0d9 (patch) | |
tree | 2161f453e18959f765834626766220ca5b096a41 /Eigen/src/Core/util/ReshapedHelper.h | |
parent | f8179385bd299966bded1b99328ef1bd67faacc6 (diff) |
Add support for automatic-size deduction in reshaped, e.g.:
mat.reshaped(4,AutoSize); <-> mat.reshaped(4,mat.size()/4);
Diffstat (limited to 'Eigen/src/Core/util/ReshapedHelper.h')
-rw-r--r-- | Eigen/src/Core/util/ReshapedHelper.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Eigen/src/Core/util/ReshapedHelper.h b/Eigen/src/Core/util/ReshapedHelper.h new file mode 100644 index 000000000..b5d59cfe8 --- /dev/null +++ b/Eigen/src/Core/util/ReshapedHelper.h @@ -0,0 +1,45 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr> +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + + +#ifndef EIGEN_RESHAPED_HELPER_H +#define EIGEN_RESHAPED_HELPER_H + +namespace Eigen { + +enum AutoSize_t { AutoSize }; + +namespace internal { + +template<typename SizeType,typename OtherSize, int TotalSize> +struct get_compiletime_reshape_size { + enum { value = get_fixed_value<SizeType>::value }; +}; + +template<typename SizeType> +Index get_runtime_reshape_size(SizeType size, Index /*other*/, Index /*total*/) { + return internal::get_runtime_value(size); +} + +template<typename OtherSize, int TotalSize> +struct get_compiletime_reshape_size<AutoSize_t,OtherSize,TotalSize> { + enum { + other_size = get_fixed_value<OtherSize>::value, + value = (TotalSize==Dynamic || other_size==Dynamic) ? Dynamic : TotalSize / other_size }; +}; + +Index get_runtime_reshape_size(AutoSize_t /*size*/, Index other, Index total) { + return total/other; +} + +} + +} // end namespace Eigen + +#endif // EIGEN_RESHAPED_HELPER_H |