Boost.uBlas 1.49
Linear Algebra in C++: matrices, vectors and numeric algorithms

size.hpp

Go to the documentation of this file.
00001 
00015 #ifndef BOOST_NUMERIC_UBLAS_OPERATION_SIZE_HPP
00016 #define BOOST_NUMERIC_UBLAS_OPERATION_SIZE_HPP
00017 
00018 
00019 #include <boost/mpl/has_xxx.hpp> 
00020 #include <boost/mpl/if.hpp>
00021 #include <boost/numeric/ublas/detail/config.hpp>
00022 #include <boost/numeric/ublas/expression_types.hpp>
00023 #include <boost/numeric/ublas/fwd.hpp>
00024 #include <boost/numeric/ublas/tags.hpp>
00025 #include <boost/numeric/ublas/traits.hpp>
00026 #include <boost/utility/enable_if.hpp>
00027 #include <cstddef>
00028 
00029 
00030 namespace boost { namespace numeric { namespace ublas {
00031 
00032 namespace detail { namespace /*<unnamed>*/ {
00033 
00035 BOOST_MPL_HAS_XXX_TRAIT_DEF(size_type)
00036 
00037 
00038 
00043 template <typename VectorT>
00044 struct vector_size_type
00045 {
00047     typedef typename vector_traits<VectorT>::size_type type;
00048 };
00049 
00055 template <typename MatrixT>
00056 struct matrix_size_type
00057 {
00059     typedef typename matrix_traits<MatrixT>::size_type type;
00060 };
00061 
00062 
00069 template <std::size_t Dim, typename CategoryT>
00070 struct size_by_dim_impl;
00071 
00072 
00080 template <typename TagT, typename CategoryT, typename OrientationT>
00081 struct size_by_tag_impl;
00082 
00083 
00088 template <>
00089 struct size_by_dim_impl<1, vector_tag>
00090 {
00096     template <typename ExprT>
00097     BOOST_UBLAS_INLINE
00098     static typename vector_traits<ExprT>::size_type apply(vector_expression<ExprT> const& ve)
00099     {
00100         return ve().size();
00101     }
00102 };
00103 
00104 
00109 template <>
00110 struct size_by_dim_impl<1, matrix_tag>
00111 {
00117     template <typename ExprT>
00118     BOOST_UBLAS_INLINE
00119     static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
00120     {
00121         return me().size1();
00122     }
00123 };
00124 
00125 
00130 template <>
00131 struct size_by_dim_impl<2, matrix_tag>
00132 {
00138     template <typename ExprT>
00139     BOOST_UBLAS_INLINE
00140     static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
00141     {
00142         return me().size2();
00143     }
00144 };
00145 
00146 
00151 template <>
00152 struct size_by_tag_impl<tag::major, matrix_tag, row_major_tag>
00153 {
00159     template <typename ExprT>
00160     BOOST_UBLAS_INLINE
00161     static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
00162     {
00163         return me().size1();
00164     }
00165 };
00166 
00167 
00172 template <>
00173 struct size_by_tag_impl<tag::minor, matrix_tag, row_major_tag>
00174 {
00180     template <typename ExprT>
00181     BOOST_UBLAS_INLINE
00182     static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
00183     {
00184         return me().size2();
00185     }
00186 };
00187 
00188 
00193 template <>
00194 struct size_by_tag_impl<tag::leading, matrix_tag, row_major_tag>
00195 {
00201     template <typename ExprT>
00202     BOOST_UBLAS_INLINE
00203     static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
00204     {
00205         return me().size2();
00206     }
00207 };
00208 
00209 
00212 template <>
00213 struct size_by_tag_impl<tag::major, matrix_tag, column_major_tag>
00214 {
00220     template <typename ExprT>
00221     BOOST_UBLAS_INLINE
00222     static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
00223     {
00224         return me().size2();
00225     }
00226 };
00227 
00228 
00231 template <>
00232 struct size_by_tag_impl<tag::minor, matrix_tag, column_major_tag>
00233 {
00239     template <typename ExprT>
00240     BOOST_UBLAS_INLINE
00241     static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
00242     {
00243         return me().size1();
00244     }
00245 };
00246 
00247 
00250 template <>
00251 struct size_by_tag_impl<tag::leading, matrix_tag, column_major_tag>
00252 {
00258     template <typename ExprT>
00259     BOOST_UBLAS_INLINE
00260     static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
00261     {
00262         return me().size1();
00263     }
00264 };
00265 
00266 
00269 template <typename TagT, typename CategoryT>
00270 struct size_by_tag_impl<TagT, CategoryT, unknown_orientation_tag>: size_by_tag_impl<TagT, CategoryT, row_major_tag>
00271 {
00272     // Empty
00273 };
00274 
00275 }} // Namespace detail::<unnamed>
00276 
00277 
00284 template <typename VectorExprT>
00285 BOOST_UBLAS_INLINE
00286 typename ::boost::lazy_enable_if_c<
00287     detail::has_size_type<VectorExprT>::value,
00288     detail::vector_size_type<VectorExprT>
00289 >::type size(vector_expression<VectorExprT> const& ve)
00290 {
00291     return ve().size();
00292 }
00293 
00294 
00303 template <std::size_t Dim, typename VectorExprT>
00304 BOOST_UBLAS_INLINE
00305 typename vector_traits<VectorExprT>::size_type size(vector_expression<VectorExprT> const& ve)
00306 {
00307     return detail::size_by_dim_impl<Dim, vector_tag>::template apply(ve);
00308 }
00309 
00310 
00320 template <std::size_t Dim, typename MatrixExprT>
00321 BOOST_UBLAS_INLINE
00322 typename matrix_traits<MatrixExprT>::size_type size(matrix_expression<MatrixExprT> const& me)
00323 {
00324     return detail::size_by_dim_impl<Dim, matrix_tag>::template apply(me);
00325 }
00326 
00327 
00337 template <typename TagT, typename MatrixExprT>
00338 BOOST_UBLAS_INLINE
00339 typename ::boost::lazy_enable_if_c<
00340     detail::has_size_type<MatrixExprT>::value,
00341     detail::matrix_size_type<MatrixExprT>
00342 >::type size(matrix_expression<MatrixExprT> const& me)
00343 {
00344     return detail::size_by_tag_impl<TagT, matrix_tag, typename matrix_traits<MatrixExprT>::orientation_category>::template apply(me);
00345 }
00346 
00347 }}} // Namespace boost::numeric::ublas
00348 
00349 
00350 #endif // BOOST_NUMERIC_UBLAS_OPERATION_SIZE_HPP