From c42c042349068fd3860b612bf59bdd400b5411f0 Mon Sep 17 00:00:00 2001 From: Jonathan Woollett-Light Date: Wed, 13 May 2020 15:54:40 +0100 Subject: [PATCH 1/4] Added examples Both a basic use case and a function to illustrate a generic use case. --- src/array.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/array.rs b/src/array.rs index 842ea6247..cac430160 100644 --- a/src/array.rs +++ b/src/array.rs @@ -376,6 +376,27 @@ where } /// Copies the data from the Array to the mutable slice `data` + /// + /// Basic case: + /// ``` + /// let a:Vec = vec![0,1,2,3,4,5,6,7,8]; + /// let b = Array::::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: + /// ``` + /// fn to_vec(array:&Array) -> Vec { + /// let mut vec = vec!(T::default();array.elements()); + /// array.host(&mut vec); + /// return vec; + /// } + /// + /// let a = Array::::new(&[0,1,2,3,4,5,6,7,8],Dim4::new(&[3,3,1,1])); + /// let b:Vec = vec![0,1,2,3,4,5,6,7,8]; + /// assert_eq!(to_vec(&a),b); + /// ``` pub fn host(&self, data: &mut [O]) { if data.len() != self.elements() { HANDLE_ERROR(AfError::ERR_SIZE); From b7058a2ae8840a57c1172069843f10daa4c4799e Mon Sep 17 00:00:00 2001 From: Jonathan Woollett-Light Date: Wed, 13 May 2020 16:00:41 +0100 Subject: [PATCH 2/4] Hid `use`s --- src/array.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/array.rs b/src/array.rs index cac430160..2fca61acb 100644 --- a/src/array.rs +++ b/src/array.rs @@ -379,6 +379,7 @@ where /// /// Basic case: /// ``` + /// # use arrayfire::{Array,Dim4,HasAfEnum}; /// let a:Vec = vec![0,1,2,3,4,5,6,7,8]; /// let b = Array::::new(&a,Dim4::new(&[3,3,1,1])); /// let mut c = vec!(u8::default();b.elements()); @@ -387,6 +388,7 @@ where /// ``` /// Generic case: /// ``` + /// # use arrayfire::{Array,Dim4,HasAfEnum}; /// fn to_vec(array:&Array) -> Vec { /// let mut vec = vec!(T::default();array.elements()); /// array.host(&mut vec); From c838e6d4a5cccfe085ed21cbb14390ada8bcc82e Mon Sep 17 00:00:00 2001 From: Jonathan Woollett-Light Date: Wed, 13 May 2020 16:06:39 +0100 Subject: [PATCH 3/4] Minor fix to formatting --- src/array.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/array.rs b/src/array.rs index 2fca61acb..f2731057d 100644 --- a/src/array.rs +++ b/src/array.rs @@ -377,7 +377,9 @@ where /// Copies the data from the Array to the mutable slice `data` /// - /// Basic case: + /// # Examples + /// + /// Basic case /// ``` /// # use arrayfire::{Array,Dim4,HasAfEnum}; /// let a:Vec = vec![0,1,2,3,4,5,6,7,8]; @@ -386,7 +388,7 @@ where /// b.host(&mut c); /// assert_eq!(c,a); /// ``` - /// Generic case: + /// Generic case /// ``` /// # use arrayfire::{Array,Dim4,HasAfEnum}; /// fn to_vec(array:&Array) -> Vec { From abc0b711f5e14bce2ccb22adfda80ddf13fea205 Mon Sep 17 00:00:00 2001 From: Jonathan Woollett-Light Date: Wed, 13 May 2020 19:05:43 +0100 Subject: [PATCH 4/4] Ran `cargo fmt` --- src/array.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/array.rs b/src/array.rs index f2731057d..5a1043a6c 100644 --- a/src/array.rs +++ b/src/array.rs @@ -376,13 +376,13 @@ where } /// Copies the data from the Array to the mutable slice `data` - /// + /// /// # Examples - /// + /// /// Basic case /// ``` /// # use arrayfire::{Array,Dim4,HasAfEnum}; - /// let a:Vec = vec![0,1,2,3,4,5,6,7,8]; + /// let a:Vec = vec![0,1,2,3,4,5,6,7,8]; /// let b = Array::::new(&a,Dim4::new(&[3,3,1,1])); /// let mut c = vec!(u8::default();b.elements()); /// b.host(&mut c); @@ -396,7 +396,7 @@ where /// array.host(&mut vec); /// return vec; /// } - /// + /// /// let a = Array::::new(&[0,1,2,3,4,5,6,7,8],Dim4::new(&[3,3,1,1])); /// let b:Vec = vec![0,1,2,3,4,5,6,7,8]; /// assert_eq!(to_vec(&a),b);