Generates random 64bits with the given shape using the Three Fry implementation. Returns the random bits and the new state.
| 167 | // Generates random 64bits with the given shape using the Three Fry |
| 168 | // implementation. Returns the random bits and the new state. |
| 169 | RngOutput ThreeFryRngBit64(XlaOp key, XlaOp initial_state, const Shape& shape) { |
| 170 | const int64 size = ShapeUtil::ElementsIn(shape); |
| 171 | std::pair<ThreeFry2x32State, XlaOp> inputs_state = |
| 172 | GetThreeFryInputsAndUpdatedState(initial_state, size); |
| 173 | ThreeFry2x32State inputs = inputs_state.first; |
| 174 | ThreeFry2x32State outputs = ThreeFry2x32(inputs, Uint64ToUint32s(key)); |
| 175 | XlaOp result = Uint32sToUint64(outputs); |
| 176 | return {Reshape(result, AsInt64Slice(shape.dimensions())), |
| 177 | inputs_state.second}; |
| 178 | } |
| 179 | |
| 180 | // The key of the Philox random number generator. |
| 181 | using Philox4x32Key = std::array<XlaOp, 2>; |
no test coverage detected