Skip to content

Added examples for arrayfire::host #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,31 @@ where
}

/// Copies the data from the Array to the mutable slice `data`
///
/// # Examples
///
/// Basic case
/// ```
/// # use arrayfire::{Array,Dim4,HasAfEnum};
/// let a:Vec<u8> = vec![0,1,2,3,4,5,6,7,8];
/// let b = Array::<u8>::new(&a,Dim4::new(&[3,3,1,1]));
/// let mut c = vec!(u8::default();b.elements());
/// b.host(&mut c);
/// assert_eq!(c,a);
/// ```
/// Generic case
/// ```
/// # use arrayfire::{Array,Dim4,HasAfEnum};
/// fn to_vec<T:HasAfEnum+Default+Clone>(array:&Array<T>) -> Vec<T> {
/// let mut vec = vec!(T::default();array.elements());
/// array.host(&mut vec);
/// return vec;
/// }
///
/// let a = Array::<u8>::new(&[0,1,2,3,4,5,6,7,8],Dim4::new(&[3,3,1,1]));
/// let b:Vec<u8> = vec![0,1,2,3,4,5,6,7,8];
/// assert_eq!(to_vec(&a),b);
/// ```
pub fn host<O: HasAfEnum>(&self, data: &mut [O]) {
if data.len() != self.elements() {
HANDLE_ERROR(AfError::ERR_SIZE);
Expand Down