Skip to content

Commit 2c62150

Browse files
Added examples for arrayfire::host (#220)
* Added examples: Both a basic use case and a function to illustrate a generic use case. * Minor fix to formatting
1 parent fb20c3c commit 2c62150

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/array.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,31 @@ where
376376
}
377377

378378
/// Copies the data from the Array to the mutable slice `data`
379+
///
380+
/// # Examples
381+
///
382+
/// Basic case
383+
/// ```
384+
/// # use arrayfire::{Array,Dim4,HasAfEnum};
385+
/// let a:Vec<u8> = vec![0,1,2,3,4,5,6,7,8];
386+
/// let b = Array::<u8>::new(&a,Dim4::new(&[3,3,1,1]));
387+
/// let mut c = vec!(u8::default();b.elements());
388+
/// b.host(&mut c);
389+
/// assert_eq!(c,a);
390+
/// ```
391+
/// Generic case
392+
/// ```
393+
/// # use arrayfire::{Array,Dim4,HasAfEnum};
394+
/// fn to_vec<T:HasAfEnum+Default+Clone>(array:&Array<T>) -> Vec<T> {
395+
/// let mut vec = vec!(T::default();array.elements());
396+
/// array.host(&mut vec);
397+
/// return vec;
398+
/// }
399+
///
400+
/// let a = Array::<u8>::new(&[0,1,2,3,4,5,6,7,8],Dim4::new(&[3,3,1,1]));
401+
/// let b:Vec<u8> = vec![0,1,2,3,4,5,6,7,8];
402+
/// assert_eq!(to_vec(&a),b);
403+
/// ```
379404
pub fn host<O: HasAfEnum>(&self, data: &mut [O]) {
380405
if data.len() != self.elements() {
381406
HANDLE_ERROR(AfError::ERR_SIZE);

0 commit comments

Comments
 (0)