Skip to content

Commit

Permalink
update code with review (openvinotoolkit#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
luo-cheng2021 authored and zhangYiIntel committed May 11, 2021
1 parent 1a4b452 commit aa22a9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
6 changes: 4 additions & 2 deletions ngraph/frontend/paddlepaddle/src/op/slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ namespace op {
NamedOutputs slice (const NodeContext& node) {
auto data = node.get_ng_input("Input");
auto axes = node.get_attribute<std::vector<int32_t>>("axes");
// TODO: support tensor type CVS-55266
auto starts = node.get_attribute<std::vector<int32_t>>("starts");
// TODO: support tensor type CVS-55266
auto ends = node.get_attribute<std::vector<int32_t>>("ends");
auto data_rank = data.get_partial_shape().rank();
size_t shape_size = data_rank.get_length();
std::vector<int32_t> fixedStarts(shape_size, 0);
std::vector<int32_t> fixedEnds(shape_size, INT_MAX);

int n = 0;
for (size_t &&i : axes) {
PDPD_ASSERT(i < shape_size, "slice: axes must be less than the X rank.");
for (auto i : axes) {
PDPD_ASSERT(i < (int32_t)shape_size, "slice: axes must be less than the X rank.");
fixedStarts[i] = starts[n];
fixedEnds[i] = ends[n];
n++;
Expand Down
35 changes: 16 additions & 19 deletions ngraph/frontend/paddlepaddle/src/op/squeeze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@
#include <paddlepaddle_frontend/utility.hpp>

namespace ngraph {
namespace frontend {
namespace pdpd {
namespace op {
namespace frontend {
namespace pdpd {
namespace op {

NamedOutputs squeeze (const NodeContext& node) {
auto data = node.get_ng_input("X");
auto axes = node.get_attribute<std::vector<int32_t>>("axes");
NamedOutputs squeeze (const NodeContext& node) {
auto data = node.get_ng_input("X");
std::vector<int32_t> axes;
if (node.has_attribute<std::vector<int32_t>>("axes")) {
axes = node.get_attribute<std::vector<int32_t>>("axes");
}

auto shape = data.get_partial_shape().to_shape();
for (auto &&i : axes) {
auto idx = i;
if (idx < 0) {
idx = i + shape.size();
}
PDPD_ASSERT(shape[idx] == 1, "squeeze: the specified dimension is not equal to one.");
}
auto axesNode = ngraph::opset6::Constant::create(ngraph::element::i32, {axes.size()}, axes);
return node.default_single_output_mapping({std::make_shared<ngraph::opset6::Squeeze>(data, axesNode)}, {"Out"});
}

auto axesNode = ngraph::opset6::Constant::create(ngraph::element::i32, {axes.size()}, axes);
return node.default_single_output_mapping({std::make_shared<ngraph::opset6::Squeeze>(data, axesNode)}, {"Out"});
}

}}}}
} // namespace op
} // namespace pdpd
} // namespace frontend
} // namespace ngraph

0 comments on commit aa22a9a

Please sign in to comment.