You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/06/03 03:38:26 UTC

[GitHub] larroy commented on a change in pull request #11107: [WIP][PoC] mxnet-lite

larroy commented on a change in pull request #11107: [WIP][PoC] mxnet-lite
URL: https://github.com/apache/incubator-mxnet/pull/11107#discussion_r192576163
 
 

 ##########
 File path: cpp-lite/include/mxnet-lite/ndarray.h
 ##########
 @@ -0,0 +1,284 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef MXNET_LITE_NDARRAY_H_
+#define MXNET_LITE_NDARRAY_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include <dmlc/logging.h>
+#include <mxnet/c_api.h>
+
+#include <mxnet-lite/context.h>
+
+namespace mxnet {
+namespace lite {
+/*!
+* \brief NDArray interface
+*/
+class NDArray {
+ public:
+  /*!
+  * \brief Block until all the pending read/write operations with respect
+  *    to current NDArray are finished, and read/write can be performed.
+  */
+  static void WaitAll() {
+    CHECK_EQ(MXNDArrayWaitAll(), 0);
+  }
+  /*!
+  * \brief Load NDArrays from binary file.
+  * \param file_name name of the binary file.
+  * \param array_list a list of NDArrays returned, do not fill the list if
+  * nullptr is given.
+  * \param array_map a map from names to NDArrays returned, do not fill the map
+  * if nullptr is given or no names is stored in binary file.
+  */
+  static std::vector<NDArray> LoadList(const std::string &file_name) {
+    mx_uint out_size, out_name_size;
+    NDArrayHandle *out_arr;
+    const char **out_names;
+    CHECK_EQ(MXNDArrayLoad(file_name.c_str(), &out_size, &out_arr,
+                           &out_name_size, &out_names), 0);
+    std::vector<NDArray> array_list;
+    array_list.reserve(out_size);
+    for (mx_uint i = 0; i < out_size; ++i) {
+      array_list.push_back(NDArray(out_arr[i]));
+    }
+    return array_list;
+  }
+  /*!
+  * \brief Load map of NDArrays from binary file.
+  * \param file_name name of the binary file.
+  * \return a list of NDArrays.
+  */
+  static std::map<std::string, NDArray> LoadDict(const std::string &file_name) {
 
 Review comment:
   can we find better names for these methods?  What about LoadMap?

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