1 | /* Copyright 2015 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_TSL_FRAMEWORK_NUMERIC_TYPES_H_ |
17 | #define TENSORFLOW_TSL_FRAMEWORK_NUMERIC_TYPES_H_ |
18 | |
19 | #include <complex> |
20 | #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" |
21 | // Disable clang-format to prevent 'FixedPoint' header from being included |
22 | // before 'Tensor' header on which it depends. |
23 | // clang-format off |
24 | #include "third_party/eigen3/unsupported/Eigen/CXX11/FixedPoint" |
25 | // clang-format on |
26 | |
27 | #include "tensorflow/tsl/platform/types.h" |
28 | |
29 | namespace tsl { |
30 | |
31 | // Single precision complex. |
32 | typedef std::complex<float> complex64; |
33 | // Double precision complex. |
34 | typedef std::complex<double> complex128; |
35 | |
36 | // We use Eigen's QInt implementations for our quantized int types. |
37 | typedef Eigen::QInt8 qint8; |
38 | typedef Eigen::QUInt8 quint8; |
39 | typedef Eigen::QInt32 qint32; |
40 | typedef Eigen::QInt16 qint16; |
41 | typedef Eigen::QUInt16 quint16; |
42 | |
43 | } // namespace tsl |
44 | |
45 | static inline tsl::bfloat16 FloatToBFloat16(float float_val) { |
46 | #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
47 | return *reinterpret_cast<tsl::bfloat16*>( |
48 | reinterpret_cast<uint16_t*>(&float_val)); |
49 | #else |
50 | return *reinterpret_cast<tsl::bfloat16*>( |
51 | &(reinterpret_cast<uint16_t*>(&float_val)[1])); |
52 | #endif |
53 | } |
54 | |
55 | namespace Eigen { |
56 | template <> |
57 | struct NumTraits<tsl::tstring> : GenericNumTraits<tsl::tstring> { |
58 | enum { |
59 | RequireInitialization = 1, |
60 | ReadCost = HugeCost, |
61 | AddCost = HugeCost, |
62 | MulCost = HugeCost |
63 | }; |
64 | |
65 | static inline int digits10() { return 0; } |
66 | |
67 | private: |
68 | static inline tsl::tstring epsilon(); |
69 | static inline tsl::tstring dummy_precision(); |
70 | static inline tsl::tstring lowest(); |
71 | static inline tsl::tstring highest(); |
72 | static inline tsl::tstring infinity(); |
73 | static inline tsl::tstring quiet_NaN(); |
74 | }; |
75 | |
76 | } // namespace Eigen |
77 | |
78 | #endif // TENSORFLOW_TSL_FRAMEWORK_NUMERIC_TYPES_H_ |
79 | |