Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_MATH_OPTIMIZATION_NON_SMOOTH_NEWTON_BIG_COMPUTE_INVERSE_D_H
00002 #define OPENTISSUE_CORE_MATH_OPTIMIZATION_NON_SMOOTH_NEWTON_BIG_COMPUTE_INVERSE_D_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/big/big_types.h>
00013 #include <OpenTissue/core/math/math_value_traits.h>
00014 #include <cmath>
00015 #include <cassert>
00016
00017 namespace OpenTissue
00018 {
00019 namespace math
00020 {
00021 namespace optimization
00022 {
00023 namespace detail
00024 {
00025
00039 template<typename T>
00040 inline void compute_inverse_D( ublas::compressed_matrix<T> & D )
00041 {
00042 using std::min;
00043
00044 typedef OpenTissue::math::ValueTraits<T> value_traits;
00045
00046 if(D.size1()>0 && D.size2()>0)
00047 {
00048 assert(D.size1() == D.size2()|| !"compute_inverse_D(): incompatible dimensions");
00049
00050 size_t const row_end = D.filled1() - 1;
00051
00052 for (size_t row = 0; row < row_end; ++ row)
00053 {
00054 size_t const begin = D.index1_data()[row];
00055 size_t const end = D.index1_data()[row + 1];
00056
00057 for (size_t j = begin; j < end; ++ j)
00058 {
00059 size_t const column = D.index2_data()[j];
00060 if( row > column)
00061 {
00062 D.value_data()[j] = - D.value_data()[j];
00063 }
00064 assert( (row!=column) || ((row == column) && (D.value_data()[j] == value_traits::one() )) || !"compute_inverse_D(): Invalid zero pattern detected");
00065 assert( (row>=column) || ((row < column) && (D.value_data()[j] == value_traits::zero() )) || !"compute_inverse_D(): Invalid zero pattern detected");
00066 }
00067 }
00068 }
00069 }
00070
00071 }
00072 }
00073 }
00074 }
00075
00076
00077 #endif