haojin2 commented on a change in pull request #11587: [MXNET-378] Adding 
depth_to_space and space_to_depth operator(Updated)
URL: https://github.com/apache/incubator-mxnet/pull/11587#discussion_r200793907
 
 

 ##########
 File path: src/operator/tensor/matrix_op.cc
 ##########
 @@ -908,5 +910,94 @@ NNVM_REGISTER_OP(_backward_squeeze)
 .set_attr<nnvm::TIsBackward>("TIsBackward", true)
 .set_attr<FCompute>("FCompute<cpu>", UnaryOp::IdentityCompute<cpu>);
 
+NNVM_REGISTER_OP(depth_to_space)
+.describe(R"code(This operators implements the depthToSpace function:
+.. math::
+    f(x, block) = ~x
+where :math:`x` is an input tensor of shape [N,C,H,W] and `~x` is the output 
tensor of shape [N,C/block^2,H*block,W*block]
+Example::
+#(1,4,2,3) input tensor
+  x = [[[[0, 1, 2],
+               [3, 4, 5]],
+          [[6, 7, 8],
+               [9, 10, 11]],
+          [[12, 13, 14],
+               [15, 16, 17]],
+          [[18, 19, 20],
+               [21, 22, 23]]]]
+  
+  y = depth_to_space(x, 2)
+
+# (1, 1, 4, 6) output tensor
+  y = [[[[0, 6, 1, 7, 2, 8],
+               [12, 18, 13, 19, 14, 20],
+               [3, 9, 4, 10, 5, 11],
+               [15, 21, 16, 22, 17, 23]]]]
+)code" ADD_FILELINE)
+.set_attr_parser(ParamParser<DepthToSpaceParam>)
+.set_num_inputs(1)
+.set_num_outputs(1)
+.set_attr<nnvm::FListInputNames>("FListInputNames",
+  [](const NodeAttrs& attrs) {
+    return std::vector<std::string>{"data"};
+  })
+.set_attr<nnvm::FInferShape>("FInferShape", DepthToSpaceOpShape)
+.set_attr<nnvm::FInferType>("FInferType", DepthToSpaceOpType)
+.set_attr<FCompute>("FCompute<cpu>", DepthToSpaceOpForward<cpu>)
+.set_attr<FResourceRequest>("FResourceRequest", [](const NodeAttrs& n) {
+  return std::vector<ResourceRequest>{ResourceRequest::kTempSpace};
+})
+.set_attr<nnvm::FInplaceOption>("FInplaceOption",
+  [](const NodeAttrs& attrs) {
+    return std::vector<std::pair<int, int> >{{0, 0}};
+  })
+.add_argument("data", "NDArray-or-Symbol", "Input ndarray")
+.add_arguments(DepthToSpaceParam::__FIELDS__());
 
 Review comment:
   You're missing FGradient declaration of both ops.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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

Reply via email to