functional.hpp
来自「CGAL is a collaborative effort of severa」· HPP 代码 · 共 1,668 行 · 第 1/5 页
HPP
1,668 行
result_type apply (const matrix_expression<E> &e) { real_type t = real_type (); size_type size2 (e ().size2 ()); for (size_type j = 0; j < size2; ++ j) { real_type u = real_type (); size_type size1 (e ().size1 ()); for (size_type i = 0; i < size1; ++ i) { real_type v (type_traits<value_type>::norm_1 (e () (i, j))); u += v; } if (u > t) t = u; } return t; } }; template<class T> struct matrix_norm_frobenius: public matrix_scalar_real_unary_functor<T> { typedef typename matrix_scalar_real_unary_functor<T>::size_type size_type; 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> static BOOST_UBLAS_INLINE result_type apply (const matrix_expression<E> &e) { real_type t = real_type (); size_type size1 (e ().size1 ()); for (size_type i = 0; i < size1; ++ i) { size_type size2 (e ().size2 ()); for (size_type j = 0; j < size2; ++ j) { real_type u (type_traits<value_type>::norm_2 (e () (i, j))); t += u * u; } } return type_traits<real_type>::sqrt (t); } }; template<class T> struct matrix_norm_inf: public matrix_scalar_real_unary_functor<T> { typedef typename matrix_scalar_real_unary_functor<T>::size_type size_type; 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> static BOOST_UBLAS_INLINE result_type apply (const matrix_expression<E> &e) { 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; static BOOST_UBLAS_INLINE size_type storage_size (size_type size1, size_type size2) { return size1 * size2; } // 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; static BOOST_UBLAS_INLINE size_type storage_size (size_type size1, size_type size2) { return size1 * size2; } // 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_ind
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?