rsl-interpolation 0.1.18

A re-write of GSL's Interpolation Routines in Rust.
Documentation
use crate::Cubic;
use crate::InterpType;
use crate::tests::XYTable;
use crate::tests::test_interp;

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

#[test]
fn gsl_test_cubic1() {
    let xa = [0.0, 1.0, 2.0];
    let ya = [0.0, 1.0, 2.0];

    let xtest = [0.0, 0.5, 1.0, 2.0];
    let ytest = [0.0, 0.5, 1.0, 2.0];
    let dytest = [1.0, 1.0, 1.0, 1.0];
    let iytest = [0.0, 0.125, 0.5, 2.0];

    let data_table = XYTable { x: &xa, y: &ya };

    let test_e_table = XYTable {
        x: &xtest,
        y: &ytest,
    };

    let test_d_table = XYTable {
        x: &xtest,
        y: &dytest,
    };

    let test_i_table = XYTable {
        x: &xtest,
        y: &iytest,
    };

    let interp = Cubic.build(&xa, &ya).unwrap();
    test_interp(data_table, test_e_table, test_d_table, test_i_table, interp);
}

/// Test taken from Young & Gregory, A Survey of Numerical Mathematics, Vol 1 Chapter 6.8
#[test]
fn gsl_test_cubic2() {
    let xa = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0];

    let ya = [
        1.0,
        0.961538461538461,
        0.862068965517241,
        0.735294117647059,
        0.609756097560976,
        0.500000000000000,
    ];

    let xtest = [
        0.00, 0.02, 0.04, 0.06, 0.08, 0.10, 0.12, 0.14, 0.16, 0.18, 0.20, 0.22, 0.24, 0.26, 0.28,
        0.30, 0.32, 0.34, 0.36, 0.38, 0.40, 0.42, 0.44, 0.46, 0.48, 0.50, 0.52, 0.54, 0.56, 0.58,
        0.60, 0.62, 0.64, 0.66, 0.68, 0.70, 0.72, 0.74, 0.76, 0.78, 0.80, 0.82, 0.84, 0.86, 0.88,
        0.90, 0.92, 0.94, 0.96, 0.98,
    ];

    #[rustfmt::skip]
    let ytest = [
        1.000000000000000, 0.997583282975581, 0.995079933416512, 0.992403318788142, 0.989466806555819,
        0.986183764184894, 0.982467559140716, 0.978231558888635, 0.973389130893999, 0.967853642622158,
        0.961538461538461, 0.954382579685350, 0.946427487413627, 0.937740299651188, 0.928388131325928,
        0.918438097365742, 0.907957312698524, 0.897012892252170, 0.885671950954575, 0.874001603733634,
        0.862068965517241, 0.849933363488199, 0.837622973848936, 0.825158185056786, 0.812559385569085,
        0.799846963843167, 0.787041308336369, 0.774162807506023, 0.761231849809467, 0.748268823704033,
        0.735294117647059, 0.722328486073082, 0.709394147325463, 0.696513685724764, 0.683709685591549,
        0.671004731246381, 0.658421407009825, 0.645982297202442, 0.633709986144797, 0.621627058157454,
        0.609756097560976, 0.598112015427308, 0.586679029833925, 0.575433685609685, 0.564352527583445,
        0.553412100584061, 0.542588949440392, 0.531859618981294, 0.521200654035625, 0.510588599432241
    ];
    #[rustfmt::skip]
    let dytest = [
        -0.120113913432180, -0.122279726798445, -0.128777166897241, -0.139606233728568, -0.154766927292426,
        -0.174259247588814, -0.198083194617734, -0.226238768379184, -0.258725968873165, -0.295544796099676,
        -0.336695250058719, -0.378333644186652, -0.416616291919835, -0.451543193258270, -0.483114348201955,
        -0.511329756750890, -0.536189418905076, -0.557693334664512, -0.575841504029200, -0.590633926999137,
        -0.602070603574326, -0.611319695518765, -0.619549364596455, -0.626759610807396, -0.632950434151589,
        -0.638121834629033, -0.642273812239728, -0.645406366983674, -0.647519498860871, -0.648613207871319,
        -0.648687494015019, -0.647687460711257, -0.645558211379322, -0.642299746019212, -0.637912064630930,
        -0.632395167214473, -0.625749053769843, -0.617973724297039, -0.609069178796061, -0.599035417266910,
        -0.587872439709585, -0.576731233416743, -0.566762785681043, -0.557967096502484, -0.550344165881066,
        -0.543893993816790, -0.538616580309654, -0.534511925359660, -0.531580028966807, -0.529820891131095
    ];

    #[rustfmt::skip]
    let iytest = [
        0.000000000000000, 0.019975905023535, 0.039902753768792, 0.059777947259733, 0.079597153869625,
        0.099354309321042, 0.119041616685866, 0.138649546385285, 0.158166836189794, 0.177580491219196,
        0.196875783942601, 0.216036382301310, 0.235045759060558, 0.253888601161251, 0.272550937842853,
        0.291020140643388, 0.309284923399436, 0.327335342246135, 0.345162795617181, 0.362760024244829,
        0.380121111159890, 0.397241442753010, 0.414117280448683, 0.430745332379281, 0.447122714446318,
        0.463246950320456, 0.479115971441505, 0.494728117018421, 0.510082134029305, 0.525177177221407,
        0.540012809111123, 0.554589001813881, 0.568906157172889, 0.582965126887879, 0.596767214344995,
        0.610314174616794, 0.623608214462242, 0.636651992326715, 0.649448618342004, 0.662001654326309,
        0.674315113784241, 0.686393423540581, 0.698241001711602, 0.709861835676399, 0.721259443710643,
        0.732436874986582, 0.743396709573044, 0.754141058435429, 0.764671563435718, 0.774989397332469
    ];

    let data_table = XYTable { x: &xa, y: &ya };

    let test_e_table = XYTable {
        x: &xtest,
        y: &ytest,
    };

    let test_d_table = XYTable {
        x: &xtest,
        y: &dytest,
    };

    let test_i_table = XYTable {
        x: &xtest,
        y: &iytest,
    };

    let interp = Cubic.build(&xa, &ya).unwrap();
    test_interp(data_table, test_e_table, test_d_table, test_i_table, interp);
}

#[test]
/// This data has been chosen to be random (uneven spacing in x and y) and the exact cubic spine
/// solution computed using Octave.
fn gsl_test_cubic3() {
    #[rustfmt::skip]
    let xa = [
        -1.2139767065644265, -0.792590494453907, -0.250954683125019, 0.665867809951305,
            0.735655088722706, 0.827622053027153, 1.426592227816582
    ];

    #[rustfmt::skip]
    let ya = [
        -0.00453877449035645, 0.49763182550668716, 0.17805472016334534, 0.40514493733644485,
        -0.21595209836959839, 0.47405586764216423, 0.46561462432146072
    ] ;

    #[rustfmt::skip]
    let xtest = [
        -1.2139767065644265, -1.0735146358609200, -0.9330525651574135, -0.7925904944539071,
        -0.6120452240109444, -0.4314999535679818, -0.2509546831250191, 0.0546528145670890,
        0.3602603122591972, 0.6658678099513053, 0.6891302362084388, 0.7123926624655723,
        0.7356550887227058, 0.7663107434908548, 0.7969663982590039, 0.8276220530271530,
        1.0272787779569625, 1.2269355028867721, 1.4265922278165817
    ];

    #[rustfmt::skip]
    let ytest = [
        -0.00453877449035645, 0.25816917628390590, 0.44938881397673230, 0.49763182550668716,
        0.31389980410075147, 0.09948951681196887, 0.17805472016334534, 1.27633142487980233,
        2.04936553432792001, 0.40514493733644485, 0.13322324792901385, -0.09656315924697809,
        -0.21595209836959839, -0.13551147728045118, 0.13466779030061801, 0.47405586764216423,
        1.68064089899304370, 1.43594739539458649, 0.46561462432146072
    ];

    #[rustfmt::skip]
    let dytest = [
        1.955137555965937, 1.700662049790549, 0.937235531264386, -0.335141999612553, -1.401385073563169,
        -0.674982149482761, 1.844066772628670, 4.202528085784793, -0.284432022227558, -11.616813551408383,
        -11.272731243226174, -7.994209291156876, -1.781247695200491, 6.373970868827501, 10.597456848997197,
        10.889210245308570, 1.803124267866902, -3.648527318598099, -5.465744514086432,
    ];

    #[rustfmt::skip]
    let iytest = [
        0.000000000000000, 0.018231117234914, 0.069178822023139, 0.137781019634897, 0.213936442847744,
        0.249280997744777, 0.267492946016120, 0.471372708120518, 1.014473660088477, 1.477731933018837,
        1.483978291717981, 1.484256847945450, 1.480341742628893, 1.474315901028282, 1.473972210647307,
        1.483279773396950, 1.728562698140330, 2.057796448999396, 2.253662886537457
    ];

    let data_table = XYTable { x: &xa, y: &ya };

    let test_e_table = XYTable {
        x: &xtest,
        y: &ytest,
    };

    let test_d_table = XYTable {
        x: &xtest,
        y: &dytest,
    };

    let test_i_table = XYTable {
        x: &xtest,
        y: &iytest,
    };

    let interp = Cubic.build(&xa, &ya).unwrap();
    test_interp(data_table, test_e_table, test_d_table, test_i_table, interp);
}