libidx
/home/rex/ebltrunk/core/libidx/include/idxops_th.hpp
00001 /***************************************************************************
00002  *   Copyright (C) 2012 by Soumith Chintala *
00003  *   soumith@gmail.com *
00004  *   All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Redistribution under a license not approved by the Open Source
00014  *       Initiative (http://www.opensource.org) must display the
00015  *       following acknowledgement in all advertising material:
00016  *        This product includes software developed at the Courant
00017  *        Institute of Mathematical Sciences (http://cims.nyu.edu).
00018  *     * The names of the authors may not be used to endorse or promote products
00019  *       derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00023  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00024  * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY
00025  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00026  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00028  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  ***************************************************************************/
00032 
00033 #ifndef IDXOPS_TH_HPP_
00034 #define IDXOPS_TH_HPP_
00035 #ifdef __TH__
00036 
00038 // idx_add
00039 #define idx_add_macro_in_place(T)                               \
00040   template<> void idx_add(idx<T> &in, idx<T> &out) {            \
00041     th_add(in, out);                                            \
00042   }
00043 
00044 #define idx_add_macro(T)                                                \
00045   template<> void idx_add(idx<T> &in1, idx<T> & in2, idx<T> &out) {     \
00046     th_add(in1, in2, out);                                              \
00047   }
00048 
00049 #define idx_copy_macro(T)                                               \
00050   template<> void idx_copy(const idx<T> &in, idx<T> &out) {             \
00051     idx_checknelems2_all(in, out);                                      \
00052     const idx<T>* const_in_ptr = &in;                                   \
00053     idx<T>* unconst_in_ptr = const_cast<idx<T>* > (const_in_ptr);       \
00054     th_copy(*unconst_in_ptr, out);                                      \
00055   }
00056 
00057 #define idx_tanh_macro(T)                                               \
00058   template<> void idx_tanh(idx<T> &inp, idx<T> &out) {                  \
00059     th_tanh(inp, out);                                                  \
00060   }
00061 #define idx_dtanh_macro(T)                                              \
00062   template<> void idx_dtanh(idx<T> &inp, idx<T> &out) {                 \
00063     th_dtanh(inp, out);                                                 \
00064   }
00065 
00066 #define idx_power_macro(T)                                              \
00067   template<> void idx_power(idx<T> &in, T p, idx<T> &out) {             \
00068     idx_checknelems2_all(in, out);                                      \
00069     th_pow(in, out, p);                                                 \
00070   }
00071 
00072 #define idx_power_macro2(T, T2)                                         \
00073   template<> void idx_power(idx<T> &in, T2 p, idx<T> &out) {            \
00074     idx_checknelems2_all(in, out);                                      \
00075     th_pow(in, out, (T) p);                                             \
00076   }
00077 
00078 
00079 #endif /* __TH__ */
00080 #endif /* IDXOPS_TH_HPP_ */