Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_MATH_OPTIMIZATION_NON_SMOOTH_NEWTON_BIG_COMPUTE_JACOBIAN_H
00002 #define OPENTISSUE_CORE_MATH_OPTIMIZATION_NON_SMOOTH_NEWTON_BIG_COMPUTE_JACOBIAN_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
00016 namespace OpenTissue
00017 {
00018 namespace math
00019 {
00020 namespace optimization
00021 {
00022 namespace detail
00023 {
00024
00037 template<typename T, typename bound_function_type>
00038 inline void compute_jacobian(
00039 ublas::compressed_matrix<T> const & A
00040 , bound_function_type const & l
00041 , bound_function_type const & u
00042 , ublas::vector<size_t> const & bitmask
00043 , ublas::compressed_matrix<T> & J
00044 )
00045 {
00046 using std::min;
00047
00048 typedef typename bound_function_type::vector_iterator vector_iterator;
00049 typedef typename OpenTissue::math::ValueTraits<T> value_traits;
00050
00051 static size_t const in_lower = 1;
00052 static size_t const in_upper = 2;
00053 static size_t const in_active = 4;
00054
00055 size_t const m = A.size1();
00056 size_t const n = A.size2();
00057
00058 J.resize(m,n,false);
00059
00060 size_t const row_end = A.filled1() - 1;
00061
00062 for (size_t i = 0; i < row_end; ++ i)
00063 {
00064 if(bitmask(i) == in_lower)
00065 {
00066 vector_iterator const begin = l.partial_begin(i);
00067 vector_iterator const end = l.partial_end(i);
00068 for(vector_iterator e = begin;e!=end;++e)
00069 J(i,e.index()) = - *e;
00070 J(i,i) = value_traits::one();
00071 }
00072 if(bitmask(i) == in_upper)
00073 {
00074 vector_iterator const begin = u.partial_begin(i);
00075 vector_iterator const end = u.partial_end(i);
00076 for(vector_iterator e = begin;e!=end;++e)
00077 J(i,e.index()) = - *e;
00078 J(i,i) = value_traits::one();
00079 }
00080 if(bitmask(i) == in_active)
00081 {
00082
00083 size_t const begin = A.index1_data()[i];
00084 size_t const end = A.index1_data()[i+1];
00085 for (size_t k = begin; k < end; ++ k)
00086 {
00087 size_t const j = A.index2_data()[k];
00088 J(i,j) = A.value_data()[k];
00089 }
00090 }
00091 }
00092 }
00093
00094 }
00095 }
00096 }
00097 }
00098
00099
00100 #endif