| 36 | std::vector<op_desc> operators() const { return {{"StridedSlice"}}; } |
| 37 | |
| 38 | instruction_ref parse(const op_desc& /*opd*/, |
| 39 | const tf_parser& /*parser*/, |
| 40 | tf_parser::node_info info, |
| 41 | std::vector<instruction_ref> args) const |
| 42 | { |
| 43 | auto starts = args[1]->eval().get<int32_t>().to_vector(); |
| 44 | auto ends = args[2]->eval().get<int32_t>().to_vector(); |
| 45 | auto l0 = args[0]; |
| 46 | size_t num_axes = l0->get_shape().lens().size(); |
| 47 | std::vector<size_t> axes = l0->get_shape().lens(); |
| 48 | |
| 49 | std::vector<int64_t> op_starts(starts.begin(), starts.end()); |
| 50 | std::vector<int64_t> op_ends(ends.begin(), ends.end()); |
| 51 | std::vector<int64_t> op_axes(num_axes); |
| 52 | std::iota(op_axes.begin(), op_axes.end(), 0); |
| 53 | uint32_t begin_mask = 0; |
| 54 | uint32_t end_mask = 0; |
| 55 | uint32_t shrink_axis_mask = 0; |
| 56 | uint32_t bitwise_compare = 1; |
| 57 | std::vector<int64_t> squeeze_axes; |
| 58 | |
| 59 | if(contains(info.attributes, "begin_mask")) |
| 60 | begin_mask = static_cast<uint32_t>(info.attributes.at("begin_mask").i()); |
| 61 | |
| 62 | if(contains(info.attributes, "end_mask")) |
| 63 | end_mask = static_cast<uint32_t>(info.attributes.at("end_mask").i()); |
| 64 | |
| 65 | if(contains(info.attributes, "shrink_axis_mask")) |
| 66 | shrink_axis_mask = static_cast<uint32_t>(info.attributes.at("shrink_axis_mask").i()); |
| 67 | |
| 68 | std::vector<int64_t> begin_axes = get_axes_from_mask(num_axes, begin_mask); |
| 69 | std::vector<int64_t> end_axes = get_axes_from_mask(num_axes, end_mask); |
| 70 | |
| 71 | for(size_t i = 0; i < num_axes; i++) |
| 72 | { |
| 73 | if(begin_axes.at(i) == 1) |
| 74 | { |
| 75 | op_starts.at(i) = 0; |
| 76 | } |
| 77 | if(end_axes.at(i) == 1) |
| 78 | { |
| 79 | op_ends.at(i) = axes.at(i); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | auto op = make_op("slice", {{"starts", op_starts}, {"ends", op_ends}, {"axes", op_axes}}); |
| 84 | auto l1 = info.add_instruction(op, l0); |
| 85 | if(shrink_axis_mask == 0) |
| 86 | return l1; |
| 87 | |
| 88 | for(size_t i = 0; i < num_axes; i++) |
| 89 | { |
| 90 | // the LSB corresponds to axis 0 when determining which axes to squeeze |
| 91 | if(((shrink_axis_mask >> i) & bitwise_compare) == 1) |
| 92 | squeeze_axes.push_back(i); |
| 93 | } |
| 94 | |
| 95 | return info.add_instruction(make_op("squeeze", {{"axes", squeeze_axes}}), l1); |
nothing calls this directly
no test coverage detected