eric-haibin-lin commented on a change in pull request #9625: sparse regression
operators
URL: https://github.com/apache/incubator-mxnet/pull/9625#discussion_r164911562
##########
File path: src/operator/regression_output-inl.h
##########
@@ -121,6 +174,80 @@ void RegressionBackward(const nnvm::NodeAttrs& attrs,
});
}
+/*!
+ * \brief Regression backward kernel for the case that
+ * label is of csr storage type.
+ * Parallelize by each row.
+ */
+template<typename OP, int req>
+struct SparseRegressionBWDKernel {
+ template<typename DType, typename IType, typename RType>
+ MSHADOW_XINLINE static void Map(int i, DType* out_data,
+ const DType* in_data,
+ const DType* label_data,
+ const IType* label_idx,
+ const RType* label_indptr,
+ const nnvm::dim_t row_length) {
+ nnvm::dim_t row_i = i * row_length;
+ RType k = label_indptr[i];
+ for (nnvm::dim_t j=0; j < row_length; j++) {
+ if (label_idx[k] == j) {
+ KERNEL_ASSIGN(out_data[row_i + j], req,
+ OP::Map(in_data[row_i + j], label_data[k]));
+ if (k < (label_indptr[i+1]-1)) k++;
+ } else {
+ KERNEL_ASSIGN(out_data[row_i + j], req,
+ OP::Map(in_data[row_i + j], static_cast<DType>(0)));
+ }
+ }
+ }
+};
+
+template<typename xpu, typename BackwardOP>
+void RegressionBackwardEx(const nnvm::NodeAttrs& attrs,
+ const OpContext& ctx,
+ const std::vector<NDArray>& inputs,
+ const std::vector<OpReqType>& req,
+ const std::vector<NDArray>& outputs) {
+ CHECK_EQ(inputs.size(), 2U);
+ CHECK_EQ(outputs.size(), 2U);
+ const RegressionOutputParam& param =
nnvm::get<RegressionOutputParam>(attrs.parsed);
+ auto label_stype = inputs[0].storage_type();
+ if (label_stype == kCSRStorage) {
Review comment:
Use `BackwardEx` to dispatch to `CsrImpl` based on stypes
----------------------------------------------------------------
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