sxjscience commented on a change in pull request #16979: [Bugfix] [Numpy] Add
`kAddTo` and kNullOp to Transpose
URL: https://github.com/apache/incubator-mxnet/pull/16979#discussion_r355589699
##########
File path: src/operator/tensor/matrix_op-inl.h
##########
@@ -323,62 +336,77 @@ void TransposeImpl(RunContext ctx,
// Example: (0, 2, 3, 1) or (0, 3, 1, 2), but not (0, 2, 1, 3).
if (isPseudo2DTranspose(axes)) {
MSHADOW_TYPE_SWITCH(ret.type_flag_, DType, {
- transpose_pseudo2D<DType>(ret, src, axes, s);
+ transpose_pseudo2D<DType, is_addto>(ret, src, axes, s);
});
return;
}
#endif
+ // Special handle the identity case
+ if (isIdentityTranspose(axes)) {
+ MSHADOW_TYPE_SWITCH(ret.type_flag_, DType, {
+ Tensor<xpu, 1, DType> in = src.get_with_shape<xpu, 1,
DType>(mshadow::Shape1(src.Size()), s);
+ Tensor<xpu, 1, DType> out = ret.get_with_shape<xpu, 1,
DType>(mshadow::Shape1(ret.Size()), s);
+ if (!is_addto) {
+ // Use memcpy to accelerate the speed
+ Copy(out, in, s);
+ } else {
+ mxnet_op::Kernel<mxnet_op::op_with_req<mshadow_op::identity, kAddTo>,
xpu>::Launch(
+ s, ret.Size(), out.dptr_, in.dptr_);
+ }
+ return;
Review comment:
moved
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services