| 89 | |
| 90 | |
| 91 | void fill_random( int64_t nnz, int gxb_sparsity_control, int gxb_format, std::int64_t seed = 12345ULL, T val_min = 0.0, T val_max = 2.0 , bool debug_print = false) { |
| 92 | |
| 93 | // std::cout << "inside fill_random, using seed "<< seed << std::endl; |
| 94 | alloc(); |
| 95 | |
| 96 | double inv_sparsity ; |
| 97 | if (nnz < 0) |
| 98 | { |
| 99 | // build a matrix with all entries present |
| 100 | inv_sparsity = 1 ; |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | inv_sparsity = ceil(((double)nrows_*ncols_)/nnz); //= values not taken per value occupied in index space |
| 105 | } |
| 106 | // |
| 107 | // std::cout<< "fill_random nrows="<< nrows_<<"ncols=" << ncols_ <<" need "<< nnz<<" values, invsparse = "<<inv_sparsity<<std::endl; |
| 108 | // std::cout<< "fill_random"<<" after alloc values"<<std::endl; |
| 109 | // std::cout<<"vdim ready "<<std::endl; |
| 110 | // std::cout<<"vlen ready "<<std::endl; |
| 111 | // std::cout<<"ready to fill p"<<std::endl; |
| 112 | |
| 113 | bool make_symmetric = false; |
| 114 | bool no_self_edges = false; |
| 115 | |
| 116 | std::mt19937 r(seed); |
| 117 | std::uniform_real_distribution<double> dis(0.0, 1.0); |
| 118 | |
| 119 | if (nnz < 0 || inv_sparsity == 1.) |
| 120 | { |
| 121 | // std::cout<<"filling dense"<<std::endl; |
| 122 | for (int64_t i = 0 ; i < nrows_ ; i++) |
| 123 | { |
| 124 | for (int64_t j = 0 ; j < ncols_ ; j++) |
| 125 | { |
| 126 | T x = (T)(dis(r) * (val_max - val_min)) + (T)val_min ; |
| 127 | if (make_symmetric) |
| 128 | { |
| 129 | // A (i,j) = x |
| 130 | cuda::jit::set_element<T> (mat, x, i, j) ; |
| 131 | // A (j,i) = x |
| 132 | cuda::jit::set_element<T> (mat, x, j, i) ; |
| 133 | } |
| 134 | else |
| 135 | { |
| 136 | // A (i,j) = x |
| 137 | cuda::jit::set_element<T> (mat, x, i, j) ; |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // std::cout << "done." << std::endl; |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | // std::cout<<"filling sparse"<<std::endl; |
| 147 | unordered_set<std::int64_t> row_lookup; |
| 148 | unordered_set<std::int64_t> key_lookup; |
no test coverage detected