Home | History | Annotate | Download | only in ops
      1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 
      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/node_def_builder.h"
     17 #include "tensorflow/core/framework/op.h"
     18 #include "tensorflow/core/framework/shape_inference_testutil.h"
     19 #include "tensorflow/core/framework/tensor.h"
     20 #include "tensorflow/core/framework/tensor_testutil.h"
     21 #include "tensorflow/core/lib/core/status_test_util.h"
     22 #include "tensorflow/core/lib/strings/str_util.h"
     23 #include "tensorflow/core/platform/test.h"
     24 
     25 namespace tensorflow {
     26 
     27 TEST(CudnnRNNOpsTest, ParamsSize_ShapeFn) {
     28   ShapeInferenceTestOp op("CudnnRNNParamsSize");
     29   INFER_OK(op, "[1];[1];[1]", "[1]");
     30 }
     31 
     32 TEST(CudnnRNNOpsTest, ForwardLstm_ShapeFn) {
     33   ShapeInferenceTestOp op("CudnnRNN");
     34   TF_ASSERT_OK(NodeDefBuilder("test", "CudnnRNN")
     35                    .Input({"input", 0, DT_FLOAT})
     36                    .Input({"input_h", 0, DT_FLOAT})
     37                    .Input({"input_c", 0, DT_FLOAT})
     38                    .Input({"params", 0, DT_FLOAT})
     39                    .Attr("rnn_mode", "lstm")
     40                    .Attr("input_mode", "auto_select")
     41                    .Attr("direction", "unidirectional")
     42                    .Finalize(&op.node_def));
     43   int seq_length = 2;
     44   int batch_size = 3;
     45   int num_units = 4;
     46   int num_layers = 5;
     47   int dir_count = 1;
     48   std::vector<int> input_shape = {seq_length, batch_size, num_units};
     49   std::vector<int> input_h_shape = {num_layers * dir_count, batch_size,
     50                                     num_units};
     51   std::vector<int> output_shape = {seq_length, batch_size,
     52                                    num_units * dir_count};
     53   auto shape_to_str = [](const std::vector<int>& v) {
     54     return strings::StrCat("[", str_util::Join(v, ","), "]");
     55   };
     56   string input_shapes_desc = strings::StrCat(
     57       shape_to_str(input_shape), ";", shape_to_str(input_h_shape), ";",
     58       shape_to_str(input_h_shape), ";", "[?]");
     59   string output_shapes_desc = "[d0_0,d0_1,d1_2];in1;in1;?";
     60   INFER_OK(op, input_shapes_desc, output_shapes_desc);
     61 }
     62 
     63 }  // end namespace tensorflow
     64