Home | History | Annotate | Download | only in kernels
      1 /* Copyright 2015-2017 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #include "tensorflow/core/framework/fake_input.h"
     17 #include "tensorflow/core/framework/node_def_builder.h"
     18 #include "tensorflow/core/framework/tensor.h"
     19 #include "tensorflow/core/framework/tensor_testutil.h"
     20 #include "tensorflow/core/framework/types.h"
     21 #include "tensorflow/core/kernels/ops_testutil.h"
     22 #include "tensorflow/core/kernels/ops_util.h"
     23 #include "tensorflow/core/lib/strings/strcat.h"
     24 #include "tensorflow/core/platform/test.h"
     25 
     26 namespace tensorflow {
     27 namespace {
     28 
     29 class IdentityNOpTest : public OpsTestBase {
     30  protected:
     31   Status Init(DataType input0_type, DataType input1_type) {
     32     TF_CHECK_OK(NodeDefBuilder("op", "IdentityN")
     33                     .Input(FakeInput({input0_type, input1_type}))
     34                     .Finalize(node_def()));
     35     return InitOp();
     36   }
     37 };
     38 
     39 TEST_F(IdentityNOpTest, Int32DoubleSuccess_6) {
     40   TF_ASSERT_OK(Init(DT_INT32, DT_DOUBLE));
     41   AddInputFromArray<int32>(TensorShape({6}), {1, 2, 3, 4, 5, 6});
     42   AddInputFromArray<double>(TensorShape({6}),
     43                             {7.3, 8.3, 9.3, 10.3, 11.3, 12.3});
     44   TF_ASSERT_OK(RunOpKernel());
     45   Tensor expected0(allocator(), DT_INT32, TensorShape({6}));
     46   test::FillValues<int32>(&expected0, {1, 2, 3, 4, 5, 6});
     47   test::ExpectTensorEqual<int32>(expected0, *GetOutput(0));
     48   Tensor expected1(allocator(), DT_DOUBLE, TensorShape({6}));
     49   test::FillValues<double>(&expected1, {7.3, 8.3, 9.3, 10.3, 11.3, 12.3});
     50   test::ExpectTensorEqual<double>(expected1, *GetOutput(1));
     51 }
     52 
     53 TEST_F(IdentityNOpTest, Int32Success_2_3) {
     54   TF_ASSERT_OK(Init(DT_INT32, DT_INT32));
     55   AddInputFromArray<int32>(TensorShape({2, 3}), {1, 2, 3, 4, 5, 6});
     56   AddInputFromArray<int32>(TensorShape({2, 3}), {7, 8, 9, 10, 11, 12});
     57   TF_ASSERT_OK(RunOpKernel());
     58   Tensor expected(allocator(), DT_INT32, TensorShape({2, 3}));
     59   test::FillValues<int32>(&expected, {1, 2, 3, 4, 5, 6});
     60   test::ExpectTensorEqual<int32>(expected, *GetOutput(0));
     61   test::FillValues<int32>(&expected, {7, 8, 9, 10, 11, 12});
     62   test::ExpectTensorEqual<int32>(expected, *GetOutput(1));
     63 }
     64 
     65 TEST_F(IdentityNOpTest, StringInt32Success) {
     66   TF_ASSERT_OK(Init(DT_STRING, DT_INT32));
     67   AddInputFromArray<string>(TensorShape({6}), {"A", "b", "C", "d", "E", "f"});
     68   AddInputFromArray<int32>(TensorShape({8}), {1, 3, 5, 7, 9, 11, 13, 15});
     69   TF_ASSERT_OK(RunOpKernel());
     70   Tensor expected0(allocator(), DT_STRING, TensorShape({6}));
     71   test::FillValues<string>(&expected0, {"A", "b", "C", "d", "E", "f"});
     72   test::ExpectTensorEqual<string>(expected0, *GetOutput(0));
     73   Tensor expected1(allocator(), DT_INT32, TensorShape({8}));
     74   test::FillValues<int32>(&expected1, {1, 3, 5, 7, 9, 11, 13, 15});
     75   test::ExpectTensorEqual<int32>(expected1, *GetOutput(1));
     76 }
     77 
     78 }  // namespace
     79 }  // namespace tensorflow
     80