one_norm.hpp
来自「矩阵运算源码最新版本」· HPP 代码 · 共 77 行
HPP
77 行
// Software License for MTL// // Copyright (c) 2007 The Trustees of Indiana University. All rights reserved.// Authors: Peter Gottschling and Andrew Lumsdaine// // This file is part of the Matrix Template Library// // See also license.mtl.txt in the distribution.#ifndef MTL_ONE_NORM_INCLUDE#define MTL_ONE_NORM_INCLUDE#include <boost/numeric/mtl/concept/collection.hpp>#include <boost/numeric/mtl/utility/is_row_major.hpp>#include <boost/numeric/mtl/utility/tag.hpp>#include <boost/numeric/mtl/utility/category.hpp>#include <boost/numeric/mtl/utility/property_map.hpp>#include <boost/numeric/mtl/operation/max_of_sums.hpp>#include <boost/numeric/mtl/vector/reduction.hpp>#include <boost/numeric/mtl/vector/reduction_functors.hpp>namespace mtl { namespace impl { // Ignore unrolling for matrices template <unsigned long Unroll, typename Matrix> typename RealMagnitude<typename Collection<Matrix>::value_type>::type inline one_norm(const Matrix& matrix, tag::matrix) { typename traits::col<Matrix>::type col(matrix); return max_of_sums(matrix, !traits::is_row_major<typename OrientedCollection<Matrix>::orientation>(), col, num_cols(matrix)); } template <unsigned long Unroll, typename Vector> typename RealMagnitude<typename Collection<Vector>::value_type>::type inline one_norm(const Vector& vector, tag::vector) { typedef typename RealMagnitude<typename Collection<Vector>::value_type>::type result_type; return vector::reduction<Unroll, vector::one_norm_functor, result_type>::apply(vector); } }template <unsigned long Unroll, typename Value>typename RealMagnitude<typename Collection<Value>::value_type>::typeinline one_norm(const Value& value){ return impl::one_norm<Unroll>(value, typename traits::category<Value>::type());}/*! One-norm for vectors and matrices: one_norm(x) \f$\rightarrow |x|_1\f$. \retval The magnitude type of the respective value type, see Magnitude. The norms are defined - For vectors: \f$|v|_1=\sum_i |v_i|\f$; and - For matrices: \f$|A|_1=\max_j\{\sum_i(|A_{ij}|)\}\f$. Vector norms are unrolled 8-fold by default. An n-fold unrolling can be generated with one_norm<n>(x). The maximum for n is 8 (it might be increased later). Matrix norms are not (yet) optimized.**/template <typename Value>typename RealMagnitude<typename Collection<Value>::value_type>::typeinline one_norm(const Value& value){ return one_norm<8>(value);}} // namespace mtl#endif // MTL_ONE_NORM_INCLUDE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?