File tree Expand file tree Collapse file tree 1 file changed +103
-0
lines changed Expand file tree Collapse file tree 1 file changed +103
-0
lines changed Original file line number Diff line number Diff line change
1
+ #![ crate_type="lib" ]
2
+
3
+ // Test cases for bounds check elimination
4
+
5
+ extern crate ndarray;
6
+
7
+ use ndarray:: prelude:: * ;
8
+
9
+ /*
10
+ pub fn testslice(a: &[f64]) -> f64 {
11
+ let mut sum = 0.;
12
+ for i in 0..a.len() {
13
+ sum += a[i];
14
+ }
15
+ sum
16
+ }
17
+
18
+ pub fn testvec(a: &Vec<f64>) -> f64 {
19
+ let mut sum = 0.;
20
+ for i in 0..a.len() {
21
+ sum += a[i];
22
+ }
23
+ sum
24
+ }
25
+
26
+ pub fn testvec_as_slice(a: &Vec<f64>) -> f64 {
27
+ let a = a.as_slice();
28
+ let mut sum = 0.;
29
+ for i in 0..a.len() {
30
+ sum += a[i];
31
+ }
32
+ sum
33
+ }
34
+ */
35
+
36
+ #[ no_mangle]
37
+ pub fn test1d_single ( a : & Array1 < f64 > , i : usize ) -> f64 {
38
+ if i < a. len ( ) { a[ i] } else { 0. }
39
+ }
40
+
41
+ #[ no_mangle]
42
+ pub fn test1d_single_mut ( a : & mut Array1 < f64 > , i : usize ) -> f64 {
43
+ if i < a. len ( ) { * & mut a[ i] } else { 0. }
44
+ }
45
+
46
+ #[ no_mangle]
47
+ pub fn test1d_len_of ( a : & Array1 < f64 > ) -> f64 {
48
+ let a = & * a;
49
+ let mut sum = 0. ;
50
+ for i in 0 ..a. len_of ( Axis ( 0 ) ) {
51
+ sum += a[ i] ;
52
+ }
53
+ sum
54
+ }
55
+
56
+ #[ no_mangle]
57
+ pub fn test1d_range ( a : & Array1 < f64 > ) -> f64 {
58
+ let mut sum = 0. ;
59
+ for i in 0 ..a. len ( ) {
60
+ sum += a[ i] ;
61
+ }
62
+ sum
63
+ }
64
+
65
+ #[ no_mangle]
66
+ pub fn test1d_while ( a : & Array1 < f64 > ) -> f64 {
67
+ let mut sum = 0. ;
68
+ let mut i = 0 ;
69
+ while i < a. len ( ) {
70
+ sum += a[ i] ;
71
+ i += 1 ;
72
+ }
73
+ sum
74
+ }
75
+
76
+ #[ no_mangle]
77
+ pub fn test2d_ranges ( a : & Array2 < f64 > ) -> f64 {
78
+ let mut sum = 0. ;
79
+ for i in 0 ..a. rows ( ) {
80
+ for j in 0 ..a. cols ( ) {
81
+ sum += a[ [ i, j] ] ;
82
+ }
83
+ }
84
+ sum
85
+ }
86
+
87
+ #[ no_mangle]
88
+ pub fn test2d_whiles ( a : & Array2 < f64 > ) -> f64 {
89
+ let mut sum = 0. ;
90
+ let mut i = 0 ;
91
+ while i < a. rows ( ) {
92
+ let mut j = 0 ;
93
+ while j < a. cols ( ) {
94
+ sum += a[ [ i, j] ] ;
95
+ j += 1 ;
96
+ }
97
+ i += 1 ;
98
+ }
99
+ sum
100
+ }
101
+
102
+ fn main ( ) {
103
+ }
You can’t perform that action at this time.
0 commit comments