@@ -11,75 +11,62 @@ fn main() {
1111 let num_rows: u64 = 5 ;
1212 let num_cols: u64 = 3 ;
1313 let values: & [ f32 ] = & [ 1.0 , 2.0 , 3.0 ] ;
14- let indices = Array :: new ( values, Dim4 :: new ( & [ 3 , 1 , 1 , 1 ] ) ) . unwrap ( ) ;
14+ let indices = Array :: new ( values, Dim4 :: new ( & [ 3 , 1 , 1 , 1 ] ) ) ;
1515
1616 let dims = Dim4 :: new ( & [ num_rows, num_cols, 1 , 1 ] ) ;
1717
18- let a = match randu :: < f32 > ( dims) {
19- Ok ( value) => value,
20- Err ( error) => panic ! ( "{}" , error) ,
21- } ;
18+ let a = randu :: < f32 > ( dims) ;
2219 af_print ! ( "Create a 5-by-3 matrix of random floats on the GPU" , a) ;
2320
2421 println ! ( "Element-wise arithmetic" ) ;
25- let b = sin ( & a)
26- . and_then ( |x| add ( & x, & 1.5 , false ) )
27- . unwrap ( ) ;
22+ let b = add ( & sin ( & a) , & 1.5 , false ) ;
2823
29- let b2 = sin ( & a) .
30- and_then ( |x| {
31- cos ( & a)
32- . and_then ( |y| add ( & x, & y, false ) )
33- } )
34- . unwrap ( ) ;
24+ let b2 = add ( & sin ( & a) , & cos ( & a) , false ) ;
3525
3626 let b3 = ! & a;
3727 af_print ! ( "sin(a) + 1.5 => " , b) ;
3828 af_print ! ( "sin(a) + cos(a) => " , b2) ;
3929 af_print ! ( "!a => " , b3) ;
4030
41- let test = & a + & b ;
31+ let test = a . clone ( ) + b . clone ( ) ;
4232 af_print ! ( "a + b" , test) ;
4333
4434 // Index array using sequences
4535 let seqs = & [ Seq :: new ( 1u32 , 3 , 1 ) , Seq :: default ( ) ] ;
46- let sub = index ( & a, seqs) . unwrap ( ) ;
36+ let sub = index ( & a, seqs) ;
4737 af_print ! ( "a(seq(1,3,1), span)" , sub) ;
4838
4939 //Index array using array and sequence
5040 let seq4gen = Seq :: new ( 0u32 , 2 , 1 ) ;
5141
52- let mut idxrs = match Indexer :: new ( ) {
53- Ok ( v) => v,
54- Err ( e) => panic ! ( "{}" , e) ,
55- } ;
42+ let mut idxrs = Indexer :: new ( ) ;
5643 idxrs. set_index ( & indices, 0 , None ) ;
5744 idxrs. set_index ( & seq4gen, 1 , Some ( false ) ) ;
5845
59- let sub2 = index_gen ( & a, idxrs) . unwrap ( ) ;
46+ let sub2 = index_gen ( & a, idxrs) ;
6047 af_print ! ( "a(indices, seq(0, 2, 1))" , sub2) ;
6148
6249 // printf("Negate the first three elements of second column\n");
6350 // B(seq(0, 2), 1) = B(seq(0, 2), 1) * -1;
6451 // af_print(B);
6552
6653 println ! ( "Fourier transform the result" ) ;
67- fft ( & b, 1.0 , 0 ) . map ( |x| print ( & x ) ) ;
54+ print ( & fft ( & b, 1.0 , 0 ) ) ;
6855
6956 println ! ( "Grab last row & col of the random matrix" ) ;
7057 print ( & a) ;
71- print ( & row ( & a, num_rows - 1 ) . unwrap ( ) ) ;
72- print ( & col ( & a, num_cols - 1 ) . unwrap ( ) ) ;
58+ print ( & row ( & a, num_rows - 1 ) ) ;
59+ print ( & col ( & a, num_cols - 1 ) ) ;
7360
7461 let r_dims = Dim4 :: new ( & [ 3 , 1 , 1 , 1 ] ) ;
7562 let r_input: [ f32 ; 3 ] = [ 1.0 , 1.0 , 1.0 ] ;
76- let r = Array :: new ( & r_input, r_dims) . unwrap ( ) ;
77- let ur = set_row ( & a, & r, num_rows - 1 ) . unwrap ( ) ;
63+ let r = Array :: new ( & r_input, r_dims) ;
64+ let ur = set_row ( & a, & r, num_rows - 1 ) ;
7865 af_print ! ( "Set last row to 1's" , ur) ;
7966
8067 let d_dims = Dim4 :: new ( & [ 2 , 3 , 1 , 1 ] ) ;
8168 let d_input: [ i32 ; 6 ] = [ 1 , 2 , 3 , 4 , 5 , 6 ] ;
82- let d = Array :: new ( & d_input, d_dims) . unwrap ( ) ;
69+ let d = Array :: new ( & d_input, d_dims) ;
8370 af_print ! ( "Create 2-by-3 matrix from host data" , d) ;
8471
8572 // printf("Copy last column onto first\n");
@@ -88,13 +75,11 @@ fn main() {
8875
8976 // // Sort A
9077 println ! ( "Sort A and print sorted array and corresponding indices" ) ;
91- sort_index ( & a, 0 , true )
92- . map ( | x | {
93- print ( & x. 0 ) ;
94- print ( & x. 1 ) ;
95- } ) ;
78+ let x = sort_index ( & a, 0 , true ) ;
79+ print ( & x. 0 ) ;
80+ print ( & x. 1 ) ;
9681
97- let u8_cnst = & constant ( 1 as u8 , dims) . unwrap ( ) ;
82+ let u8_cnst = & constant ( 1 as u8 , dims) ;
9883 af_print ! ( "u8 constant array" , u8_cnst) ;
99- println ! ( "Is u8_cnst array float precision type ? {}" , u8_cnst. is_single( ) . unwrap ( ) ) ;
84+ println ! ( "Is u8_cnst array float precision type ? {}" , u8_cnst. is_single( ) ) ;
10085}
0 commit comments