ShLibDerivImpl.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2006 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef SHLIBDERIVIMPL_HPP
00021 #define SHLIBDERIVIMPL_HPP
00022 
00023 #include "ShLibDeriv.hpp"
00024 
00025 namespace SH {
00026 
00027 template<int N, typename T>
00028 ShGeneric<N, T> dx(const ShGeneric<N, T>& var)
00029 {
00030   ShAttrib<N, SH_TEMP, T> t;
00031   shDX(t, var);
00032   return t;
00033 }
00034 
00035 template<int N, typename T>
00036 ShGeneric<N, T> dy(const ShGeneric<N, T>& var)
00037 {
00038   ShAttrib<N, SH_TEMP, T> t;
00039   shDY(t, var);
00040   return t;
00041 }
00042 
00043 template<int N, typename T>
00044 inline
00045 ShGeneric<N, T> fwidth(const ShGeneric<N, T>& var)
00046 {
00047   return max(abs(dx(var)), abs(dy(var)));
00048 }
00049 
00050 template<typename T>
00051 inline
00052 ShGeneric<2, T> gradient(const ShGeneric<1, T>& var)
00053 {
00054   return ShAttrib2f(dx(var), dy(var));
00055 }
00056 
00057 template<int N, typename T>
00058 ShMatrix<2, N, SH_TEMP, T> jacobian(const ShGeneric<N, T>& var)
00059 {
00060   ShMatrix<2, N, SH_TEMP, T> ret;
00061   ret[0] = dx(var);
00062   ret[1] = dy(var);
00063   return ret;
00064 }
00065 
00066 
00067 
00068 }
00069 
00070 #endif

Generated on Thu Feb 16 14:51:33 2006 for Sh by  doxygen 1.4.6