| 128 | } |
| 129 | |
| 130 | void QuantizedConcatTest::TestSmall32Bit(float first_min, float first_max, |
| 131 | float second_min, float second_max) { |
| 132 | TF_ASSERT_OK(NodeDefBuilder("quantized_concat_op", "QuantizedConcat") |
| 133 | .Input(FakeInput(DT_INT32)) |
| 134 | .Input(FakeInput(2, DT_QINT32)) |
| 135 | .Input(FakeInput(2, DT_FLOAT)) |
| 136 | .Input(FakeInput(2, DT_FLOAT)) |
| 137 | .Attr("N", 2) |
| 138 | .Attr("T", DataTypeToEnum<qint32>::v()) |
| 139 | .Finalize(node_def())); |
| 140 | TF_ASSERT_OK(InitOp()); |
| 141 | const int first_batch = 2; |
| 142 | const int first_height = 2; |
| 143 | const int first_width = 3; |
| 144 | Tensor first_float(DT_FLOAT, {first_batch, first_height, first_width}); |
| 145 | test::FillValues<float>(&first_float, {100, 200, 300, 400, 500, 600, 700, 800, |
| 146 | 900, 1000, 1100, 1200}); |
| 147 | Tensor first_quantized = |
| 148 | FloatTensorToQuantized<qint32>(first_float, first_min, first_max); |
| 149 | |
| 150 | const int second_batch = 2; |
| 151 | const int second_height = 2; |
| 152 | const int second_width = 3; |
| 153 | Tensor second_float(DT_FLOAT, {second_batch, second_height, second_width}); |
| 154 | test::FillValues<float>(&second_float, {1300, 1400, 1500, 1600, 1700, 1800, |
| 155 | 1900, 2000, 2100, 2200, 2300, 2400}); |
| 156 | Tensor second_quantized = |
| 157 | FloatTensorToQuantized<qint32>(second_float, second_min, second_max); |
| 158 | |
| 159 | const int expected_batch = first_batch + second_batch; |
| 160 | Tensor expected_float(DT_FLOAT, {expected_batch, first_height, first_width}); |
| 161 | test::FillValues<float>( |
| 162 | &expected_float, |
| 163 | {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, |
| 164 | 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400}); |
| 165 | |
| 166 | AddInputFromArray<int32>(TensorShape({}), {0}); |
| 167 | AddInputFromArray<qint32>(first_quantized.shape(), |
| 168 | first_quantized.flat<qint32>()); |
| 169 | AddInputFromArray<qint32>(second_quantized.shape(), |
| 170 | second_quantized.flat<qint32>()); |
| 171 | AddInputFromArray<float>(TensorShape({}), {first_min}); |
| 172 | AddInputFromArray<float>(TensorShape({}), {second_min}); |
| 173 | AddInputFromArray<float>(TensorShape({}), {first_max}); |
| 174 | AddInputFromArray<float>(TensorShape({}), {second_max}); |
| 175 | TF_ASSERT_OK(RunOpKernel()); |
| 176 | const Tensor& output_quantized = *GetOutput(0); |
| 177 | const float output_min = GetOutput(1)->flat<float>()(0); |
| 178 | const float output_max = GetOutput(2)->flat<float>()(0); |
| 179 | Tensor output_float = |
| 180 | QuantizedTensorToFloat<qint32>(output_quantized, output_min, output_max); |
| 181 | test::ExpectTensorNear<float>(expected_float, output_float, 0.2); |
| 182 | } |
| 183 | |
| 184 | TEST_F(QuantizedConcatTest, SecondDim8Bit) { |
| 185 | TestSecondDim8Bit(-10.0f, 150.0f, 0.0f, 200.0f); |
nothing calls this directly
no test coverage detected