27 if (args.op.inputs.size() != 1 && args.op.inputs.size() != 2)
30 if (args.op.outputs.size() != 1)
34 if (args.op.inputs.size() == 2)
36 const auto &inputs = args.op.inputs;
37 const auto tensors = args.reader.tensors();
38 const auto tensor_in = tensors.at(inputs.at(1));
39 assert(tensor_in !=
nullptr);
41 if (tensor_in->type() != circle::TensorType::TensorType_INT32 &&
42 tensor_in->type() != circle::TensorType::TensorType_INT64)
49static void setup_shape_attribute(
const std::vector<int32_t> &shape,
CircleReshape *node)
52 for (uint32_t i = 0; i < shape.size(); ++i)
58static CircleNode *create_shape_node(
const std::vector<int32_t> &shape,
loco::Graph *graph)
61 shape_node->dtype(loco::DataType::S32);
63 shape_node->dim(0) = shape.
size();
64 shape_node->size<loco::DataType::S32>(shape.size());
65 for (uint32_t i = 0; i < shape.size(); ++i)
67 shape_node->at<loco::DataType::S32>(i) = shape[i];
69 shape_node->name(
"Reshape/shape");
73CircleNode *CircleReshapeGraphBuilder::build_node(
const circle::OperatorT &op,
74 const std::vector<CircleNode *> &inputs,
79 auto *shape_node = (
inputs.size() == 2) ?
inputs.at(1) :
nullptr;
80 if (shape_node ==
nullptr)
82 const auto *
options = op.builtin_options.AsReshapeOptions();
83 if (options !=
nullptr)
84 shape_node = create_shape_node(
options->new_shape, graph);
87 shape_node =
graph->nodes()->create<CircleOutputDummy>();
88 shape_node->dtype(loco::DataType::S32);
90 shape_node->name(
"Reshape/dummy");
94 auto *node =
graph->nodes()->create<CircleReshape>();
96 node->
shape(shape_node);
98 const auto *
options = op.builtin_options.AsReshapeOptions();
100 setup_shape_attribute(
options->new_shape, node);
Class to build tensor data.
uint32_t size(void) const
uint32_t rank(void) const
int32_t dim(uint32_t n) const
bool validate(const ValidateArgs &args) const final
const Shape * newShape(void) const
loco::Node * shape(void) const
loco::Node * tensor(void) const