| 156 | #endif |
| 157 | |
| 158 | SymbolVar 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 | |
| 195 | cg::OperatorNodeBase::NodeProp* GetVarShape::do_make_node_prop() const { |
| 196 | auto prop = Super::do_make_node_prop(); |
nothing calls this directly
no test coverage detected