⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vector.hpp

📁 dysii是一款非常出色的滤波函数库
💻 HPP
字号:
#ifndef INDII_ML_AUX_VECTOR_HPP#define INDII_ML_AUX_VECTOR_HPP#include "boost/numeric/ublas/vector.hpp"#include "boost/numeric/ublas/vector_sparse.hpp"#include "boost/numeric/ublas/vector_proxy.hpp"#include "boost/numeric/ublas/io.hpp"#include "boost/numeric/ublas/storage.hpp"namespace indii {  namespace ml {    namespace aux {      /**       * General vector.       */      typedef boost::numeric::ublas::vector<double,          boost::numeric::ublas::unbounded_array<double> > vector;      /**       * Zero vector.       */      typedef boost::numeric::ublas::zero_vector<double> zero_vector;      /**       * Scalar vector.       */      typedef boost::numeric::ublas::scalar_vector<double> scalar_vector;      /**       * Sparse vector.       */      typedef boost::numeric::ublas::mapped_vector<double> sparse_vector;      /**       * Vector p-norm.       *       * @param P \f$p\f$; degree of the norm.       *       * @param x \f$\mathbf{x}\f$; a vector.       *       * @return \f$\|\mathbf{x}\|_p\f$; p-norm of the given vector.       *       * Implementation uses template metaprogramming to utilise uBLAS       * norm_1 and norm_2 functions where possible.       */      template <class T, unsigned int P>      double norm(const T& x);      /* Omit these from documentation */      /// @cond NORMIMPL      template <class T, unsigned int P>      struct normImpl {        static double evaluate(const T& t);      };      template <class T>      struct normImpl<T,1> {        static double evaluate(const T& t);            };            template <class T>      struct normImpl<T,2> {        static double evaluate(const T& t);            };      /// @endcond      /**       * Convert vector to double[].       *       * @param x Vector to convert.       * @param a Array into which to write conversion.       *       * The array is assumed to have a length greater than or equal       * to the vector.       */      template <class T>      void vectorToArray(const T& x, double a[]);      /**       * Convert double[] to vector.       *       * @param a Array to convert.       * @param x Vector into which to write conversion.       *       * The array is assumed to have a length greater than or equal to the       * vector.       */      template <class T>      void arrayToVector(const double a[], T& x);    }  }}/// @cond NORMIMPLtemplate <class T>inline double indii::ml::aux::normImpl<T,1>::evaluate(const T& x) {  return norm_1(x);}template <class T>inline double indii::ml::aux::normImpl<T,2>::evaluate(const T& x) {  return norm_2(x);}template <class T, unsigned int P>double indii::ml::aux::normImpl<T,P>::evaluate(const T& x) {  /* pre-condition */  assert (P > 0);  unsigned int i;  double norm = 0.0;  typename T::const_iterator iter, end;  iter = x.begin();  end = x.end();    if (P % 2 == 0) {    /* even number, needn't worry about abs() */    while (iter != end) {      norm += pow(*iter, P);      iter++;    }  } else {    /* odd number, abs() all values */    while (iter != end) {      norm += pow(fabs(*iter), P);      iter++;    }  }    return pow(norm, 1.0 / P);}/// @endcondtemplate <class T, unsigned int P>inline double indii::ml::aux::norm(const T& x) {  return normImpl<T,P>::evaluate(x);}template <class T>void indii::ml::aux::vectorToArray(const T& x, double a[]) {  unsigned int i, len = x.size();  for (i = 0; i < len; i++) {    a[i] = x(i);  }}template <class T>void indii::ml::aux::arrayToVector(const double a[], T& x) {  unsigned int i, len = x.size();  for (i = 0; i < len; i++) {    x(i) = a[i];  }}#endif

⌨️ 快捷键说明

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