Tests a while node when the result type T is S32. int32 result = 0; while (result < 5) { result = result + 1; }
| 49 | // result = result + 1; |
| 50 | // } |
| 51 | XLA_TEST_F(WhileTest, WhileWithScalarS32Result) { |
| 52 | auto result_shape = ShapeUtil::MakeShape(S32, {}); |
| 53 | |
| 54 | // Create a computation for the condition: repeat for 5 iterations. |
| 55 | XlaComputation condition; |
| 56 | { |
| 57 | XlaBuilder builder("condition"); |
| 58 | auto prev = Parameter(&builder, 0, result_shape, "prev"); |
| 59 | Gt(ConstantR0<int32>(&builder, 5), prev); |
| 60 | condition = builder.Build().ConsumeValueOrDie(); |
| 61 | } |
| 62 | |
| 63 | // Create a computation for the body: add 1 to the result variable. |
| 64 | XlaComputation body; |
| 65 | { |
| 66 | XlaBuilder builder("body"); |
| 67 | auto prev = Parameter(&builder, 0, result_shape, "prev"); |
| 68 | auto input = ConstantR0<int32>(&builder, 1); |
| 69 | Add(input, prev); |
| 70 | body = builder.Build().ConsumeValueOrDie(); |
| 71 | } |
| 72 | |
| 73 | // Create a While node with computations for the condition and the body. |
| 74 | XlaBuilder builder(TestName()); |
| 75 | auto init = ConstantR0<int32>(&builder, 0); |
| 76 | While(condition, body, init); |
| 77 | |
| 78 | ComputeAndCompareR0<int32>(&builder, 5, {}); |
| 79 | } |
| 80 | |
| 81 | // Tests a while node when the result type T is S64. |
| 82 | // |
nothing calls this directly
no test coverage detected