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

📄 vectorfunctions.h

📁 关于矩阵运算的很强的一个工具包
💻 H
📖 第 1 页 / 共 2 页
字号:
/* * Tiny Vector Matrix Library * Dense Vector Matrix Libary of Tiny size using Expression Templates * * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * * $Id: VectorFunctions.h,v 1.21 2007-06-23 15:59:00 opetzold Exp $ */#ifndef TVMET_XPR_VECTOR_FUNCTIONS_H#define TVMET_XPR_VECTOR_FUNCTIONS_Hnamespace tvmet {/* forwards */template<class T, std::size_t Sz> class Vector;/********************************************************* * PART I: DECLARATION *********************************************************//*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * Vector arithmetic functions add, sub, mul and div *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*//* * function(XprVector<E1, Sz>, XprVector<E2, Sz>) */#define TVMET_DECLARE_MACRO(NAME)					\template<class E1, class E2, std::size_t Sz>				\XprVector<								\  XprBinOp<								\    Fcnl_##NAME<typename E1::value_type, typename E2::value_type>,	\    XprVector<E1, Sz>,							\    XprVector<E2, Sz>							\  >,									\  Sz									\>									\NAME (const XprVector<E1, Sz>& lhs,					\      const XprVector<E2, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE;TVMET_DECLARE_MACRO(add)		// per se element wiseTVMET_DECLARE_MACRO(sub)		// per se element wiseTVMET_DECLARE_MACRO(mul)		// per se element wisenamespace element_wise {  TVMET_DECLARE_MACRO(div)		// not defined for vectors}#undef TVMET_DECLARE_MACRO/* * function(XprVector<E, Sz>, POD) * function(POD, XprVector<E, Sz>) * Note: - operations +,-,*,/ are per se element wise */#define TVMET_DECLARE_MACRO(NAME, POD)				\template<class E, std::size_t Sz>				\XprVector<							\  XprBinOp<							\    Fcnl_##NAME< typename E::value_type, POD >,			\    XprVector<E, Sz>,						\    XprLiteral< POD >						\  >,								\  Sz								\>								\NAME (const XprVector<E, Sz>& lhs, 				\      POD rhs) TVMET_CXX_ALWAYS_INLINE;				\								\template<class E, std::size_t Sz>				\XprVector<							\  XprBinOp<							\    Fcnl_##NAME< POD, typename E::value_type>,			\    XprLiteral< POD >,						\    XprVector<E, Sz>						\  >,								\  Sz								\>								\NAME (POD lhs, 							\      const XprVector<E, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE;TVMET_DECLARE_MACRO(add, int)TVMET_DECLARE_MACRO(sub, int)TVMET_DECLARE_MACRO(mul, int)TVMET_DECLARE_MACRO(div, int)#if defined(TVMET_HAVE_LONG_LONG)TVMET_DECLARE_MACRO(add, long long int)TVMET_DECLARE_MACRO(sub, long long int)TVMET_DECLARE_MACRO(mul, long long int)TVMET_DECLARE_MACRO(div, long long int)#endifTVMET_DECLARE_MACRO(add, float)TVMET_DECLARE_MACRO(sub, float)TVMET_DECLARE_MACRO(mul, float)TVMET_DECLARE_MACRO(div, float)TVMET_DECLARE_MACRO(add, double)TVMET_DECLARE_MACRO(sub, double)TVMET_DECLARE_MACRO(mul, double)TVMET_DECLARE_MACRO(div, double)#if defined(TVMET_HAVE_LONG_DOUBLE)TVMET_DECLARE_MACRO(add, long double)TVMET_DECLARE_MACRO(sub, long double)TVMET_DECLARE_MACRO(mul, long double)TVMET_DECLARE_MACRO(div, long double)#endif#undef TVMET_DECLARE_MACRO#if defined(TVMET_HAVE_COMPLEX)/* * function(XprMatrix<E, Rows, Cols>, complex<T>) * function(complex<T>, XprMatrix<E, Rows, Cols>) * Note: - operations +,-,*,/ are per se element wise * \todo type promotion */#define TVMET_DECLARE_MACRO(NAME)				\template<class E, std::size_t Sz, class T>			\XprVector<							\  XprBinOp<							\    Fcnl_##NAME< typename E::value_type, std::complex<T> >,	\    XprVector<E, Sz>,						\    XprLiteral< std::complex<T> >				\  >,								\  Sz								\>								\NAME (const XprVector<E, Sz>& lhs,				\      const std::complex<T>& rhs) TVMET_CXX_ALWAYS_INLINE;	\								\template<class E, std::size_t Sz, class T>			\XprVector<							\  XprBinOp<							\    Fcnl_##NAME< std::complex<T>, typename E::value_type>,	\    XprLiteral< std::complex<T> >,				\    XprVector<E, Sz>						\  >,								\  Sz								\>								\NAME (const std::complex<T>& lhs, 				\      const XprVector<E, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE;TVMET_DECLARE_MACRO(add)TVMET_DECLARE_MACRO(sub)TVMET_DECLARE_MACRO(mul)TVMET_DECLARE_MACRO(div)#undef TVMET_DECLARE_MACRO#endif // defined(TVMET_HAVE_COMPLEX)/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * vector specific functions *+++++++++++++++++++++++++++++++++++++++++++++++++++++++*/template<class E, std::size_t Sz>typename NumericTraits<typename E::value_type>::sum_typesum(const XprVector<E, Sz>& v) TVMET_CXX_ALWAYS_INLINE;template<class E, std::size_t Sz>typename NumericTraits<typename E::value_type>::sum_typeproduct(const XprVector<E, Sz>& v) TVMET_CXX_ALWAYS_INLINE;template<class E1, class E2, std::size_t Sz>typename PromoteTraits<  typename E1::value_type,  typename E2::value_type>::value_typedot(const XprVector<E1, Sz>& lhs,    const XprVector<E2, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE;template<class T, class E, std::size_t Sz>typename PromoteTraits<T, typename E::value_type>::value_typedot(const Vector<T, Sz>& lhs,    const XprVector<E, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE;template<class E, class T, std::size_t Sz>typename PromoteTraits<T, typename E::value_type>::value_typedot(const XprVector<E, Sz>& lhs,    const Vector<T, Sz>& rhs) TVMET_CXX_ALWAYS_INLINE;template<class E1, class E2>Vector<  typename PromoteTraits<    typename E1::value_type,    typename E2::value_type  >::value_type,  3>cross(const XprVector<E1, 3>& lhs,      const XprVector<E2, 3>& rhs) TVMET_CXX_ALWAYS_INLINE;template<class T, class E>Vector<  typename PromoteTraits<T, typename E::value_type>::value_type, 3>cross(const Vector<T, 3>& lhs,      const XprVector<E, 3>& rhs) TVMET_CXX_ALWAYS_INLINE;template<class E, class T>Vector<  typename PromoteTraits<T, typename E::value_type>::value_type, 3>cross(const XprVector<E, 3>& lhs,      const Vector<T, 3>& rhs) TVMET_CXX_ALWAYS_INLINE;template<class E, std::size_t Sz>typename NumericTraits<typename E::value_type>::sum_typenorm1(const XprVector<E, Sz>& v) TVMET_CXX_ALWAYS_INLINE;template<class E, std::size_t Sz>typename NumericTraits<typename E::value_type>::sum_typenorm2(const XprVector<E, Sz>& v) TVMET_CXX_ALWAYS_INLINE;template<class E, std::size_t Sz>XprVector<  XprBinOp<    Fcnl_div<typename E::value_type, typename E::value_type>,    XprVector<E, Sz>,    XprLiteral<typename E::value_type>  >,  Sz>normalize(const XprVector<E, Sz>& v) TVMET_CXX_ALWAYS_INLINE;/********************************************************* * PART II: IMPLEMENTATION *********************************************************//* * function(XprVector<E1, Sz>, XprVector<E2, Sz>) */#define TVMET_IMPLEMENT_MACRO(NAME)					\template<class E1, class E2, std::size_t Sz>				\inline									\XprVector<								\  XprBinOp<								\    Fcnl_##NAME<typename E1::value_type, typename E2::value_type>,	\    XprVector<E1, Sz>,							\    XprVector<E2, Sz>							\  >,									\  Sz									\>									\NAME (const XprVector<E1, Sz>& lhs, const XprVector<E2, Sz>& rhs) {	\  typedef XprBinOp<							\    Fcnl_##NAME<typename E1::value_type, typename E2::value_type>,	\    XprVector<E1, Sz>,							\    XprVector<E2, Sz>							\  > 							 expr_type;	\  return XprVector<expr_type, Sz>(expr_type(lhs, rhs));			\}TVMET_IMPLEMENT_MACRO(add)		// per se element wiseTVMET_IMPLEMENT_MACRO(sub)		// per se element wiseTVMET_IMPLEMENT_MACRO(mul)		// per se element wisenamespace element_wise {  TVMET_IMPLEMENT_MACRO(div)		// not defined for vectors}#undef TVMET_IMPLEMENT_MACRO/* * function(XprVector<E, Sz>, POD) * function(POD, XprVector<E, Sz>) * Note: - operations +,-,*,/ are per se element wise */#define TVMET_IMPLEMENT_MACRO(NAME, POD)				\template<class E, std::size_t Sz>					\inline									\XprVector<								\  XprBinOp<								\    Fcnl_##NAME< typename E::value_type, POD >,				\    XprVector<E, Sz>,							\    XprLiteral< POD >							\  >,									\  Sz									\>									\NAME (const XprVector<E, Sz>& lhs, POD rhs) {				\  typedef XprBinOp<							\    Fcnl_##NAME< typename E::value_type, POD >,				\    XprVector<E, Sz>,							\    XprLiteral< POD >							\  >							expr_type;	\  return XprVector<expr_type, Sz>(					\    expr_type(lhs, XprLiteral< POD >(rhs)));				\}									\									\template<class E, std::size_t Sz>					\inline									\XprVector<								\  XprBinOp<								\    Fcnl_##NAME< POD, typename E::value_type>,				\    XprLiteral< POD >,							\    XprVector<E, Sz>							\  >,									\  Sz									\>									\NAME (POD lhs, const XprVector<E, Sz>& rhs) {				\  typedef XprBinOp<							\    Fcnl_##NAME< POD, typename E::value_type>,				\    XprLiteral< POD >,							\    XprVector<E, Sz>							\  >							expr_type;	\  return XprVector<expr_type, Sz>(					\    expr_type(XprLiteral< POD >(lhs), rhs));				\}TVMET_IMPLEMENT_MACRO(add, int)TVMET_IMPLEMENT_MACRO(sub, int)

⌨️ 快捷键说明

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