ensure FastFloat flag works

This commit is contained in:
Magnus Ulimoen 2021-02-01 23:13:10 +01:00
parent 6f7268bf33
commit 299b4f8083
7 changed files with 24 additions and 28 deletions

View File

@ -31,18 +31,14 @@ impl<const B: usize> DiagonalMatrix<B> {
} }
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub(crate) struct BlockMatrix<const M: usize, const N: usize, const D: usize> { pub(crate) struct BlockMatrix<T, const M: usize, const N: usize, const D: usize> {
pub start: Matrix<Float, M, N>, pub start: Matrix<T, M, N>,
pub diag: RowVector<Float, D>, pub diag: RowVector<T, D>,
pub end: Matrix<Float, M, N>, pub end: Matrix<T, M, N>,
} }
impl<const M: usize, const N: usize, const D: usize> BlockMatrix<M, N, D> { impl<T, const M: usize, const N: usize, const D: usize> BlockMatrix<T, M, N, D> {
pub const fn new( pub const fn new(start: Matrix<T, M, N>, diag: RowVector<T, D>, end: Matrix<T, M, N>) -> Self {
start: Matrix<Float, M, N>,
diag: RowVector<Float, D>,
end: Matrix<Float, M, N>,
) -> Self {
Self { start, diag, end } Self { start, diag, end }
} }
} }
@ -57,7 +53,7 @@ pub(crate) enum OperatorType {
#[inline(always)] #[inline(always)]
/// Works on all 1d vectors /// Works on all 1d vectors
pub(crate) fn diff_op_1d_fallback<const M: usize, const N: usize, const D: usize>( pub(crate) fn diff_op_1d_fallback<const M: usize, const N: usize, const D: usize>(
matrix: &BlockMatrix<M, N, D>, matrix: &BlockMatrix<Float, M, N, D>,
optype: OperatorType, optype: OperatorType,
prev: ArrayView1<Float>, prev: ArrayView1<Float>,
mut fut: ArrayViewMut1<Float>, mut fut: ArrayViewMut1<Float>,
@ -106,7 +102,7 @@ pub(crate) fn diff_op_1d_fallback<const M: usize, const N: usize, const D: usize
#[inline(always)] #[inline(always)]
/// diff op in 1d for slices /// diff op in 1d for slices
pub(crate) fn diff_op_1d_slice<const M: usize, const N: usize, const D: usize>( pub(crate) fn diff_op_1d_slice<const M: usize, const N: usize, const D: usize>(
matrix: &BlockMatrix<M, N, D>, matrix: &BlockMatrix<Float, M, N, D>,
optype: OperatorType, optype: OperatorType,
prev: &[Float], prev: &[Float],
fut: &mut [Float], fut: &mut [Float],
@ -181,7 +177,7 @@ pub(crate) fn diff_op_1d_slice<const M: usize, const N: usize, const D: usize>(
#[inline(always)] #[inline(always)]
/// Will always work on 1d, delegated based on slicedness /// Will always work on 1d, delegated based on slicedness
pub(crate) fn diff_op_1d<const M: usize, const N: usize, const D: usize>( pub(crate) fn diff_op_1d<const M: usize, const N: usize, const D: usize>(
matrix: &BlockMatrix<M, N, D>, matrix: &BlockMatrix<Float, M, N, D>,
optype: OperatorType, optype: OperatorType,
prev: ArrayView1<Float>, prev: ArrayView1<Float>,
mut fut: ArrayViewMut1<Float>, mut fut: ArrayViewMut1<Float>,
@ -201,7 +197,7 @@ pub(crate) fn diff_op_1d<const M: usize, const N: usize, const D: usize>(
#[allow(unused)] #[allow(unused)]
/// 2D diff fallback for when matrices are not slicable /// 2D diff fallback for when matrices are not slicable
pub(crate) fn diff_op_2d_fallback<const M: usize, const N: usize, const D: usize>( pub(crate) fn diff_op_2d_fallback<const M: usize, const N: usize, const D: usize>(
matrix: &BlockMatrix<M, N, D>, matrix: &BlockMatrix<Float, M, N, D>,
optype: OperatorType, optype: OperatorType,
prev: ArrayView2<Float>, prev: ArrayView2<Float>,
mut fut: ArrayViewMut2<Float>, mut fut: ArrayViewMut2<Float>,
@ -275,7 +271,7 @@ pub(crate) fn diff_op_2d_fallback<const M: usize, const N: usize, const D: usize
} }
pub(crate) fn diff_op_2d_sliceable<const M: usize, const N: usize, const D: usize>( pub(crate) fn diff_op_2d_sliceable<const M: usize, const N: usize, const D: usize>(
matrix: &BlockMatrix<M, N, D>, matrix: &BlockMatrix<Float, M, N, D>,
optype: OperatorType, optype: OperatorType,
prev: ArrayView2<Float>, prev: ArrayView2<Float>,
mut fut: ArrayViewMut2<Float>, mut fut: ArrayViewMut2<Float>,
@ -292,7 +288,7 @@ pub(crate) fn diff_op_2d_sliceable<const M: usize, const N: usize, const D: usiz
#[inline(always)] #[inline(always)]
/// Dispatch based on strides /// Dispatch based on strides
pub(crate) fn diff_op_2d<const M: usize, const N: usize, const D: usize>( pub(crate) fn diff_op_2d<const M: usize, const N: usize, const D: usize>(
matrix: &BlockMatrix<M, N, D>, matrix: &BlockMatrix<Float, M, N, D>,
optype: OperatorType, optype: OperatorType,
prev: ArrayView2<Float>, prev: ArrayView2<Float>,
fut: ArrayViewMut2<Float>, fut: ArrayViewMut2<Float>,
@ -494,7 +490,7 @@ fn dotproduct<'a>(
#[cfg(feature = "sparse")] #[cfg(feature = "sparse")]
pub(crate) fn sparse_from_block<const M: usize, const N: usize, const D: usize>( pub(crate) fn sparse_from_block<const M: usize, const N: usize, const D: usize>(
matrix: &BlockMatrix<M, N, D>, matrix: &BlockMatrix<Float, M, N, D>,
optype: OperatorType, optype: OperatorType,
n: usize, n: usize,
) -> sprs::CsMat<Float> { ) -> sprs::CsMat<Float> {

View File

@ -27,7 +27,7 @@ impl SBP4 {
const DIFF_BLOCKEND: super::Matrix<Float, 4, 6> = const DIFF_BLOCKEND: super::Matrix<Float, 4, 6> =
super::flip_sign(super::flip_ud(super::flip_lr(Self::DIFF_BLOCK))); super::flip_sign(super::flip_ud(super::flip_lr(Self::DIFF_BLOCK)));
const DIFF: BlockMatrix<4, 6, 5> = const DIFF: BlockMatrix<Float, 4, 6, 5> =
BlockMatrix::new(Self::DIFF_BLOCK, Self::DIFF_DIAG, Self::DIFF_BLOCKEND); BlockMatrix::new(Self::DIFF_BLOCK, Self::DIFF_DIAG, Self::DIFF_BLOCKEND);
#[rustfmt::skip] #[rustfmt::skip]
@ -41,7 +41,7 @@ impl SBP4 {
[-4.0/43.0, 59.0/43.0, -110.0/43.0, 59.0/43.0, -4.0/43.0, 0.0], [-4.0/43.0, 59.0/43.0, -110.0/43.0, 59.0/43.0, -4.0/43.0, 0.0],
[-1.0/49.0, 0.0, 59.0/49.0, -118.0/49.0, 64.0/49.0, -4.0/49.0] [-1.0/49.0, 0.0, 59.0/49.0, -118.0/49.0, 64.0/49.0, -4.0/49.0]
]); ]);
const D2: BlockMatrix<4, 6, 5> = BlockMatrix::new( const D2: BlockMatrix<Float, 4, 6, 5> = BlockMatrix::new(
Self::D2BLOCK, Self::D2BLOCK,
Self::D2DIAG, Self::D2DIAG,
super::flip_ud(super::flip_lr(Self::D2BLOCK)), super::flip_ud(super::flip_lr(Self::D2BLOCK)),

View File

@ -27,7 +27,7 @@ impl SBP8 {
[2.75587615266177e-02, -8.71295642560637e-02, 5.01135077563584e-02, 7.68229253600969e-02, 4.60181213406519e-02, -7.55873581663580e-01, 0.00000000000000e+00, 8.21713248844682e-01, -2.16615355227872e-01, 4.12600676624518e-02, -3.86813134335486e-03, 0.0], [2.75587615266177e-02, -8.71295642560637e-02, 5.01135077563584e-02, 7.68229253600969e-02, 4.60181213406519e-02, -7.55873581663580e-01, 0.00000000000000e+00, 8.21713248844682e-01, -2.16615355227872e-01, 4.12600676624518e-02, -3.86813134335486e-03, 0.0],
[5.84767272160451e-03, -1.08336661209337e-02, -1.42810403117803e-02, 3.50919361287023e-02, -1.22244235731112e-02, 1.19411743193552e-01, -7.51668243727123e-01, 0.00000000000000e+00, 7.92601963555477e-01, -1.98150490888869e-01, 3.77429506454989e-02, -3.53840162301552e-03], [5.84767272160451e-03, -1.08336661209337e-02, -1.42810403117803e-02, 3.50919361287023e-02, -1.22244235731112e-02, 1.19411743193552e-01, -7.51668243727123e-01, 0.00000000000000e+00, 7.92601963555477e-01, -1.98150490888869e-01, 3.77429506454989e-02, -3.53840162301552e-03],
]); ]);
const DIFF: BlockMatrix<8, 12, 9> = BlockMatrix::new( const DIFF: BlockMatrix<Float, 8, 12, 9> = BlockMatrix::new(
Self::DIFF_BLOCK, Self::DIFF_BLOCK,
Self::DIFF_DIAG, Self::DIFF_DIAG,
super::flip_sign(super::flip_ud(super::flip_lr(Self::DIFF_BLOCK))), super::flip_sign(super::flip_ud(super::flip_lr(Self::DIFF_BLOCK))),

View File

@ -27,7 +27,7 @@ impl Upwind4 {
const DIFF_BLOCKEND: Matrix<Float, 4, 7> = const DIFF_BLOCKEND: Matrix<Float, 4, 7> =
super::flip_sign(super::flip_ud(super::flip_lr(Self::DIFF_BLOCK))); super::flip_sign(super::flip_ud(super::flip_lr(Self::DIFF_BLOCK)));
const DIFF: BlockMatrix<4, 7, 7> = const DIFF: BlockMatrix<Float, 4, 7, 7> =
BlockMatrix::new(Self::DIFF_BLOCK, Self::DIFF_DIAG, Self::DIFF_BLOCKEND); BlockMatrix::new(Self::DIFF_BLOCK, Self::DIFF_DIAG, Self::DIFF_BLOCKEND);
#[rustfmt::skip] #[rustfmt::skip]
@ -43,7 +43,7 @@ impl Upwind4 {
]]); ]]);
const DISS_BLOCKEND: Matrix<Float, 4, 7> = super::flip_ud(super::flip_lr(Self::DISS_BLOCK)); const DISS_BLOCKEND: Matrix<Float, 4, 7> = super::flip_ud(super::flip_lr(Self::DISS_BLOCK));
const DISS: BlockMatrix<4, 7, 7> = const DISS: BlockMatrix<Float, 4, 7, 7> =
BlockMatrix::new(Self::DISS_BLOCK, Self::DISS_DIAG, Self::DISS_BLOCKEND); BlockMatrix::new(Self::DISS_BLOCK, Self::DISS_DIAG, Self::DISS_BLOCKEND);
} }

View File

@ -24,7 +24,7 @@ impl Upwind4h2 {
const DIFF_DIAG: RowVector<Float, 7> = RowVector::new([[ const DIFF_DIAG: RowVector<Float, 7> = RowVector::new([[
-1.43229166666667e-02, 1.40625000000000e-01, -7.38281250000000e-01, 0.00000000000000e+00, 7.38281250000000e-01, -1.40625000000000e-01, 1.43229166666667e-02 -1.43229166666667e-02, 1.40625000000000e-01, -7.38281250000000e-01, 0.00000000000000e+00, 7.38281250000000e-01, -1.40625000000000e-01, 1.43229166666667e-02
]]); ]]);
const DIFF: BlockMatrix<4, 7, 7> = BlockMatrix::new( const DIFF: BlockMatrix<Float, 4, 7, 7> = BlockMatrix::new(
Self::DIFF_BLOCK, Self::DIFF_BLOCK,
Self::DIFF_DIAG, Self::DIFF_DIAG,
super::flip_sign(super::flip_ud(super::flip_lr(Self::DIFF_BLOCK))), super::flip_sign(super::flip_ud(super::flip_lr(Self::DIFF_BLOCK))),
@ -42,7 +42,7 @@ impl Upwind4h2 {
const DISS_DIAG: RowVector<Float, 7> = RowVector::new([[ const DISS_DIAG: RowVector<Float, 7> = RowVector::new([[
1.43229166666667e-02, -8.59375000000000e-02, 2.14843750000000e-01, -2.86458333333333e-01, 2.14843750000000e-01, -8.59375000000000e-02, 1.43229166666667e-02, 1.43229166666667e-02, -8.59375000000000e-02, 2.14843750000000e-01, -2.86458333333333e-01, 2.14843750000000e-01, -8.59375000000000e-02, 1.43229166666667e-02,
]]); ]]);
const DISS: BlockMatrix<4, 7, 7> = BlockMatrix::new( const DISS: BlockMatrix<Float, 4, 7, 7> = BlockMatrix::new(
Self::DISS_BLOCK, Self::DISS_BLOCK,
Self::DISS_DIAG, Self::DISS_DIAG,
super::flip_ud(super::flip_lr(Self::DISS_BLOCK)), super::flip_ud(super::flip_lr(Self::DISS_BLOCK)),

View File

@ -28,7 +28,7 @@ impl Upwind9 {
[-6.19425252179959e-03, 3.69595678895333e-02, -7.01892820620398e-02, -3.35233082197107e-03, 2.69304373763091e-01, -8.89857974743355e-01, 0.00000000000000e+00, 8.66656645522330e-01, -2.57919763669076e-01, 6.44799409172690e-02, -1.07466568195448e-02, 8.59732545563586e-04, 0.0], [-6.19425252179959e-03, 3.69595678895333e-02, -7.01892820620398e-02, -3.35233082197107e-03, 2.69304373763091e-01, -8.89857974743355e-01, 0.00000000000000e+00, 8.66656645522330e-01, -2.57919763669076e-01, 6.44799409172690e-02, -1.07466568195448e-02, 8.59732545563586e-04, 0.0],
[1.44853491014330e-02, -4.59275574977554e-02, 3.08833474560615e-02, 3.57240610228828e-02, -7.07760049349999e-02, 1.88587240076292e-01, -7.92626447113877e-01, 0.00000000000000e+00, 8.25608497215073e-01, -2.35888142061449e-01, 5.89720355153623e-02, -9.82867258589373e-03, 7.86293806871498e-04], [1.44853491014330e-02, -4.59275574977554e-02, 3.08833474560615e-02, 3.57240610228828e-02, -7.07760049349999e-02, 1.88587240076292e-01, -7.92626447113877e-01, 0.00000000000000e+00, 8.25608497215073e-01, -2.35888142061449e-01, 5.89720355153623e-02, -9.82867258589373e-03, 7.86293806871498e-04],
]); ]);
const DIFF: BlockMatrix<8, 13, 11> = BlockMatrix::new( const DIFF: BlockMatrix<Float, 8, 13, 11> = BlockMatrix::new(
Self::DIFF_BLOCK, Self::DIFF_BLOCK,
Self::DIFF_DIAG, Self::DIFF_DIAG,
super::flip_sign(super::flip_ud(super::flip_lr(Self::DIFF_BLOCK))), super::flip_sign(super::flip_ud(super::flip_lr(Self::DIFF_BLOCK))),
@ -50,7 +50,7 @@ impl Upwind9 {
const DISS_DIAG: RowVector<Float, 11> = RowVector::new([[ const DISS_DIAG: RowVector<Float, 11> = RowVector::new([[
1.0/1260.0, -1.0/126.0, 1.0/28.0, -2.0/21.0, 1.0/6.0, -1.0/5.0, 1.0/6.0, -2.0/21.0, 1.0/28.0, -1.0/126.0, 1.0/1260.0, 1.0/1260.0, -1.0/126.0, 1.0/28.0, -2.0/21.0, 1.0/6.0, -1.0/5.0, 1.0/6.0, -2.0/21.0, 1.0/28.0, -1.0/126.0, 1.0/1260.0,
]]); ]]);
const DISS: BlockMatrix<8, 13, 11> = BlockMatrix::new( const DISS: BlockMatrix<Float, 8, 13, 11> = BlockMatrix::new(
Self::DISS_BLOCK, Self::DISS_BLOCK,
Self::DISS_DIAG, Self::DISS_DIAG,
super::flip_ud(super::flip_lr(Self::DISS_BLOCK)), super::flip_ud(super::flip_lr(Self::DISS_BLOCK)),

View File

@ -28,7 +28,7 @@ impl Upwind9h2 {
[-1.35203347497451e-03, 5.77422023528126e-03, -1.06262408660325e-02, -2.37853245409338e-02, 2.05772021953463e-01, -8.20033622612654e-01, 0.00000000000000e+00, 8.31345778788959e-01, -2.37329555369694e-01, 5.93323888424235e-02, -9.88873147373725e-03, 7.91098517898980e-04, 0.0], [-1.35203347497451e-03, 5.77422023528126e-03, -1.06262408660325e-02, -2.37853245409338e-02, 2.05772021953463e-01, -8.20033622612654e-01, 0.00000000000000e+00, 8.31345778788959e-01, -2.37329555369694e-01, 5.93323888424235e-02, -9.88873147373725e-03, 7.91098517898980e-04, 0.0],
[-1.85246767034256e-03, 2.89905176240824e-03, 6.61951741227212e-04, 2.52792141498726e-03, -5.27086038822990e-02, 2.36934258275492e-01, -8.34333946306806e-01, 0.00000000000000e+00, 8.33639122800983e-01, -2.38182606514566e-01, 5.95456516286416e-02, -9.92427527144027e-03, 7.93942021715222e-04] [-1.85246767034256e-03, 2.89905176240824e-03, 6.61951741227212e-04, 2.52792141498726e-03, -5.27086038822990e-02, 2.36934258275492e-01, -8.34333946306806e-01, 0.00000000000000e+00, 8.33639122800983e-01, -2.38182606514566e-01, 5.95456516286416e-02, -9.92427527144027e-03, 7.93942021715222e-04]
]); ]);
const DIFF: BlockMatrix<8, 13, 11> = BlockMatrix::new( const DIFF: BlockMatrix<Float, 8, 13, 11> = BlockMatrix::new(
Self::DIFF_BLOCK, Self::DIFF_BLOCK,
Self::DIFF_DIAG, Self::DIFF_DIAG,
super::flip_sign(super::flip_ud(super::flip_lr(Self::DIFF_BLOCK))), super::flip_sign(super::flip_ud(super::flip_lr(Self::DIFF_BLOCK))),
@ -50,7 +50,7 @@ impl Upwind9h2 {
const DISS_DIAG: RowVector<Float, 11> = RowVector::new([[ const DISS_DIAG: RowVector<Float, 11> = RowVector::new([[
7.93650793650794e-04, -7.93650793650794e-03, 3.57142857142857e-02, -9.52380952380952e-02, 1.66666666666667e-01, -2.00000000000000e-01, 1.66666666666667e-01, -9.52380952380952e-02, 3.57142857142857e-02, -7.93650793650794e-03, 7.93650793650794e-04 7.93650793650794e-04, -7.93650793650794e-03, 3.57142857142857e-02, -9.52380952380952e-02, 1.66666666666667e-01, -2.00000000000000e-01, 1.66666666666667e-01, -9.52380952380952e-02, 3.57142857142857e-02, -7.93650793650794e-03, 7.93650793650794e-04
]]); ]]);
const DISS: BlockMatrix<8, 13, 11> = BlockMatrix::new( const DISS: BlockMatrix<Float, 8, 13, 11> = BlockMatrix::new(
Self::DISS_BLOCK, Self::DISS_BLOCK,
Self::DISS_DIAG, Self::DISS_DIAG,
super::flip_ud(super::flip_lr(Self::DISS_BLOCK)), super::flip_ud(super::flip_lr(Self::DISS_BLOCK)),