You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/09/30 18:56:02 UTC

[GitHub] [incubator-tvm] mwillsey commented on a change in pull request #6563: [Rust] Improve NDArray, GraphRt, and Relay bindings

mwillsey commented on a change in pull request #6563:
URL: https://github.com/apache/incubator-tvm/pull/6563#discussion_r497731475



##########
File path: rust/tvm-rt/src/ndarray.rs
##########
@@ -184,28 +246,19 @@ impl NDArray {
     /// let ctx = Context::cpu(0);
     /// let mut ndarray = NDArray::empty(&mut shape, ctx, DataType::from_str("int32").unwrap());
     /// ndarray.copy_from_buffer(&mut data);
-    /// assert_eq!(ndarray.shape(), Some(&mut shape[..]));
+    /// assert_eq!(ndarray.shape(), shape);
     /// assert_eq!(ndarray.to_vec::<i32>().unwrap(), data);
     /// ```
     pub fn to_vec<T>(&self) -> Result<Vec<T>, NDArrayError> {
-        if !self.shape().is_some() {
-            return Err(NDArrayError::EmptyArray);
-        }
-        let earr = NDArray::empty(
-            self.shape().ok_or(NDArrayError::MissingShape)?,
-            Context::cpu(0),
-            self.dtype(),
-        );
-        let target = self.copy_to_ndarray(earr)?;
-        let arr = target.as_dltensor();
-        let sz = self.size().ok_or(NDArrayError::MissingShape)?;
-        let mut v: Vec<T> = Vec::with_capacity(sz * mem::size_of::<T>());
-        unsafe {
-            v.as_mut_ptr()
-                .copy_from_nonoverlapping(arr.data as *const T, sz);
-            v.set_len(sz);
-        }
-        Ok(v)
+        let n = self.size() / size_of::<T>();

Review comment:
       Yeah i think panicking on div-by-zero would be the correct behavior. Follow up on jared, I think a goal should be to move to NDArray<T>, because right now these conversions are all effectively transmutes.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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