1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_COMPILER_XLA_CLIENT_LIB_MATH_H_ 17 #define TENSORFLOW_COMPILER_XLA_CLIENT_LIB_MATH_H_ 18 19 #include "tensorflow/compiler/xla/client/xla_builder.h" 20 21 namespace xla { 22 23 // Determines whether operand is +/-inf or nan. 24 // 25 // Raises an error if called on integral or complex values. 26 XlaOp IsPosInf(XlaOp operand); 27 XlaOp IsNegInf(XlaOp operand); 28 XlaOp IsInf(XlaOp operand); 29 XlaOp IsNan(XlaOp operand); 30 31 // Determines whether operand is equal to -0. 32 // 33 // Raises an error for integral or complex values. 34 XlaOp IsNegZero(XlaOp operand); 35 36 // Returns the next number after 'from' in the direction of 'to' the same way 37 // std::nextafter(from, to) would. 38 XlaOp NextAfter(XlaOp from, XlaOp to); 39 40 // Computes the square of 'operand'. 41 XlaOp Square(XlaOp operand); 42 43 // Computes the reciprocal of 'operand'. 44 XlaOp Reciprocal(XlaOp operand); 45 46 // Evaluates a polynomial given coefficients and 'x'. 47 // N.B. Coefficients should be supplied in decreasing order. 48 XlaOp EvaluatePolynomial(XlaOp x, absl::Span<const float> coefficients); 49 50 // Computes an approximation of the error function complement (1 - erf(x)). 51 XlaOp Erfc(XlaOp x); 52 53 // Computes an approximation of the error function. 54 XlaOp Erf(XlaOp x); 55 56 // Computes an approximation of the inverse of the error function. 57 XlaOp ErfInv(XlaOp x); 58 59 // Computes an approximation of the lgamma function. 60 XlaOp Lgamma(XlaOp input); 61 62 // Computes an approximation of the digamma function. 63 XlaOp Digamma(XlaOp input); 64 65 // Rounds the given number to even when the number is equidistant between two 66 // integers. 67 XlaOp RoundToEven(XlaOp x); 68 69 // Trigonometric functions 70 71 // Computes the arc cosine of 'x'. 72 XlaOp Acos(XlaOp x); 73 74 // Computes the arc sine of 'x'. 75 XlaOp Asin(XlaOp x); 76 77 // Computes the arc tangent of 'x'. 78 XlaOp Atan(XlaOp x); 79 80 // Computes the tangent of 'x'. 81 XlaOp Tan(XlaOp x); 82 83 // Hyperbolic trigonometric functions 84 85 // Computes the inverse hyperbolic cosine of 'x'. 86 XlaOp Acosh(XlaOp x); 87 88 // Computes the inverse hyperbolic sine of 'x'. 89 XlaOp Asinh(XlaOp x); 90 91 // Computes the inverse hyperbolic tangent of 'x'. 92 XlaOp Atanh(XlaOp x); 93 94 // Computes the hyperbolic cosine of 'x'. 95 XlaOp Cosh(XlaOp x); 96 97 // Computes the hyperbolic sine of 'x'. 98 XlaOp Sinh(XlaOp x); 99 100 // Applies a complex conjugation operation if 'a' is complex and 'conjugate' 101 // is true, otherwise returns its argument. 102 xla::XlaOp MaybeConjugate(xla::XlaOp x, bool conjugate); 103 104 } // namespace xla 105 106 #endif // TENSORFLOW_COMPILER_XLA_CLIENT_LIB_MATH_H_ 107