| 51 | |
| 52 | template <typename dtype> |
| 53 | void run_gamma(Handle* handle) { |
| 54 | using ctype = typename DTypeTrait<dtype>::ctype; |
| 55 | auto opr = handle->create_operator<GammaRNG>(); |
| 56 | |
| 57 | TensorLayout ly{TensorShape{2000000 * 5}, dtype()}; |
| 58 | |
| 59 | Tensor<ctype> out(handle, ly); |
| 60 | Tensor<ctype> shape(handle, ly); |
| 61 | Tensor<ctype> scale(handle, ly); |
| 62 | |
| 63 | auto shape_ptr = shape.ptr(); |
| 64 | auto scale_ptr = scale.ptr(); |
| 65 | for (int i = 0; i < 5; ++i) { |
| 66 | for (int j = 0; j < 2000000; ++j) { |
| 67 | shape_ptr[i * 2000000 + j] = 2 * 0.3 * i + 0.5; |
| 68 | scale_ptr[i * 2000000 + j] = i * 0.2 + 0.1; |
| 69 | } |
| 70 | } |
| 71 | opr->exec(shape.tensornd(), scale.tensornd(), out.tensornd(), {}); |
| 72 | |
| 73 | auto ptr = out.ptr(); |
| 74 | for (int i = 0; i < 5; ++i) { |
| 75 | float a = 2 * 0.3 * i + 0.5, b = i * 0.2 + 0.1; |
| 76 | float mean = a * b; |
| 77 | float std = a * (b * b); |
| 78 | auto stat = get_mean_var(ptr + i * 2000000, 2000000, ctype(mean)); |
| 79 | ASSERT_LE(std::abs(stat.first - mean), 0.01); |
| 80 | ASSERT_LE(std::abs(stat.second - std), 0.01); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | template <typename dtype> |
| 85 | void run_poisson(Handle* handle) { |
nothing calls this directly
no test coverage detected