1 #![crate_type = "lib"]
2 #![allow(
3     clippy::many_single_char_names,
4     clippy::deref_addrof,
5     clippy::unreadable_literal,
6     clippy::many_single_char_names
7 )]
8 
9 // Test cases for bounds check elimination
10 
11 use ndarray::prelude::*;
12 
13 /*
14 pub fn testslice(a: &[f64]) -> f64 {
15     let mut sum = 0.;
16     for i in 0..a.len() {
17         sum += a[i];
18     }
19     sum
20 }
21 
22 pub fn testvec(a: &Vec<f64>) -> f64 {
23     let mut sum = 0.;
24     for i in 0..a.len() {
25         sum += a[i];
26     }
27     sum
28 }
29 
30 pub fn testvec_as_slice(a: &Vec<f64>) -> f64 {
31     let a = a.as_slice();
32     let mut sum = 0.;
33     for i in 0..a.len() {
34         sum += a[i];
35     }
36     sum
37 }
38 */
39 
40 #[no_mangle]
test1d_single(a: &Array1<f64>, i: usize) -> f6441 pub fn test1d_single(a: &Array1<f64>, i: usize) -> f64 {
42     if i < a.len() {
43         a[i]
44     } else {
45         0.
46     }
47 }
48 
49 #[no_mangle]
test1d_single_mut(a: &mut Array1<f64>, i: usize) -> f6450 pub fn test1d_single_mut(a: &mut Array1<f64>, i: usize) -> f64 {
51     if i < a.len() {
52         *&mut a[i]
53     } else {
54         0.
55     }
56 }
57 
58 #[no_mangle]
test1d_len_of(a: &Array1<f64>) -> f6459 pub fn test1d_len_of(a: &Array1<f64>) -> f64 {
60     let a = &*a;
61     let mut sum = 0.;
62     for i in 0..a.len_of(Axis(0)) {
63         sum += a[i];
64     }
65     sum
66 }
67 
68 #[no_mangle]
test1d_range(a: &Array1<f64>) -> f6469 pub fn test1d_range(a: &Array1<f64>) -> f64 {
70     let mut sum = 0.;
71     for i in 0..a.len() {
72         sum += a[i];
73     }
74     sum
75 }
76 
77 #[no_mangle]
test1d_while(a: &Array1<f64>) -> f6478 pub fn test1d_while(a: &Array1<f64>) -> f64 {
79     let mut sum = 0.;
80     let mut i = 0;
81     while i < a.len() {
82         sum += a[i];
83         i += 1;
84     }
85     sum
86 }
87 
88 #[no_mangle]
test2d_ranges(a: &Array2<f64>) -> f6489 pub fn test2d_ranges(a: &Array2<f64>) -> f64 {
90     let mut sum = 0.;
91     for i in 0..a.nrows() {
92         for j in 0..a.ncols() {
93             sum += a[[i, j]];
94         }
95     }
96     sum
97 }
98 
99 #[no_mangle]
test2d_whiles(a: &Array2<f64>) -> f64100 pub fn test2d_whiles(a: &Array2<f64>) -> f64 {
101     let mut sum = 0.;
102     let mut i = 0;
103     while i < a.nrows() {
104         let mut j = 0;
105         while j < a.ncols() {
106             sum += a[[i, j]];
107             j += 1;
108         }
109         i += 1;
110     }
111     sum
112 }
113 
main()114 fn main() {}
115