Test branch computations that do not take any parameters.
| 190 | |
| 191 | // Test branch computations that do not take any parameters. |
| 192 | XLA_TEST_P(CaseOpTest, Parameters0) { |
| 193 | int num_branches = GetParam(); |
| 194 | for (int bi = -1; bi <= num_branches; ++bi) { |
| 195 | SCOPED_TRACE(bi); |
| 196 | XlaBuilder builder(TestName()); |
| 197 | XlaOp branch_index; |
| 198 | auto branch_index_arg = CreateR0Parameter<int32>(bi, 0, "branch_index_arg", |
| 199 | &builder, &branch_index); |
| 200 | auto operand = Tuple(&builder, {}); |
| 201 | |
| 202 | std::vector<XlaOp> operands(num_branches, operand); |
| 203 | std::vector<XlaComputation> branches; |
| 204 | branches.reserve(num_branches); |
| 205 | std::vector<const XlaComputation*> branches_p(num_branches); |
| 206 | for (int i = 0; i < num_branches; ++i) { |
| 207 | branches.emplace_back( |
| 208 | CreateR0ConstantComputation(static_cast<float>(i) * 10)); |
| 209 | branches_p[i] = &branches[i]; |
| 210 | } |
| 211 | Conditional(branch_index, branches_p, operands); |
| 212 | |
| 213 | float expected = 10 * static_cast<float>((bi < 0 || bi >= num_branches) |
| 214 | ? num_branches - 1 |
| 215 | : bi); |
| 216 | ComputeAndCompareR0<float>(&builder, expected, {branch_index_arg.get()}, |
| 217 | error_spec_); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | // Test true and false computations that take in 1 parameter. |
| 222 | XLA_TEST_F(ConditionalOpTest, Parameters1) { |
nothing calls this directly
no test coverage detected