| 357 | |
| 358 | template <typename dtype> |
| 359 | void run_exponential(Handle* handle) { |
| 360 | using ctype = typename DTypeTrait<dtype>::ctype; |
| 361 | auto opr = handle->create_operator<ExponentialRNG>(); |
| 362 | |
| 363 | TensorLayout ly{TensorShape{200000 * 5}, dtype()}; |
| 364 | |
| 365 | Tensor<ctype> out(handle, ly); |
| 366 | Tensor<ctype> rate(handle, ly); |
| 367 | |
| 368 | auto rate_ptr = rate.ptr(); |
| 369 | for (int i = 0; i < 5; ++i) { |
| 370 | for (int j = 0; j < 200000; ++j) { |
| 371 | rate_ptr[i * 200000 + j] = ctype(i + 1); |
| 372 | } |
| 373 | } |
| 374 | opr->exec(rate.tensornd(), out.tensornd(), {}); |
| 375 | |
| 376 | auto ptr = out.ptr(); |
| 377 | for (int i = 0; i < 5; ++i) { |
| 378 | auto stat = get_mean_var(ptr + i * 200000, 200000, ctype(i + 1)); |
| 379 | float mean = 1.0 / (i + 1); |
| 380 | float var = 1.0 / ((i + 1) * (i + 1)); |
| 381 | ASSERT_LE(std::abs(stat.first - mean), 0.01); |
| 382 | ASSERT_LE(std::abs(stat.second - var), 0.01); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | template <typename T> |
| 387 | void run_dropout(Handle* handle) { |
nothing calls this directly
no test coverage detected