You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/03/27 02:56:14 UTC

[GitHub] sxjscience commented on a change in pull request #9740: add axis support and gradient for L2norm

sxjscience commented on a change in pull request #9740: add axis support and gradient for L2norm
URL: https://github.com/apache/incubator-mxnet/pull/9740#discussion_r177294267
 
 

 ##########
 File path: src/operator/tensor/broadcast_reduce_op.h
 ##########
 @@ -862,15 +905,47 @@ void L2NormComputeImpl(mshadow::Stream<xpu> *s,
   });
 }
 
+template<typename xpu>
+void SqRootForL2(const OpContext& ctx, OpReqType req, const TBlob &output) {
+  mshadow::Stream<xpu> *s = ctx.get_stream<xpu>();
+  MSHADOW_REAL_TYPE_SWITCH(output.type_flag_, DType, {
+    MXNET_ASSIGN_REQ_SWITCH(req, Req, {
+      DType* out_data = output.dptr<DType>();
+      using namespace mxnet_op;
+      Kernel<op_with_req<mshadow_op::square_root, Req>, xpu>::Launch(
+        s, output.Size(), out_data, out_data);
+    });
+  });
+}
+
+struct square {
+  /*! \brief map a to result using defined operation */
+  template<typename DType>
+  MSHADOW_XINLINE static DType Map(DType a) {
+    return a * a;
+  }
+};
 
 Review comment:
   I think square is supported in `mshadow_op::square`.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services