MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / fill_multinomial

Function fill_multinomial

dnn/src/naive/rng/opr_impl.cpp:154–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152
153template <typename U>
154void fill_multinomial(
155 Xoroshiro128plus* rng, U* probs, dt_int32* dst, size_t num_groups,
156 size_t num_samples, size_t len_probs, bool replacement) {
157 if (!replacement) {
158 fill_multinomial_without_replacement(
159 rng, probs, dst, num_groups, num_samples, len_probs);
160 return;
161 }
162 for (size_t i = 0; i < num_groups; ++i) {
163 for (size_t j = 0; j < num_samples; ++j) {
164 U u = uniform_sample<U>(rng);
165 U cumsum_res = U(0);
166 for (size_t k = 0; k < len_probs; ++k) {
167 cumsum_res += probs[i * len_probs + k];
168 if (u <= cumsum_res) {
169 dst[i * num_samples + j] = k;
170 break;
171 }
172 }
173 }
174 }
175}
176
177template <typename T, typename U>
178void fill_poisson(Xoroshiro128plus* rng, U* dst, U* lam, size_t size) {

Callers

nothing calls this directly

Calls 2

UFunction · 0.70

Tested by

no test coverage detected