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

📄 matrix_random_access_iterator.h

📁 使用R语言的马尔科夫链蒙特卡洛模拟(MCMC)源代码程序。
💻 H
📖 第 1 页 / 共 2 页
字号:
          pos_ -= n;        } else {          offset_ -= n;          uint trailing = offset_ / lead_length_;          uint leading = offset_ % lead_length_;          pos_ = start_ + leading * lead_inc_                         + trailing * trail_inc_;        }        return *this;      }      /* + and - difference operators are outside the class */      inline difference_type operator- (const self& x) const      {        if (M_STYLE == Concrete && ORDER == M_ORDER) {          return pos_ - x.pos_;        } else {          return offset_ - x.offset_;        }      }      inline difference_type operator< (const self& x) const      {        if (M_STYLE == Concrete && ORDER == M_ORDER) {          return pos_ < x.pos_;        } else {          return offset_ < x.offset_;        }      }      inline difference_type operator> (const self& x) const      {        if (M_STYLE == Concrete && ORDER == M_ORDER) {          return pos_ > x.pos_;        } else {          return offset_ > x.offset_;        }      }      inline difference_type operator<= (const self& x) const      {        if (M_STYLE == Concrete && ORDER == M_ORDER) {          return pos_ <= x.pos_;        } else {          return offset_ <= x.offset_;        }      }      inline difference_type operator>= (const self& x) const      {        if (M_STYLE == Concrete && ORDER == M_ORDER) {          return pos_ >= x.pos_;        } else {          return offset_ >= x.offset_;        }      }    protected:      /**** INSTANCE VARIABLES ****/      T_type* start_; // pointer to beginning of data array      T_type* pos_;         // pointer to current position in array      uint offset_;  // Logical offset into matrix      // TODO Some of these can probably be uints      int lead_length_;  // Logical length of leading dimension      int lead_inc_;  // Memory distance between vectors in ldim      int trail_inc_; // Memory distance between vectors in tdim      int jump_; // Memory distance between end of one ldim vector and                 // begin of next			// Size variable for range checking#if SCYTHE_DEBUG > 2			uint size_;  // Logical matrix size#endif       };  /*! \brief An STL-compliant random access iterator for Matrix.   *   * Provides random access iteration over Matrix objects.  See   * Josuttis (1999), or some other STL reference, for a full   * description of the random access iterator interface.   *   * \see Matrix   * \see const_matrix_random_access_iterator   * \see const_matrix_forward_iterator   * \see matrix_forward_iterator   * \see const_matrix_bidirectional_iterator   * \see matrix_bidirectional_iterator   */	template <typename T_type, matrix_order ORDER, matrix_order M_ORDER,            matrix_style M_STYLE>	class matrix_random_access_iterator		: public const_matrix_random_access_iterator<T_type, ORDER,                                                  M_ORDER, M_STYLE>	{			/**** TYPEDEFS ***/			typedef matrix_random_access_iterator<T_type, ORDER, M_ORDER,                                             M_STYLE> self;			typedef const_matrix_random_access_iterator<T_type, ORDER,                                                  M_ORDER, M_STYLE> Base;				public:			/* These are a little formal, but useful */			typedef typename std::iterator_traits<Base>::value_type				value_type;			typedef typename std::iterator_traits<Base>::iterator_category				iterator_category;			typedef typename std::iterator_traits<Base>::difference_type				difference_type;			typedef typename std::iterator_traits<Base>::pointer pointer;			typedef typename std::iterator_traits<Base>::reference reference;					/**** CONSTRUCTORS ****/						/* Default constructor */			matrix_random_access_iterator ()				: Base () 			{}			/* Standard constructor */			matrix_random_access_iterator (const Matrix<value_type, M_ORDER,                                                   M_STYLE> &M)				:	Base(M)			{}      /* Copy constructor */			matrix_random_access_iterator (const self &mi)				:	Base (mi)			{}			/**** FORWARD ITERATOR FACILITIES ****/			/* We have to override a lot of these to get return values			 * right.*/      inline self& operator= (const self& mi)      {        start_ = mi.start_;        pos_ = mi.pos_;        if (M_STYLE != Concrete || M_ORDER != ORDER) {          offset_ = mi.offset_;          lead_length_ = mi.lead_length_;          lead_inc_ = mi.lead_inc_;          trail_inc_ = mi.trail_inc_;          jump_ = mi.jump_;        }#if SCYTHE_DEBUG > 2				size_ = mi.size_;#endif        return *this;      }			inline reference operator* () const			{				SCYTHE_ITER_CHECK_BOUNDS();				return *pos_;			}			inline pointer operator-> () const			{				SCYTHE_ITER_CHECK_BOUNDS();				return pos_;			}			inline self& operator++ ()			{				Base::operator++();				return *this;			}			inline self operator++ (int)			{				self tmp = *this;				++(*this);				return tmp;			}			/**** BIDIRECTIONAL ITERATOR FACILITIES ****/			inline self& operator-- ()			{				Base::operator--();				return *this;			}			inline self operator-- (int)			{				self tmp = *this;				--(*this);				return tmp;			}			/**** RANDOM ACCESS ITERATOR FACILITIES ****/      inline reference operator[] (difference_type n) const      {        if (M_STYLE == Concrete && ORDER == M_ORDER) {					SCYTHE_ITER_CHECK_POINTER_BOUNDS(start_ + n);          return *(start_ + n);        } else {          uint trailing = n / lead_length_;          uint leading = n % lead_length_;          T_type* place = start_ + leading * lead_inc_                                 + trailing * trail_inc_;					SCYTHE_ITER_CHECK_POINTER_BOUNDS(place);          return *place;        }      }			inline self& operator+= (difference_type n)			{				Base::operator+=(n);				return *this;			}			inline self& operator-= (difference_type n)			{				Base::operator-= (n);				return *this;			}			/* +  and - difference_type operators are outside the class */		private:			/* Get handles to base members.  It boggles the mind */			using Base::start_;			using Base::pos_;      using Base::offset_;      using Base::lead_length_;      using Base::lead_inc_;      using Base::trail_inc_;      using Base::jump_;#if SCYTHE_DEBUG > 2			using Base::size_;#endif	};	template <class T_type, matrix_order ORDER, matrix_order M_ORDER,            matrix_style STYLE>	inline  const_matrix_random_access_iterator<T_type, ORDER, M_ORDER, STYLE>	operator+ (const_matrix_random_access_iterator<T_type, ORDER, M_ORDER,                                                 STYLE> x, int n)	{		x += n;		return x;	}		template <class T_type, matrix_order ORDER, matrix_order M_ORDER,            matrix_style STYLE>	inline  const_matrix_random_access_iterator<T_type, ORDER, M_ORDER, STYLE>	operator+ (int n, const_matrix_random_access_iterator<T_type, ORDER,                                                        M_ORDER,                                                         STYLE> x)	{		x += n;		return x;	}	template <class T_type, matrix_order ORDER, matrix_order M_ORDER,            matrix_style STYLE>	inline  const_matrix_random_access_iterator<T_type, ORDER, M_ORDER, STYLE>	operator- (const_matrix_random_access_iterator<T_type, ORDER, M_ORDER,                                                 STYLE> x, int n)	{		x -= n;		return x;	}	template <class T_type, matrix_order ORDER, matrix_order M_ORDER,            matrix_style STYLE>	inline matrix_random_access_iterator<T_type, ORDER, M_ORDER, STYLE>	operator+ (matrix_random_access_iterator<T_type, ORDER, M_ORDER,                                           STYLE> x, int n)	{		x += n;		return x;	}		template <class T_type, matrix_order ORDER, matrix_order M_ORDER,            matrix_style STYLE>	inline matrix_random_access_iterator<T_type, ORDER, M_ORDER, STYLE>	operator+ (int n, matrix_random_access_iterator<T_type, ORDER,                                                  M_ORDER, STYLE> x)	{		x += n;		return x;	}	template <class T_type, matrix_order ORDER, matrix_order M_ORDER,            matrix_style STYLE>	inline matrix_random_access_iterator<T_type, ORDER, M_ORDER, STYLE>	operator- (matrix_random_access_iterator<T_type, ORDER, M_ORDER,                                           STYLE> x, int n)	{		x -= n;		return x;	}} // namespace scythe#endif /* SCYTHE_MATRIX_ITERATOR_H */

⌨️ 快捷键说明

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