rsl-interpolation 0.1.18

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

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

// Not implemented: Cubic Periodic Splines with more than 3 points require a solver for cyclically
// tridiagonal matrices, which is currently not implemented by ndarray_linalg.
#[ignore = "not implemented"]
/// This data has been chosen to be random (uneven spacing in x and y) and the exact cubic spine
/// solution computed using Octave.
#[test]
fn gsl_test_cubic_periodic1() {
    let xa = [
        0.000000000000000,
        0.130153674349869,
        0.164545962312740,
        0.227375461261537,
        0.256465324353657,
        0.372545206874658,
        0.520820016781720,
        0.647654717733075,
        0.753429306654340,
        0.900873984827658,
        1.000000000000000,
    ];

    let ya = [
        0.000000000000000,
        0.729629261832041,
        0.859286331568207,
        0.989913099419008,
        0.999175006262120,
        0.717928599519215,
        -0.130443237213363,
        -0.800267961158980,
        -0.999767873040527,
        -0.583333769240853,
        -0.000000000000000,
    ];

    #[rustfmt::skip]
    let xtest = [
        0.000000000000000, 0.043384558116623, 0.086769116233246, 0.130153674349869, 0.141617770337492,
        0.153081866325116, 0.164545962312740, 0.185489128629005, 0.206432294945271, 0.227375461261537,
        0.237072082292243, 0.246768703322951, 0.256465324353657, 0.295158618527324, 0.333851912700991,
        0.372545206874658, 0.421970143510346, 0.471395080146033, 0.520820016781720, 0.563098250432172,
        0.605376484082623, 0.647654717733075, 0.682912914040164, 0.718171110347252, 0.753429306654340,
        0.802577532712113, 0.851725758769885, 0.900873984827658, 0.933915989885105, 0.966957994942553,
        1.000000000000000
        ];

    #[rustfmt::skip]
    let ytest = [
        0.000000000000000, 0.268657574670719, 0.517940878523929, 0.729629261832041, 0.777012551497867,
        0.820298314554859, 0.859286331568207, 0.918833991960315, 0.962624749226346, 0.989913099419008,
        0.996756196601349, 0.999858105635752, 0.999175006262120, 0.959248551766306, 0.863713527741856,
        0.717928599519215, 0.470065187871106, 0.177694938589523, -0.130443237213363, -0.385093922365765,
        -0.613840011545983, -0.800267961158980, -0.912498361131651, -0.980219217412290, -0.999767873040528,
        -0.943635958253643, -0.800314354800596, -0.583333769240853, -0.403689914131666, -0.206151346799382,
        -0.000000000000000
    ];

    #[rustfmt::skip]
    let dytest = [
        6.275761975917336, 6.039181349093287, 5.382620652895025, 4.306079887322550, 3.957389777282752,
        3.591234754612763, 3.207614819312586, 2.473048186927024, 1.702885029353488, 0.897125346591982,
        0.513561009477969, 0.125477545550710, -0.267125045189792, -1.773533414873785, -3.141450982859891,
        -4.370877749148106, -5.562104227060234, -6.171864888961167, -6.200159734850907, -5.781556055213110,
        -4.974725570010514, -3.779668279243120, -2.569220222282655, -1.254891157670244, 0.163318914594122,
        2.074985916277011, 3.711348850147548, 5.072407716205733, 5.754438923510391, 6.155557010080926,
        6.275761975917336
    ];

    #[rustfmt::skip]
    let iytest = [
        0.000000000000000, 0.005864903144198, 0.023030998930796, 0.050262495763030, 0.058902457844100,
        0.068062330564832, 0.077693991819461, 0.096340576055474, 0.116070578226521, 0.136546192283223,
        0.146181187290769, 0.155864434185569, 0.165559443629720, 0.203636318965633, 0.239075190181586,
        0.269828050745236, 0.299428805999600, 0.315560685785616, 0.316734151903742, 0.305773798930857,
        0.284537037103156, 0.254466034797342, 0.224146112780097, 0.190643050847000, 0.155590744566140,
        0.107448508851745, 0.064263083957312, 0.029987183298960, 0.013618510529526, 0.003506827320794,
        0.000090064010007,
    ];
    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 = CubicPeriodic.build(&xa, &ya).unwrap();
    test_interp(data_table, test_e_table, test_d_table, test_i_table, interp);
}

/// This data tests the periodic case n=3
#[test]
fn gsl_test_cubic_periodic2() {
    let xa = [0.123, 0.423, 1.123];

    let ya = [0.456000000000000, 1.407056516295154, 0.456000000000000];

    #[rustfmt::skip]
    let xtest = [
        0.123000000000000, 0.133000000000000, 0.143000000000000, 0.153000000000000, 0.163000000000000,
        0.173000000000000, 0.183000000000000, 0.193000000000000, 0.203000000000000, 0.213000000000000,
        0.223000000000000, 0.233000000000000, 0.243000000000000, 0.253000000000000, 0.263000000000000,
        0.273000000000000, 0.283000000000000, 0.293000000000000, 0.303000000000000, 0.313000000000000,
        0.323000000000000, 0.333000000000000, 0.343000000000000, 0.353000000000000, 0.363000000000000,
        0.373000000000000, 0.383000000000000, 0.393000000000000, 0.403000000000000, 0.413000000000000,
        0.423000000000000, 0.446333333333333, 0.469666666666667, 0.493000000000000, 0.516333333333333,
        0.539666666666667, 0.563000000000000, 0.586333333333333, 0.609666666666667, 0.633000000000000,
        0.656333333333333, 0.679666666666667, 0.703000000000000, 0.726333333333333, 0.749666666666667,
        0.773000000000000, 0.796333333333333, 0.819666666666667, 0.843000000000000, 0.866333333333333,
        0.889666666666667, 0.913000000000000, 0.936333333333333, 0.959666666666667, 0.983000000000000,
        1.006333333333333, 1.029666666666667, 1.053000000000000, 1.076333333333333, 1.099666666666667,
        1.123000000000000
    ];

    #[rustfmt::skip]
    let ytest = [
        0.456000000000000, 0.475443822110923, 0.497423794931967, 0.521758764840979, 0.548267578215809,
        0.576769081434305, 0.607082120874316, 0.639025542913690, 0.672418193930275, 0.707078920301921,
        0.742826568406475, 0.779479984621787, 0.816858015325704, 0.854779506896076, 0.893063305710751,
        0.931528258147577, 0.969993210584403, 1.008277009399078, 1.046198500969450, 1.083576531673367,
        1.120229947888679, 1.155977595993233, 1.190638322364879, 1.224030973381464, 1.255974395420838,
        1.286287434860848, 1.314788938079344, 1.341297751454174, 1.365632721363187, 1.387612694184230,
        1.407056516295154, 1.442092968697928, 1.463321489456714, 1.471728359403224, 1.468299859369172,
        1.454022270186272, 1.429881872686237, 1.396864947700781, 1.355957776061616, 1.308146638600458,
        1.254417816149018, 1.195757589539010, 1.133152239602149, 1.067588047170148, 1.000051293074719,
        0.931528258147577, 0.863005223220435, 0.795468469125006, 0.729904276693004, 0.667298926756143,
        0.608638700146136, 0.554909877694696, 0.507098740233537, 0.466191568594372, 0.433174643608916,
        0.409034246108881, 0.394756656925981, 0.391328156891929, 0.399735026838439, 0.420963547597225,
        0.456000000000000
    ];

    #[rustfmt::skip]
    let dytest = [
        1.8115362215145774, 2.0742089736341924, 2.3187663635386602, 2.5452083912279826,
        2.7535350567021584, 2.9437463599611897, 3.1158423010050744, 3.2698228798338147,
        3.4056880964474079, 3.5234379508458549, 3.6230724430291570, 3.7045915729973125,
        3.7679953407503231, 3.8132837462881874, 3.8404567896109061, 3.8495144707184790,
        3.8404567896109061, 3.8132837462881874, 3.7679953407503231, 3.7045915729973125,
        3.6230724430291565, 3.5234379508458549, 3.4056880964474074, 3.2698228798338147,
        3.1158423010050749, 2.9437463599611897, 2.7535350567021584, 2.5452083912279830,
        2.3187663635386597, 2.0742089736341924, 1.8115362215145772, 1.1986331332354823,
        0.6279992234583869, 0.0996344921833026, -0.3864610605897765, -0.8302874348608467,
        -1.2318446306299125, -1.5911326478969707, -1.9081514866620208, -2.1829011469250670,
        -2.4153816286861041, -2.6055929319451341, -2.7535350567021584, -2.8592080029571765,
        -2.9226117707101862, -2.9437463599611893, -2.9226117707101862, -2.8592080029571760,
        -2.7535350567021593, -2.6055929319451354, -2.4153816286861045, -2.1829011469250656,
        -1.9081514866620242, -1.5911326478969716, -1.2318446306299160, -0.8302874348608498,
        -0.3864610605897769, 0.0996344921832995, 0.6279992234583824, 1.1986331332354769,
        1.8115362215145772
    ];

    #[rustfmt::skip]
    let iytest = [
        0.000000000000000, 0.004655030170954, 0.009517330277919, 0.014611356059886, 0.019959751719625,
        0.025583349923681, 0.031501171802382, 0.037730426949832, 0.044286513423914, 0.051183017746288,
        0.058431714902395, 0.066042568341453, 0.074023729976459, 0.082381540184189, 0.091120527805195,
        0.100243410143811, 0.109751092968147, 0.119642670510092, 0.129915425465314, 0.140564828993259,
        0.151584540717153, 0.162966408723997, 0.174700469564574, 0.186774948253444, 0.199176258268946,
        0.211889001553197, 0.224895968512091, 0.238178138015305, 0.251714677396289, 0.265482942452275,
        0.279458477444273, 0.312726362409309, 0.346648754292945, 0.380914974633193, 0.415237358187469,
        0.449351252932597, 0.483015020064806, 0.516010033999735, 0.548140682372425, 0.579234366037328,
        0.609141499068300, 0.637735508758604, 0.664912835620912, 0.690592933387298, 0.714718269009247,
        0.737254322657649, 0.758189587722801, 0.777535570814405, 0.795326791761572, 0.811620783612819,
        0.826498092636068, 0.840062278318649, 0.852439913367300, 0.863780583708163, 0.874256888486789,
        0.884064440068133, 0.893421864036559, 0.902570799195836, 0.911775897569142, 0.921324824399059,
        0.931528258147577
    ];

    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 = CubicPeriodic.build(&xa, &ya).unwrap();
    test_interp(data_table, test_e_table, test_d_table, test_i_table, interp);
}