• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

/data/development/ViennaCL/ViennaCL-1.1.2/viennacl/linalg/norm_1.hpp

Go to the documentation of this file.
00001 /* =======================================================================
00002    Copyright (c) 2010, Institute for Microelectronics, TU Vienna.
00003    http://www.iue.tuwien.ac.at
00004                              -----------------
00005                      ViennaCL - The Vienna Computing Library
00006                              -----------------
00007                             
00008    authors:    Karl Rupp                          rupp@iue.tuwien.ac.at
00009                Florian Rudolf                     flo.rudy+viennacl@gmail.com
00010                Josef Weinbub                      weinbub@iue.tuwien.ac.at
00011 
00012    license:    MIT (X11), see file LICENSE in the ViennaCL base directory
00013 ======================================================================= */
00014 
00015 #ifndef _VIENNACL_NORM_1_HPP_
00016 #define _VIENNACL_NORM_1_HPP_
00017 
00022 #include <math.h>    //for sqrt()
00023 #include "viennacl/forwards.h"
00024 #include "tag_of.hpp"
00025 
00026 namespace viennacl
00027 {
00028   //
00029   // generic norm_1 function
00030   //   uses tag dispatch to identify which algorithm
00031   //   should be called 
00032   //
00033   namespace linalg 
00034   {
00035     
00036     #ifdef VIENNACL_HAVE_UBLAS
00037     // ----------------------------------------------------
00038     // UBLAS
00039     //
00040     template< typename VectorT >
00041     typename VectorT::value_type
00042     norm_1(VectorT const& vector, 
00043          typename viennacl::tools::enable_if< viennacl::is_ublas< typename viennacl::traits::tag_of< VectorT >::type >::value
00044                                             >::type* dummy = 0)
00045     {
00046       // std::cout << "ublas .. " << std::endl;
00047       return boost::numeric::ublas::norm_1(vector);
00048     }
00049     #endif
00050     
00051     
00052     // ----------------------------------------------------
00053     // STL
00054     //
00055     template< typename VectorT>
00056     typename VectorT::value_type
00057     norm_1(VectorT const& v1,
00058          typename viennacl::tools::enable_if< viennacl::is_stl< typename viennacl::traits::tag_of< VectorT >::type >::value
00059                                             >::type* dummy = 0)
00060     {
00061       //std::cout << "stl .. " << std::endl;
00062       typename VectorT::value_type result = 0;
00063       for (typename VectorT::size_type i=0; i<v1.size(); ++i)
00064         result += fabs(v1[i]);
00065       
00066       return result;
00067     }
00068     
00069     // ----------------------------------------------------
00070     // VIENNACL
00071     //
00072     template< typename ScalarType, unsigned int alignment >
00073     viennacl::scalar_expression< const viennacl::vector<ScalarType, alignment>, 
00074                                  const viennacl::vector<ScalarType, alignment>,
00075                                  viennacl::op_norm_1 >
00076     norm_1(viennacl::vector<ScalarType, alignment> const & vector, 
00077          typename viennacl::tools::enable_if< viennacl::is_viennacl< typename viennacl::traits::tag_of< viennacl::vector<ScalarType, alignment> >::type >::value
00078                                             >::type* dummy = 0)
00079     {
00080       return viennacl::scalar_expression< const viennacl::vector<ScalarType, alignment>, 
00081                                           const viennacl::vector<ScalarType, alignment>,
00082                                           viennacl::op_norm_1 >(vector, vector);
00083     }
00084 
00085   } // end namespace linalg
00086 } // end namespace viennacl
00087 #endif
00088 
00089 
00090 
00091 
00092 

Generated on Sat May 21 2011 20:36:50 for ViennaCL - The Vienna Computing Library by  doxygen 1.7.1