1/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4
5You may obtain a copy of the License at
6
7    http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations 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_testutil.h"
20#include "tensorflow/core/platform/test.h"
21
22namespace tensorflow {
23
24TEST(RandomOpsTest, Multinomial_ShapeFn) {
25  ShapeInferenceTestOp op("Multinomial");
26  op.input_tensors.resize(2);
27
28  INFER_OK(op, "?;?", "[?,?]");
29  INFER_ERROR("Shape must be rank 2 but is rank 1", op, "[?];?");
30  INFER_OK(op, "[?,?];?", "[d0_0,?]");
31  INFER_OK(op, "[2,?];?", "[d0_0,?]");
32  INFER_OK(op, "[2,1];?", "[d0_0,?]");
33  Tensor num_samples = test::AsScalar<int32>(3);
34  op.input_tensors[1] = &num_samples;
35  INFER_OK(op, "[2,1];[]", "[d0_0,3]");
36  num_samples = test::AsTensor<int32>({1, 2, 3});
37  INFER_ERROR("Shape must be rank 0 but is rank 1", op, "[2,1];[3]");
38}
39
40TEST(RandomOpsTest, RandomGamma_ShapeFn) {
41  ShapeInferenceTestOp op("RandomGamma");
42  op.input_tensors.resize(2);
43
44  INFER_OK(op, "?;?", "?");
45  INFER_OK(op, "?;[3]", "?");
46  INFER_OK(op, "[1];?", "?");
47  INFER_ERROR("Shape must be rank 1 but is rank 2", op, "[1,2];[3,4]");
48  Tensor shape = test::AsTensor<int32>({1, 2, 3});
49  op.input_tensors[0] = &shape;
50  INFER_OK(op, "[3];[4,?]", "[1,2,3,d1_0,d1_1]");
51  INFER_OK(op, "[3];[4,5]", "[1,2,3,d1_0,d1_1]");
52  INFER_OK(op, "[3];[]", "[1,2,3]");
53}
54
55TEST(RandomOpsTest, RandomPoisson_ShapeFn) {
56  ShapeInferenceTestOp op("RandomPoisson");
57  op.input_tensors.resize(2);
58
59  INFER_OK(op, "?;?", "?");
60  INFER_OK(op, "?;[3]", "?");
61  INFER_OK(op, "[1];?", "?");
62  INFER_ERROR("Shape must be rank 1 but is rank 2", op, "[1,2];[3,4]");
63  Tensor shape = test::AsTensor<int32>({1, 2, 3});
64  op.input_tensors[0] = &shape;
65  INFER_OK(op, "[3];[4,?]", "[1,2,3,d1_0,d1_1]");
66  INFER_OK(op, "[3];[4,5]", "[1,2,3,d1_0,d1_1]");
67  INFER_OK(op, "[3];[]", "[1,2,3]");
68}
69
70}  // end namespace tensorflow
71