functional.hpp

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

HPP
1,668
字号
////  Copyright (c) 2000-2002//  Joerg Walter, Mathias Koch////  Permission to use, copy, modify, distribute and sell this software//  and its documentation for any purpose is hereby granted without fee,//  provided that the above copyright notice appear in all copies and//  that both that copyright notice and this permission notice appear//  in supporting documentation.  The authors make no representations//  about the suitability of this software for any purpose.//  It is provided "as is" without express or implied warranty.////  The authors gratefully acknowledge the support of//  GeNeSys mbH & Co. KG in producing this work.//#ifndef BOOST_UBLAS_FUNCTIONAL_H#define BOOST_UBLAS_FUNCTIONAL_H#include <functional>#include <boost/numeric/ublas/config.hpp>#include <boost/numeric/ublas/exception.hpp>#include <boost/numeric/ublas/traits.hpp>#ifdef BOOST_UBLAS_USE_DUFF_DEVICE#include <boost/numeric/ublas/duff.hpp>#endif#ifdef BOOST_UBLAS_USE_SIMD#include <boost/numeric/ublas/raw.hpp>#elsenamespace boost { namespace numeric { namespace ublas { namespace raw {}}}}#endif#ifdef BOOST_UBLAS_HAVE_BINDINGS#include <boost/numeric/bindings/traits/std_vector.hpp>#include <boost/numeric/bindings/traits/ublas_vector.hpp>#include <boost/numeric/bindings/traits/ublas_matrix.hpp>#include <boost/numeric/bindings/atlas/cblas.hpp>#endifnamespace boost { namespace numeric { namespace ublas {    // Scalar functors    // Unary    template<class T>    struct scalar_unary_functor {        typedef T value_type;        typedef typename type_traits<T>::const_reference argument_type;        typedef typename type_traits<T>::value_type result_type;    };    template<class T>    struct scalar_identity:        public scalar_unary_functor<T> {        typedef typename scalar_unary_functor<T>::argument_type argument_type;        typedef typename scalar_unary_functor<T>::result_type result_type;        static BOOST_UBLAS_INLINE        result_type apply (argument_type t) {            return t;        }    };    template<class T>    struct scalar_negate:        public scalar_unary_functor<T> {        typedef typename scalar_unary_functor<T>::argument_type argument_type;        typedef typename scalar_unary_functor<T>::result_type result_type;        static BOOST_UBLAS_INLINE        result_type apply (argument_type t) {            return - t;        }    };    template<class T>    struct scalar_conj:        public scalar_unary_functor<T> {        typedef typename scalar_unary_functor<T>::value_type value_type;        typedef typename scalar_unary_functor<T>::argument_type argument_type;        typedef typename scalar_unary_functor<T>::result_type result_type;        static BOOST_UBLAS_INLINE        result_type apply (argument_type t) {            return type_traits<value_type>::conj (t);        }    };    // Unary returning real    template<class T>    struct scalar_real_unary_functor {        typedef T value_type;        typedef typename type_traits<T>::const_reference argument_type;        typedef typename type_traits<T>::real_type result_type;    };    template<class T>    struct scalar_real:        public scalar_real_unary_functor<T> {        typedef typename scalar_real_unary_functor<T>::value_type value_type;        typedef typename scalar_real_unary_functor<T>::argument_type argument_type;        typedef typename scalar_real_unary_functor<T>::result_type result_type;        static BOOST_UBLAS_INLINE        result_type apply (argument_type t) {            return type_traits<value_type>::real (t);        }    };    template<class T>    struct scalar_imag:        public scalar_real_unary_functor<T> {        typedef typename scalar_real_unary_functor<T>::value_type value_type;        typedef typename scalar_real_unary_functor<T>::argument_type argument_type;        typedef typename scalar_real_unary_functor<T>::result_type result_type;        static BOOST_UBLAS_INLINE        result_type apply (argument_type t) {            return type_traits<value_type>::imag (t);        }    };    // Binary    template<class T1, class T2>    struct scalar_binary_functor {        typedef typename type_traits<T1>::const_reference argument1_type;        typedef typename type_traits<T2>::const_reference argument2_type;        typedef typename promote_traits<T1, T2>::promote_type result_type;    };    template<class T1, class T2>    struct scalar_plus:        public scalar_binary_functor<T1, T2> {        typedef typename scalar_binary_functor<T1, T2>::argument1_type argument1_type;        typedef typename scalar_binary_functor<T1, T2>::argument2_type argument2_type;        typedef typename scalar_binary_functor<T1, T2>::result_type result_type;        static BOOST_UBLAS_INLINE        result_type apply (argument1_type t1, argument2_type t2) {            return t1 + t2;        }    };    template<class T1, class T2>    struct scalar_minus:        public scalar_binary_functor<T1, T2> {        typedef typename scalar_binary_functor<T1, T2>::argument1_type argument1_type;        typedef typename scalar_binary_functor<T1, T2>::argument2_type argument2_type;        typedef typename scalar_binary_functor<T1, T2>::result_type result_type;        static BOOST_UBLAS_INLINE        result_type apply (argument1_type t1, argument2_type t2) {            return t1 - t2;        }    };    template<class T1, class T2>    struct scalar_multiplies:        public scalar_binary_functor<T1, T2> {        typedef typename scalar_binary_functor<T1, T2>::argument1_type argument1_type;        typedef typename scalar_binary_functor<T1, T2>::argument2_type argument2_type;        typedef typename scalar_binary_functor<T1, T2>::result_type result_type;        static BOOST_UBLAS_INLINE        result_type apply (argument1_type t1, argument2_type t2) {            return t1 * t2;        }    };    template<class T1, class T2>    struct scalar_divides:        public scalar_binary_functor<T1, T2> {        typedef typename scalar_binary_functor<T1, T2>::argument1_type argument1_type;        typedef typename scalar_binary_functor<T1, T2>::argument2_type argument2_type;        typedef typename scalar_binary_functor<T1, T2>::result_type result_type;        static BOOST_UBLAS_INLINE        result_type apply (argument1_type t1, argument2_type t2) {            return t1 / t2;        }    };    template<class T1, class T2>    struct scalar_binary_assign_functor {        // ISSUE Remove reference to avoid reference to reference problems        typedef typename type_traits<typename boost::remove_reference<T1>::type>::reference argument1_type;        typedef typename type_traits<T2>::const_reference argument2_type;    };    struct assign_tag {};    struct computed_assign_tag {};    template<class T1, class T2>    struct scalar_assign:        public scalar_binary_assign_functor<T1, T2> {        typedef typename scalar_binary_assign_functor<T1, T2>::argument1_type argument1_type;        typedef typename scalar_binary_assign_functor<T1, T2>::argument2_type argument2_type;        typedef assign_tag assign_category;        static BOOST_UBLAS_INLINE        void apply (argument1_type t1, argument2_type t2) {            t1 = t2;        }        template<class U1, class U2>        static BOOST_UBLAS_INLINE        scalar_assign<U1, U2> make_debug_functor () {            return scalar_assign<U1, U2> ();        }    };    template<class T1, class T2>    struct scalar_plus_assign:        public scalar_binary_assign_functor<T1, T2> {        typedef typename scalar_binary_assign_functor<T1, T2>::argument1_type argument1_type;        typedef typename scalar_binary_assign_functor<T1, T2>::argument2_type argument2_type;        typedef computed_assign_tag assign_category;        static BOOST_UBLAS_INLINE        void apply (argument1_type t1, argument2_type t2) {            t1 += t2;        }        template<class U1, class U2>        static BOOST_UBLAS_INLINE        scalar_plus_assign<U1, U2> make_debug_functor () {            return scalar_plus_assign<U1, U2> ();        }    };    template<class T1, class T2>    struct scalar_minus_assign:        public scalar_binary_assign_functor<T1, T2> {        typedef typename scalar_binary_assign_functor<T1, T2>::argument1_type argument1_type;        typedef typename scalar_binary_assign_functor<T1, T2>::argument2_type argument2_type;        typedef computed_assign_tag assign_category;        static BOOST_UBLAS_INLINE        void apply (argument1_type t1, argument2_type t2) {            t1 -= t2;        }        template<class U1, class U2>        static BOOST_UBLAS_INLINE        scalar_minus_assign<U1, U2> make_debug_functor () {            return scalar_minus_assign<U1, U2> ();        }    };    template<class T1, class T2>    struct scalar_multiplies_assign:        public scalar_binary_assign_functor<T1, T2> {        typedef typename scalar_binary_assign_functor<T1, T2>::argument1_type argument1_type;        typedef typename scalar_binary_assign_functor<T1, T2>::argument2_type argument2_type;        typedef computed_assign_tag assign_category;        static BOOST_UBLAS_INLINE        void apply (argument1_type t1, argument2_type t2) {            t1 *= t2;        }        template<class U1, class U2>        static BOOST_UBLAS_INLINE        scalar_multiplies_assign<U1, U2> make_debug_functor () {            return scalar_multiplies_assign<U1, U2> ();        }    };    template<class T1, class T2>    struct scalar_divides_assign:        public scalar_binary_assign_functor<T1, T2> {        typedef typename scalar_binary_assign_functor<T1, T2>::argument1_type argument1_type;        typedef typename scalar_binary_assign_functor<T1, T2>::argument2_type argument2_type;        typedef computed_assign_tag assign_category;        static BOOST_UBLAS_INLINE        void apply (argument1_type t1, argument2_type t2) {            t1 /= t2;        }        template<class U1, class U2>        static BOOST_UBLAS_INLINE        scalar_divides_assign<U1, U2> make_debug_functor () {            return scalar_divides_assign<U1, U2> ();        }    };    template<class T1, class T2>    struct scalar_binary_swap_functor {        typedef typename type_traits<typename boost::remove_reference<T1>::type>::reference argument1_type;        typedef typename type_traits<typename boost::remove_reference<T2>::type>::reference argument2_type;    };    template<class T1, class T2>    struct scalar_swap:        public scalar_binary_swap_functor<T1, T2> {        typedef typename scalar_binary_swap_functor<T1, T2>::argument1_type argument1_type;        typedef typename scalar_binary_swap_functor<T1, T2>::argument2_type argument2_type;        static BOOST_UBLAS_INLINE        void apply (argument1_type t1, argument2_type t2) {            std::swap (t1, t2);        }        template<class U1, class U2>        static BOOST_UBLAS_INLINE        scalar_swap<U1, U2> make_debug_functor () {            return scalar_swap<U1, U2> ();        }    };    // Vector functors    // Unary returning scalar    template<class T>    struct vector_scalar_unary_functor {        typedef std::size_t size_type;        typedef std::ptrdiff_t difference_type;        typedef T value_type;        typedef T result_type;    };    template<class T>    struct vector_sum:         public vector_scalar_unary_functor<T> {        typedef typename vector_scalar_unary_functor<T>::size_type size_type;        typedef typename vector_scalar_unary_functor<T>::difference_type difference_type;        typedef typename vector_scalar_unary_functor<T>::value_type value_type;        typedef typename vector_scalar_unary_functor<T>::result_type result_type;        template<class E>        static BOOST_UBLAS_INLINE        result_type apply (const vector_expression<E> &e) {             result_type t = result_type (0);            size_type size (e ().size ());            for (size_type i = 0; i < size; ++ i)                t += e () (i);            return t;        }        // Dense case

⌨️ 快捷键说明

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