1/* Copyright 2017 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#include <memory>
16#include <string>
17#include <unordered_map>
18#include <vector>
19
20#include "tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.h"
21#include "tensorflow/contrib/lite/toco/model.h"
22#include "tensorflow/contrib/lite/toco/tooling_util.h"
23#include "tensorflow/core/platform/logging.h"
24
25namespace toco {
26
27bool ResolveSliceAttributes::Run(Model* model, std::size_t op_index) {
28  const auto slice_it = model->operators.begin() + op_index;
29  auto* slice_op = slice_it->get();
30  if (slice_op->type != OperatorType::kSlice) return false;
31
32  auto* op = static_cast<SliceOperator*>(slice_op);
33  if (!op->begin.empty()) return false;
34
35  CHECK_EQ(op->inputs.size(), 3);
36  if (!IsConstantParameterArray(*model, op->inputs[1])) return false;
37  if (!IsConstantParameterArray(*model, op->inputs[2])) return false;
38
39  const auto& begin_array = model->GetArray(op->inputs[1]);
40  if (!begin_array.has_shape()) return false;
41
42  const auto& size_array = model->GetArray(op->inputs[2]);
43  if (!size_array.has_shape()) return false;
44
45  op->begin = begin_array.GetBuffer<ArrayDataType::kInt32>().data;
46  op->size = size_array.GetBuffer<ArrayDataType::kInt32>().data;
47
48  // TODO(dkalenichenko): Delete the extra inputs?
49
50  return true;
51}
52}  // namespace toco
53