(self)
| 485 | |
| 486 | @test_util.run_v2_only |
| 487 | def testConstantFolding(self): |
| 488 | # Constant folding handles the tf.broadcast_to operation which was not |
| 489 | # supported by the TFLite at the time this test was added. |
| 490 | input_data = constant_op.constant([1., 2., 3., 4., 5., 6., 7., 8., 9.], |
| 491 | shape=[3, 3]) |
| 492 | |
| 493 | @def_function.function |
| 494 | def func(x): |
| 495 | y_const = constant_op.constant([1., 2., 3.]) |
| 496 | y_broadcast = gen_array_ops.broadcast_to(y_const, [3, 3]) |
| 497 | return math_ops.matmul(x, y_broadcast) |
| 498 | |
| 499 | root = tracking.AutoTrackable() |
| 500 | root.f = func |
| 501 | concrete_func = root.f.get_concrete_function(input_data) |
| 502 | |
| 503 | # Convert model. |
| 504 | converter = lite.TFLiteConverterV2.from_concrete_functions([concrete_func]) |
| 505 | tflite_model = converter.convert() |
| 506 | |
| 507 | # Check values from converted model. |
| 508 | expected_value = root.f(input_data) |
| 509 | actual_value = self._evaluateTFLiteModel(tflite_model, [input_data]) |
| 510 | np.testing.assert_array_equal(expected_value.numpy(), actual_value) |
| 511 | |
| 512 | |
| 513 | if __name__ == '__main__': |
nothing calls this directly
no test coverage detected