imalsogreg commented on a change in pull request #6563:
URL: https://github.com/apache/incubator-tvm/pull/6563#discussion_r497168051
##########
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:
Could a user ever request `T ~ ()`, or some other zero-sized item,
giving a divide-by-zero error?
----------------------------------------------------------------
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:
[email protected]