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

/data/development/ViennaCL/dev/viennacl/linalg/detail/spai/small_matrix.hpp

Go to the documentation of this file.
00001 #ifndef VIENNACL_LINALG_DETAIL_SPAI_SMALL_MATRIX_HPP
00002 #define VIENNACL_LINALG_DETAIL_SPAI_SMALL_MATRIX_HPP
00003 
00004 /* =========================================================================
00005    Copyright (c) 2010-2011, Institute for Microelectronics,
00006                             Institute for Analysis and Scientific Computing,
00007                             TU Wien.
00008 
00009                             -----------------
00010                   ViennaCL - The Vienna Computing Library
00011                             -----------------
00012 
00013    Project Head:    Karl Rupp                   rupp@iue.tuwien.ac.at
00014                
00015    (A list of authors and contributors can be found in the PDF manual)
00016 
00017    License:         MIT (X11), see file LICENSE in the base directory
00018 ============================================================================= */
00019 
00026 #include <utility>
00027 #include <iostream>
00028 #include <fstream>
00029 #include <string>
00030 #include <algorithm>
00031 #include <vector>
00032 #include <math.h>
00033 #include <map>
00034 #include "boost/numeric/ublas/vector.hpp"
00035 #include "boost/numeric/ublas/matrix.hpp"
00036 #include "boost/numeric/ublas/matrix_proxy.hpp"
00037 #include "boost/numeric/ublas/vector_proxy.hpp"
00038 #include "boost/numeric/ublas/storage.hpp"
00039 #include "boost/numeric/ublas/io.hpp"
00040 #include "boost/numeric/ublas/lu.hpp"
00041 #include "boost/numeric/ublas/triangular.hpp"
00042 #include "boost/numeric/ublas/matrix_expression.hpp"
00043 #include "boost/numeric/ublas/detail/matrix_assign.hpp"
00044 
00045 
00046 
00047 namespace viennacl
00048 {
00049     namespace linalg
00050     {
00051       namespace detail
00052       {
00053         namespace spai
00054         {
00055 
00056           //
00057           // Constructs an orthonormal sparse matrix M (with M^T M = Id). Is composed of elementary 2x2 rotation matrices with suitable renumbering.
00058           //
00059           template <typename MatrixType>
00060           void make_rotation_matrix(MatrixType & mat, size_t new_size, size_t off_diagonal_distance = 4)
00061           {
00062             mat.resize(new_size, new_size, false);
00063             mat.clear();
00064 
00065             double val = 1 / sqrt(2.0);
00066 
00067             for (size_t i=0; i<new_size; ++i)
00068               mat(i,i) = val;
00069 
00070             for (size_t i=off_diagonal_distance; i<new_size; ++i)
00071             {
00072               mat(i-off_diagonal_distance, i) = val; mat(i, i-off_diagonal_distance) = -val;
00073             }
00074 
00075           }
00076 
00077 
00078           //calcualtes matrix determinant
00079           template <typename MatrixType>
00080           double determinant(boost::numeric::ublas::matrix_expression<MatrixType> const& mat_r)
00081           {
00082               double det = 1.0;
00083               
00084               MatrixType mLu(mat_r() );
00085               boost::numeric::ublas::permutation_matrix<std::size_t> pivots(mat_r().size1() );
00086               
00087               int is_singular = static_cast<int>(lu_factorize(mLu, pivots));
00088               
00089               if (!is_singular)
00090               {
00091                   for (std::size_t i=0; i < pivots.size(); ++i)
00092                   {
00093                       if (pivots(i) != i)
00094                           det *= -1.0;
00095                       
00096                       det *= mLu(i,i);
00097                   }
00098               }
00099               else
00100                   det = 0.0;
00101               
00102               return det;
00103           } 
00104           
00105         }
00106       }
00107     }
00108 }
00109 #endif

Generated on Fri Dec 30 2011 23:20:43 for ViennaCL - The Vienna Computing Library by  doxygen 1.7.1