tensorflow/core/kernels/quantized_matmul_op_test.cc
// Runs two small matrices through the operator, and leaves all the parameters
// at their default values.
Runs two small matrices through the operator, and leaves all the parameters
at their default values.
Runs two small matrices through the operator and leaves all the parameters at their default values .
TEST_F(QuantizedMatMulTest, Small_NoParams) {
  TF_ASSERT_OK(NodeDefBuilder("quantized_mat_mul_op", "QuantizedMatMul")
                   .Input(FakeInput(DT_QUINT8))
                   .Input(FakeInput(DT_QUINT8))
                   .Input(FakeInput(DT_FLOAT))
                   .Input(FakeInput(DT_FLOAT))
                   .Input(FakeInput(DT_FLOAT))
                   .Input(FakeInput(DT_FLOAT))
                   .Attr("Toutput", DataTypeToEnum<qint32>::v())
                   .Finalize(node_def()));
  TF_ASSERT_OK(InitOp());
  AddInputFromArray<quint8>(TensorShape({2, 3}), {1, 2, 3, 4, 5, 6});
  AddInputFromArray<quint8>(TensorShape({3, 4}),
                            {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18});
  AddInputFromArray<float>(TensorShape({1}), {0});
  AddInputFromArray<float>(TensorShape({1}), {255.0f});
  AddInputFromArray<float>(TensorShape({1}), {0});
  AddInputFromArray<float>(TensorShape({1}), {255.0f});
  TF_ASSERT_OK(RunOpKernel());
  Tensor expected(allocator(), DT_QINT32, TensorShape({2, 4}));
  test::FillValues<qint32>(&expected, {74, 80, 86, 92, 173, 188, 203, 218});
  test::ExpectTensorEqual<qint32>(expected, *GetOutput(0));
}
TEST_F ( QuantizedMatMulTest , Small_NoParams ) { TF_ASSERT_OK ( NodeDefBuilder ( " " , " " ) . Input ( FakeInput ( DT_QUINT8 ) ) . Input ( FakeInput ( DT_QUINT8 ) ) . Input ( FakeInput ( DT_FLOAT ) ) . Input ( FakeInput ( DT_FLOAT ) ) . Input ( FakeInput ( DT_FLOAT ) ) . Input ( FakeInput ( DT_FLOAT ) ) . Attr ( " " , DataTypeToEnum < qint32 > :: v ( ) ) . Finalize ( node_def ( ) ) ) ; TF_ASSERT_OK ( InitOp ( ) ) ; AddInputFromArray < quint8 > ( TensorShape ( { 2 , 3 } ) , { 1 , 2 , 3 , 4 , 5 , 6 } ) ; AddInputFromArray < quint8 > ( TensorShape ( { 3 , 4 } ) , { 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 } ) ; AddInputFromArray < float > ( TensorShape ( { 1 } ) , { 0 } ) ; AddInputFromArray < float > ( TensorShape ( { 1 } ) , { 255.0f } ) ; AddInputFromArray < float > ( TensorShape ( { 1 } ) , { 0 } ) ; AddInputFromArray < float > ( TensorShape ( { 1 } ) , { 255.0f } ) ; TF_ASSERT_OK ( RunOpKernel ( ) ) ; Tensor expected ( allocator ( ) , DT_QINT32 , TensorShape ( { 2 , 4 } ) ) ; test :: FillValues < qint32 > ( & expected , { 74 , 80 , 86 , 92 , 173 , 188 , 203 , 218 } ) ; test :: ExpectTensorEqual < qint32 > ( expected , * GetOutput ( 0 ) ) ; }
Runs two small matrices through the operator, and leaves all the parameters
at their default values.
Runs two small matrices through the operator and leaves all the parameters at their default values .
// A matrix is: // |  1 |  2 |  3 | // |  4 |  5 |  6 | // B matrix is: // |  7 |  8 |  9 | 10 | // | 11 | 12 | 13 | 14 | // | 15 | 16 | 17 | 18 | // Here are the results we expect, from hand calculations: // (1 * 7) + (2 * 11) + (3 * 15) = 74 // (1 * 8) + (2 * 12) + (3 * 16) = 80 // (1 * 9) + (2 * 13) + (3 * 17) = 86 // (1 * 10) + (2 * 14) + (3 * 18) = 92 // (4 * 7) + (5 * 11) + (6 * 15) = 173 // (4 * 8) + (5 * 12) + (6 * 16) = 188 // (4 * 9) + (5 * 13) + (6 * 17) = 203 // (4 * 10) + (5 * 14) + (6 * 18) = 218