76 bool is_static_shape =
true;
85 if (const_shape_node !=
nullptr)
87 LUCI_ASSERT(const_shape_node->dtype() ==
S32,
"Only support int32 CircleConst");
89 shape_by_input.
rank(const_shape_node->size<
S32>());
91 for (uint32_t axis = 0; axis < shape_by_input.
rank(); ++axis)
93 if (const_shape_node->at<
S32>(axis) < 0)
97 else if (const_shape_node->at<
S32>(axis) == 0)
99 const auto node_tensor = loco::must_cast<luci::CircleNode *>(node->
tensor());
102 shape_by_input.
dim(axis) = node_tensor->dim(axis);
111 shape_by_input.
dim(axis).
set(const_shape_node->at<
S32>(axis));
115 "Reshape infer shape is invalid.");
123 auto rank = new_shape->
rank();
125 if (shape_dummy && rank > 0)
127 is_static_shape =
true;
128 shape_by_input.
rank(rank);
129 for (uint32_t i = 0; i < rank; ++i)
131 if (new_shape->dim(i) > 0)
132 shape_by_input.
dim(i) =
static_cast<uint32_t
>(new_shape->dim(i));
135 is_static_shape =
false;
142 auto shape_node = loco::must_cast<luci::CircleNode *>(node->
shape());
143 assert(shape_node->rank() == 1);
145 auto num_elements = shape_node->dim(0).value();
146 shape_by_input.
rank(num_elements);
147 is_static_shape =
false;
156 for (uint32_t axis = 0; axis < shape_by_attr.
rank(); ++axis)
162 if (!(shape_by_input == shape_by_attr))
164 INFO(l) <<
"CircleReshape: Two new shape information mismatched : " << std::endl;
165 INFO(l) <<
" shape_by_input : " << shape_by_input << std::endl;
166 INFO(l) <<
" shape_by_attr : " << shape_by_attr << std::endl;
172 const auto input = loco::must_cast<luci::CircleNode *>(node->
tensor());
174 uint32_t input_element_count = 1;
175 uint32_t output_element_count = 1;
176 uint32_t unknown_dim_index = UINT32_MAX;
177 for (uint32_t i = 0; i < input_shape.rank(); ++i)
179 if (input_shape.dim(i).known())
180 input_element_count *= input_shape.dim(i).value();
182 is_static_shape =
false;
187 for (uint32_t dim_index = 0; dim_index <
output_shape.rank(); ++dim_index)
189 uint32_t dim_value =
output_shape.dim(dim_index).value();
192 LUCI_ASSERT(unknown_dim_index == UINT32_MAX,
"More than one unknown dimension");
193 unknown_dim_index = dim_index;
201 if (dim_index < input_shape.rank())
202 dim_value = input_shape.dim(dim_index).value();
209 output_element_count *= dim_value;
212 if (unknown_dim_index != UINT32_MAX)
214 output_shape.dim(unknown_dim_index) = input_element_count / output_element_count;