75 bool is_static_shape =
true;
84 if (const_shape_node !=
nullptr)
86 LUCI_ASSERT(const_shape_node->dtype() ==
S32,
"Only support int32 CircleConst");
88 shape_by_input.
rank(const_shape_node->size<
S32>());
90 for (uint32_t axis = 0; axis < shape_by_input.
rank(); ++axis)
92 if (const_shape_node->at<
S32>(axis) < 0)
96 else if (const_shape_node->at<
S32>(axis) == 0)
98 const auto node_tensor = loco::must_cast<luci::CircleNode *>(node->
tensor());
101 shape_by_input.
dim(axis) = node_tensor->dim(axis);
110 shape_by_input.
dim(axis).
set(const_shape_node->at<
S32>(axis));
114 "Reshape infer shape is invalid.");
122 auto rank = new_shape->
rank();
124 if (shape_dummy && rank > 0)
126 is_static_shape =
true;
127 shape_by_input.
rank(rank);
128 for (uint32_t i = 0; i < rank; ++i)
130 if (new_shape->dim(i) > 0)
131 shape_by_input.
dim(i) =
static_cast<uint32_t
>(new_shape->dim(i));
134 is_static_shape =
false;
141 auto shape_node = loco::must_cast<luci::CircleNode *>(node->
shape());
142 assert(shape_node->rank() == 1);
144 auto num_elements = shape_node->dim(0).value();
145 shape_by_input.
rank(num_elements);
146 is_static_shape =
false;
155 for (uint32_t axis = 0; axis < shape_by_attr.
rank(); ++axis)
161 if (!(shape_by_input == shape_by_attr))
163 INFO(l) <<
"CircleReshape: Two new shape information mismatched : " << std::endl;
164 INFO(l) <<
" shape_by_input : " << shape_by_input << std::endl;
165 INFO(l) <<
" shape_by_attr : " << shape_by_attr << std::endl;
171 const auto input = loco::must_cast<luci::CircleNode *>(node->
tensor());
173 uint32_t input_element_count = 1;
174 uint32_t output_element_count = 1;
175 uint32_t unknown_dim_index = UINT32_MAX;
176 for (uint32_t i = 0; i < input_shape.rank(); ++i)
178 if (input_shape.dim(i).known())
179 input_element_count *= input_shape.dim(i).value();
181 is_static_shape =
false;
186 for (uint32_t dim_index = 0; dim_index <
output_shape.rank(); ++dim_index)
188 uint32_t dim_value =
output_shape.dim(dim_index).value();
191 LUCI_ASSERT(unknown_dim_index == UINT32_MAX,
"More than one unknown dimension");
192 unknown_dim_index = dim_index;
200 if (dim_index < input_shape.rank())
201 dim_value = input_shape.dim(dim_index).value();
208 output_element_count *= dim_value;
211 if (unknown_dim_index != UINT32_MAX)
213 if (input_element_count % output_element_count != 0)
215 INTERNAL_EXN(
"Reshape Op cannot infer unknown dimension from inputs.");
217 output_shape.dim(unknown_dim_index) = input_element_count / output_element_count;