MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / LogSum

Function LogSum

external/sentencepiece/src/util.cc:297–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

295
296namespace log_domain {
297double LogSum(const std::vector<double> &xs) {
298 if (xs.empty()) {
299 return -1.0 * std::numeric_limits<double>::max();
300 }
301 double sum = xs.front();
302
303 auto log_add = [](double xa, double xb) {
304 if (xa > xb) {
305 std::swap(xa, xb);
306 }
307 return xb + std::log1p(std::exp(xa - xb));
308 };
309 for (int i = 1; i < xs.size(); ++i) {
310 sum = log_add(sum, xs[i]);
311 }
312 return sum;
313}
314} // namespace log_domain
315} // namespace sentencepiece

Callers 1

SampleEncodeMethod · 0.85

Calls 4

maxFunction · 0.85
swapFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected