abstract away cfg

This commit is contained in:
Magnus Ulimoen 2020-02-27 22:27:11 +01:00
parent ba420b1554
commit 3ac17995cd
4 changed files with 10 additions and 13 deletions

View File

@ -252,10 +252,7 @@ impl Field {
x in x,
y in y)
{
#[cfg(feature = "f32")]
use std::f32::consts::PI;
#[cfg(not(feature = "f32"))]
use std::f64::consts::PI;
use crate::consts::PI;
let dx = (x - vortex_param.x0) - t;
let dy = y - vortex_param.y0;

View File

@ -3,6 +3,13 @@ pub type Float = f32;
#[cfg(not(feature = "f32"))]
pub type Float = f64;
pub(crate) mod consts {
#[cfg(feature = "f32")]
pub(crate) use std::f32::consts::*;
#[cfg(not(feature = "f32"))]
pub(crate) use std::f64::consts::*;
}
pub mod euler;
pub mod grid;
pub mod integrate;

View File

@ -142,10 +142,7 @@ impl<UO: UpwindOperator> System<UO> {
}
fn gaussian(x: Float, x0: Float, y: Float, y0: Float) -> Float {
#[cfg(feature = "f32")]
use std::f32::consts::PI;
#[cfg(not(feature = "f32"))]
use std::f64::consts::PI;
use crate::consts::PI;
let x = x - x0;
let y = y - y0;

View File

@ -26,10 +26,6 @@ macro_rules! diff_simd_row_7_47 {
impl $self {
#[inline(never)]
fn $name(prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) {
#[cfg(feature = "f32")]
type SimdIndex = packed_simd::u32x8;
#[cfg(not(feature = "f32"))]
type SimdIndex = packed_simd::u64x8;
assert_eq!(prev.shape(), fut.shape());
assert!(prev.len_of(Axis(1)) >= 2 * $BLOCK.len());
assert!(prev.len() >= SimdT::lanes());
@ -98,7 +94,7 @@ macro_rules! diff_simd_row_7_47 {
let last_elems =
unsafe { SimdT::from_slice_unaligned_unchecked(&prev[nx - 8..]) }
.shuffle1_dyn(SimdIndex::new(7, 6, 5, 4, 3, 2, 1, 0));
.shuffle1_dyn([7, 6, 5, 4, 3, 2, 1, 0].into());
if $symmetric {
fut[nx - 4] = idx * (block[3] * last_elems).sum();
fut[nx - 3] = idx * (block[2] * last_elems).sum();