123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- /**
- * \file size.hpp
- *
- * \brief The family of \c size operations.
- *
- * Copyright (c) 2009-2010, Marco Guazzone
- *
- * Distributed under the Boost Software License, Version 1.0. (See
- * accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * \author Marco Guazzone, marco.guazzone@gmail.com
- */
- #ifndef BOOST_NUMERIC_UBLAS_OPERATION_SIZE_HPP
- #define BOOST_NUMERIC_UBLAS_OPERATION_SIZE_HPP
- #include <boost/mpl/has_xxx.hpp>
- #include <boost/mpl/if.hpp>
- #include <boost/numeric/ublas/detail/config.hpp>
- #include <boost/numeric/ublas/expression_types.hpp>
- #include <boost/numeric/ublas/fwd.hpp>
- #include <boost/numeric/ublas/tags.hpp>
- #include <boost/numeric/ublas/traits.hpp>
- #include <boost/utility/enable_if.hpp>
- #include <cstddef>
- namespace boost { namespace numeric { namespace ublas {
- namespace detail { namespace /*<unnamed>*/ {
- /// Define a \c has_size_type trait class.
- BOOST_MPL_HAS_XXX_TRAIT_DEF(size_type)
- /**
- * \brief Wrapper type-traits used in \c boost::lazy_enabled_if for getting the
- * size type (see below).
- * \tparam VectorT A vector type.
- */
- template <typename VectorT>
- struct vector_size_type
- {
- /// The size type.
- typedef typename vector_traits<VectorT>::size_type type;
- };
- /**
- * \brief Wrapper type-traits used in \c boost::lazy_enabled_if for getting the
- * size type (see below).
- * \tparam MatrixT A matrix type.
- */
- template <typename MatrixT>
- struct matrix_size_type
- {
- /// The size type.
- typedef typename matrix_traits<MatrixT>::size_type type;
- };
- /**
- * \brief Auxiliary class for computing the size of the given dimension for
- * a container of the given category.
- * \tparam Dim The dimension number (starting from 1).
- * \tparam CategoryT The category type (e.g., vector_tag).
- */
- template <std::size_t Dim, typename CategoryT>
- struct size_by_dim_impl;
- /**
- * \brief Auxiliary class for computing the size of the given dimension for
- * a container of the given category and with the given orientation.
- * \tparam Dim The dimension number (starting from 1).
- * \tparam CategoryT The category type (e.g., vector_tag).
- * \tparam OrientationT The orientation category type (e.g., row_major_tag).
- */
- template <typename TagT, typename CategoryT, typename OrientationT>
- struct size_by_tag_impl;
- /**
- * \brief Specialization of \c size_by_dim_impl for computing the size of a
- * vector.
- */
- template <>
- struct size_by_dim_impl<1, vector_tag>
- {
- /**
- * \brief Compute the size of the given vector.
- * \tparam ExprT A vector expression type.
- * \pre ExprT must be a model of VectorExpression.
- */
- template <typename ExprT>
- BOOST_UBLAS_INLINE
- static typename vector_traits<ExprT>::size_type apply(vector_expression<ExprT> const& ve)
- {
- return ve().size();
- }
- };
- /**
- * \brief Specialization of \c size_by_dim_impl for computing the number of
- * rows of a matrix
- */
- template <>
- struct size_by_dim_impl<1, matrix_tag>
- {
- /**
- * \brief Compute the number of rows of the given matrix.
- * \tparam ExprT A matrix expression type.
- * \pre ExprT must be a model of MatrixExpression.
- */
- template <typename ExprT>
- BOOST_UBLAS_INLINE
- static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
- {
- return me().size1();
- }
- };
- /**
- * \brief Specialization of \c size_by_dim_impl for computing the number of
- * columns of a matrix
- */
- template <>
- struct size_by_dim_impl<2, matrix_tag>
- {
- /**
- * \brief Compute the number of columns of the given matrix.
- * \tparam ExprT A matrix expression type.
- * \pre ExprT must be a model of MatrixExpression.
- */
- template <typename ExprT>
- BOOST_UBLAS_INLINE
- static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
- {
- return me().size2();
- }
- };
- /**
- * \brief Specialization of \c size_by_tag_impl for computing the size of the
- * major dimension of a row-major oriented matrix.
- */
- template <>
- struct size_by_tag_impl<tag::major, matrix_tag, row_major_tag>
- {
- /**
- * \brief Compute the number of rows of the given matrix.
- * \tparam ExprT A matrix expression type.
- * \pre ExprT must be a model of MatrixExpression.
- */
- template <typename ExprT>
- BOOST_UBLAS_INLINE
- static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
- {
- return me().size1();
- }
- };
- /**
- * \brief Specialization of \c size_by_tag_impl for computing the size of the
- * minor dimension of a row-major oriented matrix.
- */
- template <>
- struct size_by_tag_impl<tag::minor, matrix_tag, row_major_tag>
- {
- /**
- * \brief Compute the number of columns of the given matrix.
- * \tparam ExprT A matrix expression type.
- * \pre ExprT must be a model of MatrixExpression.
- */
- template <typename ExprT>
- BOOST_UBLAS_INLINE
- static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
- {
- return me().size2();
- }
- };
- /**
- * \brief Specialization of \c size_by_tag_impl for computing the size of the
- * leading dimension of a row-major oriented matrix.
- */
- template <>
- struct size_by_tag_impl<tag::leading, matrix_tag, row_major_tag>
- {
- /**
- * \brief Compute the number of columns of the given matrix.
- * \tparam ExprT A matrix expression type.
- * \pre ExprT must be a model of MatrixExpression.
- */
- template <typename ExprT>
- BOOST_UBLAS_INLINE
- static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
- {
- return me().size2();
- }
- };
- /// \brief Specialization of \c size_by_tag_impl for computing the size of the
- /// major dimension of a column-major oriented matrix.
- template <>
- struct size_by_tag_impl<tag::major, matrix_tag, column_major_tag>
- {
- /**
- * \brief Compute the number of columns of the given matrix.
- * \tparam ExprT A matrix expression type.
- * \pre ExprT must be a model of MatrixExpression.
- */
- template <typename ExprT>
- BOOST_UBLAS_INLINE
- static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
- {
- return me().size2();
- }
- };
- /// \brief Specialization of \c size_by_tag_impl for computing the size of the
- /// minor dimension of a column-major oriented matrix.
- template <>
- struct size_by_tag_impl<tag::minor, matrix_tag, column_major_tag>
- {
- /**
- * \brief Compute the number of rows of the given matrix.
- * \tparam ExprT A matrix expression type.
- * \pre ExprT must be a model of MatrixExpression.
- */
- template <typename ExprT>
- BOOST_UBLAS_INLINE
- static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
- {
- return me().size1();
- }
- };
- /// \brief Specialization of \c size_by_tag_impl for computing the size of the
- /// leading dimension of a column-major oriented matrix.
- template <>
- struct size_by_tag_impl<tag::leading, matrix_tag, column_major_tag>
- {
- /**
- * \brief Compute the number of rows of the given matrix.
- * \tparam ExprT A matrix expression type.
- * \pre ExprT must be a model of MatrixExpression.
- */
- template <typename ExprT>
- BOOST_UBLAS_INLINE
- static typename matrix_traits<ExprT>::size_type apply(matrix_expression<ExprT> const& me)
- {
- return me().size1();
- }
- };
- /// \brief Specialization of \c size_by_tag_impl for computing the size of the
- /// given dimension of a unknown oriented expression.
- template <typename TagT, typename CategoryT>
- struct size_by_tag_impl<TagT, CategoryT, unknown_orientation_tag>: size_by_tag_impl<TagT, CategoryT, row_major_tag>
- {
- // Empty
- };
- }} // Namespace detail::<unnamed>
- /**
- * \brief Return the number of columns.
- * \tparam VectorExprT A type which models the vector expression concept.
- * \param ve A vector expression.
- * \return The length of the input vector expression.
- */
- template <typename VectorExprT>
- BOOST_UBLAS_INLINE
- typename ::boost::lazy_enable_if_c<
- detail::has_size_type<VectorExprT>::value,
- detail::vector_size_type<VectorExprT>
- >::type size(vector_expression<VectorExprT> const& ve)
- {
- return ve().size();
- }
- /**
- * \brief Return the size of the given dimension for the given vector
- * expression.
- * \tparam Dim The dimension number (starting from 1).
- * \tparam VectorExprT A vector expression type.
- * \param ve A vector expression.
- * \return The length of the input vector expression.
- */
- template <std::size_t Dim, typename VectorExprT>
- BOOST_UBLAS_INLINE
- typename vector_traits<VectorExprT>::size_type size(vector_expression<VectorExprT> const& ve)
- {
- return detail::size_by_dim_impl<Dim, vector_tag>::apply(ve);
- }
- /**
- * \brief Return the size of the given dimension for the given matrix
- * expression.
- * \tparam Dim The dimension number (starting from 1).
- * \tparam MatrixExprT A matrix expression type.
- * \param e A matrix expression.
- * \return The size of the input matrix expression associated to the dimension
- * \a Dim.
- */
- template <std::size_t Dim, typename MatrixExprT>
- BOOST_UBLAS_INLINE
- typename matrix_traits<MatrixExprT>::size_type size(matrix_expression<MatrixExprT> const& me)
- {
- return detail::size_by_dim_impl<Dim, matrix_tag>::apply(me);
- }
- /**
- * \brief Return the size of the given dimension tag for the given matrix
- * expression.
- * \tparam TagT The dimension tag type (e.g., tag::major).
- * \tparam MatrixExprT A matrix expression type.
- * \param e A matrix expression.
- * \return The size of the input matrix expression associated to the dimension
- * tag \a TagT.
- */
- template <typename TagT, typename MatrixExprT>
- BOOST_UBLAS_INLINE
- typename ::boost::lazy_enable_if_c<
- detail::has_size_type<MatrixExprT>::value,
- detail::matrix_size_type<MatrixExprT>
- >::type size(matrix_expression<MatrixExprT> const& me)
- {
- return detail::size_by_tag_impl<TagT, matrix_tag, typename matrix_traits<MatrixExprT>::orientation_category>::apply(me);
- }
- }}} // Namespace boost::numeric::ublas
- #endif // BOOST_NUMERIC_UBLAS_OPERATION_SIZE_HPP
|