| 49 | return {descs, success}; |
| 50 | } |
| 51 | VarNodeArray apply_on_var_node(const OpDef& def, const VarNodeArray& inputs) { |
| 52 | auto&& op = def.cast_final_safe<MeshGrid>(); |
| 53 | std::vector<size_t> indexs(inputs.size()); |
| 54 | std::iota(indexs.begin(), indexs.end(), 0); |
| 55 | auto cn = inputs[0]->comp_node(); |
| 56 | auto graph = inputs[0]->owner_graph(); |
| 57 | if (op.indexing == "xy") { |
| 58 | if (indexs.size() >= 2) { |
| 59 | std::swap(indexs[0], indexs[1]); |
| 60 | } |
| 61 | } else { |
| 62 | mgb_assert(op.indexing == "ij", "meshgrid only support \"ij\" or \"xy\""); |
| 63 | } |
| 64 | VarNodeArray shps; |
| 65 | for (size_t ind = 0; ind < inputs.size(); ind++) { |
| 66 | auto&& inp = inputs[indexs[ind]]; |
| 67 | shps.push_back(opr::GetVarShape::make(inp).node()); |
| 68 | } |
| 69 | VarNode* tshp = opr::Concat::make(shps, 0, cn).node(); |
| 70 | VarNodeArray results; |
| 71 | auto t_ndim = inputs.size(); |
| 72 | for (size_t ind = 0; ind < inputs.size(); ind++) { |
| 73 | auto axis = indexs[ind]; |
| 74 | HostTensorND hv = HostTensorND(cn, {t_ndim}, dtype::Int32()); |
| 75 | auto* ptr = hv.ptr<dt_int32>(); |
| 76 | std::fill_n(ptr, t_ndim, 1); |
| 77 | ptr[axis] = -1; |
| 78 | auto shp = opr::ImmutableTensor::make(*graph, hv, cn).node(); |
| 79 | auto tmp = opr::Reshape::make(inputs[ind], shp, axis).node(); |
| 80 | results.push_back(opr::Broadcast::make(tmp, tshp).node()); |
| 81 | } |
| 82 | return results; |
| 83 | } |
| 84 | SmallVector<TensorPtr> apply_on_physical_tensor( |
| 85 | const OpDef& def, const SmallVector<TensorPtr>& inputs, |
| 86 | SmallVector<LogicalTensorDesc>& output_descs, const bool& validated) { |
nothing calls this directly
no test coverage detected