1/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
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/common_shape_fns.h"
17#include "tensorflow/core/framework/op.h"
18#include "tensorflow/core/framework/shape_inference.h"
19
20namespace tensorflow {
21
22// --------------------------------------------------------------------------
23REGISTER_OP("Roll")
24 .Input("input: T")
25 .Input("shift: Tshift")
26 .Input("axis: Taxis")
27 .Output("output: T")
28 .Attr("T: type")
29 .Attr("Tshift: {int32,int64}")
30 .Attr("Taxis: {int32,int64}")
31 .SetShapeFn([](shape_inference::InferenceContext* c) {
32 shape_inference::ShapeHandle unused;
33 // The `input` must be 1-D or higher
34 TF_RETURN_IF_ERROR(c->WithRankAtLeast(c->input(0), 1, &unused));
35 // The `shift` must be scalar or 1-D.
36 TF_RETURN_IF_ERROR(c->WithRankAtMost(c->input(1), 1, &unused));
37 // The `axis` must be scalar or 1-D.
38 TF_RETURN_IF_ERROR(c->WithRankAtMost(c->input(2), 1, &unused));
39 // Validate 'shift' is the same shape as axis'.
40 TF_RETURN_IF_ERROR(c->Merge(c->input(1), c->input(2), &unused));
41 return shape_inference::UnchangedShape(c);
42 });
43
44} // namespace tensorflow
45