00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_RANDOM_INCLUDE
00013 #define MTL_RANDOM_INCLUDE
00014
00015
00016
00017
00018 #include <cstdlib>
00019 #include <boost/numeric/mtl/concept/collection.hpp>
00020 #include <boost/numeric/mtl/matrix/inserter.hpp>
00021 #include <boost/numeric/mtl/utility/enable_if.hpp>
00022
00023 namespace mtl {
00024
00025 template <typename T> struct seed {};
00026
00027 namespace vector {
00028
00029 template <typename Vector, typename Seed>
00030 typename mtl::traits::enable_if_vector<Vector>::type
00031 inline random(Vector& v, Seed& s)
00032 {
00033 typedef typename Collection<Vector>::size_type size_type;
00034 for (size_type i= 0; i < size(v); i++)
00035 v[i]= rand();
00036 }
00037
00038 template <typename Vector>
00039 typename mtl::traits::enable_if_vector<Vector>::type
00040 inline random(Vector& v)
00041 {
00042 random(v, seed<typename Collection<Vector>::value_type>());
00043 }
00044
00045
00046 }
00047
00048 namespace matrix {
00049
00050 template <typename Matrix, typename Seed>
00051 typename mtl::traits::enable_if_matrix<Matrix>::type
00052 inline random(Matrix& A, Seed& s)
00053 {
00054 typedef typename Collection<Matrix>::size_type size_type;
00055 inserter<Matrix> ins(A, A.dim2());
00056 for (size_type r= 0; r < num_rows(A); r++)
00057 for (size_type c= 0; c < num_cols(A); c++)
00058 ins[r][c] << rand();
00059 }
00060
00061 }
00062
00063 }
00064
00065 #endif // MTL_RANDOM_INCLUDE