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

Method RunR2ToR0Test

tensorflow/compiler/xla/tests/reduce_test.cc:203–227  ·  view source on GitHub ↗

Runs an R2 => R0 reduction test with the given number of (rows, cols).

Source from the content-addressed store, hash-verified

201
202 // Runs an R2 => R0 reduction test with the given number of (rows, cols).
203 void RunR2ToR0Test(int64 rows, int64 cols, int64 minor = 1, int64 major = 0) {
204 XlaBuilder builder(TestName());
205 XlaComputation add_f32 = CreateScalarAddComputation(F32, &builder);
206 const Shape input_shape = ShapeUtil::MakeShape(F32, {rows, cols});
207 auto input = Parameter(&builder, 0, input_shape, "input");
208 auto zero = ConstantR0<float>(&builder, 0.0);
209 Reduce(input, zero, add_f32, /*dimensions_to_reduce=*/{0, 1});
210
211 Array2D<float> input_data(rows, cols);
212 input_data.FillRandom(3.14f, 0.04);
213 Literal input_literal = LiteralUtil::CreateR2FromArray2D(input_data);
214 input_literal =
215 input_literal.Relayout(LayoutUtil::MakeLayout({minor, major}));
216 std::unique_ptr<GlobalData> input_global_data =
217 client_->TransferToServer(input_literal).ConsumeValueOrDie();
218
219 float expected = 0.0;
220 for (int64 rowno = 0; rowno < rows; ++rowno) {
221 for (int64 colno = 0; colno < cols; ++colno) {
222 expected += input_data(rowno, colno);
223 }
224 }
225 ComputeAndCompareR0<float>(&builder, expected, {input_global_data.get()},
226 ErrorSpec(0.01, 1e-4));
227 }
228
229 // Runs an R2 => R1 reduction test with the given number of (rows, cols).
230 void RunR2ToR1Test(int64 rows, int64 cols, int64 minor = 1, int64 major = 0) {

Callers

nothing calls this directly

Calls 12

TestNameFunction · 0.85
MakeShapeFunction · 0.85
RelayoutMethod · 0.80
ConsumeValueOrDieMethod · 0.80
ErrorSpecClass · 0.70
ParameterFunction · 0.50
ReduceFunction · 0.50
MakeLayoutFunction · 0.50
FillRandomMethod · 0.45
TransferToServerMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected