MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / make

Method make

src/opr/impl/tensor_manip.cpp:158–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156#endif
157
158SymbolVar GetVarShape::make(
159 const VarNodeArrayView& inp, Param param, const OperatorNodeConfig& config) {
160 mgb_assert(!inp.empty());
161
162#if !MGB_BUILD_SLIM_SERVING
163 // try to apply shortcut and omit scalar shapes to optimize
164 VarNodeArray inp_vp;
165 inp_vp.reserve(inp.size());
166 auto&& mgr = inp[0]->owner_graph()->static_infer_manager();
167 for (auto var : inp) {
168 auto&& it = mgr.get_infer_type(var);
169 if (it.shape & cg::static_infer::InferType::CONST) {
170 if (mgr.infer_shape(var).is_scalar()) {
171 // scalar does not affect broadcast result
172 continue;
173 }
174 }
175 if (auto opr = get_shape_shortcut(var)) {
176 // current var replaced by a shortcut
177 auto&& op_inp = opr->input();
178 inp_vp.insert(inp_vp.end(), op_inp.begin(), op_inp.end());
179 continue;
180 }
181 inp_vp.push_back(var);
182 }
183 if (inp_vp.empty()) {
184 // all inputs are scalar
185 mgb_assert(param.axis == OptionalAxis::INVALID_AXIS || param.axis == 0);
186 return SymbolVar{inp[0]}.make_scalar(1);
187 }
188#else
189 auto&& inp_vp = inp;
190#endif
191 return SymbolVar{inp[0]}.insert_single_output_opr<GetVarShape>(
192 inp_vp, param, config);
193}
194
195cg::OperatorNodeBase::NodeProp* GetVarShape::do_make_node_prop() const {
196 auto prop = Super::do_make_node_prop();

Callers

nothing calls this directly

Calls 15

get_shape_shortcutFunction · 0.85
check_is_shape_ofFunction · 0.85
emplace_backMethod · 0.80
backMethod · 0.80
frontMethod · 0.80
resizeMethod · 0.80
makeFunction · 0.50
emptyMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
owner_graphMethod · 0.45
get_infer_typeMethod · 0.45

Tested by

no test coverage detected