functional.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 1,692 行 · 第 1/5 页
HPP
1,692 行
// Guard against size_type overflow BOOST_UBLAS_CHECK (size_j == 0 || size_i <= (std::numeric_limits<size_type>::max) () / size_j, bad_size ()); return size_i * size_j; } // Indexing conversion to storage element static BOOST_UBLAS_INLINE size_type element (size_type i, size_type size_i, size_type j, size_type size_j) { BOOST_UBLAS_CHECK (i < size_i, bad_index ()); BOOST_UBLAS_CHECK (j < size_j, bad_index ()); detail::ignore_unused_variable_warning(size_i); // Guard against size_type overflow BOOST_UBLAS_CHECK (i <= ((std::numeric_limits<size_type>::max) () - j) / size_j, bad_index ()); return i * size_j + j; } static BOOST_UBLAS_INLINE size_type address (size_type i, size_type size_i, size_type j, size_type size_j) { BOOST_UBLAS_CHECK (i <= size_i, bad_index ()); BOOST_UBLAS_CHECK (j <= size_j, bad_index ()); // Guard against size_type overflow - address may be size_j past end of storage BOOST_UBLAS_CHECK (size_j == 0 || i <= ((std::numeric_limits<size_type>::max) () - j) / size_j, bad_index ()); detail::ignore_unused_variable_warning(size_i); return i * size_j + j; } // Storage element to index conversion static BOOST_UBLAS_INLINE difference_type distance_i (difference_type k, size_type /* size_i */, size_type size_j) { return size_j != 0 ? k / size_j : 0; } static BOOST_UBLAS_INLINE difference_type distance_j (difference_type k, size_type /* size_i */, size_type /* size_j */) { return k; } static BOOST_UBLAS_INLINE size_type index_i (difference_type k, size_type /* size_i */, size_type size_j) { return size_j != 0 ? k / size_j : 0; } static BOOST_UBLAS_INLINE size_type index_j (difference_type k, size_type /* size_i */, size_type size_j) { return size_j != 0 ? k % size_j : 0; } static BOOST_UBLAS_INLINE bool fast_i () { return false; } static BOOST_UBLAS_INLINE bool fast_j () { return true; } // Iterating storage elements template<class I> static BOOST_UBLAS_INLINE void increment_i (I &it, size_type /* size_i */, size_type size_j) { it += size_j; } template<class I> static BOOST_UBLAS_INLINE void increment_i (I &it, difference_type n, size_type /* size_i */, size_type size_j) { it += n * size_j; } template<class I> static BOOST_UBLAS_INLINE void decrement_i (I &it, size_type /* size_i */, size_type size_j) { it -= size_j; } template<class I> static BOOST_UBLAS_INLINE void decrement_i (I &it, difference_type n, size_type /* size_i */, size_type size_j) { it -= n * size_j; } template<class I> static BOOST_UBLAS_INLINE void increment_j (I &it, size_type /* size_i */, size_type /* size_j */) { ++ it; } template<class I> static BOOST_UBLAS_INLINE void increment_j (I &it, difference_type n, size_type /* size_i */, size_type /* size_j */) { it += n; } template<class I> static BOOST_UBLAS_INLINE void decrement_j (I &it, size_type /* size_i */, size_type /* size_j */) { -- it; } template<class I> static BOOST_UBLAS_INLINE void decrement_j (I &it, difference_type n, size_type /* size_i */, size_type /* size_j */) { it -= n; } // Triangular access static BOOST_UBLAS_INLINE size_type triangular_size (size_type size_i, size_type size_j) { size_type size = (std::max) (size_i, size_j); // Guard against size_type overflow - simplified BOOST_UBLAS_CHECK (size == 0 || size / 2 < (std::numeric_limits<size_type>::max) () / size /* +1/2 */, bad_size ()); return ((size + 1) * size) / 2; } static BOOST_UBLAS_INLINE size_type lower_element (size_type i, size_type size_i, size_type j, size_type size_j) { BOOST_UBLAS_CHECK (i < size_i, bad_index ()); BOOST_UBLAS_CHECK (j < size_j, bad_index ()); BOOST_UBLAS_CHECK (i >= j, bad_index ()); detail::ignore_unused_variable_warning(size_i); detail::ignore_unused_variable_warning(size_j); // FIXME size_type overflow // 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 size_i, size_type j, size_type size_j) { BOOST_UBLAS_CHECK (i < size_i, bad_index ()); BOOST_UBLAS_CHECK (j < size_j, bad_index ()); BOOST_UBLAS_CHECK (i <= j, bad_index ()); // FIXME size_type overflow // 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) (size_i, size_j) - i + 1)) / 2 + j - i; } // Major and minor indices static BOOST_UBLAS_INLINE size_type index_M (size_type index1, size_type /* index2 */) { return index1; } static BOOST_UBLAS_INLINE size_type index_m (size_type /* index1 */, size_type index2) { return index2; } static BOOST_UBLAS_INLINE size_type size_M (size_type size_i, size_type /* size_j */) { return size_i; } static BOOST_UBLAS_INLINE size_type size_m (size_type /* size_i */, size_type size_j) { return size_j; } }; // This functor defines storage layout and it's properties // matrix (i,j) -> storage [i + j * size_i] template <class Z, class D> struct basic_column_major { typedef Z size_type; typedef D difference_type; typedef column_major_tag orientation_category; static BOOST_UBLAS_INLINE size_type storage_size (size_type size_i, size_type size_j) { // Guard against size_type overflow BOOST_UBLAS_CHECK (size_i == 0 || size_j <= (std::numeric_limits<size_type>::max) () / size_i, bad_size ()); return size_i * size_j; } // Indexing conversion to storage element static BOOST_UBLAS_INLINE size_type element (size_type i, size_type size_i, size_type j, size_type size_j) { BOOST_UBLAS_CHECK (i < size_i, bad_index ()); BOOST_UBLAS_CHECK (j < size_j, bad_index ()); detail::ignore_unused_variable_warning(size_j); // Guard against size_type overflow BOOST_UBLAS_CHECK (j <= ((std::numeric_limits<size_type>::max) () - i) / size_i, bad_index ()); return i + j * size_i; } static BOOST_UBLAS_INLINE size_type address (size_type i, size_type size_i, size_type j, size_type size_j) { BOOST_UBLAS_CHECK (i <= size_i, bad_index ()); BOOST_UBLAS_CHECK (j <= size_j, bad_index ()); detail::ignore_unused_variable_warning(size_j); // Guard against size_type overflow - address may be size_i past end of storage BOOST_UBLAS_CHECK (size_i == 0 || j <= ((std::numeric_limits<size_type>::max) () - i) / size_i, bad_index ()); return i + j * size_i; } // Storage element to index conversion static BOOST_UBLAS_INLINE difference_type distance_i (difference_type k, size_type /* size_i */, size_type /* size_j */) { return k; } static BOOST_UBLAS_INLINE difference_type distance_j (difference_type k, size_type size_i, size_type /* size_j */) { return size_i != 0 ? k / size_i : 0; } static BOOST_UBLAS_INLINE size_type index_i (difference_type k, size_type size_i, size_type /* size_j */) { return size_i != 0 ? k % size_i : 0; } static BOOST_UBLAS_INLINE size_type index_j (difference_type k, size_type size_i, size_type /* size_j */) { return size_i != 0 ? k / size_i : 0; } static BOOST_UBLAS_INLINE bool fast_i () { return true; } static BOOST_UBLAS_INLINE bool fast_j () { return false; } // Iterating template<class I> static BOOST_UBLAS_INLINE void increment_i (I &it, size_type /* size_i */, size_type /* size_j */) { ++ it; } template<class I> static BOOST_UBLAS_INLINE void increment_i (I &it, difference_type n, size_type /* size_i */, size_type /* size_j */) { it += n; } template<class I> static BOOST_UBLAS_INLINE void decrement_i (I &it, size_type /* size_i */, size_type /* size_j */) { -- it; } template<class I> static BOOST_UBLAS_INLINE void decrement_i (I &it, difference_type n, size_type /* size_i */, size_type /* size_j */) { it -= n; } template<class I> static BOOST_UBLAS_INLINE void increment_j (I &it, size_type size_i, size_type /* size_j */) { it += size_i; } template<class I> static BOOST_UBLAS_INLINE void increment_j (I &it, difference_type n, size_type size_i, size_type /* size_j */) { it += n * size_i; } template<class I> static BOOST_UBLAS_INLINE void decrement_j (I &it, size_type size_i, size_type /* size_j */) { it -= size_i; } template<class I> static BOOST_UBLAS_INLINE void decrement_j (I &it, difference_type n, size_type size_i, size_type /* size_j */) { it -= n* size_i; } // Triangular access static BOOST_UBLAS_INLINE size_type triangular_size (size_type size_i, size_type size_j) { size_type size = (std::max) (size_i, size_j); // Guard against size_type overflow - simplified BOOST_UBLAS_CHECK (size == 0 || size / 2 < (std::numeric_limits<size_type>::max) () / size /* +1/2 */, bad_size ()); return ((size + 1) * size) / 2; } static BOOST_UBLAS_INLINE size_type lower_element (size_type i, size_type size_i, size_type j, size_type size_j) { BOOST_UBLAS_CHECK (i < size_i, bad_index ()); BOOST_UBLAS_CHECK (j < size_j, bad_index ()); BOOST_UBLAS_CHECK (i >= j, bad_index ()); // FIXME size_type overflow // 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) (size_i, size_j) - j + 1)) / 2; } static BOOST_UBLAS_INLINE size_type upper_element (size_type i, size_type size_i, size_type j, size_type size_j) { BOOST_UBLAS_CHECK (i < size_i, bad_index ()); BOOST_UBLAS_CHECK (j < size_j, bad_index ()); BOOST_UBLAS_CHECK (i <= j, bad_index ()); // FIXME size_type overflow // sigma_j (j + 1) = (j + 1) * j / 2 // j = 0 1 2 3, sigma = 0 1 3 6 return i + ((j + 1) * j) / 2; } // Major and minor indices static BOOST_UBLAS_INLINE size_type index_M (size_type /* index1 */, size_type index2) { return index2; } static BOOST_UBLAS_INLINE size_type index_m (size_type index1, size_type /* index2 */) { return index1; } static BOOST_UBLAS_INLINE size_type size_M (size_type /* size_i */, size_type size_j) { return size_j; } static BOOST_UBLAS_
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?