blitz Version 0.10
|
00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * blitz/tvecglobs.h TinyVector global functions 00004 * 00005 * $Id: tvecglobs.h,v 1.6 2011/03/25 22:41:16 julianc Exp $ 00006 * 00007 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org> 00008 * 00009 * This file is a part of Blitz. 00010 * 00011 * Blitz is free software: you can redistribute it and/or modify 00012 * it under the terms of the GNU Lesser General Public License 00013 * as published by the Free Software Foundation, either version 3 00014 * of the License, or (at your option) any later version. 00015 * 00016 * Blitz is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with Blitz. If not, see <http://www.gnu.org/licenses/>. 00023 * 00024 * Suggestions: blitz-devel@lists.sourceforge.net 00025 * Bugs: blitz-support@lists.sourceforge.net 00026 * 00027 * For more information, please see the Blitz++ Home Page: 00028 * https://sourceforge.net/projects/blitz/ 00029 * 00030 ***************************************************************************/ 00031 00032 #ifndef BZ_TVECGLOBS_H 00033 #define BZ_TVECGLOBS_H 00034 00035 #ifndef BZ_META_METAPROG_H 00036 #include <blitz/meta/metaprog.h> 00037 #endif 00038 00039 #ifndef BZ_NUMTRAIT_H 00040 #include <blitz/numtrait.h> 00041 #endif 00042 00043 #include <blitz/tvcross.h> // Cross products 00044 #include <blitz/meta/dot.h> 00045 #include <blitz/meta/product.h> 00046 #include <blitz/meta/sum.h> 00047 00048 BZ_NAMESPACE(blitz) 00049 00050 template<typename T_numtype1, typename T_numtype2, int N_length> 00051 inline BZ_PROMOTE(T_numtype1, T_numtype2) 00052 dot(const TinyVector<T_numtype1, N_length>& a, 00053 const TinyVector<T_numtype2, N_length>& b) 00054 { 00055 return _bz_meta_vectorDot<N_length, 0>::f(a,b); 00056 } 00057 00058 template<typename T_expr1, typename T_numtype2, int N_length> 00059 inline BZ_PROMOTE(_bz_typename T_expr1::T_numtype, T_numtype2) 00060 dot(_bz_VecExpr<T_expr1> a, const TinyVector<T_numtype2, N_length>& b) 00061 { 00062 return _bz_meta_vectorDot<N_length, 0>::f_value_ref(a,b); 00063 } 00064 00065 template<typename T_numtype1, typename T_expr2, int N_length> 00066 inline BZ_PROMOTE(T_numtype1, _bz_typename T_expr2::T_numtype) 00067 dot(const TinyVector<T_numtype1, N_length>& a, _bz_VecExpr<T_expr2> b) 00068 { 00069 return _bz_meta_vectorDot<N_length, 0>::f_ref_value(a,b); 00070 } 00071 00072 template<typename T_numtype1, int N_length> 00073 inline BZ_SUMTYPE(T_numtype1) 00074 product(const TinyVector<T_numtype1, N_length>& a) 00075 { 00076 return _bz_meta_vectorProduct<N_length, 0>::f(a); 00077 } 00078 00079 template<typename T_numtype, int N_length> 00080 inline BZ_SUMTYPE(T_numtype) 00081 sum(const TinyVector<T_numtype, N_length>& a) 00082 { 00083 return _bz_meta_vectorSum<N_length, 0>::f(a); 00084 } 00085 00086 // explicit returntype functions follow 00087 00088 template<typename T_ret> 00089 class _bz_returntype { 00090 public: 00091 00092 template<typename T_numtype1, typename T_numtype2, int N_length> 00093 static inline T_ret 00094 dot(const TinyVector<T_numtype1, N_length>& a, 00095 const TinyVector<T_numtype2, N_length>& b) 00096 { 00097 return _bz_meta_vectorDotRet<N_length, 0, T_ret>::f(a,b); 00098 }; 00099 00100 template<typename T_expr1, typename T_numtype2, int N_length> 00101 static inline T_ret 00102 dot(_bz_VecExpr<T_expr1> a, const TinyVector<T_numtype2, N_length>& b) 00103 { 00104 return _bz_meta_vectorDotRet<N_length, 0, T_ret>::f_value_ref(a,b); 00105 }; 00106 00107 template<typename T_numtype1, typename T_expr2, int N_length> 00108 static inline T_ret 00109 dot(const TinyVector<T_numtype1, N_length>& a, _bz_VecExpr<T_expr2> b) 00110 { 00111 return _bz_meta_vectorDotRet<N_length, 0, T_ret>::f_ref_value(a,b); 00112 }; 00113 00114 template<typename T_numtype1, int N_length> 00115 static inline T_ret 00116 product(const TinyVector<T_numtype1, N_length>& a) 00117 { 00118 return _bz_meta_vectorProductRet<N_length, 0, T_ret>::f(a); 00119 }; 00120 00121 template<typename T_numtype, int N_length> 00122 static inline T_ret 00123 sum(const TinyVector<T_numtype, N_length>& a) 00124 { 00125 return _bz_meta_vectorSumRet<N_length, 0, T_ret>::f(a); 00126 }; 00127 00128 }; 00129 00130 BZ_NAMESPACE_END 00131 00132 #endif // BZ_TVECGLOBS_H 00133