| 372 | } |
| 373 | |
| 374 | XlaOp ErfInv64(XlaOp x) { |
| 375 | constexpr std::array<double, 23> w_less_than_6_25_constants = { |
| 376 | -3.6444120640178196996e-21, -1.685059138182016589e-19, |
| 377 | 1.2858480715256400167e-18, 1.115787767802518096e-17, |
| 378 | -1.333171662854620906e-16, 2.0972767875968561637e-17, |
| 379 | 6.6376381343583238325e-15, -4.0545662729752068639e-14, |
| 380 | -8.1519341976054721522e-14, 2.6335093153082322977e-12, |
| 381 | -1.2975133253453532498e-11, -5.4154120542946279317e-11, |
| 382 | 1.051212273321532285e-09, -4.1126339803469836976e-09, |
| 383 | -2.9070369957882005086e-08, 4.2347877827932403518e-07, |
| 384 | -1.3654692000834678645e-06, -1.3882523362786468719e-05, |
| 385 | 0.0001867342080340571352, -0.00074070253416626697512, |
| 386 | -0.0060336708714301490533, 0.24015818242558961693, |
| 387 | 1.6536545626831027356}; |
| 388 | constexpr std::array<double, 19> w_less_than_16_constants = { |
| 389 | 2.2137376921775787049e-09, 9.0756561938885390979e-08, |
| 390 | -2.7517406297064545428e-07, 1.8239629214389227755e-08, |
| 391 | 1.5027403968909827627e-06, -4.013867526981545969e-06, |
| 392 | 2.9234449089955446044e-06, 1.2475304481671778723e-05, |
| 393 | -4.7318229009055733981e-05, 6.8284851459573175448e-05, |
| 394 | 2.4031110387097893999e-05, -0.0003550375203628474796, |
| 395 | 0.00095328937973738049703, -0.0016882755560235047313, |
| 396 | 0.0024914420961078508066, -0.0037512085075692412107, |
| 397 | 0.005370914553590063617, 1.0052589676941592334, |
| 398 | 3.0838856104922207635, |
| 399 | }; |
| 400 | constexpr std::array<double, 17> w_greater_than_16_constants = { |
| 401 | -2.7109920616438573243e-11, -2.5556418169965252055e-10, |
| 402 | 1.5076572693500548083e-09, -3.7894654401267369937e-09, |
| 403 | 7.6157012080783393804e-09, -1.4960026627149240478e-08, |
| 404 | 2.9147953450901080826e-08, -6.7711997758452339498e-08, |
| 405 | 2.2900482228026654717e-07, -9.9298272942317002539e-07, |
| 406 | 4.5260625972231537039e-06, -1.9681778105531670567e-05, |
| 407 | 7.5995277030017761139e-05, -0.00021503011930044477347, |
| 408 | -0.00013871931833623122026, 1.0103004648645343977, |
| 409 | 4.8499064014085844221, |
| 410 | }; |
| 411 | // Compute logarithm of (1+arg) using log1p(arg) which is more precise than |
| 412 | // log(1+arg) when arg is close to zero. For more details, see |
| 413 | // https://en.cppreference.com/w/cpp/numeric/math/log1p |
| 414 | auto w = -Log1p(-x * x); |
| 415 | |
| 416 | auto lt_6_25 = Lt(w, ScalarLike(x, 6.25)); |
| 417 | auto lt_16 = Lt(w, ScalarLike(x, 16)); |
| 418 | auto coefficient = [&](int i) { |
| 419 | auto c = FullLike(x, w_less_than_6_25_constants[i]); |
| 420 | if (i < 19) { |
| 421 | c = Select(lt_6_25, c, FullLike(x, w_less_than_16_constants[i])); |
| 422 | } |
| 423 | if (i < 17) { |
| 424 | c = Select(lt_16, c, FullLike(x, w_greater_than_16_constants[i])); |
| 425 | } |
| 426 | return c; |
| 427 | }; |
| 428 | auto sqrt_w = Sqrt(w); |
| 429 | w = Select(lt_6_25, w - ScalarLike(x, 3.125), |
| 430 | sqrt_w - Select(lt_16, ScalarLike(x, 3.25), ScalarLike(x, 5.0))); |
| 431 | auto p = coefficient(0); |
no test coverage detected