algebramix_doc 0.3
|
00001 00002 /****************************************************************************** 00003 * MODULE : polynomial_kronecker.hpp 00004 * DESCRIPTION: Multiplication of polynomials via Kronecker substitution 00005 * COPYRIGHT : (C) 2009 Gregoire Lecerf 00006 ******************************************************************************* 00007 * This software falls under the GNU general public license and comes WITHOUT 00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details. 00009 * If you don't have this file, write to the Free Software Foundation, Inc., 00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00011 ******************************************************************************/ 00012 00013 #ifndef __MMX_POLYNOMIAL_KRONECKER_HPP 00014 #define __MMX_POLYNOMIAL_KRONECKER_HPP 00015 #include <algebramix/polynomial_naive.hpp> 00016 00017 namespace mmx { 00018 #define TMPL template<typename C> 00019 00020 /****************************************************************************** 00021 * Kronecker variant (for the product) 00022 ******************************************************************************/ 00023 00024 template<typename V> 00025 struct polynomial_kronecker: public V { 00026 typedef typename V::Vec Vec; 00027 typedef typename V::Naive Naive; 00028 typedef typename V::Positive Positive; 00029 typedef polynomial_kronecker<typename V::No_simd> No_simd; 00030 typedef polynomial_kronecker<typename V::No_thread> No_thread; 00031 typedef polynomial_kronecker<typename V::No_scaled> No_scaled; 00032 }; 00033 00034 template<typename F, typename V, typename W> 00035 struct implementation<F,V,polynomial_kronecker<W> >: 00036 public implementation<F,V,W> {}; 00037 00038 /****************************************************************************** 00039 * Kronecker multiplication 00040 ******************************************************************************/ 00041 00042 template<typename V,typename W> 00043 struct implementation<polynomial_multiply,V,polynomial_kronecker<W> >: 00044 public implementation<polynomial_linear,V> 00045 { 00046 typedef polynomial_multiply_threshold<polynomial_kronecker<W> > Th; 00047 typedef implementation<polynomial_multiply,W> Fallback; 00048 00049 template<typename C,typename K> static inline void 00050 mul (C* dest, const C* s1, const K* s2, nat n1, nat n2) { 00051 Fallback::mul (dest, s1, s2, n1, n2); } 00052 00053 TMPL static inline void 00054 tmul (C* dest, const C* s1, const C* s2, nat n1, nat n2) { 00055 Fallback::tmul (dest, s1, s2, n1, n2); } 00056 00057 TMPL static inline void 00058 mul (C* dest, const C* s1, const C* s2, nat n1, nat n2) { 00059 if (min (n1, n2) < Threshold(C,Th)) 00060 Fallback::mul (dest, s1, s2, n1, n2); 00061 else mul_kronecker (dest, s1, n1, s2, n2); } 00062 00063 TMPL static inline void 00064 square (C* dest, const C* s, nat n) { 00065 if (n < Threshold(C,Th)) Fallback::square (dest, s, n); 00066 else square_kronecker (dest, s, n); } 00067 00068 }; // implementation<polynomial_multiply,V,polynomial_kronecker<W> > 00069 00070 #undef TMPL 00071 } // namespace mmx 00072 #endif // __MMX_POLYNOMIAL_KRONECKER_HPP