File indexing completed on 2025-01-18 09:43:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_NUMERIC_UBLAS_OPERATION_SIZE_HPP
0016 #define BOOST_NUMERIC_UBLAS_OPERATION_SIZE_HPP
0017
0018
0019 #include <boost/mpl/has_xxx.hpp>
0020 #include <boost/mpl/if.hpp>
0021 #include <boost/numeric/ublas/detail/config.hpp>
0022 #include <boost/numeric/ublas/expression_types.hpp>
0023 #include <boost/numeric/ublas/fwd.hpp>
0024 #include <boost/numeric/ublas/tags.hpp>
0025 #include <boost/numeric/ublas/traits.hpp>
0026 #include <boost/utility/enable_if.hpp>
0027 #include <cstddef>
0028
0029
0030 namespace boost { namespace numeric { namespace ublas {
0031
0032 namespace detail { namespace {
0033
0034
0035 BOOST_MPL_HAS_XXX_TRAIT_DEF(size_type)
0036
0037
0038
0039
0040
0041
0042
0043 template <typename VectorT>
0044 struct vector_size_type
0045 {
0046
0047 typedef typename vector_traits<VectorT>::size_type type;
0048 };
0049
0050
0051
0052
0053
0054
0055 template <typename MatrixT>
0056 struct matrix_size_type
0057 {
0058
0059 typedef typename matrix_traits<MatrixT>::size_type type;
0060 };
0061
0062
0063
0064
0065
0066
0067
0068
0069 template <std::size_t Dim, typename CategoryT>
0070 struct size_by_dim_impl;
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 template <typename TagT, typename CategoryT, typename OrientationT>
0081 struct size_by_tag_impl;
0082
0083
0084
0085
0086
0087
0088 template <>
0089 struct size_by_dim_impl<1, vector_tag>
0090 {
0091
0092
0093
0094
0095
0096 template <typename ExprT>
0097 BOOST_UBLAS_INLINE
0098 static typename vector_traits<ExprT>::size_type apply(vector_expression<ExprT> const& ve)
0099 {
0100 return ve().size();
0101 }
0102 };
0103
0104
0105
0106
0107
0108
0109 template <>
0110 struct size_by_dim_impl<1, matrix_tag>
0111 {
0112
0113
0114
0115
0116
0117 template <typename ExprT>
0118 BOOST_UBLAS_INLINE
0119 static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
0120 {
0121 return me().size1();
0122 }
0123 };
0124
0125
0126
0127
0128
0129
0130 template <>
0131 struct size_by_dim_impl<2, matrix_tag>
0132 {
0133
0134
0135
0136
0137
0138 template <typename ExprT>
0139 BOOST_UBLAS_INLINE
0140 static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
0141 {
0142 return me().size2();
0143 }
0144 };
0145
0146
0147
0148
0149
0150
0151 template <>
0152 struct size_by_tag_impl<tag::major, matrix_tag, row_major_tag>
0153 {
0154
0155
0156
0157
0158
0159 template <typename ExprT>
0160 BOOST_UBLAS_INLINE
0161 static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
0162 {
0163 return me().size1();
0164 }
0165 };
0166
0167
0168
0169
0170
0171
0172 template <>
0173 struct size_by_tag_impl<tag::minor, matrix_tag, row_major_tag>
0174 {
0175
0176
0177
0178
0179
0180 template <typename ExprT>
0181 BOOST_UBLAS_INLINE
0182 static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
0183 {
0184 return me().size2();
0185 }
0186 };
0187
0188
0189
0190
0191
0192
0193 template <>
0194 struct size_by_tag_impl<tag::leading, matrix_tag, row_major_tag>
0195 {
0196
0197
0198
0199
0200
0201 template <typename ExprT>
0202 BOOST_UBLAS_INLINE
0203 static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
0204 {
0205 return me().size2();
0206 }
0207 };
0208
0209
0210
0211
0212 template <>
0213 struct size_by_tag_impl<tag::major, matrix_tag, column_major_tag>
0214 {
0215
0216
0217
0218
0219
0220 template <typename ExprT>
0221 BOOST_UBLAS_INLINE
0222 static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
0223 {
0224 return me().size2();
0225 }
0226 };
0227
0228
0229
0230
0231 template <>
0232 struct size_by_tag_impl<tag::minor, matrix_tag, column_major_tag>
0233 {
0234
0235
0236
0237
0238
0239 template <typename ExprT>
0240 BOOST_UBLAS_INLINE
0241 static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
0242 {
0243 return me().size1();
0244 }
0245 };
0246
0247
0248
0249
0250 template <>
0251 struct size_by_tag_impl<tag::leading, matrix_tag, column_major_tag>
0252 {
0253
0254
0255
0256
0257
0258 template <typename ExprT>
0259 BOOST_UBLAS_INLINE
0260 static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
0261 {
0262 return me().size1();
0263 }
0264 };
0265
0266
0267
0268
0269 template <typename TagT, typename CategoryT>
0270 struct size_by_tag_impl<TagT, CategoryT, unknown_orientation_tag>: size_by_tag_impl<TagT, CategoryT, row_major_tag>
0271 {
0272
0273 };
0274
0275 }}
0276
0277
0278
0279
0280
0281
0282
0283
0284 template <typename VectorExprT>
0285 BOOST_UBLAS_INLINE
0286 typename ::boost::lazy_enable_if_c<
0287 detail::has_size_type<VectorExprT>::value,
0288 detail::vector_size_type<VectorExprT>
0289 >::type size(vector_expression<VectorExprT> const& ve)
0290 {
0291 return ve().size();
0292 }
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303 template <std::size_t Dim, typename VectorExprT>
0304 BOOST_UBLAS_INLINE
0305 typename vector_traits<VectorExprT>::size_type size(vector_expression<VectorExprT> const& ve)
0306 {
0307 return detail::size_by_dim_impl<Dim, vector_tag>::apply(ve);
0308 }
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320 template <std::size_t Dim, typename MatrixExprT>
0321 BOOST_UBLAS_INLINE
0322 typename matrix_traits<MatrixExprT>::size_type size(matrix_expression<MatrixExprT> const& me)
0323 {
0324 return detail::size_by_dim_impl<Dim, matrix_tag>::apply(me);
0325 }
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337 template <typename TagT, typename MatrixExprT>
0338 BOOST_UBLAS_INLINE
0339 typename ::boost::lazy_enable_if_c<
0340 detail::has_size_type<MatrixExprT>::value,
0341 detail::matrix_size_type<MatrixExprT>
0342 >::type size(matrix_expression<MatrixExprT> const& me)
0343 {
0344 return detail::size_by_tag_impl<TagT, matrix_tag, typename matrix_traits<MatrixExprT>::orientation_category>::apply(me);
0345 }
0346
0347 }}}
0348
0349
0350 #endif