Skip to content

Commit 2e3fc42

Browse files
committed
rustfmt changes after 2018 edition
1 parent 4e86043 commit 2e3fc42

File tree

31 files changed

+4034
-2003
lines changed

31 files changed

+4034
-2003
lines changed

build.rs

Lines changed: 163 additions & 126 deletions
Large diffs are not rendered by default.

examples/acoustic_wave.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::f64::consts::*;
21
use arrayfire::*;
2+
use std::f64::consts::*;
33

44
fn main() {
55
set_device(0);
@@ -8,20 +8,20 @@ fn main() {
88
}
99

1010
fn normalise(a: &Array<f32>) -> Array<f32> {
11-
(a/(max_all(&abs(a)).0 as f32 * 2.0f32)) + 0.5f32
11+
(a / (max_all(&abs(a)).0 as f32 * 2.0f32)) + 0.5f32
1212
}
1313

1414
fn acoustic_wave_simulation() {
1515
// Speed of sound
16-
let c :f32 = 0.1;
16+
let c: f32 = 0.1;
1717
// Distance step
18-
let dx :f32 = 0.5;
18+
let dx: f32 = 0.5;
1919
// Time step
20-
let dt :f32 = 1.0;
20+
let dt: f32 = 1.0;
2121

2222
// Grid size.
23-
let nx : u64 = 1500;
24-
let ny : u64 = 1500;
23+
let nx: u64 = 1500;
24+
let ny: u64 = 1500;
2525

2626
// Grid dimensions.
2727
let dims = Dim4::new(&[nx, ny, 1, 1]);
@@ -32,34 +32,37 @@ fn acoustic_wave_simulation() {
3232
let mut p_dot = p.clone();
3333

3434
// Laplacian (Del^2) convolution kernel.
35-
let laplacian_values: [f32; 9] = [0.0, 1.0, 0.0,
36-
1.0, -4.0, 1.0,
37-
0.0, 1.0, 0.0];
35+
let laplacian_values: [f32; 9] = [0.0, 1.0, 0.0, 1.0, -4.0, 1.0, 0.0, 1.0, 0.0];
3836
let laplacian_kernel = Array::new(&laplacian_values, Dim4::new(&[3, 3, 1, 1])) / (dx * dx);
3937

4038
// Create a window to show the waves.
4139
let mut win = Window::new(1000, 1000, "Waves".to_string());
4240

4341
// Hann windowed pulse.
44-
let pulse_time :f32 = 100.0;
45-
let centre_freq :f32 = 0.05;
46-
let twopi = PI as f32 * 2.0;
42+
let pulse_time: f32 = 100.0;
43+
let centre_freq: f32 = 0.05;
44+
let twopi = PI as f32 * 2.0;
4745

4846
// Number of samples in pulse.
49-
let pulse_n = (pulse_time/dt).floor() as u64;
47+
let pulse_n = (pulse_time / dt).floor() as u64;
5048

51-
let i = range::<f32>(Dim4::new(&[pulse_n, 1, 1, 1]), 0);
52-
let t = i.clone() * dt;
49+
let i = range::<f32>(Dim4::new(&[pulse_n, 1, 1, 1]), 0);
50+
let t = i.clone() * dt;
5351
let hmg_wnd = cos(&(i * (twopi / pulse_n as f32))) * -0.46f32 + 0.54f32;
54-
let wave = sin(&(&t * centre_freq * twopi));
55-
let pulse = wave * hmg_wnd;
52+
let wave = sin(&(&t * centre_freq * twopi));
53+
let pulse = wave * hmg_wnd;
5654

5755
// Iteration count.
5856
let mut it = 0;
5957

6058
while !win.is_closed() {
6159
// Convole with laplacian to get spacial second derivative.
62-
let lap_p = convolve2(&p, &laplacian_kernel, ConvMode::DEFAULT, ConvDomain::SPATIAL);
60+
let lap_p = convolve2(
61+
&p,
62+
&laplacian_kernel,
63+
ConvMode::DEFAULT,
64+
ConvDomain::SPATIAL,
65+
);
6366
// Calculate the updated pressure and d(pressure)/dt fields.
6467
p_dot += lap_p * (c * dt);
6568
p += &p_dot * dt;
@@ -68,7 +71,11 @@ fn acoustic_wave_simulation() {
6871
// Location of the source.
6972
let seqs = &[Seq::new(700.0, 800.0, 1.0), Seq::new(800.0, 800.0, 1.0)];
7073
// Set the pressure there.
71-
p = assign_seq(&p, seqs, &index(&pulse, &[Seq::new(it as f64, it as f64, 1.0)]));
74+
p = assign_seq(
75+
&p,
76+
seqs,
77+
&index(&pulse, &[Seq::new(it as f64, it as f64, 1.0)]),
78+
);
7279
}
7380

7481
// Draw the image.

examples/helloworld.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ fn main() {
77
print!("Info String:\n{}", info_string(true));
88
println!("Arrayfire version: {:?}", get_version());
99
let (name, platform, toolkit, compute) = device_info();
10-
print!("Name: {}\nPlatform: {}\nToolkit: {}\nCompute: {}\n", name, platform, toolkit, compute);
10+
print!(
11+
"Name: {}\nPlatform: {}\nToolkit: {}\nCompute: {}\n",
12+
name, platform, toolkit, compute
13+
);
1114
println!("Revision: {}", get_revision());
1215

1316
let num_rows: u64 = 5;
@@ -23,11 +26,11 @@ fn main() {
2326
af_print!("Create a 5-by-3 float matrix on the GPU", a);
2427

2528
println!("Element-wise arithmetic");
26-
let b = add(&sin(&a), &1.5f32, false);
29+
let b = add(&sin(&a), &1.5f32, false);
2730

2831
let b2 = add(&sin(&a), &cos(&a), false);
2932

30-
let b3 = ! &a;
33+
let b3 = !&a;
3134
af_print!("sin(a) + 1.5 a.k.a b => ", b);
3235
af_print!("sin(a) + cos(a) => ", b2);
3336
af_print!("!a => ", b3);
@@ -80,5 +83,8 @@ fn main() {
8083

8184
let u8_cnst = &constant(1 as u8, dims);
8285
af_print!("u8 constant array", u8_cnst);
83-
println!("Is u8_cnst array float precision type ? {}", u8_cnst.is_single());
86+
println!(
87+
"Is u8_cnst array float precision type ? {}",
88+
u8_cnst.is_single()
89+
);
8490
}

examples/histogram.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use arrayfire::*;
12
use std::env;
23
use std::path::PathBuf;
3-
use arrayfire::*;
44

55
#[allow(unused_variables)]
66
#[allow(unused_must_use)]
@@ -9,7 +9,10 @@ fn main() {
99
info();
1010

1111
let assets_dir = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap())
12-
.join("arrayfire").join("assets").join("examples").join("images");
12+
.join("arrayfire")
13+
.join("assets")
14+
.join("examples")
15+
.join("images");
1316

1417
let img_wnd = Window::new(480, 640, String::from("Input Image"));
1518
img_wnd.set_position(100, 100);
@@ -26,7 +29,11 @@ fn main() {
2629
img_wnd.draw_image(&disp_img, None);
2730
hst_wnd.draw_hist(&hst, 0.0, 255.0, None);
2831

29-
if img_wnd.is_closed() == true { break; }
30-
if hst_wnd.is_closed() == true { break; }
32+
if img_wnd.is_closed() == true {
33+
break;
34+
}
35+
if hst_wnd.is_closed() == true {
36+
break;
37+
}
3138
}
3239
}

examples/pi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::time::Instant;
21
use arrayfire::*;
2+
use std::time::Instant;
33

44
#[allow(unused_must_use)]
55
#[allow(unused_variables)]
@@ -23,7 +23,7 @@ fn main() {
2323
let root = &sqrt(xplusy);
2424
let cnst = &constant(1, dims);
2525
let (real, imag) = sum_all(&le(root, cnst, false));
26-
let pi_val = real*4.0/(samples as f64);
26+
let pi_val = real * 4.0 / (samples as f64);
2727
}
2828

2929
println!("Estimated Pi Value in {:?}", start.elapsed());

examples/snow.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ fn main() {
1313
loop {
1414
wnd.draw_image(&randu::<f32>(dims), None);
1515

16-
if wnd.is_closed() == true { break; }
16+
if wnd.is_closed() == true {
17+
break;
18+
}
1719
}
1820
}

examples/unified.rs

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,55 @@ use arrayfire::*;
22

33
#[cfg(op_assign)]
44
fn helper(dims: Dim4) {
5-
let mut a = randu::<f32>(dims);
6-
let b = randu::<f32>(dims);
7-
print(&a);
8-
print(&b);
9-
a += b;
10-
print(&a);
5+
let mut a = randu::<f32>(dims);
6+
let b = randu::<f32>(dims);
7+
print(&a);
8+
print(&b);
9+
a += b;
10+
print(&a);
1111
}
1212

1313
#[cfg(not(op_assign))]
1414
fn helper(dims: Dim4) {
15-
let b = randu::<f32>(dims);
16-
print(&b);
15+
let b = randu::<f32>(dims);
16+
print(&b);
1717
}
1818

1919
#[allow(unused_must_use)]
20-
fn test_backend(){
21-
info();
20+
fn test_backend() {
21+
info();
2222

23-
println!("Create a 10-by-10 matrix of random floats on the compute device");
24-
let num_rows: u64 = 10;
25-
let num_cols: u64 = 10;
26-
let dims = Dim4::new(&[num_rows, num_cols, 1, 1]);
23+
println!("Create a 10-by-10 matrix of random floats on the compute device");
24+
let num_rows: u64 = 10;
25+
let num_cols: u64 = 10;
26+
let dims = Dim4::new(&[num_rows, num_cols, 1, 1]);
2727

28-
helper(dims)
28+
helper(dims)
2929
}
3030

31-
3231
#[allow(unused_must_use)]
3332
fn main() {
34-
println!("There are {:?} available backends", get_backend_count());
35-
let available = get_available_backends();
36-
37-
if available.contains(&Backend::CPU) {
38-
println!("Evaluating CPU Backend...");
39-
set_backend(Backend::CPU);
40-
println!("There are {} CPU compute devices", device_count());
41-
test_backend();
42-
}
43-
44-
if available.contains(&Backend::CUDA) {
45-
println!("Evaluating CUDA Backend...");
46-
set_backend(Backend::CUDA);
47-
println!("There are {} CUDA compute devices", device_count());
48-
test_backend();
49-
}
50-
51-
if available.contains(&Backend::OPENCL) {
52-
println!("Evaluating OpenCL Backend...");
53-
set_backend(Backend::OPENCL);
54-
println!("There are {} OpenCL compute devices", device_count());
55-
test_backend();
56-
}
33+
println!("There are {:?} available backends", get_backend_count());
34+
let available = get_available_backends();
35+
36+
if available.contains(&Backend::CPU) {
37+
println!("Evaluating CPU Backend...");
38+
set_backend(Backend::CPU);
39+
println!("There are {} CPU compute devices", device_count());
40+
test_backend();
41+
}
42+
43+
if available.contains(&Backend::CUDA) {
44+
println!("Evaluating CUDA Backend...");
45+
set_backend(Backend::CUDA);
46+
println!("There are {} CUDA compute devices", device_count());
47+
test_backend();
48+
}
49+
50+
if available.contains(&Backend::OPENCL) {
51+
println!("Evaluating OpenCL Backend...");
52+
set_backend(Backend::OPENCL);
53+
println!("There are {} OpenCL compute devices", device_count());
54+
test_backend();
55+
}
5756
}

0 commit comments

Comments
 (0)