⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functional.hpp

📁 boost库提供标准的C++ API 配合dev c++使用,功能更加强大
💻 HPP
📖 第 1 页 / 共 5 页
字号:
        typedef typename matrix_scalar_real_unary_functor<T>::difference_type difference_type;
        typedef typename matrix_scalar_real_unary_functor<T>::value_type value_type;
        typedef typename matrix_scalar_real_unary_functor<T>::real_type real_type;
        typedef typename matrix_scalar_real_unary_functor<T>::result_type result_type;

        template<class E>
        BOOST_UBLAS_INLINE
        result_type operator () (const matrix_expression<E> &e) const {
            real_type t = real_type ();
            size_type size1 (e ().size1 ());
            for (size_type i = 0; i < size1; ++ i) {
                real_type u = real_type ();
                size_type size2 (e ().size2 ());
                for (size_type j = 0; j < size2; ++ j) {
                    real_type v (type_traits<value_type>::norm_inf (e () (i, j)));
                    u += v;
                }
                if (u > t) 
                    t = u;  
            }
            return t; 
        }
    };

    // This functor computes the address translation
    // matrix [i] [j] -> storage [i * size2 + j]
    struct row_major {
        typedef std::size_t size_type;
        typedef std::ptrdiff_t difference_type;
        typedef row_major_tag orientation_category;

        // Indexing
        static
        BOOST_UBLAS_INLINE
        size_type element (size_type i, size_type size1, size_type j, size_type size2) {
            // Guarding against overflow.
            BOOST_UBLAS_CHECK ((size1 * size2) / size1 == size2, bad_size ());
            BOOST_UBLAS_CHECK (i < size1, bad_index ());
            BOOST_UBLAS_CHECK (j < size2, bad_index ());
            return i * size2 + j;
        }
        static
        BOOST_UBLAS_INLINE
        size_type address (size_type i, size_type size1, size_type j, size_type size2) {
            // Guarding against overflow.
            BOOST_UBLAS_CHECK (size1 == 0 || (size1 * size2) / size1 == size2, bad_size ());
            BOOST_UBLAS_CHECK (i <= size1, bad_index ());
            BOOST_UBLAS_CHECK (j <= size2, bad_index ());
            return i * size2 + j;
        }
        static
        BOOST_UBLAS_INLINE
        difference_type distance1 (difference_type k, size_type /* size1 */, size_type size2) {
            return size2 != 0 ? k / size2 : 0;
        }
        static
        BOOST_UBLAS_INLINE
        difference_type distance2 (difference_type k, size_type /* size1 */, size_type /* size2 */) {
            return k;
        }
        static
        BOOST_UBLAS_INLINE
        size_type index1 (difference_type k, size_type /* size1 */, size_type size2) {
            return size2 != 0 ? k / size2 : 0;
        }
        static
        BOOST_UBLAS_INLINE
        size_type index2 (difference_type k, size_type /* size1 */, size_type size2) {
            return size2 != 0 ? k % size2 : 0;
        }
        static
        BOOST_UBLAS_INLINE
        bool fast1 () {
            return false;
        }
        static
        BOOST_UBLAS_INLINE
        size_type one1 (size_type /* size1 */, size_type size2) {
            return size2;
        }
        static
        BOOST_UBLAS_INLINE
        bool fast2 () {
            return true;
        }
        static
        BOOST_UBLAS_INLINE
        size_type one2 (size_type /* size1 */, size_type /* size2 */) {
            return 1;
        }

        static
        BOOST_UBLAS_INLINE
        size_type lower_element (size_type i, size_type size1, size_type j, size_type size2) {
            BOOST_UBLAS_CHECK (i < size1, bad_index ());
            BOOST_UBLAS_CHECK (j < size2, bad_index ());
            BOOST_UBLAS_CHECK (i >= j, bad_index ());
            // sigma_i (i + 1) = (i + 1) * i / 2
            // i = 0 1 2 3, sigma = 0 1 3 6
            return ((i + 1) * i) / 2 + j;
        }
        static
        BOOST_UBLAS_INLINE
        size_type upper_element (size_type i, size_type size1, size_type j, size_type size2) {
            BOOST_UBLAS_CHECK (i < size1, bad_index ());
            BOOST_UBLAS_CHECK (j < size2, bad_index ());
            BOOST_UBLAS_CHECK (i <= j, bad_index ());
            // sigma_i (size - i) = size * i - i * (i - 1) / 2
            // i = 0 1 2 3, sigma = 0 4 7 9
            return (i * (2 * std::max (size1, size2) - i + 1)) / 2 + j - i;
        }

        static
        BOOST_UBLAS_INLINE
        size_type element1 (size_type i, size_type size1, size_type /* j */, size_type /* size2 */) {
            BOOST_UBLAS_CHECK (i < size1, bad_index ());
            return i;
        }
        static
        BOOST_UBLAS_INLINE
        size_type element2 (size_type /* i */, size_type /* size1 */, size_type j, size_type size2) {
            BOOST_UBLAS_CHECK (j < size2, bad_index ());
            return j;
        }
        static
        BOOST_UBLAS_INLINE
        size_type address1 (size_type i, size_type size1, size_type /* j */, size_type /* size2 */) {
            BOOST_UBLAS_CHECK (i <= size1, bad_index ());
            return i;
        }
        static
        BOOST_UBLAS_INLINE
        size_type address2 (size_type /* i */, size_type /* size1 */, size_type j, size_type size2) {
            BOOST_UBLAS_CHECK (j <= size2, bad_index ());
            return j;
        }
        static
        BOOST_UBLAS_INLINE
        size_type index1 (size_type index1, size_type /* index2 */) {
            return index1;
        }
        static
        BOOST_UBLAS_INLINE
        size_type index2 (size_type /* index1 */, size_type index2) {
            return index2;
        }
        static
        BOOST_UBLAS_INLINE
        size_type size1 (size_type size1, size_type /* size2 */) {
            return size1;
        }
        static
        BOOST_UBLAS_INLINE
        size_type size2 (size_type /* size1 */, size_type size2) {
            return size2;
        }

        // Iterating
        template<class I>
        static
        BOOST_UBLAS_INLINE
        void increment1 (I &it, size_type /* size1 */, size_type size2) {
            it += size2;
        }
        template<class I>
        static
        BOOST_UBLAS_INLINE
        void decrement1 (I &it, size_type /* size1 */, size_type size2) {
            it -= size2;
        }
        template<class I>
        static
        BOOST_UBLAS_INLINE
        void increment2 (I &it, size_type /* size1 */, size_type /* size2 */) {
            ++ it;
        }
        template<class I>
        static
        BOOST_UBLAS_INLINE
        void decrement2 (I &it, size_type /* size1 */, size_type /* size2 */) {
            -- it;
        }
    };

    // This functor computes the address translation
    // matrix [i] [j] -> storage [i + j * size1]
    struct column_major {
        typedef std::size_t size_type;
        typedef std::ptrdiff_t difference_type;
        typedef column_major_tag orientation_category;

        // Indexing
        static
        BOOST_UBLAS_INLINE
        size_type element (size_type i, size_type size1, size_type j, size_type size2) {
            // Guarding against overflow.
            BOOST_UBLAS_CHECK ((size1 * size2) / size1 == size2, bad_size ());
            BOOST_UBLAS_CHECK (i < size1, bad_index ());
            BOOST_UBLAS_CHECK (j < size2, bad_index ());
            return i + j * size1;
        }
        static
        BOOST_UBLAS_INLINE
        size_type address (size_type i, size_type size1, size_type j, size_type size2) {
            // Guarding against overflow.
            BOOST_UBLAS_CHECK (size1 == 0 || (size1 * size2) / size1 == size2, bad_size ());
            BOOST_UBLAS_CHECK (i <= size1, bad_index ());
            BOOST_UBLAS_CHECK (j <= size2, bad_index ());
            return i + j * size1;
        }
        static
        BOOST_UBLAS_INLINE
        difference_type distance1 (difference_type k, size_type /* size1 */, size_type /* size2 */) {
            return k;
        }
        static
        BOOST_UBLAS_INLINE
        difference_type distance2 (difference_type k, size_type size1, size_type /* size2 */) {
            return size1 != 0 ? k / size1 : 0;
        }
        static
        BOOST_UBLAS_INLINE
        size_type index1 (difference_type k, size_type size1, size_type /* size2 */) {
            return size1 != 0 ? k % size1 : 0;
        }
        static
        BOOST_UBLAS_INLINE
        size_type index2 (difference_type k, size_type size1, size_type /* size2 */) {
            return size1 != 0 ? k / size1 : 0;
        }
        static
        BOOST_UBLAS_INLINE
        bool fast1 () {
            return true;
        }
        static
        BOOST_UBLAS_INLINE
        size_type one1 (size_type /* size1 */, size_type /* size2 */) {
            return 1;
        }
        static
        BOOST_UBLAS_INLINE
        bool fast2 () {
            return false;
        }
        static
        BOOST_UBLAS_INLINE
        size_type one2 (size_type size1, size_type /* size2 */) {
            return size1;
        }

        static
        BOOST_UBLAS_INLINE
        size_type lower_element (size_type i, size_type size1, size_type j, size_type size2) {
            BOOST_UBLAS_CHECK (i < size1, bad_index ());
            BOOST_UBLAS_CHECK (j < size2, bad_index ());
            BOOST_UBLAS_CHECK (i >= j, bad_index ());
            // sigma_j (size - j) = size * j - j * (j - 1) / 2
            // j = 0 1 2 3, sigma = 0 4 7 9
            return i - j + (j * (2 * std::max (size1, size2) - j + 1)) / 2;
        }
        static
        BOOST_UBLAS_INLINE
        size_type upper_element (size_type i, size_type size1, size_type j, size_type size2) {
            BOOST_UBLAS_CHECK (i < size1, bad_index ());
            BOOST_UBLAS_CHECK (j < size2, bad_index ());
            BOOST_UBLAS_CHECK (i <= j, bad_index ());
            // sigma_j (j + 1) = (j + 1) * j / 2
            // j = 0 1 2 3, sigma = 0 1 3 6
            return i + ((j + 1) * j) / 2;
        }

        static
        BOOST_UBLAS_INLINE
        size_type element1 (size_type /* i */, size_type /* size1 */, size_type j, size_type size2) {
            BOOST_UBLAS_CHECK (j < size2, bad_index ());
            return j;
        }
        static
        BOOST_UBLAS_INLINE
        size_type element2 (size_type i, size_type size1, size_type /* j */, size_type /* size2 */) {
            BOOST_UBLAS_CHECK (i < size1, bad_index ());
            return i;
        }
        static
        BOOST_UBLAS_INLINE
        size_type address1 (size_type /* i */, size_type /* size1 */, size_type j, size_type size2) {
            BOOST_UBLAS_CHECK (j <= size2, bad_index ());
            return j;
        }
        static
        BOOST_UBLAS_INLINE
        size_type address2 (size_type i, size_type size1, size_type /* j */, size_type /* size2 */) {
            BOOST_UBLAS_CHECK (i <= size1, bad_index ());
            return i;
        }
        static
        BOOST_UBLAS_INLINE
        size_type index1 (size_type /* index1 */, size_type index2) {
            return index2;
        }
        static
        BOOST_UBLAS_INLINE
        size_type index2 (size_type index1, size_type /* index2 */) {
            return index1;
        }
        static
        BOOST_UBLAS_INLINE
        size_type size1 (size_type /* size1 */, size_type size2) {
            return size2;
        }
        static
        BOOST_UBLAS_INLINE
        size_type size2 (size_type size1, size_type /* size2 */) {
            return size1;
        }

        // Iterating
        template<class I>
        static
        BOOST_UBLAS_INLINE
        void increment1 (I &it, size_type /* size1 */, size_type /* size2 */) {
            ++ it;
        }
        template<class I>
        static
        BOOST_UBLAS_INLI

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -