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

Function XLA_TEST_P

tensorflow/compiler/xla/tests/cholesky_test.cc:183–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181 public ::testing::WithParamInterface<CholeskyTestCase> {};
182
183XLA_TEST_P(RandomCholeskyTest, Random) {
184 XlaBuilder builder(TestName());
185
186 auto test_params = GetParam();
187 std::vector<int64> dimensions = {std::get<0>(test_params),
188 std::get<1>(test_params),
189 std::get<1>(test_params)};
190 bool lower = std::get<2>(test_params);
191 Shape shape = ShapeUtil::MakeShape(F32, dimensions);
192 TF_ASSERT_OK_AND_ASSIGN(
193 auto literal, LiteralUtil::CreateRandomLiteral<F32>(shape, 0.0, 1.0));
194
195 auto input = Parameter(&builder, 0, shape, "input");
196 // Form a random positive definite matrix.
197 auto matrix =
198 BatchDot(input, TransposeInMinorDims(input), PrecisionConfig::HIGHEST);
199
200 auto cholesky = Triangle(Cholesky(matrix, lower), lower);
201
202 // Verify that ||matrix - cholesky * cholesky_t||_2 ~= 0
203 XlaOp verification;
204 if (lower) {
205 verification = BatchDot(cholesky, TransposeInMinorDims(cholesky),
206 PrecisionConfig::HIGHEST);
207 } else {
208 verification = BatchDot(TransposeInMinorDims(cholesky), cholesky,
209 PrecisionConfig::HIGHEST);
210 }
211 auto delta = matrix - verification;
212 Reduce(delta * delta, ConstantR0<float>(&builder, 0.0),
213 CreateScalarAddComputation(F32, &builder), {0, 1, 2});
214
215 TF_ASSERT_OK_AND_ASSIGN(auto input_data, client_->TransferToServer(literal));
216 ComputeAndCompareR0<float>(&builder, 0.0, {input_data.get()},
217 ErrorSpec(1e-4, 1e-4));
218}
219
220INSTANTIATE_TEST_SUITE_P(RandomCholeskyTestInstance, RandomCholeskyTest,
221 ::testing::Values(CholeskyTestCase{1, 1, true},

Callers

nothing calls this directly

Calls 12

TestNameFunction · 0.85
GetParamFunction · 0.85
MakeShapeFunction · 0.85
BatchDotFunction · 0.85
TransposeInMinorDimsFunction · 0.85
TriangleFunction · 0.85
ErrorSpecClass · 0.70
ParameterFunction · 0.50
CholeskyFunction · 0.50
ReduceFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected