rsl-interpolation 0.1.18

A re-write of GSL's Interpolation Routines in Rust.
Documentation
use crate::{
    Bilinear, Interp2dType,
    tests::{XYZTable, test_interp2d, test_interp2d_extra},
};

#[test]
fn test_type_fields() {
    let _ = <Bilinear as Interp2dType<f64>>::name(&Bilinear);
    let _ = <Bilinear as Interp2dType<f64>>::min_size(&Bilinear);
}

/// Tests bilinear interpolation using a symmetric function, f(x,y)=f(y,x), and diagonal
/// interpolation points (x,y) where x=y. If these tests don't pass, something is seriously broken.
#[test]
fn gsl_test_bilinear_symmetric() {
    let xa = [0.0, 1.0, 2.0, 3.0];
    let ya = [0.0, 1.0, 2.0, 3.0];
    #[rustfmt::skip]
    let za = [
        1.0, 1.1, 1.2, 1.3,
        1.1, 1.2, 1.3, 1.4,
        1.2, 1.3, 1.4, 1.5,
        1.3, 1.4, 1.5, 1.6,
    ];

    let xtest = [0.0, 0.5, 1.0, 1.5, 2.5, 3.0];
    let ytest = [0.0, 0.5, 1.0, 1.5, 2.5, 3.0];
    let ztest = [1.0, 1.1, 1.2, 1.3, 1.5, 1.6];

    let data_table = XYZTable {
        x: &xa,
        y: &ya,
        z: &za,
    };

    let test_e_table = XYZTable {
        x: &xtest,
        y: &ytest,
        z: &ztest,
    };

    let interp = Bilinear.build(&xa, &ya, &za).unwrap();
    test_interp2d(data_table, test_e_table, interp);
}

#[test]
fn gsl_test_bilinear_asymmetric_z() {
    let xa = [0.0, 1.0, 2.0, 3.0];
    let ya = [0.0, 1.0, 2.0, 3.0];
    #[rustfmt::skip]
    let za = [
        1.0, 1.1, 1.2, 1.4,
        1.3, 1.4, 1.5, 1.7,
        1.5, 1.6, 1.7, 1.9,
        1.6, 1.9, 2.2, 2.3,
    ];

    let xtest = [
        0.0, 0.5, 1.0, 1.5, 2.5, 3.0, 1.3954, 1.6476, 0.824957, 2.41108, 2.98619, 1.36485,
    ];
    let ytest = [
        0.0, 0.5, 1.0, 1.5, 2.5, 3.0, 0.265371, 2.13849, 1.62114, 1.22198, 0.724681, 0.0596087,
    ];

    // results computed using Mathematica 9.0.1.0
    #[rustfmt::skip]
    let ztest = [
        1.0, 1.2, 1.4, 1.55, 2.025, 2.3, 1.2191513, 1.7242442248,
        1.5067237, 1.626612, 1.6146423, 1.15436761,
    ];

    let data_table = XYZTable {
        x: &xa,
        y: &ya,
        z: &za,
    };

    let test_e_table = XYZTable {
        x: &xtest,
        y: &ytest,
        z: &ztest,
    };

    let interp = Bilinear.build(&xa, &ya, &za).unwrap();
    test_interp2d(data_table, test_e_table, interp);
}

/// Extra test that includes all derivatives, and iterates through all (x, y) pairs.
#[test]
fn extra_test_bilinear() {
    let xa = [0.0, 1.0];
    let ya = [0.0, 1.0];
    #[rustfmt::skip]
    let za = [
        0.0, 1.0,
        1.0, 0.5
    ];
    let xtest = [
        0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000,
    ];

    let ytest = [
        0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000,
    ];
    let ztest = [
        0.00000000, 0.12500000, 0.25000000, 0.37500000, 0.50000000, 0.62500000, 0.75000000,
        0.87500000, 1.00000000, 0.12500000, 0.22656250, 0.32812500, 0.42968750, 0.53125000,
        0.63281250, 0.73437500, 0.83593750, 0.93750000, 0.25000000, 0.32812500, 0.40625000,
        0.48437500, 0.56250000, 0.64062500, 0.71875000, 0.79687500, 0.87500000, 0.37500000,
        0.42968750, 0.48437500, 0.53906250, 0.59375000, 0.64843750, 0.70312500, 0.75781250,
        0.81250000, 0.50000000, 0.53125000, 0.56250000, 0.59375000, 0.62500000, 0.65625000,
        0.68750000, 0.71875000, 0.75000000, 0.62500000, 0.63281250, 0.64062500, 0.64843750,
        0.65625000, 0.66406250, 0.67187500, 0.67968750, 0.68750000, 0.75000000, 0.73437500,
        0.71875000, 0.70312500, 0.68750000, 0.67187500, 0.65625000, 0.64062500, 0.62500000,
        0.87500000, 0.83593750, 0.79687500, 0.75781250, 0.71875000, 0.67968750, 0.64062500,
        0.60156250, 0.56250000, 1.00000000, 0.93750000, 0.87500000, 0.81250000, 0.75000000,
        0.68750000, 0.62500000, 0.56250000, 0.50000000,
    ];

    let dxtest = [
        1.000000, 0.812500, 0.625000, 0.437500, 0.250000, 0.062500, -0.12500, -0.31250, -0.50000,
        1.000000, 0.812500, 0.625000, 0.437500, 0.250000, 0.062500, -0.12500, -0.31250, -0.50000,
        1.000000, 0.812500, 0.625000, 0.437500, 0.250000, 0.062500, -0.12500, -0.31250, -0.50000,
        1.000000, 0.812500, 0.625000, 0.437500, 0.250000, 0.062500, -0.12500, -0.31250, -0.50000,
        1.000000, 0.812500, 0.625000, 0.437500, 0.250000, 0.062500, -0.12500, -0.31250, -0.50000,
        1.000000, 0.812500, 0.625000, 0.437500, 0.250000, 0.062500, -0.12500, -0.31250, -0.50000,
        1.000000, 0.812500, 0.625000, 0.437500, 0.250000, 0.062500, -0.12500, -0.31250, -0.50000,
        1.000000, 0.812500, 0.625000, 0.437500, 0.250000, 0.062500, -0.12500, -0.31250, -0.50000,
        1.000000, 0.812500, 0.625000, 0.437500, 0.250000, 0.062500, -0.12500, -0.31250, -0.50000,
    ];

    let dytest = [
        1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
        0.812500, 0.812500, 0.812500, 0.812500, 0.812500, 0.812500, 0.812500, 0.812500, 0.812500,
        0.625000, 0.625000, 0.625000, 0.625000, 0.625000, 0.625000, 0.625000, 0.625000, 0.625000,
        0.437500, 0.437500, 0.437500, 0.437500, 0.437500, 0.437500, 0.437500, 0.437500, 0.437500,
        0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000, 0.250000,
        0.062500, 0.062500, 0.062500, 0.062500, 0.062500, 0.062500, 0.062500, 0.062500, 0.062500,
        -0.12500, -0.12500, -0.12500, -0.12500, -0.12500, -0.12500, -0.12500, -0.12500, -0.12500,
        -0.31250, -0.31250, -0.31250, -0.31250, -0.31250, -0.31250, -0.31250, -0.31250, -0.31250,
        -0.50000, -0.50000, -0.50000, -0.50000, -0.50000, -0.50000, -0.50000, -0.50000, -0.50000,
    ];

    let dxxtest = [0.0; 81];
    let dyytest = [0.0; 81];
    let dxytest = [-1.5; 81];

    let data_table = XYZTable {
        x: &xa,
        y: &ya,
        z: &za,
    };

    let test_e_table = XYZTable {
        x: &xtest,
        y: &ytest,
        z: &ztest,
    };

    let test_dx_table = XYZTable {
        x: &xtest,
        y: &ytest,
        z: &dxtest,
    };

    let test_dy_table = XYZTable {
        x: &xtest,
        y: &ytest,
        z: &dytest,
    };

    let test_dxx_table = XYZTable {
        x: &xtest,
        y: &ytest,
        z: &dxxtest,
    };

    let test_dyy_table = XYZTable {
        x: &xtest,
        y: &ytest,
        z: &dyytest,
    };

    let test_dxy_table = XYZTable {
        x: &xtest,
        y: &ytest,
        z: &dxytest,
    };

    let interp = Bilinear.build(&xa, &ya, &za).unwrap();
    test_interp2d_extra(
        data_table,
        test_e_table,
        test_dx_table,
        test_dy_table,
        test_dxx_table,
        test_dyy_table,
        test_dxy_table,
        interp,
    );
}