Skip to content

Commit 7ba96af

Browse files
committed
Fixed documentation tests(example code stubs)
1 parent 9514647 commit 7ba96af

File tree

9 files changed

+64
-34
lines changed

9 files changed

+64
-34
lines changed

examples/helloworld.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() {
1515
let dims = Dim4::new(&[num_rows, num_cols, 1, 1]);
1616

1717
println!("Create a 5-by-3 matrix of random floats on the GPU");
18-
let a = match randu(dims, Aftype::F32) {
18+
let a = match randu::<f32>(dims) {
1919
Ok(value) => value,
2020
Err(error) => panic!("{}", error),
2121
};

src/array.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl Array {
119119
/// # Examples
120120
///
121121
/// ```
122+
/// use arrayfire::{Array, Dim4};
122123
/// let values: &[f32] = &[1.0, 2.0, 3.0];
123124
/// let indices = Array::new(values, Dim4::new(&[3, 1, 1, 1])).unwrap();
124125
/// ```
@@ -388,25 +389,27 @@ impl Drop for Array {
388389
///
389390
/// # Examples
390391
///
391-
/// ```
392+
/// ```
393+
/// use arrayfire::{Dim4, print, randu};
392394
/// println!("Create a 5-by-3 matrix of random floats on the GPU");
395+
/// let dims = Dim4::new(&[3, 1, 1, 1]);
393396
/// let a = match randu::<f32>(dims) {
394397
/// Ok(value) => value,
395398
/// Err(error) => panic!("{}", error),
396399
/// };
397400
/// print(&a);
398-
/// ```
401+
/// ```
399402
///
400-
/// The sample output will look like below:
403+
/// The sample output will look like below:
401404
///
402-
/// ```
403-
/// [5 3 1 1]
404-
/// 0.7402 0.4464 0.7762
405-
/// 0.9210 0.6673 0.2948
406-
/// 0.0390 0.1099 0.7140
407-
/// 0.9690 0.4702 0.3585
408-
/// 0.9251 0.5132 0.6814
409-
/// ```
405+
/// ```bash
406+
/// [5 3 1 1]
407+
/// 0.7402 0.4464 0.7762
408+
/// 0.9210 0.6673 0.2948
409+
/// 0.0390 0.1099 0.7140
410+
/// 0.9690 0.4702 0.3585
411+
/// 0.9251 0.5132 0.6814
412+
/// ```
410413
pub fn print(input: &Array) -> Result<(), AfError> {
411414
unsafe {
412415
let ret_val = af_print_array(input.get() as AfArray);

src/data/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ pub fn upper(input: &Array, is_unit_diag: bool) -> Result<Array, AfError> {
537537
/// This function does the C-equivalent of the following statement, except that the operation
538538
/// happens on a GPU for all elements simultaneously.
539539
///
540-
/// ```
540+
/// ```ignore
541541
/// c = cond ? a : b; /// where cond, a & b are all objects of type Array
542542
/// ```
543543
///
@@ -570,7 +570,7 @@ pub fn select(a: &Array, cond: &Array, b: &Array) -> Result<Array, AfError> {
570570
/// This function does the C-equivalent of the following statement, except that the operation
571571
/// happens on a GPU for all elements simultaneously.
572572
///
573-
/// ```
573+
/// ```ignore
574574
/// c = cond ? a : b; /// where a is a scalar(f64) and b is Array
575575
/// ```
576576
///
@@ -603,7 +603,7 @@ pub fn selectl(a: f64, cond: &Array, b: &Array) -> Result<Array, AfError> {
603603
/// This function does the C-equivalent of the following statement, except that the operation
604604
/// happens on a GPU for all elements simultaneously.
605605
///
606-
/// ```
606+
/// ```ignore
607607
/// c = cond ? a : b; /// where a is Array and b is a scalar(f64)
608608
/// ```
609609
///
@@ -636,7 +636,7 @@ pub fn selectr(a: &Array, cond: &Array, b: f64) -> Result<Array, AfError> {
636636
/// This function does the C-equivalent of the following statement, except that the operation
637637
/// happens on a GPU for all elements simultaneously.
638638
///
639-
/// ```
639+
/// ```ignore
640640
/// a = cond ? a : b; /// where cond, a & b are all objects of type Array
641641
/// ```
642642
///
@@ -666,7 +666,7 @@ pub fn replace(a: &mut Array, cond: &Array, b: &Array) -> Result<(), AfError> {
666666
/// This function does the C-equivalent of the following statement, except that the operation
667667
/// happens on a GPU for all elements simultaneously.
668668
///
669-
/// ```
669+
/// ```ignore
670670
/// a = cond ? a : b; /// where cond, a are Arrays and b is scalar(f64)
671671
/// ```
672672
///

src/device/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn get_version() -> Result<(i32, i32, i32), AfError> {
4545
///
4646
/// An example output of `af::info` call looks like below
4747
///
48-
/// ```
48+
/// ```ignore
4949
/// ArrayFire v3.0.0 (CUDA, 64-bit Mac OSX, build d8d4b38)
5050
/// Platform: CUDA Toolkit 7, Driver: CUDA Driver Version: 7000
5151
/// [0] GeForce GT 750M, 2048 MB, CUDA Compute 3.0

src/dim4.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ impl Default for Dim4 {
1919
/// # Examples
2020
///
2121
/// ```
22+
/// use arrayfire::Dim4;
23+
///
2224
/// let dims = Dim4::new(&[4, 4, 2, 1]);
2325
/// println!("0th Dimension length is {}", dims[0]); // -> 4
2426
/// println!("1th Dimension length is {}", dims[1]); // -> 4
@@ -38,6 +40,8 @@ impl Index<usize> for Dim4 {
3840
/// # Examples
3941
///
4042
/// ```
43+
/// use arrayfire::Dim4;
44+
///
4145
/// let dims = Dim4::new(&[4, 4, 2, 1]);
4246
/// println!("0th Dimension length is {}", dims[0]); // -> 4
4347
/// ```
@@ -53,6 +57,7 @@ impl Dim4 {
5357
/// # Examples
5458
///
5559
/// ```
60+
/// use arrayfire::Dim4;
5661
/// let dims = Dim4::new(&[4, 4, 2, 1]);
5762
/// ```
5863
pub fn new(dims: &[u64; 4]) -> Dim4 {

src/graphics.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,23 @@ pub struct Cell {
5454
///
5555
/// # Examples
5656
///
57-
/// ```
58-
/// let wnd = Window::new(1280, 720, String::from("Image Histogram")).unwrap();
59-
/// let img = match load_image("Path to image", true/*If color image, 'false' otherwise*/) {
57+
/// ```no_run
58+
/// use arrayfire::{histogram, load_image, Window};
59+
/// let mut wnd = Window::new(1280, 720, String::from("Image Histogram")).unwrap();
60+
/// let img = match load_image("Path to image".to_string(), true/*If color image, 'false' otherwise*/) {
6061
/// Ok(img) => img,
6162
/// Err(err) => panic!("Image loading failed with error code {}", err),
6263
/// };
63-
/// let hst = histogram(img, 256, 0, 255).unwrap();
64+
/// let hst = histogram(&img, 256, 0 as f64, 255 as f64).unwrap();
6465
///
6566
/// loop {
6667
/// wnd.grid(2, 1);
6768
///
6869
/// wnd.set_view(0, 0);
69-
/// wnd.draw_image(img, Some("Input Image"));
70+
/// wnd.draw_image(&img, Some("Input Image".to_string()));
7071
///
7172
/// wnd.set_view(1, 0);
72-
/// wnd.draw_histogram(hst, 0.0, 255.0, Some("Input Image Histogram"));
73+
/// wnd.draw_hist(&hst, 0.0, 255.0, Some("Input Image Histogram".to_string()));
7374
///
7475
/// wnd.show();
7576
///

src/image/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ hsvrgb_func_def!(rgb2hsv, af_rgb2hsv);
968968
///
969969
/// # Examples
970970
///
971-
/// ```
971+
/// ```ignore
972972
/// A [5 5 1 1]
973973
/// 10 15 20 25 30
974974
/// 11 16 21 26 31

src/index.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ impl Drop for Indexer {
125125
/// # Examples
126126
///
127127
/// ```
128+
/// use arrayfire::{Dim4, Seq, index, randu, print};
129+
/// let dims = Dim4::new(&[5, 5, 1, 1]);
128130
/// let a = randu::<f32>(dims).unwrap();
129131
/// let seqs = &[Seq::new(1.0, 3.0, 1.0), Seq::default()];
130132
/// let sub = index(&a, seqs).unwrap();
@@ -153,10 +155,12 @@ pub fn index<T: Copy>(input: &Array, seqs: &[Seq<T>]) -> Result<Array, AfError>
153155
/// # Examples
154156
///
155157
/// ```
158+
/// use arrayfire::{Dim4, randu, row, print};
159+
/// let dims = Dim4::new(&[5, 5, 1, 1]);
156160
/// let a = randu::<f32>(dims).unwrap();
157161
/// println!("Grab last row of the random matrix");
158162
/// print(&a);
159-
/// print(&row(&a, num_rows - 1).unwrap());
163+
/// print(&row(&a, 4).unwrap());
160164
/// ```
161165
#[allow(dead_code)]
162166
pub fn row(input: &Array, row_num: u64) -> Result<Array, AfError> {
@@ -189,10 +193,12 @@ pub fn set_rows(input: &Array, new_rows: &Array, first: u64, last: u64) -> Resul
189193
/// # Examples
190194
///
191195
/// ```
196+
/// use arrayfire::{Dim4, randu, col, print};
197+
/// let dims = Dim4::new(&[5, 5, 1, 1]);
192198
/// let a = randu::<f32>(dims).unwrap();
193199
/// println!("Grab last col of the random matrix");
194200
/// print(&a);
195-
/// print(&row(&a, num_cols - 1).unwrap());
201+
/// print(&col(&a, 4).unwrap());
196202
/// ```
197203
#[allow(dead_code)]
198204
pub fn col(input: &Array, col_num: u64) -> Result<Array, AfError> {
@@ -287,6 +293,7 @@ pub fn lookup(input: &Array, indices: &Array, seq_dim: i32) -> Result<Array, AfE
287293
/// # Examples
288294
///
289295
/// ```
296+
/// use arrayfire::{constant, Dim4, Seq, assign_seq, print};
290297
/// let a = constant(2.0 as f32, Dim4::new(&[5, 3, 1, 1])).unwrap();
291298
/// let b = constant(1.0 as f32, Dim4::new(&[3, 3, 1, 1])).unwrap();
292299
/// let seqs = &[Seq::new(1.0, 3.0, 1.0), Seq::default()];
@@ -327,6 +334,7 @@ pub fn assign_seq<T: Copy>(lhs: &Array, seqs: &[Seq<T>], rhs: &Array) -> Result<
327334
/// # Examples
328335
///
329336
/// ```
337+
/// use arrayfire::{Array, Dim4, Seq, print, randu, index_gen, Indexer};
330338
/// let values: &[f32] = &[1.0, 2.0, 3.0];
331339
/// let indices = Array::new(values, Dim4::new(&[3, 1, 1, 1])).unwrap();
332340
/// let seq4gen = Seq::new(0.0, 2.0, 1.0);
@@ -370,6 +378,7 @@ pub fn index_gen(input: &Array, indices: Indexer) -> Result<Array, AfError> {
370378
/// # Examples
371379
///
372380
/// ```
381+
/// use arrayfire::{Array, Dim4, Seq, print, randu, constant, Indexer, assign_gen};
373382
/// let values: &[f32] = &[1.0, 2.0, 3.0];
374383
/// let indices = Array::new(values, Dim4::new(&[3, 1, 1, 1])).unwrap();
375384
/// let seq4gen = Seq::new(0.0, 2.0, 1.0);
@@ -390,7 +399,7 @@ pub fn index_gen(input: &Array, indices: Indexer) -> Result<Array, AfError> {
390399
/// idxrs.set_index(&indices, 0, None); // 2nd parameter is indexing dimension
391400
/// idxrs.set_index(&seq4gen, 1, Some(false)); // 3rd parameter indicates batch operation
392401
///
393-
/// let sub2 = assign_gen(&a, idxrs, &b).unwrap();
402+
/// let sub2 = assign_gen(&a, &idxrs, &b).unwrap();
394403
/// println!("a(indices, seq(0, 2, 1))"); print(&sub2);
395404
/// // [5 3 1 1]
396405
/// // 0.0000 0.2190 0.3835

src/macros.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,20 @@
3636
/// # Examples
3737
///
3838
/// ```
39-
/// mem_info!("Here");
39+
/// # #[macro_use(mem_info)] extern crate arrayfire;
40+
/// # fn main() {
41+
/// use arrayfire::{Dim4, device_mem_info, print, randu};
42+
///
43+
/// let dims = Dim4::new(&[5, 5, 1, 1]);
44+
/// let a = randu::<f32>(dims).unwrap();
45+
/// print(&a);
46+
/// mem_info!("Hello!");
47+
/// # }
4048
/// ```
4149
///
4250
/// Sample Output:
4351
///
44-
/// ```
52+
/// ```ignore
4553
/// AF Memory: Here
4654
/// Allocated [ Bytes | Buffers ] = [ 4096 | 4 ]
4755
/// In Use [ Bytes | Buffers ] = [ 2048 | 2 ]
@@ -66,11 +74,15 @@ macro_rules! mem_info {
6674
///
6775
/// ```
6876
/// # #[macro_use] extern crate arrayfire;
77+
///
6978
/// # fn main() {
70-
/// let a = &randu::<f32>(Dim4::new(&[5, 3, 1, 1])).unwrap();
71-
/// let b = &randu::<f32>(Dim4::new(&[5, 3, 1, 1])).unwrap();
72-
/// let c = &randu::<f32>(Dim4::new(&[5, 3, 1, 1])).unwrap();
73-
/// let d = join_many![2; a, b, c];
79+
/// use arrayfire::{Dim4, join_many, print, randu};
80+
///
81+
/// let a = &randu::<f32>(Dim4::new(&[5, 3, 1, 1])).unwrap();
82+
/// let b = &randu::<f32>(Dim4::new(&[5, 3, 1, 1])).unwrap();
83+
/// let c = &randu::<f32>(Dim4::new(&[5, 3, 1, 1])).unwrap();
84+
/// let d = join_many![2; a, b, c];
85+
/// print(&d.unwrap());
7486
/// # }
7587
/// ```
7688
///

0 commit comments

Comments
 (0)