MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ThreeFryRngBit32

Function ThreeFryRngBit32

tensorflow/compiler/xla/client/lib/prng.cc:150–165  ·  view source on GitHub ↗

Generates random 32bits with the given shape using the Three Fry implementation. Returns the random bits and the new state.

Source from the content-addressed store, hash-verified

148// Generates random 32bits with the given shape using the Three Fry
149// implementation. Returns the random bits and the new state.
150RngOutput 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.

Callers 1

ThreeFryBitGeneratorFunction · 0.85

Calls 9

ThreeFry2x32Function · 0.85
Uint64ToUint32sFunction · 0.85
ConcatInDimFunction · 0.85
SliceFunction · 0.50
ReshapeFunction · 0.50
AsInt64SliceFunction · 0.50
builderMethod · 0.45
dimensionsMethod · 0.45

Tested by

no test coverage detected