aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/framework/shape_inference_testutil.h
blob: 221ec875fb03c4de6b7107fe63bc6bdfac1b1dc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef THIRD_PARTY_TENSORFLOW_CORE_FRAMEWORK_SHAPE_INFERENCE_TESTUTIL_H_
#define THIRD_PARTY_TENSORFLOW_CORE_FRAMEWORK_SHAPE_INFERENCE_TESTUTIL_H_

#include <vector>
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/platform/types.h"

// Contains utilities for writing tests for shape inference functions.

namespace tensorflow {

class NodeDef;

// Run shape inference for <op_name>, given inputs specified by <ins>
// and returns an error if the inferred shape does not match expected_outs.
//
// <ins> is a semicolon separated list of shapes. Each shape is formatted
// according to the formatting per
// shape_inference::InferenceContext::InferenceContext.
//
// <expected_outs> is a semicolon separated list of shapes. Each shape is
// formatted as one of:
// * ? - an unknown shape, but not matching an input shape
// * in0|in2|... - output shape must be the same as one of these input shapes.
// * [1,?,d0_0|d0_1] - output shape is of known rank, with comma-separated
//      dimension values.
//      Each dimension value is one of:
//      * a constant, which means that constant not equal to a specific input
//      * ?, which means an unknown dim size not equal to a specific input
//      * d0_0|d1_2, indicating that the dim size must be equal to one of
//            the given input dimensions; the first number is the input # and
//            the second is which dimension in that input it corresponds to.
// <expected_outs> can be "e"; this is used to indicate that shape inference
// should have failed.
Status InferShapes(const string& op_name, const string& ins,
                   const string& expected_outs,
                   const NodeDef* node_def = nullptr);

#define INFER_OK(op, i, o) EXPECT_EQ("", InferShapes(op, i, o).error_message())
#define INFER_ERROR(s, op, i) \
  EXPECT_EQ(s, InferShapes(op, i, "e").error_message())
#define INFER_OK_WITH_DEF(op, nd, i, o) \
  EXPECT_EQ("", InferShapes(op, i, o, nd).error_message())
#define INFER_ERROR_WITH_DEF(s, op, nd, i) \
  EXPECT_EQ(s, InferShapes(op, i, "e", nd).error_message())

}  // namespace tensorflow

#endif  // THIRD_PARTY_TENSORFLOW_CORE_FRAMEWORK_SHAPE_INFERENCE_TESTUTIL_H_