sl@0: // sl@0: // Copyright (c) 2000-2002 sl@0: // Joerg Walter, Mathias Koch sl@0: // sl@0: // Permission to use, copy, modify, distribute and sell this software sl@0: // and its documentation for any purpose is hereby granted without fee, sl@0: // provided that the above copyright notice appear in all copies and sl@0: // that both that copyright notice and this permission notice appear sl@0: // in supporting documentation. The authors make no representations sl@0: // about the suitability of this software for any purpose. sl@0: // It is provided "as is" without express or implied warranty. sl@0: // sl@0: // The authors gratefully acknowledge the support of sl@0: // GeNeSys mbH & Co. KG in producing this work. sl@0: // sl@0: sl@0: #ifndef _BOOST_UBLAS_FUNCTIONAL_ sl@0: #define _BOOST_UBLAS_FUNCTIONAL_ sl@0: sl@0: #include sl@0: sl@0: #include sl@0: #ifdef BOOST_UBLAS_USE_DUFF_DEVICE sl@0: #include sl@0: #endif sl@0: #ifdef BOOST_UBLAS_USE_SIMD sl@0: #include sl@0: #else sl@0: namespace boost { namespace numeric { namespace ublas { namespace raw { sl@0: }}}} sl@0: #endif sl@0: #ifdef BOOST_UBLAS_HAVE_BINDINGS sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #endif sl@0: sl@0: #include sl@0: sl@0: sl@0: sl@0: namespace boost { namespace numeric { namespace ublas { sl@0: sl@0: // Scalar functors sl@0: sl@0: // Unary sl@0: template sl@0: struct scalar_unary_functor { sl@0: typedef T value_type; sl@0: typedef typename type_traits::const_reference argument_type; sl@0: typedef typename type_traits::value_type result_type; sl@0: }; sl@0: sl@0: template sl@0: struct scalar_identity: sl@0: public scalar_unary_functor { sl@0: typedef typename scalar_unary_functor::argument_type argument_type; sl@0: typedef typename scalar_unary_functor::result_type result_type; sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (argument_type t) { sl@0: return t; sl@0: } sl@0: }; sl@0: template sl@0: struct scalar_negate: sl@0: public scalar_unary_functor { sl@0: typedef typename scalar_unary_functor::argument_type argument_type; sl@0: typedef typename scalar_unary_functor::result_type result_type; sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (argument_type t) { sl@0: return - t; sl@0: } sl@0: }; sl@0: template sl@0: struct scalar_conj: sl@0: public scalar_unary_functor { sl@0: typedef typename scalar_unary_functor::value_type value_type; sl@0: typedef typename scalar_unary_functor::argument_type argument_type; sl@0: typedef typename scalar_unary_functor::result_type result_type; sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (argument_type t) { sl@0: return type_traits::conj (t); sl@0: } sl@0: }; sl@0: sl@0: // Unary returning real sl@0: template sl@0: struct scalar_real_unary_functor { sl@0: typedef T value_type; sl@0: typedef typename type_traits::const_reference argument_type; sl@0: typedef typename type_traits::real_type result_type; sl@0: }; sl@0: sl@0: template sl@0: struct scalar_real: sl@0: public scalar_real_unary_functor { sl@0: typedef typename scalar_real_unary_functor::value_type value_type; sl@0: typedef typename scalar_real_unary_functor::argument_type argument_type; sl@0: typedef typename scalar_real_unary_functor::result_type result_type; sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (argument_type t) { sl@0: return type_traits::real (t); sl@0: } sl@0: }; sl@0: template sl@0: struct scalar_imag: sl@0: public scalar_real_unary_functor { sl@0: typedef typename scalar_real_unary_functor::value_type value_type; sl@0: typedef typename scalar_real_unary_functor::argument_type argument_type; sl@0: typedef typename scalar_real_unary_functor::result_type result_type; sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (argument_type t) { sl@0: return type_traits::imag (t); sl@0: } sl@0: }; sl@0: sl@0: // Binary sl@0: template sl@0: struct scalar_binary_functor { sl@0: typedef typename type_traits::const_reference argument1_type; sl@0: typedef typename type_traits::const_reference argument2_type; sl@0: typedef typename promote_traits::promote_type result_type; sl@0: }; sl@0: sl@0: template sl@0: struct scalar_plus: sl@0: public scalar_binary_functor { sl@0: typedef typename scalar_binary_functor::argument1_type argument1_type; sl@0: typedef typename scalar_binary_functor::argument2_type argument2_type; sl@0: typedef typename scalar_binary_functor::result_type result_type; sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (argument1_type t1, argument2_type t2) { sl@0: return t1 + t2; sl@0: } sl@0: }; sl@0: template sl@0: struct scalar_minus: sl@0: public scalar_binary_functor { sl@0: typedef typename scalar_binary_functor::argument1_type argument1_type; sl@0: typedef typename scalar_binary_functor::argument2_type argument2_type; sl@0: typedef typename scalar_binary_functor::result_type result_type; sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (argument1_type t1, argument2_type t2) { sl@0: return t1 - t2; sl@0: } sl@0: }; sl@0: template sl@0: struct scalar_multiplies: sl@0: public scalar_binary_functor { sl@0: typedef typename scalar_binary_functor::argument1_type argument1_type; sl@0: typedef typename scalar_binary_functor::argument2_type argument2_type; sl@0: typedef typename scalar_binary_functor::result_type result_type; sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (argument1_type t1, argument2_type t2) { sl@0: return t1 * t2; sl@0: } sl@0: }; sl@0: template sl@0: struct scalar_divides: sl@0: public scalar_binary_functor { sl@0: typedef typename scalar_binary_functor::argument1_type argument1_type; sl@0: typedef typename scalar_binary_functor::argument2_type argument2_type; sl@0: typedef typename scalar_binary_functor::result_type result_type; sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (argument1_type t1, argument2_type t2) { sl@0: return t1 / t2; sl@0: } sl@0: }; sl@0: sl@0: template sl@0: struct scalar_binary_assign_functor { sl@0: // ISSUE Remove reference to avoid reference to reference problems sl@0: typedef typename type_traits::type>::reference argument1_type; sl@0: typedef typename type_traits::const_reference argument2_type; sl@0: }; sl@0: sl@0: struct assign_tag {}; sl@0: struct computed_assign_tag {}; sl@0: sl@0: template sl@0: struct scalar_assign: sl@0: public scalar_binary_assign_functor { sl@0: typedef typename scalar_binary_assign_functor::argument1_type argument1_type; sl@0: typedef typename scalar_binary_assign_functor::argument2_type argument2_type; sl@0: #if BOOST_WORKAROUND( __IBMCPP__, <=600 ) sl@0: static const bool computed ; sl@0: #else sl@0: static const bool computed = false ; sl@0: #endif sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: void apply (argument1_type t1, argument2_type t2) { sl@0: t1 = t2; sl@0: } sl@0: sl@0: template sl@0: struct rebind { sl@0: typedef scalar_assign other; sl@0: }; sl@0: }; sl@0: sl@0: #if BOOST_WORKAROUND( __IBMCPP__, <=600 ) sl@0: template sl@0: const bool scalar_assign::computed = false; sl@0: #endif sl@0: sl@0: template sl@0: struct scalar_plus_assign: sl@0: public scalar_binary_assign_functor { sl@0: typedef typename scalar_binary_assign_functor::argument1_type argument1_type; sl@0: typedef typename scalar_binary_assign_functor::argument2_type argument2_type; sl@0: #if BOOST_WORKAROUND( __IBMCPP__, <=600 ) sl@0: static const bool computed ; sl@0: #else sl@0: static const bool computed = true ; sl@0: #endif sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: void apply (argument1_type t1, argument2_type t2) { sl@0: t1 += t2; sl@0: } sl@0: sl@0: template sl@0: struct rebind { sl@0: typedef scalar_plus_assign other; sl@0: }; sl@0: }; sl@0: sl@0: #if BOOST_WORKAROUND( __IBMCPP__, <=600 ) sl@0: template sl@0: const bool scalar_plus_assign::computed = true; sl@0: #endif sl@0: sl@0: template sl@0: struct scalar_minus_assign: sl@0: public scalar_binary_assign_functor { sl@0: typedef typename scalar_binary_assign_functor::argument1_type argument1_type; sl@0: typedef typename scalar_binary_assign_functor::argument2_type argument2_type; sl@0: #if BOOST_WORKAROUND( __IBMCPP__, <=600 ) sl@0: static const bool computed ; sl@0: #else sl@0: static const bool computed = true ; sl@0: #endif sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: void apply (argument1_type t1, argument2_type t2) { sl@0: t1 -= t2; sl@0: } sl@0: sl@0: template sl@0: struct rebind { sl@0: typedef scalar_minus_assign other; sl@0: }; sl@0: }; sl@0: sl@0: #if BOOST_WORKAROUND( __IBMCPP__, <=600 ) sl@0: template sl@0: const bool scalar_minus_assign::computed = true; sl@0: #endif sl@0: sl@0: template sl@0: struct scalar_multiplies_assign: sl@0: public scalar_binary_assign_functor { sl@0: typedef typename scalar_binary_assign_functor::argument1_type argument1_type; sl@0: typedef typename scalar_binary_assign_functor::argument2_type argument2_type; sl@0: static const bool computed = true; sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: void apply (argument1_type t1, argument2_type t2) { sl@0: t1 *= t2; sl@0: } sl@0: sl@0: template sl@0: struct rebind { sl@0: typedef scalar_multiplies_assign other; sl@0: }; sl@0: }; sl@0: template sl@0: struct scalar_divides_assign: sl@0: public scalar_binary_assign_functor { sl@0: typedef typename scalar_binary_assign_functor::argument1_type argument1_type; sl@0: typedef typename scalar_binary_assign_functor::argument2_type argument2_type; sl@0: static const bool computed ; sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: void apply (argument1_type t1, argument2_type t2) { sl@0: t1 /= t2; sl@0: } sl@0: sl@0: template sl@0: struct rebind { sl@0: typedef scalar_divides_assign other; sl@0: }; sl@0: }; sl@0: template sl@0: const bool scalar_divides_assign::computed = true; sl@0: sl@0: template sl@0: struct scalar_binary_swap_functor { sl@0: typedef typename type_traits::type>::reference argument1_type; sl@0: typedef typename type_traits::type>::reference argument2_type; sl@0: }; sl@0: sl@0: template sl@0: struct scalar_swap: sl@0: public scalar_binary_swap_functor { sl@0: typedef typename scalar_binary_swap_functor::argument1_type argument1_type; sl@0: typedef typename scalar_binary_swap_functor::argument2_type argument2_type; sl@0: sl@0: static BOOST_UBLAS_INLINE sl@0: void apply (argument1_type t1, argument2_type t2) { sl@0: std::swap (t1, t2); sl@0: } sl@0: sl@0: template sl@0: struct rebind { sl@0: typedef scalar_swap other; sl@0: }; sl@0: }; sl@0: sl@0: // Vector functors sl@0: sl@0: // Unary returning scalar sl@0: template sl@0: struct vector_scalar_unary_functor { sl@0: typedef std::size_t size_type; sl@0: typedef std::ptrdiff_t difference_type; sl@0: typedef T value_type; sl@0: typedef T result_type; sl@0: }; sl@0: sl@0: template sl@0: struct vector_sum: sl@0: public vector_scalar_unary_functor { sl@0: typedef typename vector_scalar_unary_functor::size_type size_type; sl@0: typedef typename vector_scalar_unary_functor::difference_type difference_type; sl@0: typedef typename vector_scalar_unary_functor::value_type value_type; sl@0: typedef typename vector_scalar_unary_functor::result_type result_type; sl@0: sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const vector_expression &e) { sl@0: result_type t = result_type (0); sl@0: size_type size (e ().size ()); sl@0: for (size_type i = 0; i < size; ++ i) sl@0: t += e () (i); sl@0: return t; sl@0: } sl@0: // Dense case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (difference_type size, I it) { sl@0: result_type t = result_type (0); sl@0: while (-- size >= 0) sl@0: t += *it, ++ it; sl@0: return t; sl@0: } sl@0: // Sparse case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I it, const I &it_end) { sl@0: result_type t = result_type (0); sl@0: while (it != it_end) sl@0: t += *it, ++ it; sl@0: return t; sl@0: } sl@0: }; sl@0: sl@0: // Unary returning real scalar sl@0: template sl@0: struct vector_scalar_real_unary_functor { sl@0: typedef std::size_t size_type; sl@0: typedef std::ptrdiff_t difference_type; sl@0: typedef T value_type; sl@0: typedef typename type_traits::real_type real_type; sl@0: typedef real_type result_type; sl@0: }; sl@0: sl@0: template sl@0: struct vector_norm_1: sl@0: public vector_scalar_real_unary_functor { sl@0: typedef typename vector_scalar_real_unary_functor::size_type size_type; sl@0: typedef typename vector_scalar_real_unary_functor::difference_type difference_type; sl@0: typedef typename vector_scalar_real_unary_functor::value_type value_type; sl@0: typedef typename vector_scalar_real_unary_functor::real_type real_type; sl@0: typedef typename vector_scalar_real_unary_functor::result_type result_type; sl@0: sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const vector_expression &e) { sl@0: real_type t = real_type (); sl@0: size_type size (e ().size ()); sl@0: for (size_type i = 0; i < size; ++ i) { sl@0: real_type u (type_traits::type_abs (e () (i))); sl@0: t += u; sl@0: } sl@0: return t; sl@0: } sl@0: // Dense case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (difference_type size, I it) { sl@0: real_type t = real_type (); sl@0: while (-- size >= 0) { sl@0: real_type u (type_traits::norm_1 (*it)); sl@0: t += u; sl@0: ++ it; sl@0: } sl@0: return t; sl@0: } sl@0: // Sparse case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I it, const I &it_end) { sl@0: real_type t = real_type (); sl@0: while (it != it_end) { sl@0: real_type u (type_traits::norm_1 (*it)); sl@0: t += u; sl@0: ++ it; sl@0: } sl@0: return t; sl@0: } sl@0: }; sl@0: template sl@0: struct vector_norm_2: sl@0: public vector_scalar_real_unary_functor { sl@0: typedef typename vector_scalar_real_unary_functor::size_type size_type; sl@0: typedef typename vector_scalar_real_unary_functor::difference_type difference_type; sl@0: typedef typename vector_scalar_real_unary_functor::value_type value_type; sl@0: typedef typename vector_scalar_real_unary_functor::real_type real_type; sl@0: typedef typename vector_scalar_real_unary_functor::result_type result_type; sl@0: sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const vector_expression &e) { sl@0: #ifndef BOOST_UBLAS_SCALED_NORM sl@0: real_type t = real_type (); sl@0: size_type size (e ().size ()); sl@0: for (size_type i = 0; i < size; ++ i) { sl@0: real_type u (type_traits::norm_2 (e () (i))); sl@0: t += u * u; sl@0: } sl@0: return type_traits::type_sqrt (t); sl@0: #else sl@0: real_type scale = real_type (); sl@0: real_type sum_squares (1); sl@0: size_type size (e ().size ()); sl@0: for (size_type i = 0; i < size; ++ i) { sl@0: real_type u (type_traits::norm_2 (e () (i))); sl@0: if (scale < u) { sl@0: real_type v (scale / u); sl@0: sum_squares = sum_squares * v * v + real_type (1); sl@0: scale = u; sl@0: } else { sl@0: real_type v (u / scale); sl@0: sum_squares += v * v; sl@0: } sl@0: } sl@0: return scale * type_traits::type_sqrt (sum_squares); sl@0: #endif sl@0: } sl@0: // Dense case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (difference_type size, I it) { sl@0: #ifndef BOOST_UBLAS_SCALED_NORM sl@0: real_type t = real_type (); sl@0: while (-- size >= 0) { sl@0: real_type u (type_traits::norm_2 (*it)); sl@0: t += u * u; sl@0: ++ it; sl@0: } sl@0: return type_traits::type_sqrt (t); sl@0: #else sl@0: real_type scale = real_type (); sl@0: real_type sum_squares (1); sl@0: while (-- size >= 0) { sl@0: real_type u (type_traits::norm_2 (*it)); sl@0: if (scale < u) { sl@0: real_type v (scale / u); sl@0: sum_squares = sum_squares * v * v + real_type (1); sl@0: scale = u; sl@0: } else { sl@0: real_type v (u / scale); sl@0: sum_squares += v * v; sl@0: } sl@0: ++ it; sl@0: } sl@0: return scale * type_traits::type_sqrt (sum_squares); sl@0: #endif sl@0: } sl@0: // Sparse case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I it, const I &it_end) { sl@0: #ifndef BOOST_UBLAS_SCALED_NORM sl@0: real_type t = real_type (); sl@0: while (it != it_end) { sl@0: real_type u (type_traits::norm_2 (*it)); sl@0: t += u * u; sl@0: ++ it; sl@0: } sl@0: return type_traits::type_sqrt (t); sl@0: #else sl@0: real_type scale = real_type (); sl@0: real_type sum_squares (1); sl@0: while (it != it_end) { sl@0: real_type u (type_traits::norm_2 (*it)); sl@0: if (scale < u) { sl@0: real_type v (scale / u); sl@0: sum_squares = sum_squares * v * v + real_type (1); sl@0: scale = u; sl@0: } else { sl@0: real_type v (u / scale); sl@0: sum_squares += v * v; sl@0: } sl@0: ++ it; sl@0: } sl@0: return scale * type_traits::type_sqrt (sum_squares); sl@0: #endif sl@0: } sl@0: }; sl@0: template sl@0: struct vector_norm_inf: sl@0: public vector_scalar_real_unary_functor { sl@0: typedef typename vector_scalar_real_unary_functor::size_type size_type; sl@0: typedef typename vector_scalar_real_unary_functor::difference_type difference_type; sl@0: typedef typename vector_scalar_real_unary_functor::value_type value_type; sl@0: typedef typename vector_scalar_real_unary_functor::real_type real_type; sl@0: typedef typename vector_scalar_real_unary_functor::result_type result_type; sl@0: sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const vector_expression &e) { sl@0: real_type t = real_type (); sl@0: size_type size (e ().size ()); sl@0: for (size_type i = 0; i < size; ++ i) { sl@0: real_type u (type_traits::norm_inf (e () (i))); sl@0: if (u > t) sl@0: t = u; sl@0: } sl@0: return t; sl@0: } sl@0: // Dense case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (difference_type size, I it) { sl@0: real_type t = real_type (); sl@0: while (-- size >= 0) { sl@0: real_type u (type_traits::norm_inf (*it)); sl@0: if (u > t) sl@0: t = u; sl@0: ++ it; sl@0: } sl@0: return t; sl@0: } sl@0: // Sparse case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I it, const I &it_end) { sl@0: real_type t = real_type (); sl@0: while (it != it_end) { sl@0: real_type u (type_traits::norm_inf (*it)); sl@0: if (u > t) sl@0: t = u; sl@0: ++ it; sl@0: } sl@0: return t; sl@0: } sl@0: }; sl@0: sl@0: // Unary returning index sl@0: template sl@0: struct vector_scalar_index_unary_functor { sl@0: typedef std::size_t size_type; sl@0: typedef std::ptrdiff_t difference_type; sl@0: typedef T value_type; sl@0: typedef typename type_traits::real_type real_type; sl@0: typedef size_type result_type; sl@0: }; sl@0: sl@0: template sl@0: struct vector_index_norm_inf: sl@0: public vector_scalar_index_unary_functor { sl@0: typedef typename vector_scalar_index_unary_functor::size_type size_type; sl@0: typedef typename vector_scalar_index_unary_functor::difference_type difference_type; sl@0: typedef typename vector_scalar_index_unary_functor::value_type value_type; sl@0: typedef typename vector_scalar_index_unary_functor::real_type real_type; sl@0: typedef typename vector_scalar_index_unary_functor::result_type result_type; sl@0: sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const vector_expression &e) { sl@0: // ISSUE For CBLAS compatibility return 0 index in empty case sl@0: result_type i_norm_inf (0); sl@0: real_type t = real_type (); sl@0: size_type size (e ().size ()); sl@0: for (size_type i = 0; i < size; ++ i) { sl@0: real_type u (type_traits::norm_inf (e () (i))); sl@0: if (u > t) { sl@0: i_norm_inf = i; sl@0: t = u; sl@0: } sl@0: } sl@0: return i_norm_inf; sl@0: } sl@0: // Dense case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (difference_type size, I it) { sl@0: // ISSUE For CBLAS compatibility return 0 index in empty case sl@0: result_type i_norm_inf (0); sl@0: real_type t = real_type (); sl@0: while (-- size >= 0) { sl@0: real_type u (type_traits::norm_inf (*it)); sl@0: if (u > t) { sl@0: i_norm_inf = it.index (); sl@0: t = u; sl@0: } sl@0: ++ it; sl@0: } sl@0: return i_norm_inf; sl@0: } sl@0: // Sparse case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I it, const I &it_end) { sl@0: // ISSUE For CBLAS compatibility return 0 index in empty case sl@0: result_type i_norm_inf (0); sl@0: real_type t = real_type (); sl@0: while (it != it_end) { sl@0: real_type u (type_traits::norm_inf (*it)); sl@0: if (u > t) { sl@0: i_norm_inf = it.index (); sl@0: t = u; sl@0: } sl@0: ++ it; sl@0: } sl@0: return i_norm_inf; sl@0: } sl@0: }; sl@0: sl@0: // Binary returning scalar sl@0: template sl@0: struct vector_scalar_binary_functor { sl@0: typedef std::size_t size_type; sl@0: typedef std::ptrdiff_t difference_type; sl@0: typedef TR value_type; sl@0: typedef TR result_type; sl@0: }; sl@0: sl@0: template sl@0: struct vector_inner_prod: sl@0: public vector_scalar_binary_functor { sl@0: typedef typename vector_scalar_binary_functor::size_type size_type ; sl@0: typedef typename vector_scalar_binary_functor::difference_type difference_type; sl@0: typedef typename vector_scalar_binary_functor::value_type value_type; sl@0: typedef typename vector_scalar_binary_functor::result_type result_type; sl@0: sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const vector_container &c1, sl@0: const vector_container &c2) { sl@0: #ifdef BOOST_UBLAS_USE_SIMD sl@0: using namespace raw; sl@0: size_type size (BOOST_UBLAS_SAME (c1 ().size (), c2 ().size ())); sl@0: const T1 *data1 = data_const (c1 ()); sl@0: const T2 *data2 = data_const (c2 ()); sl@0: size_type s1 = stride (c1 ()); sl@0: size_type s2 = stride (c2 ()); sl@0: result_type t = result_type (0); sl@0: if (s1 == 1 && s2 == 1) { sl@0: for (size_type i = 0; i < size; ++ i) sl@0: t += data1 [i] * data2 [i]; sl@0: } else if (s2 == 1) { sl@0: for (size_type i = 0, i1 = 0; i < size; ++ i, i1 += s1) sl@0: t += data1 [i1] * data2 [i]; sl@0: } else if (s1 == 1) { sl@0: for (size_type i = 0, i2 = 0; i < size; ++ i, i2 += s2) sl@0: t += data1 [i] * data2 [i2]; sl@0: } else { sl@0: for (size_type i = 0, i1 = 0, i2 = 0; i < size; ++ i, i1 += s1, i2 += s2) sl@0: t += data1 [i1] * data2 [i2]; sl@0: } sl@0: return t; sl@0: #elif defined(BOOST_UBLAS_HAVE_BINDINGS) sl@0: return boost::numeric::bindings::atlas::dot (c1 (), c2 ()); sl@0: #else sl@0: return apply (static_cast > (c1), static_cast > (c2)); sl@0: #endif sl@0: } sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const vector_expression &e1, sl@0: const vector_expression &e2) { sl@0: size_type size (BOOST_UBLAS_SAME (e1 ().size (), e2 ().size ())); sl@0: result_type t = result_type (0); sl@0: #ifndef BOOST_UBLAS_USE_DUFF_DEVICE sl@0: for (size_type i = 0; i < size; ++ i) sl@0: t += e1 () (i) * e2 () (i); sl@0: #else sl@0: size_type i (0); sl@0: DD (size, 4, r, (t += e1 () (i) * e2 () (i), ++ i)); sl@0: #endif sl@0: return t; sl@0: } sl@0: // Dense case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (difference_type size, I1 it1, I2 it2) { sl@0: result_type t = result_type (0); sl@0: #ifndef BOOST_UBLAS_USE_DUFF_DEVICE sl@0: while (-- size >= 0) sl@0: t += *it1 * *it2, ++ it1, ++ it2; sl@0: #else sl@0: DD (size, 4, r, (t += *it1 * *it2, ++ it1, ++ it2)); sl@0: #endif sl@0: return t; sl@0: } sl@0: // Packed case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &it1_end, I2 it2, const I2 &it2_end) { sl@0: result_type t = result_type (0); sl@0: difference_type it1_size (it1_end - it1); sl@0: difference_type it2_size (it2_end - it2); sl@0: difference_type diff (0); sl@0: if (it1_size > 0 && it2_size > 0) sl@0: diff = it2.index () - it1.index (); sl@0: if (diff != 0) { sl@0: difference_type size = (std::min) (diff, it1_size); sl@0: if (size > 0) { sl@0: it1 += size; sl@0: it1_size -= size; sl@0: diff -= size; sl@0: } sl@0: size = (std::min) (- diff, it2_size); sl@0: if (size > 0) { sl@0: it2 += size; sl@0: it2_size -= size; sl@0: diff += size; sl@0: } sl@0: } sl@0: difference_type size ((std::min) (it1_size, it2_size)); sl@0: while (-- size >= 0) sl@0: t += *it1 * *it2, ++ it1, ++ it2; sl@0: return t; sl@0: } sl@0: // Sparse case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &it1_end, I2 it2, const I2 &it2_end, sparse_bidirectional_iterator_tag) { sl@0: result_type t = result_type (0); sl@0: if (it1 != it1_end && it2 != it2_end) { sl@0: size_type it1_index = it1.index (), it2_index = it2.index (); sl@0: while (true) { sl@0: difference_type compare = it1_index - it2_index; sl@0: if (compare == 0) { sl@0: t += *it1 * *it2, ++ it1, ++ it2; sl@0: if (it1 != it1_end && it2 != it2_end) { sl@0: it1_index = it1.index (); sl@0: it2_index = it2.index (); sl@0: } else sl@0: break; sl@0: } else if (compare < 0) { sl@0: increment (it1, it1_end, - compare); sl@0: if (it1 != it1_end) sl@0: it1_index = it1.index (); sl@0: else sl@0: break; sl@0: } else if (compare > 0) { sl@0: increment (it2, it2_end, compare); sl@0: if (it2 != it2_end) sl@0: it2_index = it2.index (); sl@0: else sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: return t; sl@0: } sl@0: }; sl@0: sl@0: // Matrix functors sl@0: sl@0: // Binary returning vector sl@0: template sl@0: struct matrix_vector_binary_functor { sl@0: typedef std::size_t size_type; sl@0: typedef std::ptrdiff_t difference_type; sl@0: typedef TR value_type; sl@0: typedef TR result_type; sl@0: }; sl@0: sl@0: template sl@0: struct matrix_vector_prod1: sl@0: public matrix_vector_binary_functor { sl@0: typedef typename matrix_vector_binary_functor::size_type size_type; sl@0: typedef typename matrix_vector_binary_functor::difference_type difference_type; sl@0: typedef typename matrix_vector_binary_functor::value_type value_type; sl@0: typedef typename matrix_vector_binary_functor::result_type result_type; sl@0: sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const matrix_container &c1, sl@0: const vector_container &c2, sl@0: size_type i) { sl@0: #ifdef BOOST_UBLAS_USE_SIMD sl@0: using namespace raw; sl@0: size_type size = BOOST_UBLAS_SAME (c1 ().size2 (), c2 ().size ()); sl@0: const T1 *data1 = data_const (c1 ()) + i * stride1 (c1 ()); sl@0: const T2 *data2 = data_const (c2 ()); sl@0: size_type s1 = stride2 (c1 ()); sl@0: size_type s2 = stride (c2 ()); sl@0: result_type t = result_type (0); sl@0: if (s1 == 1 && s2 == 1) { sl@0: for (size_type j = 0; j < size; ++ j) sl@0: t += data1 [j] * data2 [j]; sl@0: } else if (s2 == 1) { sl@0: for (size_type j = 0, j1 = 0; j < size; ++ j, j1 += s1) sl@0: t += data1 [j1] * data2 [j]; sl@0: } else if (s1 == 1) { sl@0: for (size_type j = 0, j2 = 0; j < size; ++ j, j2 += s2) sl@0: t += data1 [j] * data2 [j2]; sl@0: } else { sl@0: for (size_type j = 0, j1 = 0, j2 = 0; j < size; ++ j, j1 += s1, j2 += s2) sl@0: t += data1 [j1] * data2 [j2]; sl@0: } sl@0: return t; sl@0: #elif defined(BOOST_UBLAS_HAVE_BINDINGS) sl@0: return boost::numeric::bindings::atlas::dot (c1 ().row (i), c2 ()); sl@0: #else sl@0: return apply (static_cast > (c1), static_cast > (c2, i)); sl@0: #endif sl@0: } sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const matrix_expression &e1, sl@0: const vector_expression &e2, sl@0: size_type i) { sl@0: size_type size = BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size ()); sl@0: result_type t = result_type (0); sl@0: #ifndef BOOST_UBLAS_USE_DUFF_DEVICE sl@0: for (size_type j = 0; j < size; ++ j) sl@0: t += e1 () (i, j) * e2 () (j); sl@0: #else sl@0: size_type j (0); sl@0: DD (size, 4, r, (t += e1 () (i, j) * e2 () (j), ++ j)); sl@0: #endif sl@0: return t; sl@0: } sl@0: // Dense case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (difference_type size, I1 it1, I2 it2) { sl@0: result_type t = result_type (0); sl@0: #ifndef BOOST_UBLAS_USE_DUFF_DEVICE sl@0: while (-- size >= 0) sl@0: t += *it1 * *it2, ++ it1, ++ it2; sl@0: #else sl@0: DD (size, 4, r, (t += *it1 * *it2, ++ it1, ++ it2)); sl@0: #endif sl@0: return t; sl@0: } sl@0: // Packed case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &it1_end, I2 it2, const I2 &it2_end) { sl@0: result_type t = result_type (0); sl@0: difference_type it1_size (it1_end - it1); sl@0: difference_type it2_size (it2_end - it2); sl@0: difference_type diff (0); sl@0: if (it1_size > 0 && it2_size > 0) sl@0: diff = it2.index () - it1.index2 (); sl@0: if (diff != 0) { sl@0: difference_type size = (std::min) (diff, it1_size); sl@0: if (size > 0) { sl@0: it1 += size; sl@0: it1_size -= size; sl@0: diff -= size; sl@0: } sl@0: size = (std::min) (- diff, it2_size); sl@0: if (size > 0) { sl@0: it2 += size; sl@0: it2_size -= size; sl@0: diff += size; sl@0: } sl@0: } sl@0: difference_type size ((std::min) (it1_size, it2_size)); sl@0: while (-- size >= 0) sl@0: t += *it1 * *it2, ++ it1, ++ it2; sl@0: return t; sl@0: } sl@0: // Sparse case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &it1_end, I2 it2, const I2 &it2_end, sl@0: sparse_bidirectional_iterator_tag, sparse_bidirectional_iterator_tag) { sl@0: result_type t = result_type (0); sl@0: if (it1 != it1_end && it2 != it2_end) { sl@0: size_type it1_index = it1.index2 (), it2_index = it2.index (); sl@0: while (true) { sl@0: difference_type compare = it1_index - it2_index; sl@0: if (compare == 0) { sl@0: t += *it1 * *it2, ++ it1, ++ it2; sl@0: if (it1 != it1_end && it2 != it2_end) { sl@0: it1_index = it1.index2 (); sl@0: it2_index = it2.index (); sl@0: } else sl@0: break; sl@0: } else if (compare < 0) { sl@0: increment (it1, it1_end, - compare); sl@0: if (it1 != it1_end) sl@0: it1_index = it1.index2 (); sl@0: else sl@0: break; sl@0: } else if (compare > 0) { sl@0: increment (it2, it2_end, compare); sl@0: if (it2 != it2_end) sl@0: it2_index = it2.index (); sl@0: else sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: return t; sl@0: } sl@0: // Sparse packed case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &it1_end, I2 it2, const I2 &/* it2_end */, sl@0: sparse_bidirectional_iterator_tag, packed_random_access_iterator_tag) { sl@0: result_type t = result_type (0); sl@0: while (it1 != it1_end) { sl@0: t += *it1 * it2 () (it1.index2 ()); sl@0: ++ it1; sl@0: } sl@0: return t; sl@0: } sl@0: // Packed sparse case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &/* it1_end */, I2 it2, const I2 &it2_end, sl@0: packed_random_access_iterator_tag, sparse_bidirectional_iterator_tag) { sl@0: result_type t = result_type (0); sl@0: while (it2 != it2_end) { sl@0: t += it1 () (it1.index1 (), it2.index ()) * *it2; sl@0: ++ it2; sl@0: } sl@0: return t; sl@0: } sl@0: // Another dispatcher sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &it1_end, I2 it2, const I2 &it2_end, sl@0: sparse_bidirectional_iterator_tag) { sl@0: typedef typename I1::iterator_category iterator1_category; sl@0: typedef typename I2::iterator_category iterator2_category; sl@0: return apply (it1, it1_end, it2, it2_end, iterator1_category (), iterator2_category ()); sl@0: } sl@0: }; sl@0: sl@0: template sl@0: struct matrix_vector_prod2: sl@0: public matrix_vector_binary_functor { sl@0: typedef typename matrix_vector_binary_functor::size_type size_type; sl@0: typedef typename matrix_vector_binary_functor::difference_type difference_type; sl@0: typedef typename matrix_vector_binary_functor::value_type value_type; sl@0: typedef typename matrix_vector_binary_functor::result_type result_type; sl@0: sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const vector_container &c1, sl@0: const matrix_container &c2, sl@0: size_type i) { sl@0: #ifdef BOOST_UBLAS_USE_SIMD sl@0: using namespace raw; sl@0: size_type size = BOOST_UBLAS_SAME (c1 ().size (), c2 ().size1 ()); sl@0: const T1 *data1 = data_const (c1 ()); sl@0: const T2 *data2 = data_const (c2 ()) + i * stride2 (c2 ()); sl@0: size_type s1 = stride (c1 ()); sl@0: size_type s2 = stride1 (c2 ()); sl@0: result_type t = result_type (0); sl@0: if (s1 == 1 && s2 == 1) { sl@0: for (size_type j = 0; j < size; ++ j) sl@0: t += data1 [j] * data2 [j]; sl@0: } else if (s2 == 1) { sl@0: for (size_type j = 0, j1 = 0; j < size; ++ j, j1 += s1) sl@0: t += data1 [j1] * data2 [j]; sl@0: } else if (s1 == 1) { sl@0: for (size_type j = 0, j2 = 0; j < size; ++ j, j2 += s2) sl@0: t += data1 [j] * data2 [j2]; sl@0: } else { sl@0: for (size_type j = 0, j1 = 0, j2 = 0; j < size; ++ j, j1 += s1, j2 += s2) sl@0: t += data1 [j1] * data2 [j2]; sl@0: } sl@0: return t; sl@0: #elif defined(BOOST_UBLAS_HAVE_BINDINGS) sl@0: return boost::numeric::bindings::atlas::dot (c1 (), c2 ().column (i)); sl@0: #else sl@0: return apply (static_cast > (c1), static_cast > (c2, i)); sl@0: #endif sl@0: } sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const vector_expression &e1, sl@0: const matrix_expression &e2, sl@0: size_type i) { sl@0: size_type size = BOOST_UBLAS_SAME (e1 ().size (), e2 ().size1 ()); sl@0: result_type t = result_type (0); sl@0: #ifndef BOOST_UBLAS_USE_DUFF_DEVICE sl@0: for (size_type j = 0; j < size; ++ j) sl@0: t += e1 () (j) * e2 () (j, i); sl@0: #else sl@0: size_type j (0); sl@0: DD (size, 4, r, (t += e1 () (j) * e2 () (j, i), ++ j)); sl@0: #endif sl@0: return t; sl@0: } sl@0: // Dense case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (difference_type size, I1 it1, I2 it2) { sl@0: result_type t = result_type (0); sl@0: #ifndef BOOST_UBLAS_USE_DUFF_DEVICE sl@0: while (-- size >= 0) sl@0: t += *it1 * *it2, ++ it1, ++ it2; sl@0: #else sl@0: DD (size, 4, r, (t += *it1 * *it2, ++ it1, ++ it2)); sl@0: #endif sl@0: return t; sl@0: } sl@0: // Packed case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &it1_end, I2 it2, const I2 &it2_end) { sl@0: result_type t = result_type (0); sl@0: difference_type it1_size (it1_end - it1); sl@0: difference_type it2_size (it2_end - it2); sl@0: difference_type diff (0); sl@0: if (it1_size > 0 && it2_size > 0) sl@0: diff = it2.index1 () - it1.index (); sl@0: if (diff != 0) { sl@0: difference_type size = (std::min) (diff, it1_size); sl@0: if (size > 0) { sl@0: it1 += size; sl@0: it1_size -= size; sl@0: diff -= size; sl@0: } sl@0: size = (std::min) (- diff, it2_size); sl@0: if (size > 0) { sl@0: it2 += size; sl@0: it2_size -= size; sl@0: diff += size; sl@0: } sl@0: } sl@0: difference_type size ((std::min) (it1_size, it2_size)); sl@0: while (-- size >= 0) sl@0: t += *it1 * *it2, ++ it1, ++ it2; sl@0: return t; sl@0: } sl@0: // Sparse case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &it1_end, I2 it2, const I2 &it2_end, sl@0: sparse_bidirectional_iterator_tag, sparse_bidirectional_iterator_tag) { sl@0: result_type t = result_type (0); sl@0: if (it1 != it1_end && it2 != it2_end) { sl@0: size_type it1_index = it1.index (), it2_index = it2.index1 (); sl@0: while (true) { sl@0: difference_type compare = it1_index - it2_index; sl@0: if (compare == 0) { sl@0: t += *it1 * *it2, ++ it1, ++ it2; sl@0: if (it1 != it1_end && it2 != it2_end) { sl@0: it1_index = it1.index (); sl@0: it2_index = it2.index1 (); sl@0: } else sl@0: break; sl@0: } else if (compare < 0) { sl@0: increment (it1, it1_end, - compare); sl@0: if (it1 != it1_end) sl@0: it1_index = it1.index (); sl@0: else sl@0: break; sl@0: } else if (compare > 0) { sl@0: increment (it2, it2_end, compare); sl@0: if (it2 != it2_end) sl@0: it2_index = it2.index1 (); sl@0: else sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: return t; sl@0: } sl@0: // Packed sparse case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &/* it1_end */, I2 it2, const I2 &it2_end, sl@0: packed_random_access_iterator_tag, sparse_bidirectional_iterator_tag) { sl@0: result_type t = result_type (0); sl@0: while (it2 != it2_end) { sl@0: t += it1 () (it2.index1 ()) * *it2; sl@0: ++ it2; sl@0: } sl@0: return t; sl@0: } sl@0: // Sparse packed case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &it1_end, I2 it2, const I2 &/* it2_end */, sl@0: sparse_bidirectional_iterator_tag, packed_random_access_iterator_tag) { sl@0: result_type t = result_type (0); sl@0: while (it1 != it1_end) { sl@0: t += *it1 * it2 () (it1.index (), it2.index2 ()); sl@0: ++ it1; sl@0: } sl@0: return t; sl@0: } sl@0: // Another dispatcher sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &it1_end, I2 it2, const I2 &it2_end, sl@0: sparse_bidirectional_iterator_tag) { sl@0: typedef typename I1::iterator_category iterator1_category; sl@0: typedef typename I2::iterator_category iterator2_category; sl@0: return apply (it1, it1_end, it2, it2_end, iterator1_category (), iterator2_category ()); sl@0: } sl@0: }; sl@0: sl@0: // Binary returning matrix sl@0: template sl@0: struct matrix_matrix_binary_functor { sl@0: typedef std::size_t size_type; sl@0: typedef std::ptrdiff_t difference_type; sl@0: typedef TR value_type; sl@0: typedef TR result_type; sl@0: }; sl@0: sl@0: template sl@0: struct matrix_matrix_prod: sl@0: public matrix_matrix_binary_functor { sl@0: typedef typename matrix_matrix_binary_functor::size_type size_type; sl@0: typedef typename matrix_matrix_binary_functor::difference_type difference_type; sl@0: typedef typename matrix_matrix_binary_functor::value_type value_type; sl@0: typedef typename matrix_matrix_binary_functor::result_type result_type; sl@0: sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const matrix_container &c1, sl@0: const matrix_container &c2, sl@0: size_type i, size_type j) { sl@0: #ifdef BOOST_UBLAS_USE_SIMD sl@0: using namespace raw; sl@0: size_type size = BOOST_UBLAS_SAME (c1 ().size2 (), c2 ().sizc1 ()); sl@0: const T1 *data1 = data_const (c1 ()) + i * stride1 (c1 ()); sl@0: const T2 *data2 = data_const (c2 ()) + j * stride2 (c2 ()); sl@0: size_type s1 = stride2 (c1 ()); sl@0: size_type s2 = stride1 (c2 ()); sl@0: result_type t = result_type (0); sl@0: if (s1 == 1 && s2 == 1) { sl@0: for (size_type k = 0; k < size; ++ k) sl@0: t += data1 [k] * data2 [k]; sl@0: } else if (s2 == 1) { sl@0: for (size_type k = 0, k1 = 0; k < size; ++ k, k1 += s1) sl@0: t += data1 [k1] * data2 [k]; sl@0: } else if (s1 == 1) { sl@0: for (size_type k = 0, k2 = 0; k < size; ++ k, k2 += s2) sl@0: t += data1 [k] * data2 [k2]; sl@0: } else { sl@0: for (size_type k = 0, k1 = 0, k2 = 0; k < size; ++ k, k1 += s1, k2 += s2) sl@0: t += data1 [k1] * data2 [k2]; sl@0: } sl@0: return t; sl@0: #elif defined(BOOST_UBLAS_HAVE_BINDINGS) sl@0: return boost::numeric::bindings::atlas::dot (c1 ().row (i), c2 ().column (j)); sl@0: #else sl@0: return apply (static_cast > (c1), static_cast > (c2, i)); sl@0: #endif sl@0: } sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const matrix_expression &e1, sl@0: const matrix_expression &e2, sl@0: size_type i, size_type j) { sl@0: size_type size = BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size1 ()); sl@0: result_type t = result_type (0); sl@0: #ifndef BOOST_UBLAS_USE_DUFF_DEVICE sl@0: for (size_type k = 0; k < size; ++ k) sl@0: t += e1 () (i, k) * e2 () (k, j); sl@0: #else sl@0: size_type k (0); sl@0: DD (size, 4, r, (t += e1 () (i, k) * e2 () (k, j), ++ k)); sl@0: #endif sl@0: return t; sl@0: } sl@0: // Dense case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (difference_type size, I1 it1, I2 it2) { sl@0: result_type t = result_type (0); sl@0: #ifndef BOOST_UBLAS_USE_DUFF_DEVICE sl@0: while (-- size >= 0) sl@0: t += *it1 * *it2, ++ it1, ++ it2; sl@0: #else sl@0: DD (size, 4, r, (t += *it1 * *it2, ++ it1, ++ it2)); sl@0: #endif sl@0: return t; sl@0: } sl@0: // Packed case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &it1_end, I2 it2, const I2 &it2_end, packed_random_access_iterator_tag) { sl@0: result_type t = result_type (0); sl@0: difference_type it1_size (it1_end - it1); sl@0: difference_type it2_size (it2_end - it2); sl@0: difference_type diff (0); sl@0: if (it1_size > 0 && it2_size > 0) sl@0: diff = it2.index1 () - it1.index2 (); sl@0: if (diff != 0) { sl@0: difference_type size = (std::min) (diff, it1_size); sl@0: if (size > 0) { sl@0: it1 += size; sl@0: it1_size -= size; sl@0: diff -= size; sl@0: } sl@0: size = (std::min) (- diff, it2_size); sl@0: if (size > 0) { sl@0: it2 += size; sl@0: it2_size -= size; sl@0: diff += size; sl@0: } sl@0: } sl@0: difference_type size ((std::min) (it1_size, it2_size)); sl@0: while (-- size >= 0) sl@0: t += *it1 * *it2, ++ it1, ++ it2; sl@0: return t; sl@0: } sl@0: // Sparse case sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (I1 it1, const I1 &it1_end, I2 it2, const I2 &it2_end, sparse_bidirectional_iterator_tag) { sl@0: result_type t = result_type (0); sl@0: if (it1 != it1_end && it2 != it2_end) { sl@0: size_type it1_index = it1.index2 (), it2_index = it2.index1 (); sl@0: while (true) { sl@0: difference_type compare = it1_index - it2_index; sl@0: if (compare == 0) { sl@0: t += *it1 * *it2, ++ it1, ++ it2; sl@0: if (it1 != it1_end && it2 != it2_end) { sl@0: it1_index = it1.index2 (); sl@0: it2_index = it2.index1 (); sl@0: } else sl@0: break; sl@0: } else if (compare < 0) { sl@0: increment (it1, it1_end, - compare); sl@0: if (it1 != it1_end) sl@0: it1_index = it1.index2 (); sl@0: else sl@0: break; sl@0: } else if (compare > 0) { sl@0: increment (it2, it2_end, compare); sl@0: if (it2 != it2_end) sl@0: it2_index = it2.index1 (); sl@0: else sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: return t; sl@0: } sl@0: }; sl@0: sl@0: // Unary returning scalar norm sl@0: template sl@0: struct matrix_scalar_real_unary_functor { sl@0: typedef std::size_t size_type; sl@0: typedef std::ptrdiff_t difference_type; sl@0: typedef T value_type; sl@0: typedef typename type_traits::real_type real_type; sl@0: typedef real_type result_type; sl@0: }; sl@0: sl@0: template sl@0: struct matrix_norm_1: sl@0: public matrix_scalar_real_unary_functor { sl@0: typedef typename matrix_scalar_real_unary_functor::size_type size_type; sl@0: typedef typename matrix_scalar_real_unary_functor::difference_type difference_type; sl@0: typedef typename matrix_scalar_real_unary_functor::value_type value_type; sl@0: typedef typename matrix_scalar_real_unary_functor::real_type real_type; sl@0: typedef typename matrix_scalar_real_unary_functor::result_type result_type; sl@0: sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const matrix_expression &e) { sl@0: real_type t = real_type (); sl@0: size_type size2 (e ().size2 ()); sl@0: for (size_type j = 0; j < size2; ++ j) { sl@0: real_type u = real_type (); sl@0: size_type size1 (e ().size1 ()); sl@0: for (size_type i = 0; i < size1; ++ i) { sl@0: real_type v (type_traits::norm_1 (e () (i, j))); sl@0: u += v; sl@0: } sl@0: if (u > t) sl@0: t = u; sl@0: } sl@0: return t; sl@0: } sl@0: }; sl@0: template sl@0: struct matrix_norm_frobenius: sl@0: public matrix_scalar_real_unary_functor { sl@0: typedef typename matrix_scalar_real_unary_functor::size_type size_type; sl@0: typedef typename matrix_scalar_real_unary_functor::difference_type difference_type; sl@0: typedef typename matrix_scalar_real_unary_functor::value_type value_type; sl@0: typedef typename matrix_scalar_real_unary_functor::real_type real_type; sl@0: typedef typename matrix_scalar_real_unary_functor::result_type result_type; sl@0: sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const matrix_expression &e) { sl@0: real_type t = real_type (); sl@0: size_type size1 (e ().size1 ()); sl@0: for (size_type i = 0; i < size1; ++ i) { sl@0: size_type size2 (e ().size2 ()); sl@0: for (size_type j = 0; j < size2; ++ j) { sl@0: real_type u (type_traits::norm_2 (e () (i, j))); sl@0: t += u * u; sl@0: } sl@0: } sl@0: return type_traits::type_sqrt (t); sl@0: } sl@0: }; sl@0: template sl@0: struct matrix_norm_inf: sl@0: public matrix_scalar_real_unary_functor { sl@0: typedef typename matrix_scalar_real_unary_functor::size_type size_type; sl@0: typedef typename matrix_scalar_real_unary_functor::difference_type difference_type; sl@0: typedef typename matrix_scalar_real_unary_functor::value_type value_type; sl@0: typedef typename matrix_scalar_real_unary_functor::real_type real_type; sl@0: typedef typename matrix_scalar_real_unary_functor::result_type result_type; sl@0: sl@0: template sl@0: static BOOST_UBLAS_INLINE sl@0: result_type apply (const matrix_expression &e) { sl@0: real_type t = real_type (); sl@0: size_type size1 (e ().size1 ()); sl@0: for (size_type i = 0; i < size1; ++ i) { sl@0: real_type u = real_type (); sl@0: size_type size2 (e ().size2 ()); sl@0: for (size_type j = 0; j < size2; ++ j) { sl@0: real_type v (type_traits::norm_inf (e () (i, j))); sl@0: u += v; sl@0: } sl@0: if (u > t) sl@0: t = u; sl@0: } sl@0: return t; sl@0: } sl@0: }; sl@0: sl@0: // This functor computes the address translation sl@0: // matrix [i] [j] -> storage [i * size2 + j] sl@0: template sl@0: struct basic_row_major { sl@0: typedef Z size_type; sl@0: typedef D difference_type; sl@0: typedef row_major_tag orientation_category; sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type storage_size (size_type size1, size_type size2) { sl@0: // Guard against size_type overflow sl@0: BOOST_UBLAS_CHECK (size2 == 0 || size1 <= (std::numeric_limits::max) () / size2, bad_size ()); sl@0: return size1 * size2; sl@0: } sl@0: sl@0: // Indexing sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type element (size_type i, size_type size1, size_type j, size_type size2) { sl@0: BOOST_UBLAS_CHECK (i < size1, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2, bad_index ()); sl@0: detail::ignore_unused_variable_warning(size1); sl@0: // Guard against size_type overflow sl@0: BOOST_UBLAS_CHECK (i <= ((std::numeric_limits::max) () - j) / size2, bad_index ()); sl@0: return i * size2 + j; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type address (size_type i, size_type size1, size_type j, size_type size2) { sl@0: BOOST_UBLAS_CHECK (i <= size1, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j <= size2, bad_index ()); sl@0: // Guard against size_type overflow - address may be size2 past end of storage sl@0: BOOST_UBLAS_CHECK (size2 == 0 || i <= ((std::numeric_limits::max) () - j) / size2, bad_index ()); sl@0: detail::ignore_unused_variable_warning(size1); sl@0: return i * size2 + j; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: difference_type distance1 (difference_type k, size_type /* size1 */, size_type size2) { sl@0: return size2 != 0 ? k / size2 : 0; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: difference_type distance2 (difference_type k, size_type /* size1 */, size_type /* size2 */) { sl@0: return k; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 (difference_type k, size_type /* size1 */, size_type size2) { sl@0: return size2 != 0 ? k / size2 : 0; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 (difference_type k, size_type /* size1 */, size_type size2) { sl@0: return size2 != 0 ? k % size2 : 0; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool fast1 () { sl@0: return false; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type one1 (size_type /* size1 */, size_type size2) { sl@0: return size2; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool fast2 () { sl@0: return true; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type one2 (size_type /* size1 */, size_type /* size2 */) { sl@0: return 1; sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type triangular_size (size_type size1, size_type size2) { sl@0: size_type size = (std::max) (size1, size2); sl@0: // Guard against size_type overflow - simplified sl@0: BOOST_UBLAS_CHECK (size == 0 || size / 2 < (std::numeric_limits::max) () / size /* +1/2 */, bad_size ()); sl@0: return ((size + 1) * size) / 2; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type lower_element (size_type i, size_type size1, size_type j, size_type size2) { sl@0: BOOST_UBLAS_CHECK (i < size1, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2, bad_index ()); sl@0: BOOST_UBLAS_CHECK (i >= j, bad_index ()); sl@0: detail::ignore_unused_variable_warning(size1); sl@0: detail::ignore_unused_variable_warning(size2); sl@0: // FIXME size_type overflow sl@0: // sigma_i (i + 1) = (i + 1) * i / 2 sl@0: // i = 0 1 2 3, sigma = 0 1 3 6 sl@0: return ((i + 1) * i) / 2 + j; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type upper_element (size_type i, size_type size1, size_type j, size_type size2) { sl@0: BOOST_UBLAS_CHECK (i < size1, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2, bad_index ()); sl@0: BOOST_UBLAS_CHECK (i <= j, bad_index ()); sl@0: // FIXME size_type overflow sl@0: // sigma_i (size - i) = size * i - i * (i - 1) / 2 sl@0: // i = 0 1 2 3, sigma = 0 4 7 9 sl@0: return (i * (2 * (std::max) (size1, size2) - i + 1)) / 2 + j - i; sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type element1 (size_type i, size_type size1, size_type /* j */, size_type /* size2 */) { sl@0: BOOST_UBLAS_CHECK (i < size1, bad_index ()); sl@0: detail::ignore_unused_variable_warning(size1); sl@0: return i; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type element2 (size_type /* i */, size_type /* size1 */, size_type j, size_type size2) { sl@0: BOOST_UBLAS_CHECK (j < size2, bad_index ()); sl@0: detail::ignore_unused_variable_warning(size2); sl@0: return j; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type address1 (size_type i, size_type size1, size_type /* j */, size_type /* size2 */) { sl@0: BOOST_UBLAS_CHECK (i <= size1, bad_index ()); sl@0: detail::ignore_unused_variable_warning(size1); sl@0: return i; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type address2 (size_type /* i */, size_type /* size1 */, size_type j, size_type size2) { sl@0: BOOST_UBLAS_CHECK (j <= size2, bad_index ()); sl@0: detail::ignore_unused_variable_warning(size2); sl@0: return j; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 (size_type index1, size_type /* index2 */) { sl@0: return index1; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 (size_type /* index1 */, size_type index2) { sl@0: return index2; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type size1 (size_type size1, size_type /* size2 */) { sl@0: return size1; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type size2 (size_type /* size1 */, size_type size2) { sl@0: return size2; sl@0: } sl@0: sl@0: // Iterating sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: void increment1 (I &it, size_type /* size1 */, size_type size2) { sl@0: it += size2; sl@0: } sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: void decrement1 (I &it, size_type /* size1 */, size_type size2) { sl@0: it -= size2; sl@0: } sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: void increment2 (I &it, size_type /* size1 */, size_type /* size2 */) { sl@0: ++ it; sl@0: } sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: void decrement2 (I &it, size_type /* size1 */, size_type /* size2 */) { sl@0: -- it; sl@0: } sl@0: }; sl@0: sl@0: // This functor computes the address translation sl@0: // matrix [i] [j] -> storage [i + j * size1] sl@0: template sl@0: struct basic_column_major { sl@0: typedef Z size_type; sl@0: typedef D difference_type; sl@0: typedef column_major_tag orientation_category; sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type storage_size (size_type size1, size_type size2) { sl@0: // Guard against size_type overflow sl@0: BOOST_UBLAS_CHECK (size1 == 0 || size2 <= (std::numeric_limits::max) () / size1, bad_size ()); sl@0: return size1 * size2; sl@0: } sl@0: sl@0: // Indexing sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type element (size_type i, size_type size1, size_type j, size_type size2) { sl@0: BOOST_UBLAS_CHECK (i < size1, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2, bad_index ()); sl@0: detail::ignore_unused_variable_warning(size2); sl@0: // Guard against size_type overflow sl@0: BOOST_UBLAS_CHECK (j <= ((std::numeric_limits::max) () - i) / size1, bad_index ()); sl@0: return i + j * size1; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type address (size_type i, size_type size1, size_type j, size_type size2) { sl@0: BOOST_UBLAS_CHECK (i <= size1, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j <= size2, bad_index ()); sl@0: detail::ignore_unused_variable_warning(size2); sl@0: // Guard against size_type overflow - address may be size1 past end of storage sl@0: BOOST_UBLAS_CHECK (size1 == 0 || j <= ((std::numeric_limits::max) () - i) / size1, bad_index ()); sl@0: return i + j * size1; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: difference_type distance1 (difference_type k, size_type /* size1 */, size_type /* size2 */) { sl@0: return k; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: difference_type distance2 (difference_type k, size_type size1, size_type /* size2 */) { sl@0: return size1 != 0 ? k / size1 : 0; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 (difference_type k, size_type size1, size_type /* size2 */) { sl@0: return size1 != 0 ? k % size1 : 0; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 (difference_type k, size_type size1, size_type /* size2 */) { sl@0: return size1 != 0 ? k / size1 : 0; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool fast1 () { sl@0: return true; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type one1 (size_type /* size1 */, size_type /* size2 */) { sl@0: return 1; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool fast2 () { sl@0: return false; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type one2 (size_type size1, size_type /* size2 */) { sl@0: return size1; sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type triangular_size (size_type size1, size_type size2) { sl@0: size_type size = (std::max) (size1, size2); sl@0: // Guard against size_type overflow - simplified sl@0: BOOST_UBLAS_CHECK (size == 0 || size / 2 < (std::numeric_limits::max) () / size /* +1/2 */, bad_size ()); sl@0: return ((size + 1) * size) / 2; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type lower_element (size_type i, size_type size1, size_type j, size_type size2) { sl@0: BOOST_UBLAS_CHECK (i < size1, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2, bad_index ()); sl@0: BOOST_UBLAS_CHECK (i >= j, bad_index ()); sl@0: // FIXME size_type overflow sl@0: // sigma_j (size - j) = size * j - j * (j - 1) / 2 sl@0: // j = 0 1 2 3, sigma = 0 4 7 9 sl@0: return i - j + (j * (2 * (std::max) (size1, size2) - j + 1)) / 2; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type upper_element (size_type i, size_type size1, size_type j, size_type size2) { sl@0: BOOST_UBLAS_CHECK (i < size1, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2, bad_index ()); sl@0: BOOST_UBLAS_CHECK (i <= j, bad_index ()); sl@0: // FIXME size_type overflow sl@0: // sigma_j (j + 1) = (j + 1) * j / 2 sl@0: // j = 0 1 2 3, sigma = 0 1 3 6 sl@0: return i + ((j + 1) * j) / 2; sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type element1 (size_type /* i */, size_type /* size1 */, size_type j, size_type size2) { sl@0: BOOST_UBLAS_CHECK (j < size2, bad_index ()); sl@0: detail::ignore_unused_variable_warning(size2); sl@0: return j; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type element2 (size_type i, size_type size1, size_type /* j */, size_type /* size2 */) { sl@0: BOOST_UBLAS_CHECK (i < size1, bad_index ()); sl@0: detail::ignore_unused_variable_warning(size1); sl@0: return i; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type address1 (size_type /* i */, size_type /* size1 */, size_type j, size_type size2) { sl@0: BOOST_UBLAS_CHECK (j <= size2, bad_index ()); sl@0: detail::ignore_unused_variable_warning(size2); sl@0: return j; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type address2 (size_type i, size_type size1, size_type /* j */, size_type /* size2 */) { sl@0: BOOST_UBLAS_CHECK (i <= size1, bad_index ()); sl@0: detail::ignore_unused_variable_warning(size1); sl@0: return i; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 (size_type /* index1 */, size_type index2) { sl@0: return index2; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 (size_type index1, size_type /* index2 */) { sl@0: return index1; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type size1 (size_type /* size1 */, size_type size2) { sl@0: return size2; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type size2 (size_type size1, size_type /* size2 */) { sl@0: return size1; sl@0: } sl@0: sl@0: // Iterating sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: void increment1 (I &it, size_type /* size1 */, size_type /* size2 */) { sl@0: ++ it; sl@0: } sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: void decrement1 (I &it, size_type /* size1 */, size_type /* size2 */) { sl@0: -- it; sl@0: } sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: void increment2 (I &it, size_type size1, size_type /* size2 */) { sl@0: it += size1; sl@0: } sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: void decrement2 (I &it, size_type size1, size_type /* size2 */) { sl@0: it -= size1; sl@0: } sl@0: }; sl@0: sl@0: sl@0: template sl@0: struct basic_full { sl@0: typedef Z size_type; sl@0: sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type packed_size (size_type size1, size_type size2) { sl@0: return L::storage_size (size1, size2); sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool zero (size_type /* i */, size_type /* j */) { sl@0: return false; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool one (size_type /* i */, size_type /* j */) { sl@0: return false; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool other (size_type /* i */, size_type /* j */) { sl@0: return true; sl@0: } sl@0: }; sl@0: sl@0: template sl@0: struct basic_lower { sl@0: typedef Z size_type; sl@0: sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type packed_size (L, size_type size1, size_type size2) { sl@0: return L::triangular_size (size1, size2); sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool zero (size_type i, size_type j) { sl@0: return j > i; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool one (size_type /* i */, size_type /* j */) { sl@0: return false; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool other (size_type i, size_type j) { sl@0: return j <= i; sl@0: } sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type element (L, size_type i, size_type size1, size_type j, size_type size2) { sl@0: return L::lower_element (i, size1, j, size2); sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type restrict1 (size_type i, size_type j) { sl@0: return (std::max) (i, j); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type restrict2 (size_type i, size_type j) { sl@0: return (std::min) (i + 1, j); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type mutable_restrict1 (size_type i, size_type j) { sl@0: return (std::max) (i, j); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type mutable_restrict2 (size_type i, size_type j) { sl@0: return (std::min) (i + 1, j); sl@0: } sl@0: }; sl@0: template sl@0: struct basic_upper { sl@0: typedef Z size_type; sl@0: sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type packed_size (L, size_type size1, size_type size2) { sl@0: return L::triangular_size (size1, size2); sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool zero (size_type i, size_type j) { sl@0: return j < i; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool one (size_type /* i */, size_type /* j */) { sl@0: return false; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool other (size_type i, size_type j) { sl@0: return j >= i; sl@0: } sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type element (L, size_type i, size_type size1, size_type j, size_type size2) { sl@0: return L::upper_element (i, size1, j, size2); sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type restrict1 (size_type i, size_type j) { sl@0: return (std::min) (i, j + 1); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type restrict2 (size_type i, size_type j) { sl@0: return (std::max) (i, j); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type mutable_restrict1 (size_type i, size_type j) { sl@0: return (std::min) (i, j + 1); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type mutable_restrict2 (size_type i, size_type j) { sl@0: return (std::max) (i, j); sl@0: } sl@0: }; sl@0: template sl@0: struct basic_unit_lower : public basic_lower { sl@0: typedef Z size_type; sl@0: sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type packed_size (L, size_type size1, size_type size2) { sl@0: // Zero size strict triangles are bad at this point sl@0: BOOST_UBLAS_CHECK (size1 != 0 && size2 != 0, bad_index ()); sl@0: return L::triangular_size (size1 - 1, size2 - 1); sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool one (size_type i, size_type j) { sl@0: return j == i; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool other (size_type i, size_type j) { sl@0: return j < i; sl@0: } sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type element (L, size_type i, size_type size1, size_type j, size_type size2) { sl@0: // Zero size strict triangles are bad at this point sl@0: BOOST_UBLAS_CHECK (size1 != 0 && size2 != 0, bad_index ()); sl@0: return L::lower_element (i, size1 - 1, j, size2 - 1); sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type mutable_restrict1 (size_type i, size_type j) { sl@0: return (std::max) (i, j); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type mutable_restrict2 (size_type i, size_type j) { sl@0: return (std::min) (i, j); sl@0: } sl@0: }; sl@0: template sl@0: struct basic_unit_upper : public basic_upper { sl@0: typedef Z size_type; sl@0: sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type packed_size (L, size_type size1, size_type size2) { sl@0: // Zero size strict triangles are bad at this point sl@0: BOOST_UBLAS_CHECK (size1 != 0 && size2 != 0, bad_index ()); sl@0: return L::triangular_size (size1 - 1, size2 - 1); sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool one (size_type i, size_type j) { sl@0: return j == i; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool other (size_type i, size_type j) { sl@0: return j > i; sl@0: } sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type element (L, size_type i, size_type size1, size_type j, size_type size2) { sl@0: // Zero size strict triangles are bad at this point sl@0: BOOST_UBLAS_CHECK (size1 != 0 && size2 != 0, bad_index ()); sl@0: return L::upper_element (i, size1 - 1, j, size2 - 1); sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type mutable_restrict1 (size_type i, size_type j) { sl@0: return (std::min) (i, j); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type mutable_restrict2 (size_type i, size_type j) { sl@0: return (std::max) (i, j); sl@0: } sl@0: }; sl@0: template sl@0: struct basic_strict_lower : public basic_lower { sl@0: typedef Z size_type; sl@0: sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type packed_size (L, size_type size1, size_type size2) { sl@0: // Zero size strict triangles are bad at this point sl@0: BOOST_UBLAS_CHECK (size1 != 0 && size2 != 0, bad_index ()); sl@0: return L::triangular_size (size1 - 1, size2 - 1); sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool zero (size_type i, size_type j) { sl@0: return j >= i; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool one (size_type /*i*/, size_type /*j*/) { sl@0: return false; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool other (size_type i, size_type j) { sl@0: return j < i; sl@0: } sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type element (L, size_type i, size_type size1, size_type j, size_type size2) { sl@0: // Zero size strict triangles are bad at this point sl@0: BOOST_UBLAS_CHECK (size1 != 0 && size2 != 0, bad_index ()); sl@0: return L::lower_element (i, size1 - 1, j, size2 - 1); sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type restrict1 (size_type i, size_type j) { sl@0: return (std::max) (i, j); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type restrict2 (size_type i, size_type j) { sl@0: return (std::min) (i, j); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type mutable_restrict1 (size_type i, size_type j) { sl@0: return (std::max) (i, j); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type mutable_restrict2 (size_type i, size_type j) { sl@0: return (std::min) (i, j); sl@0: } sl@0: }; sl@0: template sl@0: struct basic_strict_upper : public basic_upper { sl@0: typedef Z size_type; sl@0: sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type packed_size (L, size_type size1, size_type size2) { sl@0: // Zero size strict triangles are bad at this point sl@0: BOOST_UBLAS_CHECK (size1 != 0 && size2 != 0, bad_index ()); sl@0: return L::triangular_size (size1 - 1, size2 - 1); sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool zero (size_type i, size_type j) { sl@0: return j <= i; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool one (size_type /*i*/, size_type /*j*/) { sl@0: return false; sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: bool other (size_type i, size_type j) { sl@0: return j > i; sl@0: } sl@0: template sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type element (L, size_type i, size_type size1, size_type j, size_type size2) { sl@0: // Zero size strict triangles are bad at this point sl@0: BOOST_UBLAS_CHECK (size1 != 0 && size2 != 0, bad_index ()); sl@0: return L::upper_element (i, size1 - 1, j, size2 - 1); sl@0: } sl@0: sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type restrict1 (size_type i, size_type j) { sl@0: return (std::min) (i, j); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type restrict2 (size_type i, size_type j) { sl@0: return (std::max) (i, j); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type mutable_restrict1 (size_type i, size_type j) { sl@0: return (std::min) (i, j); sl@0: } sl@0: static sl@0: BOOST_UBLAS_INLINE sl@0: size_type mutable_restrict2 (size_type i, size_type j) { sl@0: return (std::max) (i, j); sl@0: } sl@0: }; sl@0: sl@0: }}} sl@0: sl@0: #endif