Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_MATH_BIG_BIG_GENERATE_RANDOM_H
00002 #define OPENTISSUE_CORE_MATH_BIG_BIG_GENERATE_RANDOM_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_random.h>
00013 #include <OpenTissue/core/math/math_value_traits.h>
00014 #include <OpenTissue/core/math/math_is_number.h>
00015
00016
00017 namespace OpenTissue
00018 {
00019 namespace math
00020 {
00021 namespace big
00022 {
00023
00035 template<typename matrix_type>
00036 inline void generate_random( size_t const & m, size_t const & n, matrix_type & A )
00037 {
00038 typedef typename matrix_type::value_type value_type;
00039 typedef OpenTissue::math::ValueTraits<value_type> value_traits;
00040
00041 Random<value_type> value(value_traits::zero(),value_traits::one());
00042
00043 assert( m>0 || !"generate_random(): m was out of range");
00044 assert( n>0 || !"generate_random(): n was out of range");
00045
00046 A.resize(m,n,false);
00047 A.clear();
00048
00049 for(size_t i=0;i<A.size1();++i)
00050 {
00051 for(size_t j=0;j<A.size2();++j)
00052 {
00053 A(i,j) = value();
00054 assert( is_number( A(i,j) ) || !"generate_random(): not a number encountered");
00055 }
00056 }
00057 }
00058
00059
00070 template<typename value_type>
00071 inline void generate_random( size_t const & n, ublas::vector<value_type> & v )
00072 {
00073 typedef ValueTraits<value_type> value_traits;
00074
00075 Random<value_type> value(value_traits::zero(),value_traits::one());
00076
00077 assert( n>0 || !"generate_random(): n was out of range");
00078
00079 v.resize(n,false);
00080 v.clear();
00081
00082 for(size_t i=0;i<n;++i)
00083 {
00084 v(i) = value();
00085 assert( is_number( v(i) ) || !"generate_random(): not a number encountered");
00086 }
00087 }
00088
00089
00090 }
00091 }
00092 }
00093
00094
00095 #endif