| 206 | |
| 207 | template <typename T> |
| 208 | void run_beta(Handle* handle) { |
| 209 | using ctype = typename DTypeTrait<T>::ctype; |
| 210 | auto opr = handle->create_operator<BetaRNG>(); |
| 211 | |
| 212 | TensorLayout ly{TensorShape{200000 * 5}, T()}; |
| 213 | |
| 214 | SyncedTensor<ctype> out(handle, ly); |
| 215 | SyncedTensor<ctype> alpha(handle, ly); |
| 216 | SyncedTensor<ctype> beta(handle, ly); |
| 217 | auto alpha_ptr = alpha.ptr_mutable_host(); |
| 218 | auto beta_ptr = beta.ptr_mutable_host(); |
| 219 | for (int i = 0; i < 5; ++i) { |
| 220 | for (int j = 0; j < 200000; ++j) { |
| 221 | alpha_ptr[i * 200000 + j] = 0.3 * i + 0.1; |
| 222 | beta_ptr[i * 200000 + j] = 2 * i * 0.3 + 0.1; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | opr->exec(alpha.tensornd_dev(), beta.tensornd_dev(), out.tensornd_dev(), {}); |
| 227 | |
| 228 | auto ptr = out.ptr_mutable_host(); |
| 229 | for (int i = 0; i < 5; ++i) { |
| 230 | float a = 0.3 * i + 0.1, b = 2 * i * 0.3 + 0.1; |
| 231 | float mean = a / (a + b); |
| 232 | float std = a * b / ((a + b) * (a + b) * (a + b + 1)); |
| 233 | auto stat = get_mean_var(ptr + i * 200000, 200000, ctype(mean)); |
| 234 | ASSERT_LE(std::abs(stat.first - mean), 0.01); |
| 235 | ASSERT_LE(std::abs(stat.second - std), 0.01); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | template <typename T> |
| 240 | void run_permutation(Handle* handle) { |
nothing calls this directly
no test coverage detected