rsl-interpolation 0.1.18

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

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

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

    let xtest = [0.0, 0.5, 1.0, 2.0, 2.5, 3.95];
    let ytest = [0.0, 0.5, 1.0, 2.0, 2.5, 3.95];
    let dytest = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0];
    let iytest = [0.0, 0.125, 0.5, 2.0, 3.125, 7.80125];

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

#[test]
fn gsl_test_steffen2() {
    #[rustfmt::skip]
    let xa = [
        4.673405471947611, 4.851675778029557, 6.185473620119991, 7.066003430727031, 7.236222118389267,
        7.82067161881444, 8.054504031621493, 8.615033792800752, 9.16666529764867, 9.442092828126395,
        10.719577968900381, 11.741967577609238, 12.564881194673035, 12.938424721515084, 12.985892202096888,
        13.995771653255744, 14.459157783380315, 15.834857667614848, 15.887779086499942, 18.64645279534696,
        19.256361741244287, 19.85100457105047, 19.943627313550987, 20.5033910115468, 20.895380493234843,
        21.759942483053962, 21.948984866760803, 22.2504057728461, 22.741860290952104, 23.088720630939164,
    ];

    #[rustfmt::skip]
    let ya = [
        -6.131584089652438, 4.997132870704837, 9.50359639889188, -3.788474042493764, 1.98825324341826,
        -6.553460294945401, 8.44565760012345, -3.643687601520438, -4.720262269613782, -5.31956608504474,
        4.7484698519996655, 1.8191111043001218, 2.7234424260251124, -7.282776099988966, -6.966038807035955,
        2.6047260012112545, -3.6363485275348033, -4.124714595822157, -4.820986899771757, -2.8550035950284602,
        6.017204757558943, 6.7275899382734075, -9.423359755713639, -0.3645325139870703, 6.925739188986089,
        -0.07843256857855074, 1.6744315603866244, -8.332083151442944, 6.059246349756446, -7.360159198725659,
    ];

    #[rustfmt::skip]
    let xtest = [
        4.6734054719476106, 4.8516757780295574, 4.8575586235375265, 5.0417117751274407, 5.2258649267173567,
        5.4100180783072727, 5.5941712298971886, 5.7783243814871028, 5.9624775330770188, 6.1466306846669347,
        6.1854736201199909, 6.3307838362568507, 6.5149369878467667, 6.6990901394366809, 6.8832432910265968,
        7.0660034307270312, 7.0673964426165128, 7.236222118389267, 7.2515495942064288, 7.4357027457963438,
        7.6198558973862589, 7.8040090489761749, 7.8206716188144396, 7.9881622005660908, 8.0545040316214926,
        8.172315352156005, 8.356468503745921, 8.5406216553358369, 8.6150337928007517, 8.7247748069257529,
        8.9089279585156689, 9.0930811101055831, 9.1666652976486702, 9.277234261695499, 9.4420928281263947,
        9.461387413285415, 9.645540564875331, 9.8296937164652469, 10.013846868055161, 10.198000019645077,
        10.382153171234993, 10.566306322824907, 10.719577968900381, 10.750459474414823, 10.934612626004739,
        11.118765777594655, 11.302918929184571, 11.487072080774485, 11.671225232364399, 11.741967577609238,
        11.855378383954315, 12.039531535544231, 12.223684687134147, 12.407837838724063, 12.564881194673035,
        12.591990990313979, 12.776144141903895, 12.938424721515084, 12.960297293493811, 12.985892202096888,
        13.144450445083727, 13.328603596673641, 13.512756748263556, 13.696909899853472, 13.881063051443387,
        13.995771653255744, 14.065216203033303, 14.249369354623219, 14.433522506213134, 14.459157783380315,
        14.617675657803051, 14.801828809392966, 14.985981960982881, 15.170135112572796, 15.354288264162712,
        15.538441415752628, 15.722594567342544, 15.834857667614848, 15.90674771893246, 15.887779086499942,
        16.090900870522375, 16.27505402211229, 16.459207173702204, 16.643360325292122, 16.827513476882036,
        17.01166662847195, 17.195819780061868, 17.379972931651782, 17.5641260832417, 17.748279234831614,
        17.932432386421532, 18.116585538011446, 18.300738689601364, 18.484891841191278, 18.64645279534696,
        18.669044992781188, 18.853198144371106, 19.03735129596102, 19.221504447550938, 19.256361741244287,
        19.405657599140852, 19.58981075073077, 19.773963902320684, 19.851004571050471, 19.958117053910598,
        19.943627313550987, 20.142270205500516, 20.32642335709043, 20.5033910115468, 20.510576508680348,
        20.694729660270262, 20.87888281186018, 20.895380493234843, 21.063035963450094, 21.247189115040012,
        21.431342266629926, 21.61549541821984, 21.759942483053962, 21.799648569809754, 21.948984866760803,
        21.983801721399669, 22.167954872989586, 22.250405772846101, 22.352108024579501, 22.536261176169418,
        22.720414327759332, 22.741860290952104, 22.90456747934925, 23.088720630939164,
    ];

    #[rustfmt::skip]
    let ytest = [
        -6.1315840896524376, 4.9971328707048368, 5.0367975988827167, 6.1897906340782765,
        7.170975366812117, 7.9803517970842286, 8.6179199248946077, 9.083679750243256,
        9.3776312731301772, 9.4997744935553676, 9.5035963988918795, 8.5371013292095554,
        5.3135045284256019, 1.2120062346303317, -2.3083133782071208, -3.788474042493764,
        -3.7873197326712797, 1.98825324341826, 1.9709370138809248, -0.31768851396215103,
        -4.2211558425051745, -6.5330277558649303, -6.5534602949454008, 5.5087083141507147,
        8.4456576001234502, 7.1443430435268214, 1.9932653799771245, -2.8426372908118083,
        -3.6436876015204378, -3.9926784426485034, -4.3315242293057175, -4.5849882013553547,
        -4.7202622696137819, -5.0157009305506106, -5.3195660850447402, -5.3127453670702938,
        -4.6348437675141847, -3.1014810884327102, -1.0745634258401102, 1.0840031242494419,
        3.0123124658217071, 4.3484585028624627, 4.7484698519996655, 4.740613456600772,
        4.4142234654988952, 3.7574719541934956, 2.9757785771330334, 2.274562988765974,
        1.8592448435407634, 1.8191111043001218, 1.8659054809992697, 2.0883298868527498,
        2.3859686670095699, 2.6372078307738107, 2.7234424260251124, 2.5729816013335247,
        -3.258105131647655, -7.2827760999889657, -7.179945071809863, -6.9660388070359547,
        -5.5662805880783406, -3.3905902235190721, -1.0497645733987406, 1.0095869363327665,
        2.3408548797255095, 2.6047260012112545, 2.2325150500282476, -0.91241316251151927,
        -3.5649171021138555, -3.6363485275348033, -3.7309363021244821, -3.8038342533632736,
        -3.8503835649797429, -3.8846412514674595, -3.920664327319995, -3.9725098070309213,
        -4.0542347050938083, -4.1247145958221569, -4.8208939493861829, -4.8209868997717571,
        -4.8103284962540727, -4.7822416973267625, -4.7366335526042516, -4.6735040620865389,
        -4.5928532257736272, -4.4946810436655156, -4.3789875157622005, -4.2457726420636881,
        -4.0950364225699714, -3.9267788572810582, -3.7409999461969403, -3.537699689317626,
        -3.3168780866431069, -3.0785351381733914, -2.8550035950284602, -2.7914506045621672,
        -0.46968123806956008, 3.263658433044764, 5.8622198554846658, 6.0172047575589431,
        6.3291356295622618, 6.5905310151592165, 6.7156659481449141, 6.7275899382734075,
        -9.4118959280855066, -9.4233597557136388, -7.6111870705157543, -3.9651685725226056,
        -0.36453251398707032, -0.23537781181431175, 4.0332797539781309, 6.899794364641159,
        6.9257391889860891, 6.2377210430025594, 4.3902665602806792, 2.1878722453596344,
        0.44278317319805183, -0.078432568578550743, 0.12107113682074738, 1.6744315603866244,
        1.3047436323966959, -6.4955024539509765, -8.3320831514429443, -6.7382472104931805,
        0.61052993339902706, 5.9794239504090552, 6.0592463497564459, 1.5387265272596853,
        -7.3601591987256612,
    ];

    #[rustfmt::skip]
    let dytest = [
        62.426083204466224, 6.757341159173202, 6.727537246743899, 5.7945730211610407, 4.8616087955781726,
        3.9286445699953054, 2.9956803444124378, 2.0627161188295791, 1.1297518932467119, 0.1967876676638447,
        0.0, -12.480296842307126, -21.209126982426163, -22.014768399615317, -14.897221093874615,
        0.0, 1.65274069980919, 0.0, -2.2393981239975669, -19.714311699236049, -19.77742868994725,
        -2.4287490961310456, 0.0, 78.213312807624717, 0.0, -20.358420305108574, -31.350476855816961,
        -16.93545425712459, -3.9032385156832157, -2.5401833171916435, -1.3740294011308083,
        -1.6128919418291603, -2.1012124848241789, -2.8800570317456784, 0.0, 0.70341285683675259,
        6.3314138906742139, 9.9941697310971538, 11.69168037810557, 11.42394583169949, 9.1909660918788916,
        4.992741158643824, 0.0, -0.50358091648162351, -2.8552721239834269, -4.0914806331173992,
        -4.2122064438835425, -3.2174495562818706, -1.1072099703123885, 0.0, 0.78347408424733667,
        1.5221058615312819, 1.6003417148468082, 1.018181644193916, 0.0, -10.817925943273289,
        -39.490030870551372, 0.0, 8.0126635338650072, 6.7986203849007927, 10.557804177353285,
        12.667135433334296, 12.351260158262027, 9.6101783521364421, 4.44389001495753, 0.0,
        -10.1306309231183, -19.882866043398995, -4.7826445467139278, -0.70998925548225966,
        -0.49283947499262398, -0.31159279753453034, -0.20667940230488324, -0.17809928930368468,
        -0.22585245853093405, -0.3499389099866323, -0.55035864367077902, -0.70998925548225966,
        0.0098004308855327432, 0.0, 0.10494594234665755, 0.20009145380778143, 0.2952369652689053,
        0.39038247673003107, 0.48552798819115495, 0.58067349965227877, 0.67581901111340459,
        0.77096452257452841, 0.86611003403565412, 0.96125554549677805, 1.0564010569579039,
        1.1515465684190276, 1.2466920798801533, 1.3418375913412772, 1.4253105022449177,
        4.1661049863071913, 18.74497348837053, 19.496500284294363, 6.4206853740787171, 2.3892836005304425,
        1.7894106566060179, 1.0494805960296585, 0.30955053545331346, 0.0, 1.5724451183167569,
        0.0, 16.386389851530527, 21.613477536080744, 17.603560096681914, 18.338573561497682,
        23.697110333020628, 3.1105642331329868, 0.0, -7.5982202651552164, -11.73098890423519,
        -11.453053366134201, -6.7644136508523696, 0.0, 9.2309078320594402, 0.0, -20.350273706124355,
        -39.581660196515507, 0.0, 28.835095151183879, 42.753317235684989, 7.3325239511975031,
        0.0, -47.053315974301256, -38.688209637869583,
    ];

    #[rustfmt::skip]
    let iytest = [
        0.0, 0.046311303303274043, 0.07582542065258166, 1.1121678097008914, 2.345017979757877,
        3.7427368904558875, 5.2736855014272832, 6.9062247723044061, 8.6087156627196464, 10.349519132305348,
        10.718617229125304, 12.051326255780914, 13.351310568583624, 13.954434023333466, 13.833375399536308,
        13.23478503216295, 13.229508179502936, 13.081569421202504, 13.111955459764134, 13.313565584429645,
        12.895822708651364, 11.856586384851303, 11.747502930901248, 11.477166081331394, 11.968731461589641,
        12.910617813249443, 13.783041410703255, 13.664096839344904, 13.416752727534579, 12.996373500853053,
        12.226613834386363, 11.406286934906419, 11.064147626707395, 10.526693424249395, 9.6682418398824055,
        9.5656469982362644, 8.633802142647145, 7.911116775692733, 7.5218036771498298, 7.5234294786346014,
        7.9069146636026106, 8.5965335673487839, 9.3034583640488648, 9.4500169740341917, 10.299608964240058,
        11.055524261651918, 11.675840089542856, 12.156462347951148, 12.53112561368027, 12.660771626086403,
        12.868892222896084, 13.230897278463143, 13.642654271367054, 14.106816365848598, 14.529836204259333,
        14.602291235557717, 14.620235691106975, 13.678281413948246, 13.51979351456291, 13.338827208895861,
        12.337400222501822, 11.506721190837634, 11.098761199438101, 11.102808164918775, 11.425905470576772,
        11.714428553431798, 11.886459852625201, 12.035570442032403, 11.580639494361572, 11.488113239473538,
        10.903735363611753, 10.209447282562856, 9.5043766268555689, 8.7920812597559994, 8.0735304010092825,
        7.347104626839644, 6.6085958699503662, 6.1496664193039994, 5.821344166329677, 5.9127911070795323,
        4.9342652985615576, 4.050745397809842, 3.1740110751228041, 2.3072889415487108, 1.4538056081358768,
        0.61678768593257072, -0.20053821401294236, -0.99494548065234767, -1.7632075029373926,
        -2.5020976698197641, -3.2083893702512087, -3.8788559931834152, -4.5102709275681283,
        -5.0994075623570394, -5.5789032190742072, -5.6428026999265457, -5.9842769011998804,
        -5.729140886963938, -4.8519085924998322, -4.6444581063590329, -3.7217151397093993,
        -2.5300254086689806, -1.3027452894525609, -0.78475347239267057, -1.0460847630211827,
        -0.90959826921338605, -2.6553766359304607, -3.7360597404585745, -4.1087031972797643,
        -4.1108616867222691, -3.776307276733156, -2.7114490122334045, -2.5973338374383879,
        -1.4760729895576692, -0.48580494729501034, 0.11910209432525942, 0.34807359178739627,
        0.36262668088219696, 0.3622604193055981, 0.51348240778475363, 0.56740090208414018,
        0.14380211642697149, -0.48989527970345625, -1.2810928311228711, -1.8846453955503084,
        -1.1777647142370817, -1.0483932372566702, -0.32646483194908105, -0.88612247621927298,
    ];

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

/// Custom against GSL, for f(x) = 1 + x^2.
#[test]
fn extra_test_steffen() {
    let xa = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0];

    #[rustfmt::skip]
    let ya = [
        1.000000000000000, 1.040000000000000, 1.160000000000000,
        1.360000000000000, 1.640000000000000, 2.000000000000000,
    ];

    #[rustfmt::skip]
    let xtest = [
        0.000000000000000, 0.042105263157895, 0.084210526315789, 0.126315789473684, 0.168421052631579,
        0.210526315789474, 0.252631578947368, 0.294736842105263, 0.336842105263158, 0.378947368421053,
        0.421052631578947, 0.463157894736842, 0.505263157894737, 0.547368421052632, 0.589473684210526,
        0.631578947368421, 0.673684210526316, 0.715789473684211, 0.757894736842106, 0.800000000000000,
        0.842105263157895, 0.884210526315790, 0.926315789473685, 0.968421052631579,
    ];

    #[rustfmt::skip]
    let ytest = [
        1.000000000000000, 1.007021431695583, 1.012736550517568, 1.019384749963552, 1.029205423531127,
        1.044321329639889, 1.063822714681441, 1.086869806094183, 1.113462603878117, 1.143601108033241,
        1.177285318559557, 1.214515235457064, 1.255290858725762, 1.299612188365651, 1.347479224376731,
        1.398891966759003, 1.453850415512466, 1.512354570637120, 1.574404432132964, 1.640000000000001,
        1.710540895174224, 1.785933809593236, 1.863939349759441, 1.942318122175245,
    ];

    #[rustfmt::skip]
    let dytest = [
        0.200000000000000, 0.142382271468144, 0.137950138504155, 0.186703601108033, 0.288642659279779,
        0.421052631578948, 0.505263157894738, 0.589473684210527, 0.673684210526317, 0.757894736842106,
        0.842105263157894, 0.926315789473683, 1.010526315789472, 1.094736842105262, 1.178947368421052,
        1.263157894736843, 1.347368421052633, 1.431578947368423, 1.515789473684212, 1.600000000000001,
        1.741828254847646, 1.830470914127424, 1.865927977839335, 1.848199445983379,
    ];

    #[rustfmt::skip]
    let d2ytest = [
        -2.000000000000002, -0.736842105263158, 0.526315789473685, 1.789473684210528, 3.052631578947372,
        2.000000000000010, 2.000000000000004, 1.999999999999999, 1.999999999999993, 1.999999999999988,
        1.999999999999979, 1.999999999999990, 2.000000000000001, 2.000000000000012, 2.000000000000024,
        2.000000000000021, 2.000000000000010, 1.999999999999999, 1.999999999999988, 3.999999999999984,
        2.736842105263146, 1.473684210526307, 0.210526315789469, -1.052631578947370,
    ];

    #[rustfmt::skip]
    let iytest = [
        0.000000000000000, 0.042261595087003, 0.084783470558595, 0.127557768893732, 0.170670922823899,
        0.214303251202799, 0.258672790008262, 0.303938086212762, 0.350248432716139, 0.397753122418234,
        0.446601448218885, 0.496942703017933, 0.548926179715216, 0.602701171210575, 0.658416970403849,
        0.716222870194878, 0.776268163483501, 0.838702143169559, 0.903674102152890, 0.971333333333334,
        1.041850083000182, 1.115446980916353, 1.192281177502731, 1.272415532927669,
    ];

    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_d2_table = XYTable {
        x: &xtest,
        y: &d2ytest,
    };

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

    let interp = Steffen.build(&xa, &ya).unwrap();
    test_interp_extra(
        data_table,
        test_e_table,
        test_d_table,
        test_d2_table,
        test_i_table,
        interp,
    );
}