Unpacks the given dimension of a rank-R tensor into rank-(R-1) variable. For example, given a variable of shape (A, B, C, D); If axis == 0 then the i'th variable in output is the slice value[i, :, :, :] and each variable in output will have shape (B, C, D). (Note that the dimension unpacked along is gone, unlike split). If axis == 1 then the i'th variable in output is the slice value[:, i, :, :] a
| 1264 | The list of variable objects unstacked from value. |
| 1265 | */ |
| 1266 | std::vector <VARP> _Unstack(VARP value, int axis) { |
| 1267 | std::unique_ptr<OpT> op(new OpT); |
| 1268 | op->type = OpType_Unpack; |
| 1269 | auto info_value = value->getInfo(); |
| 1270 | if (info_value == nullptr) { |
| 1271 | MNN_ERROR("Unstack: value info is null.\n"); |
| 1272 | return {}; |
| 1273 | } |
| 1274 | auto dims = info_value->dim; |
| 1275 | auto dimsize = dims.size(); |
| 1276 | MNN_ASSERT(dimsize >= 1); |
| 1277 | axis = axis % dimsize; |
| 1278 | if(axis < 0) { |
| 1279 | axis += dimsize; |
| 1280 | } |
| 1281 | auto size = dims[axis]; |
| 1282 | MNN_ASSERT(size > 0); |
| 1283 | auto axisParam = new AxisT; |
| 1284 | axisParam->axis = axis; |
| 1285 | op->main.type = OpParameter_Axis; |
| 1286 | op->main.value = axisParam; |
| 1287 | EXPRP expr = Expr::create(std::move(op), {value}, size); |
| 1288 | std::vector<VARP> res; |
| 1289 | for (int i = 0; i < size; ++i) { |
| 1290 | res.emplace_back(Variable::create(expr, i)); |
| 1291 | } |
| 1292 | return res; |
| 1293 | } |
| 1294 | |
| 1295 | /*Returns the rank of a variable. |
| 1296 | Returns a 0-D int32 variable representing the rank of input. |