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

Function apply_on_var_node

imperative/src/impl/ops/broadcast.cpp:51–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49 return {descs, success};
50}
51VarNodeArray 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}
84SmallVector<TensorPtr> apply_on_physical_tensor(
85 const OpDef& def, const SmallVector<TensorPtr>& inputs,
86 SmallVector<LogicalTensorDesc>& output_descs, const bool& validated) {

Callers

nothing calls this directly

Calls 12

swapFunction · 0.85
makeFunction · 0.70
iotaFunction · 0.50
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
comp_nodeMethod · 0.45
owner_graphMethod · 0.45
push_backMethod · 0.45
nodeMethod · 0.45
make_nameMethod · 0.45
paramMethod · 0.45

Tested by

no test coverage detected