Generates random 32bits with the given shape using the Three Fry implementation. Returns the random bits and the new state.
| 148 | // Generates random 32bits with the given shape using the Three Fry |
| 149 | // implementation. Returns the random bits and the new state. |
| 150 | RngOutput ThreeFryRngBit32(XlaOp key, XlaOp initial_state, const Shape& shape) { |
| 151 | XlaBuilder* builder = key.builder(); |
| 152 | const int64 size = ShapeUtil::ElementsIn(shape); |
| 153 | const int64 half_size = CeilOfRatio<int64>(size, 2); |
| 154 | const bool size_is_odd = (half_size * 2 != size); |
| 155 | std::pair<ThreeFry2x32State, XlaOp> inputs_state = |
| 156 | GetThreeFryInputsAndUpdatedState(initial_state, half_size); |
| 157 | ThreeFry2x32State inputs = inputs_state.first; |
| 158 | ThreeFry2x32State outputs = ThreeFry2x32(inputs, Uint64ToUint32s(key)); |
| 159 | if (size_is_odd) { |
| 160 | outputs[1] = Slice(outputs[1], {0}, {half_size - 1}, {1}); |
| 161 | } |
| 162 | XlaOp result = ConcatInDim(builder, outputs, 0); |
| 163 | return {Reshape(result, AsInt64Slice(shape.dimensions())), |
| 164 | inputs_state.second}; |
| 165 | } |
| 166 | |
| 167 | // Generates random 64bits with the given shape using the Three Fry |
| 168 | // implementation. Returns the random bits and the new state. |
no test coverage detected