cjolivier01 commented on a change in pull request #9770: eye operator, for 
default storage type
URL: https://github.com/apache/incubator-mxnet/pull/9770#discussion_r170006130
 
 

 ##########
 File path: src/operator/tensor/init_op.h
 ##########
 @@ -428,6 +405,39 @@ void FillComputeZerosEx(const nnvm::NodeAttrs& attrs,
   }
 }
 
+
+template<typename xpu>
+void EyeFill(const nnvm::NodeAttrs& attrs,
+             const OpContext& ctx,
+             const std::vector<TBlob>& inputs,
+             const std::vector<OpReqType>& req,
+             const std::vector<TBlob>& outputs) {
+  CHECK_EQ(inputs.size(), 0U);
+  CHECK_EQ(outputs.size(), 1U);
+  CHECK_EQ(req.size(), 1U);
+  mshadow::Stream<xpu> *s = ctx.get_stream<xpu>();
+  const EyeParam& param = nnvm::get<EyeParam>(attrs.parsed);
+  const TBlob& out_data = outputs[0];
+  const nnvm::dim_t num_cols = param.M > 0 ? param.M : param.N;
+
+  const nnvm::dim_t cnnz = std::max(num_cols - std::abs(param.k), 
(nnvm::dim_t)0);
+  const nnvm::dim_t rnnz = std::max(param.N - std::abs(param.k), 
(nnvm::dim_t)0);
+  const nnvm::dim_t nnz = param.k > 0 ? std::min(cnnz, param.N) :
+                                        std::min(rnnz, num_cols);
+  using namespace mxnet_op;
+  MSHADOW_TYPE_SWITCH(out_data.type_flag_, DType, {
+    MXNET_ASSIGN_REQ_SWITCH(req[0], req_type, {
+      Fill(s, out_data, req[0], static_cast<DType>(0));
+      if (nnz > 0) {
+        Kernel<eye_dns_fill<req_type>, xpu>::Launch(
+          s, nnz, out_data.dptr<DType>(),
+          std::max((nnvm::dim_t)0, param.k), param.k, num_cols);
 
 Review comment:
   nit: 
   ```cpp
   static_cast<nnvm::dim_t>(0)
   ```
   or
   ```cpp
   0LL
   ```
   although the latter sort of ties dim_t to a specific type.
   

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


With regards,
Apache Git Services

Reply via email to