Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_MATH_BIG_PROD_H
00002 #define OPENTISSUE_CORE_MATH_BIG_PROD_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 {
00029 template<typename T>
00030 inline void prod(
00031 boost::numeric::ublas::compressed_matrix<T> const & A
00032 , boost::numeric::ublas::vector<T> const & x
00033 , boost::numeric::ublas::vector<T> & y
00034 )
00035 {
00036 typedef boost::numeric::ublas::vector<T> vector_type;
00037 typedef typename vector_type::size_type size_type;
00038 typedef typename vector_type::value_type real_type;
00039
00040 assert(A.size1()>0 || !"prod(): A was empty" );
00041 assert(A.size2()>0 || !"prod(): A was empty" );
00042 assert(A.size2() == x.size() || !"prod(): incompatible dimensions");
00043 assert(A.size1() == y.size() || !"prod(): incompatible dimensions");
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 size_type row_end = A.filled1 () - 1;
00068 for (size_type i = 0; i < row_end; ++ i)
00069 {
00070 size_type begin = A.index1_data()[i];
00071 size_type end = A.index1_data()[i + 1];
00072 real_type t = real_type();
00073 for (size_type j = begin; j < end; ++ j)
00074 t += A.value_data()[j] * x( A.index2_data()[j] );
00075 y (i) = t;
00076 }
00077 }
00078
00079
00088 template<typename T>
00089 inline void prod(
00090 boost::numeric::ublas::compressed_matrix<T> const & A
00091 , boost::numeric::ublas::vector<T> const & x
00092 , T const & s
00093 , boost::numeric::ublas::vector<T> & y
00094 )
00095 {
00096 typedef boost::numeric::ublas::vector<T> vector_type;
00097 typedef typename vector_type::size_type size_type;
00098 typedef typename vector_type::value_type real_type;
00099
00100 assert(A.size1()>0 || !"prod(): A was empty" );
00101 assert(A.size2()>0 || !"prod(): A was empty" );
00102 assert(A.size2() == x.size() || !"prod(): incompatible dimensions");
00103 assert(A.size1() == y.size() || !"prod(): incompatible dimensions");
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 size_type row_end = A.filled1 () - 1;
00128 for (size_type i = 0; i < row_end; ++ i)
00129 {
00130 size_type begin = A.index1_data()[i];
00131 size_type end = A.index1_data()[i + 1];
00132 real_type t = real_type();
00133 for (size_type j = begin; j < end; ++ j)
00134 t += A.value_data()[j] * x( A.index2_data()[j] );
00135 y (i) = t*s;
00136 }
00137 }
00138
00139
00140
00141 }
00142 }
00143 }
00144
00145 #endif