Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_MATH_BIG_BIG_GRAM_SCHMIDT_H
00002 #define OPENTISSUE_CORE_MATH_BIG_BIG_GRAM_SCHMIDT_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <boost/numeric/ublas/vector.hpp>
00013 #include <boost/numeric/ublas/vector_proxy.hpp>
00014
00015 #include <boost/numeric/ublas/matrix.hpp>
00016 #include <boost/numeric/ublas/matrix_proxy.hpp>
00017
00018 #include <boost/numeric/ublas/vector_expression.hpp>
00019 #include <boost/numeric/ublas/matrix_expression.hpp>
00020
00021 namespace ublas = boost::numeric::ublas;
00022
00023 #include <OpenTissue/core/math/math_value_traits.h>
00024
00025
00026 namespace OpenTissue
00027 {
00028 namespace math
00029 {
00030 namespace big
00031 {
00041 template<typename matrix_type>
00042 inline void gram_schmidt( matrix_type & A )
00043 {
00044 using namespace ublas;
00045
00046 using std::fabs;
00047
00048 typedef typename matrix_type::value_type value_type;
00049 typedef typename matrix_type::size_type size_type;
00050 typedef OpenTissue::math::ValueTraits<value_type> value_traits;
00051
00052 size_type const & m = A.size1();
00053 size_type const & n = A.size2();
00054
00055 assert( m>0 || !"gram_schmidt(): m was out of range");
00056 assert( n>0 || !"gram_schmidt(): n was out of range");
00057
00058
00059 for (size_type k = 0; k < n; ++k )
00060 {
00061 value_type lgth = ublas::norm_2( column(A,k) );
00062 if( ! (fabs(lgth)> value_traits::zero()) )
00063 return;
00064 column(A,k) = column(A,k) / lgth;
00065 for (size_type j = k+1; j < n; ++j )
00066 {
00067 value_type dot = ublas::inner_prod ( column(A,k), column(A,j) );
00068 column(A,j) -= dot*column(A,k);
00069 }
00070 }
00071
00072 }
00073
00074 }
00075 }
00076 }
00077
00078
00079 #endif