functional.hpp

来自「CGAL is a collaborative effort of severa」· HPP 代码 · 共 1,668 行 · 第 1/5 页

HPP
1,668
字号
        template<class I>        static BOOST_UBLAS_INLINE        result_type apply (difference_type size, I it) {             result_type t = result_type (0);            while (-- size >= 0)                t += *it, ++ it;            return t;         }        // Sparse case        template<class I>        static BOOST_UBLAS_INLINE        result_type apply (I it, const I &it_end) {            result_type t = result_type (0);            while (it != it_end)                 t += *it, ++ it;            return t;         }    };    // Unary returning real scalar     template<class T>    struct vector_scalar_real_unary_functor {        typedef std::size_t size_type;        typedef std::ptrdiff_t difference_type;        typedef T value_type;        typedef typename type_traits<T>::real_type real_type;        typedef real_type result_type;    };    template<class T>    struct vector_norm_1:        public vector_scalar_real_unary_functor<T> {        typedef typename vector_scalar_real_unary_functor<T>::size_type size_type;        typedef typename vector_scalar_real_unary_functor<T>::difference_type difference_type;        typedef typename vector_scalar_real_unary_functor<T>::value_type value_type;        typedef typename vector_scalar_real_unary_functor<T>::real_type real_type;        typedef typename vector_scalar_real_unary_functor<T>::result_type result_type;        template<class E>        static BOOST_UBLAS_INLINE        result_type apply (const vector_expression<E> &e) {            real_type t = real_type ();            size_type size (e ().size ());            for (size_type i = 0; i < size; ++ i) {                real_type u (type_traits<value_type>::norm_1 (e () (i)));                t += u;            }            return t;        }        // Dense case        template<class I>        static BOOST_UBLAS_INLINE        result_type apply (difference_type size, I it) {            real_type t = real_type ();            while (-- size >= 0) {                real_type u (type_traits<value_type>::norm_1 (*it));                t += u;                ++ it;            }            return t;        }        // Sparse case        template<class I>        static BOOST_UBLAS_INLINE        result_type apply (I it, const I &it_end) {            real_type t = real_type ();            while (it != it_end) {                real_type u (type_traits<value_type>::norm_1 (*it));                t += u;                ++ it;            }            return t;        }    };    template<class T>    struct vector_norm_2:        public vector_scalar_real_unary_functor<T> {        typedef typename vector_scalar_real_unary_functor<T>::size_type size_type;        typedef typename vector_scalar_real_unary_functor<T>::difference_type difference_type;        typedef typename vector_scalar_real_unary_functor<T>::value_type value_type;        typedef typename vector_scalar_real_unary_functor<T>::real_type real_type;        typedef typename vector_scalar_real_unary_functor<T>::result_type result_type;        template<class E>        static BOOST_UBLAS_INLINE        result_type apply (const vector_expression<E> &e) {#ifndef BOOST_UBLAS_SCALED_NORM            real_type t = real_type ();            size_type size (e ().size ());            for (size_type i = 0; i < size; ++ i) {                real_type u (type_traits<value_type>::norm_2 (e () (i)));                t +=  u * u;            }            return type_traits<real_type>::sqrt (t);#else            real_type scale = real_type ();            real_type sum_squares (1);            size_type size (e ().size ());            for (size_type i = 0; i < size; ++ i) {                real_type u (type_traits<value_type>::norm_2 (e () (i)));                if (scale < u) {                    real_type v (scale / u);                    sum_squares = sum_squares * v * v + real_type (1);                    scale = u;                } else {                    real_type v (u / scale);                    sum_squares += v * v;                }            }            return scale * type_traits<real_type>::sqrt (sum_squares);#endif        }        // Dense case        template<class I>        static BOOST_UBLAS_INLINE        result_type apply (difference_type size, I it) {#ifndef BOOST_UBLAS_SCALED_NORM            real_type t = real_type ();            while (-- size >= 0) {                real_type u (type_traits<value_type>::norm_2 (*it));                t +=  u * u;                ++ it;            }            return type_traits<real_type>::sqrt (t);#else            real_type scale = real_type ();            real_type sum_squares (1);            while (-- size >= 0) {                real_type u (type_traits<value_type>::norm_2 (*it));                if (scale < u) {                    real_type v (scale / u);                    sum_squares = sum_squares * v * v + real_type (1);                    scale = u;                } else {                    real_type v (u / scale);                    sum_squares += v * v;                }                ++ it;            }            return scale * type_traits<real_type>::sqrt (sum_squares);#endif        }        // Sparse case        template<class I>        static BOOST_UBLAS_INLINE        result_type apply (I it, const I &it_end) {#ifndef BOOST_UBLAS_SCALED_NORM            real_type t = real_type ();            while (it != it_end) {                real_type u (type_traits<value_type>::norm_2 (*it));                t +=  u * u;                ++ it;            }            return type_traits<real_type>::sqrt (t);#else            real_type scale = real_type ();            real_type sum_squares (1);            while (it != it_end) {                real_type u (type_traits<value_type>::norm_2 (*it));                if (scale < u) {                    real_type v (scale / u);                    sum_squares = sum_squares * v * v + real_type (1);                    scale = u;                } else {                    real_type v (u / scale);                    sum_squares += v * v;                }                ++ it;            }            return scale * type_traits<real_type>::sqrt (sum_squares);#endif        }    };    template<class T>    struct vector_norm_inf:        public vector_scalar_real_unary_functor<T> {        typedef typename vector_scalar_real_unary_functor<T>::size_type size_type;        typedef typename vector_scalar_real_unary_functor<T>::difference_type difference_type;        typedef typename vector_scalar_real_unary_functor<T>::value_type value_type;        typedef typename vector_scalar_real_unary_functor<T>::real_type real_type;        typedef typename vector_scalar_real_unary_functor<T>::result_type result_type;        template<class E>        static BOOST_UBLAS_INLINE        result_type apply (const vector_expression<E> &e) {            real_type t = real_type ();            size_type size (e ().size ());            for (size_type i = 0; i < size; ++ i) {                real_type u (type_traits<value_type>::norm_inf (e () (i)));                if (u > t)                    t = u;            }            return t;        }        // Dense case        template<class I>        static BOOST_UBLAS_INLINE        result_type apply (difference_type size, I it) {            real_type t = real_type ();            while (-- size >= 0) {                real_type u (type_traits<value_type>::norm_inf (*it));                if (u > t)                    t = u;                ++ it;            }            return t;        }        // Sparse case        template<class I>        static BOOST_UBLAS_INLINE        result_type apply (I it, const I &it_end) {             real_type t = real_type ();            while (it != it_end) {                real_type u (type_traits<value_type>::norm_inf (*it));                if (u > t)                     t = u;                ++ it;            }            return t;         }    };    // Unary returning index    template<class T>    struct vector_scalar_index_unary_functor {        typedef std::size_t size_type;        typedef std::ptrdiff_t difference_type;        typedef T value_type;        typedef typename type_traits<T>::real_type real_type;        typedef size_type result_type;    };    template<class T>    struct vector_index_norm_inf:        public vector_scalar_index_unary_functor<T> {        typedef typename vector_scalar_index_unary_functor<T>::size_type size_type;        typedef typename vector_scalar_index_unary_functor<T>::difference_type difference_type;        typedef typename vector_scalar_index_unary_functor<T>::value_type value_type;        typedef typename vector_scalar_index_unary_functor<T>::real_type real_type;        typedef typename vector_scalar_index_unary_functor<T>::result_type result_type;        template<class E>        static BOOST_UBLAS_INLINE        result_type apply (const vector_expression<E> &e) {            // ISSUE For CBLAS compatibility return 0 index in empty case            result_type i_norm_inf (0);            real_type t = real_type ();            size_type size (e ().size ());            for (size_type i = 0; i < size; ++ i) {                real_type u (type_traits<value_type>::norm_inf (e () (i)));                if (u > t) {                    i_norm_inf = i;                    t = u;                }            }            return i_norm_inf;        }        // Dense case        template<class I>        static BOOST_UBLAS_INLINE        result_type apply (difference_type size, I it) {            // ISSUE For CBLAS compatibility return 0 index in empty case            result_type i_norm_inf (0);            real_type t = real_type ();            while (-- size >= 0) {                real_type u (type_traits<value_type>::norm_inf (*it));                if (u > t) {                    i_norm_inf = it.index ();                    t = u;                }                ++ it;            }            return i_norm_inf;        }        // Sparse case        template<class I>        static BOOST_UBLAS_INLINE        result_type apply (I it, const I &it_end) {            // ISSUE For CBLAS compatibility return 0 index in empty case            result_type i_norm_inf (0);            real_type t = real_type ();            while (it != it_end) {                real_type u (type_traits<value_type>::norm_inf (*it));                if (u > t) {                    i_norm_inf = it.index ();                    t = u;                }                ++ it;            }            return i_norm_inf;        }    };    // Binary returning scalar    template<class T1, class T2, class TR>    struct vector_scalar_binary_functor {        typedef std::size_t size_type;        typedef std::ptrdiff_t difference_type;        typedef TR value_type;        typedef TR result_type;    };    template<class T1, class T2, class TR>    struct vector_inner_prod:        public vector_scalar_binary_functor<T1, T2, TR> {        typedef typename vector_scalar_binary_functor<T1, T2, TR>::size_type size_type ;        typedef typename vector_scalar_binary_functor<T1, T2, TR>::difference_type difference_type;        typedef typename vector_scalar_binary_functor<T1, T2, TR>::value_type value_type;        typedef typename vector_scalar_binary_functor<T1, T2, TR>::result_type result_type;        template<class E1, class E2>        static BOOST_UBLAS_INLINE        result_type apply (const vector_expression<E1> &e1,                                 const vector_expression<E2> &e2,                                 concrete_tag) {#ifndef BOOST_UBLAS_HAVE_BINDINGS            using namespace raw;            size_type size (BOOST_UBLAS_SAME (e1 ().size (), e2 ().size ()));            const T1 *data1 = data_const (e1 ());            const T2 *data2 = data_const (e2 ());            size_type s1 = stride (e1 ());            size_type s2 = stride (e2 ());            result_type t = result_type (0);            if (s1 == 1 && s2 == 1) {                for (size_type i = 0; i < size; ++ i)                    t += data1 [i] * data2 [i];            } else if (s2 == 1) {                for (size_type i = 0, i1 = 0; i < size; ++ i, i1 += s1)                    t += data1 [i1] * data2 [i];            } else if (s1 == 1) {                for (size_type i = 0, i2 = 0; i < size; ++ i, i2 += s2)                    t += data1 [i] * data2 [i2];            } else {                for (size_type i = 0, i1 = 0, i2 = 0; i < size; ++ i, i1 += s1, i2 += s2)

⌨️ 快捷键说明

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