MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Cosh

Function Cosh

tensorflow/compiler/xla/client/lib/math.cc:1262–1267  ·  view source on GitHub ↗

Cosh(x) = (e^x + e^-x) / 2 = e^(x + log(1/2)) + e^(-x + log(1/2)). The second formulation avoids overflowing when e^x = inf but (e^x)/2 is not inf. This incorrectly overflows to inf for two f32 input values, namely +/-89.4159851, due to rounding error when computing x +/- log(1/2). The correct answer of 3.40281961e+38 (0x7f7fffec) is very close to max-float, so we deem this acceptable.

Source from the content-addressed store, hash-verified

1260// correct answer of 3.40281961e+38 (0x7f7fffec) is very close to max-float, so
1261// we deem this acceptable.
1262XlaOp Cosh(XlaOp x) {
1263 return DoWithUpcastToF32(x, {BF16, F16}, [](XlaOp x) {
1264 auto log_one_half = Log(ScalarLike(x, 0.5));
1265 return Exp(x + log_one_half) + Exp(-x + log_one_half);
1266 });
1267}
1268
1269// Sinh(x) = (e^x - e^-x) / 2
1270// = e^(x + log(1/2)) - e^(-x + log(1/2)).

Callers 5

unary_ops.ccFile · 0.50
TEST_FFunction · 0.50
TestCWiseGradMethod · 0.50
SinhGradFunction · 0.50
AsinhGradFunction · 0.50

Calls 4

DoWithUpcastToF32Function · 0.85
ScalarLikeFunction · 0.85
LogFunction · 0.50
ExpFunction · 0.50

Tested by 2

TEST_FFunction · 0.40
TestCWiseGradMethod · 0.40