| 11 | |
| 12 | template <typename T> |
| 13 | void run_gamma(Handle* handle) { |
| 14 | using ctype = typename DTypeTrait<T>::ctype; |
| 15 | auto opr = handle->create_operator<GammaRNG>(); |
| 16 | |
| 17 | TensorLayout ly{TensorShape{2000000 * 5}, T()}; |
| 18 | |
| 19 | SyncedTensor<ctype> out(handle, ly); |
| 20 | SyncedTensor<ctype> shape(handle, ly); |
| 21 | SyncedTensor<ctype> scale(handle, ly); |
| 22 | auto shape_ptr = shape.ptr_mutable_host(); |
| 23 | auto scale_ptr = scale.ptr_mutable_host(); |
| 24 | for (int i = 0; i < 5; ++i) { |
| 25 | for (int j = 0; j < 2000000; ++j) { |
| 26 | shape_ptr[i * 2000000 + j] = 2 * 0.3 * i + 0.3; |
| 27 | scale_ptr[i * 2000000 + j] = i * 0.2 + 0.1; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | opr->exec(shape.tensornd_dev(), scale.tensornd_dev(), out.tensornd_dev(), {}); |
| 32 | |
| 33 | auto ptr = out.ptr_mutable_host(); |
| 34 | for (int i = 0; i < 5; ++i) { |
| 35 | float a = 2 * 0.3 * i + 0.3, b = i * 0.2 + 0.1; |
| 36 | float mean = a * b; |
| 37 | float std = a * (b * b); |
| 38 | auto stat = get_mean_var(ptr + i * 2000000, 2000000, ctype(mean)); |
| 39 | ASSERT_LE(std::abs(stat.first - mean), 0.01); |
| 40 | ASSERT_LE(std::abs(stat.second - std), 0.01); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | template <typename T> |
| 45 | void run_poisson(Handle* handle) { |
nothing calls this directly
no test coverage detected