|
27 | 27 |
|
28 | 28 | namespace k2 {
|
29 | 29 |
|
| 30 | +// Currently, only used in k2/csrc/rnnt_decode.cu |
| 31 | +// See https://github.com/k2-fsa/k2/pull/951#issuecomment-1096650842 |
| 32 | +__host__ __device__ __forceinline__ int64_t Pow(int64_t base, |
| 33 | + int64_t exponent) { |
| 34 | + K2_CHECK_GE(exponent, 0); |
| 35 | + int64_t exp = 0; |
| 36 | + int64_t result = 1; |
| 37 | + while (exp < exponent) { |
| 38 | + result *= base; |
| 39 | + exp++; |
| 40 | + } |
| 41 | + return result; |
| 42 | +} |
| 43 | + |
30 | 44 | /*
|
31 | 45 | Returns index of highest bit set, in range -1..30.
|
32 | 46 | HighestBitSet(0) = -1,
|
@@ -106,29 +120,29 @@ int32_t RandIntGeometric(int32_t min, int32_t max);
|
106 | 120 | type, but for types float and double it "fixes" the broken behavior of
|
107 | 121 | the C++ standard w.r.t. infinity allowing infinities to be parsed.
|
108 | 122 | */
|
109 |
| -template<class T> struct InputFixer { |
| 123 | +template <class T> |
| 124 | +struct InputFixer { |
110 | 125 | T t;
|
111 | 126 | // cast operator
|
112 | 127 | operator T() const { return t; }
|
113 | 128 | };
|
114 | 129 |
|
115 |
| - |
116 | 130 | namespace internal {
|
117 | 131 | template <typename Real>
|
118 | 132 | Real FixedRead(std::istream &is);
|
119 | 133 | }
|
120 | 134 |
|
121 | 135 | template <typename T>
|
122 |
| -inline std::istream &operator >>(std::istream &is, InputFixer<T> &f) { |
| 136 | +inline std::istream &operator>>(std::istream &is, InputFixer<T> &f) { |
123 | 137 | return is >> f.t;
|
124 | 138 | }
|
125 | 139 | template <>
|
126 |
| -inline std::istream &operator >>(std::istream &is, InputFixer<float> &f) { |
| 140 | +inline std::istream &operator>>(std::istream &is, InputFixer<float> &f) { |
127 | 141 | f.t = internal::FixedRead<float>(is);
|
128 | 142 | return is;
|
129 | 143 | }
|
130 | 144 | template <>
|
131 |
| -inline std::istream &operator >>(std::istream &is, InputFixer<double> &f) { |
| 145 | +inline std::istream &operator>>(std::istream &is, InputFixer<double> &f) { |
132 | 146 | f.t = internal::FixedRead<double>(is);
|
133 | 147 | return is;
|
134 | 148 | }
|
|
0 commit comments