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

📄 primitives.hpp

📁 模糊聚類分析源碼。包含教學文件
💻 HPP
字号:
/*    Context       : Matrix and Vector Operation  Author        : Frank Hoeppner, see also AUTHORS file   Description   : header of function module primitives                    History       : see source file  Comment       :     This file was generated automatically. DO NOT EDIT.  Copyright     : Copyright (C) 1999-2000 Frank Hoeppner    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#ifndef primitives_HEADER#define primitives_HEADER/* configuration include */#ifdef HAVE_CONFIG_H/*//FILETREE_IFDEF HAVE_CONFIG_H*/#include "config.h"/*//FILETREE_ENDIF*/#endif/* necessary includes */#include <functional> // STL binary_function#include <complex.h> // complex<DATA>//#define INLINE inline/* global types and constants */enum compare_type { cmp_less,cmp_equal,cmp_greater,cmp_none };typedef int index_type;#define EPSILON_INT 0.5#define EPSILON_FLOAT 1E-4#define EPSILON_DOUBLE 1E-8/* data interface *//* Primitives interface */template <class DATA> inlineintsignum  (  const DATA& a_value  );template <class DATA> inlineDATAbound  (  const DATA a_min,  const DATA a_value,  const DATA a_max  );template <class DATA> inlineintrespect_bounds  (  const DATA a_min,  DATA& a_value,  const DATA a_max  );template <class S,class T>struct set_to : public binary_function<S, T, void>   {  inline void operator()(S& x, const T& y) const;  };template <class S,class T> struct num_equal : public  binary_function<S,T,bool>   {  inline bool operator()(const S&,const T&) const;  };  template <class S,class T>inline bool equal(const S& s,const T& t) { num_equal<S,T> eq; return eq(s,t); }template <class S,class T>struct incr_by : public binary_function<S, T, void>   {  inline void operator()(S& x, const T& y) const;  };template <class S,class T>struct decr_by : public binary_function<S, T, void>   {  inline void operator()(S& x, const T& y) const;  };template <class S,class T>struct incr_by_sqr : public binary_function<S, T, void>   {  void operator()(S& x, const T& y) const { x += (S) (y*y); }  };template <class S,class T>struct set_to_max : public binary_function<S, T, void>   {  void operator()(S& x, const T& y) const { if (y>x) x=y; }  };template <class S,class T>struct difference_abs : public binary_function<S, T, S>   {  S operator()(const S& x, const T& y) const { return fabs(x-y); }  };template <class S,class T>struct difference_sqr : public binary_function<S, T, S>   {  S operator()(const S& x, const T& y) const { S h = x-y; return h*h; }  };template <class S,class T>struct div_by : public binary_function<S, T, void>   {  inline void operator()(S& x, const T& y) const;  };/* inline implementation */template <class DATA> inlineintsignum  (  const DATA& a_value  )  {  return (a_value>0) ? 1 : ( (a_value<0) ? -1 : 0 );  }template <class DATA> inlineDATAbound  (  const DATA a_min,  const DATA a_value,  const DATA a_max  )  {  return (a_value<a_min) ? a_min : ( (a_value>a_max) ? a_max : a_value );  }template <class DATA> inlineintrespect_bounds  (  const DATA a_min,  DATA& a_value,  const DATA a_max  )  {  if (a_value<a_min) { a_value = a_min; return 1; }  else if (a_value>a_max) { a_value = a_max; return 1; }  else { return 0; }  }template <class M1,class M2>struct default_operator_compare  : public binary_function<M1,M2,compare_type>  {  inline compare_type operator()(const M1& a,const M2& b) const    { return (a<b)?cmp_less:            ((b<a)?cmp_greater:cmp_equal); }  };struct bit_inclusion_compare  : public binary_function<int,int,compare_type>  {  inline compare_type operator()(const int a,const int b) const    { return (  (a==b)    ? cmp_equal:             ( ((a&b)==a) ? cmp_less:             ( ((a&b)==b) ? cmp_greater:cmp_none   ))); }  };template <class S,class T>inline void set_to<S,T>::operator()(S& x, const T& y) const   { x = (S) y; }inline void set_to<int,float>::operator()(int& x,const float& y) const   { x = (int) ((y<0) ? y-0.5 : y+0.5); }inline void set_to<long,float>::operator()(long& x,const float& y) const   { x = (int) ((y<0) ? y-0.5 : y+0.5); }inline void set_to<int,double>::operator()(int& x,const double& y) const   { x = (int) ((y<0) ? y-0.5 : y+0.5); }inline void set_to<long,double>::operator()(long& x,const double& y) const   { x = (int) ((y<0) ? y-0.5 : y+0.5); }template <class S,class T>inline bool num_equal<S,T>::operator()(const S& x, const T& y) const   {   warning("no specialization for comparison...");  return (x==y);   }#define ONEf ((float)1.0)#define ONEd ((double)1.0)inline bool num_equal<double,int>::operator()(const double& x, const int& y) const   { return (fabs(x-y) <= EPSILON_INT*(ONEf+fabs(x)+fabs(y))); }inline bool num_equal<float,int>::operator()(const float& x, const int& y) const   { return (fabs(x-y) <= EPSILON_FLOAT*(ONEf+fabs(x)+fabs(y))); }inline bool num_equal<double,double>::operator()(const double& x, const double& y) const   { return (fabs(x-y) <= EPSILON_DOUBLE*(ONEd+fabs(x)+fabs(y))); }inline bool num_equal<float,double>::operator()(const float& x, const double& y) const   { return (fabs(x-y) <= EPSILON_FLOAT*(ONEf+fabs(x)+fabs(y))); }inline bool num_equal<double,float>::operator()(const double& x, const float& y) const   { return (fabs(x-y) <= EPSILON_FLOAT*(ONEf+fabs(x)+fabs(y))); }inline bool num_equal<float,float>::operator()(const float& x, const float& y) const   { return (fabs(x-y) <= EPSILON_FLOAT*(ONEf+fabs(x)+fabs(y))); }inline bool num_equal< complex<float>,float >::operator()(const complex<float>& x, const float& y) const   { float n( ONEf+norm(x)+fabs(y) );    return (fabs(x.real()-y) <= EPSILON_FLOAT*n) &&            (fabs(x.imag()) <= EPSILON_FLOAT*n); }inline bool num_equal< float,complex<float> >::operator()(const float& x, const complex<float>& y) const   { float n( ONEf+fabs(x)+norm(y) );    return (fabs(y.real()-x) <= EPSILON_FLOAT*n) &&            (fabs(y.imag()) <= EPSILON_FLOAT*n); }inline bool num_equal< complex<float>,complex<float> >::operator()(const complex<float>& x, const complex<float>& y) const   { float n( ONEf+norm(x)+norm(y) );    return (fabs(x.real()-y.real()) <= EPSILON_FLOAT*n) &&            (fabs(x.imag()-y.imag()) <= EPSILON_FLOAT*n); }inline bool num_equal< complex<float>,double >::operator()(const complex<float>& x, const double& y) const   { float n( ONEf+norm(x)+fabs(y) );    return (fabs(x.real()-y) <= EPSILON_FLOAT*n) &&            (fabs(x.imag()) <= EPSILON_FLOAT*n); }inline bool num_equal< complex<double>,double >::operator()(const complex<double>& x, const double& y) const   { double n( ONEd+norm(x)+fabs(y) );    return (fabs(x.real()-y) <= EPSILON_DOUBLE*n) &&            (fabs(x.imag()) <= EPSILON_DOUBLE*n); }inline bool num_equal< complex<double>,float >::operator()(const complex<double>& x, const float& y) const   { double n( ONEd+norm(x)+fabs(y) );    return (fabs(x.real()-y) <= EPSILON_FLOAT*n) &&            (fabs(x.imag()) <= EPSILON_FLOAT*n); }inline bool num_equal< complex<double>,complex<double> >::operator()(const complex<double>& x, const complex<double>& y) const   { double n( ONEd+norm(x)+norm(y) );    return (fabs(x.real()-y.real()) <= EPSILON_DOUBLE*n) &&            (fabs(x.imag()-y.imag()) <= EPSILON_DOUBLE*n); }template <class S,class T>inline void incr_by<S,T>::operator()(S& x, const T& y) const  { x += (S) y; }template <class S,class T>inline void decr_by<S,T>::operator()(S& x, const T& y) const  { x -= (S) y; }template <class S,class T>inline void div_by<S,T>::operator()(S& x, const T& y) const  { x /= (S) y; }#endif /* primitives_HEADER */

⌨️ 快捷键说明

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