Skip to content

Commit

Permalink
♻️ format
Browse files Browse the repository at this point in the history
  • Loading branch information
jvdd committed Nov 5, 2022
1 parent 768a6df commit ba60c71
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 14 deletions.
10 changes: 8 additions & 2 deletions benches/bench_f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ fn get_random_f16_array(n: usize) -> Array1<f16> {
// Replace NaNs and Infs with 0
let data: Vec<f16> = data
.iter()
.map(|&x| if x.is_nan() || x.is_infinite() { f16::from_bits(0) } else { x })
.map(|&x| {
if x.is_nan() || x.is_infinite() {
f16::from_bits(0)
} else {
x
}
})
.collect();
let arr:Array1<f16> = Array1::from(data);
let arr: Array1<f16> = Array1::from(data);
arr
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod scalar_f16;
mod scalar_generic;
mod simd;
mod task;
mod utils;
mod scalar_generic;
mod scalar_f16;

pub use scalar_generic::*;
pub use simd::{simd_f32, simd_f64, simd_i16, simd_i32, simd_i64};
Expand Down
2 changes: 1 addition & 1 deletion src/scalar_f16.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ndarray::ArrayView1;
#[cfg(feature = "half")]
use half::f16;
use ndarray::ArrayView1;

// ------ On ArrayView1

Expand Down
11 changes: 8 additions & 3 deletions src/simd/simd_f16.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{max_index_value, min_index_value};
use crate::task::argminmax_generic;
use crate::utils::{max_index_value, min_index_value};
use ndarray::ArrayView1;
use std::arch::x86_64::*;

Expand Down Expand Up @@ -66,7 +66,7 @@ unsafe fn core_argminmax_256(sim_arr: ArrayView1<f16>, offset: usize) -> (f16, u
.skip(1)
.for_each(|step| {
new_index = _mm256_add_epi16(new_index, increment);

let new_values = _mm256_loadu_si256(step.as_ptr() as *const __m256i);
let new_values = f16_as_m256i_to_ord_i16(new_values);
let gt_mask = _mm256_cmpgt_epi16(new_values, values_high);
Expand All @@ -92,7 +92,12 @@ unsafe fn core_argminmax_256(sim_arr: ArrayView1<f16>, offset: usize) -> (f16, u
let index_array = reg_to_i16_arr(index_low);
let (index_min, value_min) = min_index_value(&index_array, &value_array);

(ord_i16_to_f16(value_min), index_min as usize, ord_i16_to_f16(value_max), index_max as usize)
(
ord_i16_to_f16(value_min),
index_min as usize,
ord_i16_to_f16(value_max),
index_max as usize,
)
}

//----- TESTS -----
Expand Down
2 changes: 1 addition & 1 deletion src/simd/simd_f32.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{max_index_value, min_index_value};
use crate::task::argminmax_generic;
use crate::utils::{max_index_value, min_index_value};
use ndarray::ArrayView1;
use std::arch::x86_64::*;

Expand Down
2 changes: 1 addition & 1 deletion src/simd/simd_f64.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{max_index_value, min_index_value};
use crate::task::argminmax_generic;
use crate::utils::{max_index_value, min_index_value};
use ndarray::ArrayView1;
use std::arch::x86_64::*;

Expand Down
2 changes: 1 addition & 1 deletion src/simd/simd_i16.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{max_index_value, min_index_value};
use crate::task::argminmax_generic;
use crate::utils::{max_index_value, min_index_value};
use ndarray::ArrayView1;
use std::arch::x86_64::*;

Expand Down
2 changes: 1 addition & 1 deletion src/simd/simd_i32.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{max_index_value, min_index_value};
use crate::task::argminmax_generic;
use crate::utils::{max_index_value, min_index_value};
use ndarray::ArrayView1;
use std::arch::x86_64::*;

Expand Down
2 changes: 1 addition & 1 deletion src/simd/simd_i64.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{max_index_value, min_index_value};
use crate::task::argminmax_generic;
use crate::utils::{max_index_value, min_index_value};
use ndarray::ArrayView1;
use std::arch::x86_64::*;

Expand Down
2 changes: 1 addition & 1 deletion src/task.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::scalar_generic::scalar_argminmax; // TODO: dit in macro doorgeven
use crate::scalar_generic::scalar_argminmax; // TODO: dit in macro doorgeven

use ndarray::{ArrayView1, Axis};
use std::cmp::Ordering;
Expand Down

0 comments on commit ba60c71

Please # to comment.