You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by gi...@git.apache.org on 2017/10/14 05:45:52 UTC

[GitHub] piiswrong commented on a change in pull request #8259: [WIP] check_format of ndrray, mainly for csr

piiswrong commented on a change in pull request #8259: [WIP] check_format of ndrray, mainly for csr
URL: https://github.com/apache/incubator-mxnet/pull/8259#discussion_r144687068
 
 

 ##########
 File path: include/mxnet/ndarray.h
 ##########
 @@ -309,6 +309,62 @@ class NDArray {
     return true;
   }
   /*!
+   * \brief check whether the matrix format is valid
+   * \param full_check if `True`, rigorous check, O(N) operations
+   *    Otherwise basic check, O(1) operations
+   */
+  inline void check_format(const bool full_check = true) const {
+    auto stype = storage_type();
+    if (stype == kCSRStorage) {
+      CHECK_EQ(shape().ndim(), 2)
+               << "CSR only for two dimension";
+      CHECK(aux_shape(csr::kIdx).ndim() == 1 &&
+            aux_shape(csr::kIndPtr).ndim() == 1 &&
+            storage_shape().ndim() == 1)
+            << "data, indices, and indptr should be 1-D";
+      CHECK_EQ(aux_shape(csr::kIndPtr)[0], shape()[0] + 1)
+               << "index pointer size" << aux_shape(csr::kIndPtr)[0]
+               << "should be " << (shape()[0] + 1);
+      CHECK_EQ(aux_shape(csr::kIdx)[0], storage_shape()[0])
+               << "indices and data should have the same size";
+      auto type = aux_type(csr::kIndPtr);
+      MSHADOW_TYPE_SWITCH(type, IType, {
+        auto dptr = aux_data(csr::kIndPtr).dptr<IType>();
+        CHECK_EQ(dptr[0], 0)
+                 << "index pointer should start with 0";
+        const nnvm::dim_t end = aux_shape(csr::kIndPtr)[0];
+        CHECK_GE(dptr[end-1], aux_shape(csr::kIdx)[0])
 
 Review comment:
   Also this needs to be pushed to engine. Can't do it 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:
users@infra.apache.org


With regards,
Apache Git Services