From 12c5b044863cb5aad51609bae7f57bd46aa3f167 Mon Sep 17 00:00:00 2001 From: Ed J Date: Wed, 11 Dec 2024 13:16:53 +0000 Subject: [PATCH] Func tests capture PCHIP behaviour needed --- Libtmp/t/func.t | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Libtmp/t/func.t b/Libtmp/t/func.t index fe930d339..82aea16ec 100644 --- a/Libtmp/t/func.t +++ b/Libtmp/t/func.t @@ -51,4 +51,32 @@ is_pdl $obj->interpolate( $xi ), $ans, {atol=>6, test_name=>'broadcasting non-si is_pdl pchip( $x, $y, $xi ), $ans, {atol=>6, test_name=>'pchip'}; is_pdl spline( $x, $y, $xi ), $ans, {atol=>6, test_name=>'spline'}; +$x = sequence(10); +$y = pdl('43.3 44.3 47.3 52.3 59.3 68.3 79.3 92.3 107.3 124.3; -23 -22 -15 4 41 102 193 320 489 706'); +my ($g) = chsp([0,0], [0,0], $x, $y); +is_pdl $g, pdl('0 2 4 6 8 10 12 14 16 18; 0 3 12 27 48 75 108 147 192 243'), 'chsp'; +($g) = chic([0,0], [0,0], 0, $x, $y); +is_pdl $g, pdl('0 1.5 3.75 5.8333333 7.875 9.9 11.916667 13.928571 15.9375 18; 0 1.75 10.230769 25.107143 46.061224 73.039474 106.02752 145.02027 190.01554 241'), 'chic'; +($g) = chim($x, $y); +is_pdl $g, pdl('0 1.5 3.75 5.8333333 7.875 9.9 11.916667 13.928571 15.9375 18; 0 1.75 10.230769 25.107143 46.061224 73.039474 106.02752 145.02027 190.01554 241'), 'chim'; +my ($yi) = chfe($x, $y, $g, [1,1], $xi); +is_pdl $yi, my $yi_exp = pdl('48.56375 54.173375 61.777925 71.38055 82.98225; -10.973827 12.780893 56.345513 125.71307 226.88177'), 'chfe'; +($yi) = chfd($x, $y, $g, [0,0], $xi); +is_pdl $yi, $yi_exp, 'chfd'; +my ($integral) = chia($x, $y, $g, [0,0], 3, 4); +is_pdl $integral, pdl(55.6298611111111,20.7538265306122), 'chia'; +($integral) = chid($x, $y, $g, [0,0], 3, 4); +is_pdl $integral, pdl(55.6298611111111,20.7538265306122), 'chid'; +my $nknots = zeroes(longlong, 2); +my $t = zeroes( 2*$x->dim(0)+4, 2 ); +my ($bcoef, $ndim, $kord) = chbs($x, $y, $g, 0, $nknots, $t); +is_pdl $nknots, longlong(24,24), 'chbs nknots'; +is_pdl $t, pdl('0 0 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 9 9; 0 0 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 9 9'), 'chbs t'; +is_pdl $bcoef, pdl('43.3 43.3 43.8 44.8 46.05 48.55 50.355556 54.244444 56.675 61.925 65 71.6 75.327778 83.272222 87.657143 96.942857 101.9875 112.6125 118.3 124.3; -23 -23 -22.583333 -21.416667 -18.410256 -11.589744 -4.3690476 12.369048 25.646259 56.353741 77.653509 126.34649 157.65749 228.34251 271.65991 368.34009 425.66149 552.33851 625.66667 706'), 'chbs bcoef'; +is_pdl $ndim, longlong(20,20), 'chbs ndim'; +is_pdl $kord, longlong(4,4), 'chbs kord'; +my $x_slice = $x->slice('*1,0:-2'); # because calling with last value is out of range +my ($val) = bvalu($t, $bcoef, 0, $x_slice); +is_pdl $val->t, pdl('43.3 44.3 47.3 52.3 59.3 68.3 79.3 92.3 107.3; -23 -22 -15 4 41 102 193 320 489'), 'bvalu'; + done_testing;