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

Method UniformChiSquared

tensorflow/compiler/xla/tests/prng_test.cc:146–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144} // namespace
145
146double PrngTest::UniformChiSquared(int32 range_size, int32 expected_count,
147 int64 seed) {
148 int32 sample_size = range_size * expected_count;
149
150 XlaBuilder builder(TestName());
151 RngUniform(ConstantR0<int32>(&builder, 0),
152 ConstantR0<int32>(&builder, range_size),
153 ShapeUtil::MakeShape(S32, {sample_size}));
154
155 SetSeed(seed);
156 auto actual =
157 ExecuteAndTransfer(&builder, /*arguments=*/{}).ConsumeValueOrDie();
158 std::vector<int32> counts(range_size, 0);
159 actual.EachCell<int32>(
160 [&counts](absl::Span<const int64>, int32 value) { ++counts[value]; });
161 int64 sum = 0;
162 for (int32 i = 0; i < range_size; ++i) {
163 sum += Square(static_cast<int64>(counts[i] - expected_count));
164 }
165 return static_cast<double>(sum) / expected_count;
166}
167
168// We only test distribution of uniform discrete PRNG as other types are based
169// on it.

Callers

nothing calls this directly

Calls 5

TestNameFunction · 0.85
RngUniformFunction · 0.85
MakeShapeFunction · 0.85
ConsumeValueOrDieMethod · 0.80
SquareFunction · 0.70

Tested by

no test coverage detected