Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_MATH_BIG_PROD_ADD_H
00002 #define OPENTISSUE_CORE_MATH_BIG_PROD_ADD_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/big/big_types.h>
00013
00014 #include <cassert>
00015
00016 namespace OpenTissue
00017 {
00018 namespace math
00019 {
00020 namespace big
00021 {
00022
00032 template<typename T>
00033 inline void prod_add(
00034 boost::numeric::ublas::compressed_matrix<T> const & A
00035 , boost::numeric::ublas::vector<T> const & x
00036 , boost::numeric::ublas::vector<T> & y
00037 )
00038 {
00039 typedef boost::numeric::ublas::vector<T> vector_type;
00040 typedef typename vector_type::size_type size_type;
00041 typedef typename vector_type::value_type real_type;
00042
00043 assert(A.size1()>0 || !"prod_add(): A was empty" );
00044 assert(A.size2()>0 || !"prod_add(): A was empty" );
00045 assert(A.size2() == x.size() || !"prod_add(): incompatible dimensions");
00046 assert(A.size1() == y.size() || !"prod_add(): incompatible dimensions");
00047
00048 size_type row_end = A.filled1 () - 1;
00049 for (size_type i = 0; i < row_end; ++ i)
00050 {
00051 size_type begin = A.index1_data()[i];
00052 size_type end = A.index1_data()[i + 1];
00053 real_type t = real_type();
00054 for (size_type j = begin; j < end; ++ j)
00055 t += A.value_data()[j] * x( A.index2_data()[j] );
00056 y (i) += t;
00057 }
00058 }
00059
00070 template<typename T>
00071 inline void prod_add(
00072 boost::numeric::ublas::compressed_matrix<T> const & A
00073 , boost::numeric::ublas::vector<T> const & x
00074 , T const & s
00075 , boost::numeric::ublas::vector<T> & y
00076 )
00077 {
00078 typedef boost::numeric::ublas::vector<T> vector_type;
00079 typedef typename vector_type::size_type size_type;
00080 typedef typename vector_type::value_type real_type;
00081
00082 assert(A.size1()>0 || !"prod_add(): A was empty" );
00083 assert(A.size2()>0 || !"prod_add(): A was empty" );
00084 assert(A.size2() == x.size() || !"prod_add(): incompatible dimensions");
00085 assert(A.size1() == y.size() || !"prod_add(): incompatible dimensions");
00086
00087 size_type row_end = A.filled1 () - 1;
00088 for (size_type i = 0; i < row_end; ++ i)
00089 {
00090 size_type begin = A.index1_data()[i];
00091 size_type end = A.index1_data()[i + 1];
00092 real_type t = real_type();
00093 for (size_type j = begin; j < end; ++ j)
00094 t += A.value_data()[j] * x( A.index2_data()[j] );
00095 y (i) += t*s;
00096 }
00097 }
00098
00099
00100 }
00101 }
00102 }
00103
00104 #endif