VecMath.h

Go to the documentation of this file.
00001 /*
00002  * Expression Template Matrix Library
00003  *
00004  * Copyright (C) 2004 - 2006 Ricky Lung <mtlung@users.sourceforge.net>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00030 #ifdef _MSC_VER
00031 #   pragma once
00032 #   pragma warning( push )
00033 #   pragma warning( disable : 4127 4786 )
00034 #endif  // _MSC_VER
00035 
00036 #ifndef EXMAT_MATH_VECMATH_H
00037 #define EXMAT_MATH_VECMATH_H
00038 
00039 #include "../View/View.h"
00040 #include "Utility.h"
00041 
00042 #if EXMAT_ENABLE_SIMD
00043 //# include "SIMD/SIMDVecMath.h"
00044 #endif  // EXMAT_ENABLE_SIMD
00045 
00046 
00047 namespace exmat {
00048 
00057 
00069 template<class L, class R, class ErrChk1, class ErrChk2> EXMAT_INLINE2 static
00070 typename TypeTraits<typename L::value_type, typename R::value_type>::HigherValue
00071 dot(const Vec<L,ErrChk1>& lv, const Vec<R,ErrChk2>& rv) {
00072     // Compiler should be able to eliminate the if/else statements
00073     if(L::ROWS == 1) {
00074         if(R::ROWS == 1)
00075             return (lv * trans(rv)).getAt(0);           // RowVec, RowVec
00076         else
00077             return (lv * rv).getAt(0);                  // RowVec, ColVec
00078     } else {
00079         if(R::ROWS == 1)
00080             return (trans(lv) * trans(rv)).getAt(0);    // ColVec, RowVec
00081         else
00082             return (trans(lv) * rv).getAt(0);           // ColVec, ColVec
00083     }
00084 }
00085 
00087 template<class Rep, class ErrChk>
00088 EXMAT_INLINE2 static typename Rep::value_type
00089 norm(const Vec<Rep,ErrChk>& v) {
00090     typedef typename Rep::value_type value_type;
00091     value_type tmp = dot(v, v);
00092     return value_type(Math::sqrt(tmp));
00093 }
00094 
00096 template<class Rep, class ErrChk>
00097 EXMAT_INLINE2 static typename Rep::value_type
00098 norm2(const Vec<Rep,ErrChk>& v) {
00099     return dot(v, v);
00100 }
00101 
00103 // This function assumes a 3D column vector as it's output
00104 template<class L, class R, class LErrChk, class RErrChk> EXMAT_INLINE2 static
00105 const Vec<DenseColVecCon<typename TypeTraits<typename L::value_type, typename R::value_type>::HigherValue, 3>,
00106     typename ResultantChecker<LErrChk,RErrChk>::RET>
00107 cross(const Vec<L,LErrChk>& A, const Vec<R,RErrChk>& B) {
00108     typedef Vec<DenseColVecCon<TTYPENAME TypeTraits<TTYPENAME L::value_type, TTYPENAME R::value_type>::HigherValue, 3>,
00109         TTYPENAME ResultantChecker<LErrChk,RErrChk>::RET> RETType;
00110     RETType tmp;
00111     tmp.setAt(0) = A.getAt(1) * B.getAt(2) - A.getAt(2) * B.getAt(1);
00112     tmp.setAt(1) = A.getAt(2) * B.getAt(0) - A.getAt(0) * B.getAt(2);
00113     tmp.setAt(2) = A.getAt(0) * B.getAt(1) - A.getAt(1) * B.getAt(0);
00114     return tmp;
00115 }
00116 
00118 
00119 
00123 
00124 namespace Math {
00125 
00127 template<class Rep, class ErrChk>
00128 EXMAT_INLINE2 static typename Rep::value_type min(Mat<Rep,ErrChk>& m) {
00129     return ::exmat::Math::min(m.getRawData(), m.size());
00130 }
00131 
00133 template<class Rep, class ErrChk>
00134 EXMAT_INLINE2 static typename Rep::value_type max(Mat<Rep,ErrChk>& m) {
00135     return ::exmat::Math::max(m.getRawData(), m.size());
00136 }
00137 
00139 template<class Rep, class ErrChk>
00140 EXMAT_INLINE2 static typename Rep::value_type sum(Mat<Rep,ErrChk>& m) {
00141     return ::exmat::Math::sum(m.getRawData(), m.size());
00142 }
00144 template<class Rep, class ErrChk>
00145 EXMAT_INLINE2 static void rcp(Mat<Rep,ErrChk>& m) {
00146     ::exmat::Math::rcp(m.getRawData(), m.getRawData(), m.size());
00147 }
00148 
00150 template<class Rep, class ErrChk>
00151 EXMAT_INLINE2 static void sqrt(Mat<Rep,ErrChk>& m) {
00152     ::exmat::Math::sqrt(m.getRawData(), m.getRawData(), m.size());
00153 }
00154 
00156 template<class Rep, class ErrChk>
00157 EXMAT_INLINE2 static void rsqrt(Mat<Rep,ErrChk>& m) {
00158     ::exmat::Math::rsqrt(m.getRawData(), m.getRawData(), m.size());
00159 }
00160 
00162 template<class Rep, class ErrChk>
00163 EXMAT_INLINE2 static void exp(Mat<Rep,ErrChk>& m) {
00164     ::exmat::Math::exp(m.getRawData(), m.getRawData(), m.size());
00165 }
00166 
00168 template<class Rep, class ErrChk>
00169 EXMAT_INLINE2 static void log(Mat<Rep,ErrChk>& m) {
00170     ::exmat::Math::log(m.getRawData(), m.getRawData(), m.size());
00171 }
00172 
00174 template<class Rep, class ErrChk>
00175 EXMAT_INLINE2 static void sin(Mat<Rep,ErrChk>& m) {
00176     ::exmat::Math::sin(m.getRawData(), m.getRawData(), m.size());
00177 }
00178 
00180 template<class Rep, class ErrChk>
00181 EXMAT_INLINE2 static void cos(Mat<Rep,ErrChk>& m) {
00182     ::exmat::Math::cos(m.getRawData(), m.getRawData(), m.size());
00183 }
00184 
00186 template<class Rep, class ErrChk>
00187 EXMAT_INLINE2 static void tan(Mat<Rep,ErrChk>& m) {
00188     ::exmat::Math::tan(m.getRawData(), m.getRawData(), m.size());
00189 }
00190 
00192 template<class Rep, class ErrChk>
00193 EXMAT_INLINE2 static void asin(Mat<Rep,ErrChk>& m) {
00194     ::exmat::Math::asin(m.getRawData(), m.getRawData(), m.size());
00195 }
00196 
00198 template<class Rep, class ErrChk>
00199 EXMAT_INLINE2 static void acos(Mat<Rep,ErrChk>& m) {
00200     ::exmat::Math::acos(m.getRawData(), m.getRawData(), m.size());
00201 }
00202 
00204 template<class Rep, class ErrChk>
00205 EXMAT_INLINE2 static void atan(Mat<Rep,ErrChk>& m) {
00206     ::exmat::Math::atan(m.getRawData(), m.getRawData(), m.size());
00207 }
00208 
00209 }   // namespace Math
00210 
00212 
00213     // end of groupMathFun
00215 
00216 
00218 // Include the specialized math functions for the SIMD container type
00220 #if EXMAT_ENABLE_SIMD
00221 //  #include "SIMD/SIMDMathSpecialization.h"
00222 #endif  // EXMAT_ENABLE_SIMD
00223 
00224 
00225 }   // namespace exmat
00226 
00227 #ifdef _MSC_VER
00228 #   pragma warning( pop )
00229 #endif  // _MSC_VER
00230 
00231 #endif  // EXMAT_MATH_VECMATH_H

Generated on Sat May 6 23:12:03 2006 for Exmat by  doxygen 1.4.6-NO