diff options
author | Gael Guennebaud <g.gael@free.fr> | 2017-01-29 15:20:35 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2017-01-29 15:20:35 +0100 |
commit | 24409f3acdd987f2734cb3b67d5a78e1d70fd362 (patch) | |
tree | b88a1a068a4e3a573f67d1e315dc265326c200bc /Eigen/src/plugins | |
parent | 9036cda36484c4d7268b928b5976534c8ef3ce42 (diff) |
Use fix<> API to specify compile-time reshaped sizes.
Diffstat (limited to 'Eigen/src/plugins')
-rw-r--r-- | Eigen/src/plugins/ReshapedMethods.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Eigen/src/plugins/ReshapedMethods.h b/Eigen/src/plugins/ReshapedMethods.h new file mode 100644 index 000000000..20563c2f9 --- /dev/null +++ b/Eigen/src/plugins/ReshapedMethods.h @@ -0,0 +1,46 @@ + +/// \returns as expression of \c *this with reshaped sizes. +/// +/// \param nRows the number of rows in the reshaped expression, specified at either run-time or compile-time +/// \param nCols the number of columns in the reshaped expression, specified at either run-time or compile-time +/// \tparam NRowsType the type of the value handling the number of rows, typically Index. +/// \tparam NColsType the type of the value handling the number of columns, typically Index. +/// +/// Dynamic size example: \include MatrixBase_reshaped_int_int.cpp +/// Output: \verbinclude MatrixBase_reshaped_int_int.out +/// +/// The number of rows \a nRows and columns \a nCols can also be specified at compile-time by passing Eigen::fix<N>, +/// or Eigen::fix<N>(n) as arguments. In the later case, \c n plays the role of a runtime fallback value in case \c N equals Eigen::Dynamic. +/// Here is an example with a fixed number of rows and columns: +/// \include MatrixBase_reshaped_fixed.cpp +/// Output: \verbinclude MatrixBase_reshaped_fixed.out +/// +/// \sa class Reshaped, fix, fix<N>(int) +/// +template<typename NRowsType, typename NColsType> +EIGEN_DEVICE_FUNC +#ifndef EIGEN_PARSED_BY_DOXYGEN +inline Reshaped<Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value> +#else +inline Reshaped<Derived,...> +#endif +reshaped(NRowsType nRows, NColsType nCols) +{ + return Reshaped<Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>( + derived(), internal::get_runtime_value(nRows), internal::get_runtime_value(nCols)); +} + +/** This is the const version of reshaped(NRowsType,NColsType). */ +template<typename NRowsType, typename NColsType> +EIGEN_DEVICE_FUNC +#ifndef EIGEN_PARSED_BY_DOXYGEN +inline const Reshaped<const Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value> +#else +inline const Reshaped<const Derived,...> +#endif +reshaped(NRowsType nRows, NColsType nCols) const +{ + return Reshaped<const Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>( + derived(), internal::get_runtime_value(nRows), internal::get_runtime_value(nCols)); +} + |