eric-haibin-lin commented on a change in pull request #10208: [MXNET-117] 
Sparse operator broadcast_mul/div(csr, dense) = csr
URL: https://github.com/apache/incubator-mxnet/pull/10208#discussion_r179316685
 
 

 ##########
 File path: src/operator/tensor/elemwise_binary_broadcast_op.h
 ##########
 @@ -185,6 +230,94 @@ void BinaryBroadcastCompute(const nnvm::NodeAttrs& attrs,
   }
 }
 
+template<typename xpu, typename OP>
+void BinaryBroadcastCsrDnsCsrImpl(const OpContext& ctx,
+                                  const NDArray& csr,
+                                  const NDArray& dns,
+                                  const OpReqType req,
+                                  const NDArray& output) {
+  using namespace mshadow;
+  using namespace mxnet_op;
+  using namespace csr;
+  CHECK(req != kAddTo && req != kWriteInplace);
+  mshadow::Stream<xpu> *s = ctx.get_stream<xpu>();
+  bool col_vec;
+  if (dns.shape().ndim() == 1) {
+    col_vec = false;
+  } else {
+    col_vec = (dns.shape()[0] == csr.shape()[0])? true : false;
+  }
+
+  if (csr.storage_initialized()) {
+    const nnvm::dim_t nnz = csr.storage_shape()[0];
+    const nnvm::dim_t num_rows = output.shape()[0];
+    output.CheckAndAlloc({Shape1(num_rows + 1), Shape1(nnz)});
+
+    MSHADOW_TYPE_SWITCH(output.dtype(), DType, {
+      MSHADOW_IDX_TYPE_SWITCH(output.aux_type(kIdx), CType, {
+        MSHADOW_IDX_TYPE_SWITCH(output.aux_type(kIndPtr), RType, {
+          MXNET_ASSIGN_REQ_SWITCH(req, req_type, {
+            if ((dns.shape().ndim() == 2 && dns.shape()[0] == 1 && 
dns.shape()[1] == 1) ||
+                (dns.shape().ndim() == 1 && dns.shape()[0] == 1)) {
+              Kernel<op_with_req<OP, req_type>, xpu>::Launch(
+                s, nnz, output.data().dptr<DType>(), csr.data().dptr<DType>(),
+                dns.data().dptr<DType>()[0]);
+            } else {
+              Kernel<csr_dns_csr_broadcast_kernel<req_type, OP>, xpu>::Launch(
+                s, num_rows, csr.data().dptr<DType>(), 
csr.aux_data(kIdx).dptr<CType>(),
+                csr.aux_data(kIndPtr).dptr<RType>(), dns.data().dptr<DType>(),
+                output.data().dptr<DType>(), csr.shape()[1], col_vec);
+            }
+            Copy(output.aux_data(kIdx).FlatTo1D<xpu, CType>(),
+                 csr.aux_data(kIdx).FlatTo1D<xpu, CType>());
+            Copy(output.aux_data(kIndPtr).FlatTo1D<xpu, RType>(),
+                 csr.aux_data(kIndPtr).FlatTo1D<xpu, RType>());
+          });
+        });
+      });
+    });
+  // If input csr is an empty matrix, fill zeros and return
+  } else {
+    FillZerosCsrImpl(s, output);
+    return;
+  }
+}
+
+template<typename xpu, typename OP>
+void BinaryBroadcastComputeCsrEx(const nnvm::NodeAttrs& attrs,
 
 Review comment:
   rename to `BinaryBroadcastComputeEx`

----------------------------------------------------------------
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