ZiyueHuang commented on a change in pull request #8259: check_format of ndrray, 
mainly for csr
URL: https://github.com/apache/incubator-mxnet/pull/8259#discussion_r145035545
 
 

 ##########
 File path: src/common/utils.h
 ##########
 @@ -43,9 +43,84 @@
 #include <algorithm>
 #include <functional>
 
+#include "../operator/mxnet_op.h"
+#include "../ndarray/ndarray_function.h"
+
 namespace mxnet {
 namespace common {
 
+struct indptr_check {
+  template<typename DType>
+  MSHADOW_XINLINE static void Map(int i, mshadow::default_real_t* out, const 
DType* in,
+                                  const nnvm::dim_t end, const nnvm::dim_t 
idx_size) {
+    if ((in[i+1] < in[i]) || (i == 0 && in[i] != static_cast<DType>(0)) ||
+        (i == end && in[i] < static_cast<DType>(idx_size))) out[0] = 1;
+  }
+};
+
+struct idx_check {
+  template<typename DType>
+  MSHADOW_XINLINE static void Map(int i, mshadow::default_real_t* out,
+                                  const DType* in, const nnvm::dim_t ncols) {
+    if (in[i] >= static_cast<DType>(ncols)) out[0] = 1;
+  }
+};
+
+template<typename xpu>
+void CheckFormatWrapper(const RunContext &rctx, const NDArray *input,
+                        NDArray *cpu_ret, const bool &full_check);
+
+template<typename xpu>
+void CheckFormatImpl(const RunContext &rctx, const NDArray *input,
+                     NDArray *cpu_ret, const bool &full_check) {
 
 Review comment:
   `xpu_ret` is used for kernel launch with `input`, which can be on cpu/gpu. 
Then copy the `err` number to `cpu_ret` for checking outside of engine, mainly 
for inspecting data on cpu.
   ```
   auto err = cpu_ret.data().dptr<mshadow::default_real_t>();
   CHECK_EQ(*err, 0) << "Check validity of the CSRNDArray";
   ```
   If data is on gpu, can't do like this.
 
----------------------------------------------------------------
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