MCPcopy Create free account
hub / github.com/clab/dynet / sample

Method sample

examples/sequence-to-sequence/encdec.h:361–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359
360private:
361 inline int sample(const vector<float>& v) {
362 float p = (float)rand() / (float) RAND_MAX;
363 float cumul = 0.f;
364 int idx = 0;
365 while (idx < static_cast<int>(v.size()) && p > cumul) {
366 cumul += v[idx];
367 idx += 1;
368 }
369 return idx ? idx - 1 : 0;
370 }
371};

Callers 1

RandomSampleMethod · 0.45

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected