Skip to content

Commit

Permalink
rustfmt changes after 2018 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
9prady9 committed Jan 23, 2019
1 parent 4e86043 commit 2e3fc42
Show file tree
Hide file tree
Showing 31 changed files with 4,034 additions and 2,003 deletions.
289 changes: 163 additions & 126 deletions build.rs

Large diffs are not rendered by default.

47 changes: 27 additions & 20 deletions examples/acoustic_wave.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::f64::consts::*;
use arrayfire::*;
use std::f64::consts::*;

fn main() {
set_device(0);
Expand All @@ -8,20 +8,20 @@ fn main() {
}

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

fn acoustic_wave_simulation() {
// Speed of sound
let c :f32 = 0.1;
let c: f32 = 0.1;
// Distance step
let dx :f32 = 0.5;
let dx: f32 = 0.5;
// Time step
let dt :f32 = 1.0;
let dt: f32 = 1.0;

// Grid size.
let nx : u64 = 1500;
let ny : u64 = 1500;
let nx: u64 = 1500;
let ny: u64 = 1500;

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

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

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

// Hann windowed pulse.
let pulse_time :f32 = 100.0;
let centre_freq :f32 = 0.05;
let twopi = PI as f32 * 2.0;
let pulse_time: f32 = 100.0;
let centre_freq: f32 = 0.05;
let twopi = PI as f32 * 2.0;

// Number of samples in pulse.
let pulse_n = (pulse_time/dt).floor() as u64;
let pulse_n = (pulse_time / dt).floor() as u64;

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

// Iteration count.
let mut it = 0;

while !win.is_closed() {
// Convole with laplacian to get spacial second derivative.
let lap_p = convolve2(&p, &laplacian_kernel, ConvMode::DEFAULT, ConvDomain::SPATIAL);
let lap_p = convolve2(
&p,
&laplacian_kernel,
ConvMode::DEFAULT,
ConvDomain::SPATIAL,
);
// Calculate the updated pressure and d(pressure)/dt fields.
p_dot += lap_p * (c * dt);
p += &p_dot * dt;
Expand All @@ -68,7 +71,11 @@ fn acoustic_wave_simulation() {
// Location of the source.
let seqs = &[Seq::new(700.0, 800.0, 1.0), Seq::new(800.0, 800.0, 1.0)];
// Set the pressure there.
p = assign_seq(&p, seqs, &index(&pulse, &[Seq::new(it as f64, it as f64, 1.0)]));
p = assign_seq(
&p,
seqs,
&index(&pulse, &[Seq::new(it as f64, it as f64, 1.0)]),
);
}

// Draw the image.
Expand Down
14 changes: 10 additions & 4 deletions examples/helloworld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ fn main() {
print!("Info String:\n{}", info_string(true));
println!("Arrayfire version: {:?}", get_version());
let (name, platform, toolkit, compute) = device_info();
print!("Name: {}\nPlatform: {}\nToolkit: {}\nCompute: {}\n", name, platform, toolkit, compute);
print!(
"Name: {}\nPlatform: {}\nToolkit: {}\nCompute: {}\n",
name, platform, toolkit, compute
);
println!("Revision: {}", get_revision());

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

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

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

let b3 = ! &a;
let b3 = !&a;
af_print!("sin(a) + 1.5 a.k.a b => ", b);
af_print!("sin(a) + cos(a) => ", b2);
af_print!("!a => ", b3);
Expand Down Expand Up @@ -80,5 +83,8 @@ fn main() {

let u8_cnst = &constant(1 as u8, dims);
af_print!("u8 constant array", u8_cnst);
println!("Is u8_cnst array float precision type ? {}", u8_cnst.is_single());
println!(
"Is u8_cnst array float precision type ? {}",
u8_cnst.is_single()
);
}
15 changes: 11 additions & 4 deletions examples/histogram.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use arrayfire::*;
use std::env;
use std::path::PathBuf;
use arrayfire::*;

#[allow(unused_variables)]
#[allow(unused_must_use)]
Expand All @@ -9,7 +9,10 @@ fn main() {
info();

let assets_dir = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap())
.join("arrayfire").join("assets").join("examples").join("images");
.join("arrayfire")
.join("assets")
.join("examples")
.join("images");

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

if img_wnd.is_closed() == true { break; }
if hst_wnd.is_closed() == true { break; }
if img_wnd.is_closed() == true {
break;
}
if hst_wnd.is_closed() == true {
break;
}
}
}
4 changes: 2 additions & 2 deletions examples/pi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::time::Instant;
use arrayfire::*;
use std::time::Instant;

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

println!("Estimated Pi Value in {:?}", start.elapsed());
Expand Down
4 changes: 3 additions & 1 deletion examples/snow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ fn main() {
loop {
wnd.draw_image(&randu::<f32>(dims), None);

if wnd.is_closed() == true { break; }
if wnd.is_closed() == true {
break;
}
}
}
77 changes: 38 additions & 39 deletions examples/unified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,55 @@ use arrayfire::*;

#[cfg(op_assign)]
fn helper(dims: Dim4) {
let mut a = randu::<f32>(dims);
let b = randu::<f32>(dims);
print(&a);
print(&b);
a += b;
print(&a);
let mut a = randu::<f32>(dims);
let b = randu::<f32>(dims);
print(&a);
print(&b);
a += b;
print(&a);
}

#[cfg(not(op_assign))]
fn helper(dims: Dim4) {
let b = randu::<f32>(dims);
print(&b);
let b = randu::<f32>(dims);
print(&b);
}

#[allow(unused_must_use)]
fn test_backend(){
info();
fn test_backend() {
info();

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

helper(dims)
helper(dims)
}


#[allow(unused_must_use)]
fn main() {
println!("There are {:?} available backends", get_backend_count());
let available = get_available_backends();

if available.contains(&Backend::CPU) {
println!("Evaluating CPU Backend...");
set_backend(Backend::CPU);
println!("There are {} CPU compute devices", device_count());
test_backend();
}

if available.contains(&Backend::CUDA) {
println!("Evaluating CUDA Backend...");
set_backend(Backend::CUDA);
println!("There are {} CUDA compute devices", device_count());
test_backend();
}

if available.contains(&Backend::OPENCL) {
println!("Evaluating OpenCL Backend...");
set_backend(Backend::OPENCL);
println!("There are {} OpenCL compute devices", device_count());
test_backend();
}
println!("There are {:?} available backends", get_backend_count());
let available = get_available_backends();

if available.contains(&Backend::CPU) {
println!("Evaluating CPU Backend...");
set_backend(Backend::CPU);
println!("There are {} CPU compute devices", device_count());
test_backend();
}

if available.contains(&Backend::CUDA) {
println!("Evaluating CUDA Backend...");
set_backend(Backend::CUDA);
println!("There are {} CUDA compute devices", device_count());
test_backend();
}

if available.contains(&Backend::OPENCL) {
println!("Evaluating OpenCL Backend...");
set_backend(Backend::OPENCL);
println!("There are {} OpenCL compute devices", device_count());
test_backend();
}
}
Loading

0 comments on commit 2e3fc42

Please sign in to comment.