diff --git a/lib/PDL/Stats/TS.pd b/lib/PDL/Stats/TS.pd index 3bb1386..aae2e0f 100644 --- a/lib/PDL/Stats/TS.pd +++ b/lib/PDL/Stats/TS.pd @@ -78,7 +78,7 @@ loop (h) %{ PMCode => pp_line_numbers(__LINE__, <<'EOF'), sub PDL::acf { my ($self, $h) = @_; - $h ||= $self->dim(0) - 1; + $h //= $self->dim(0) - 1; PDL::_acf_int($self, my $r = PDL->null, $h+1); $r; } @@ -133,7 +133,7 @@ loop (h) %{ PMCode => pp_line_numbers(__LINE__, <<'EOF'), sub PDL::acvf { my ($self, $h) = @_; - $h ||= $self->dim(0) - 1; + $h //= $self->dim(0) - 1; PDL::_acvf_int($self, my $v = PDL->null, $h+1); $v; } diff --git a/t/ts.t b/t/ts.t index d3fc97a..d5472de 100644 --- a/t/ts.t +++ b/t/ts.t @@ -12,6 +12,8 @@ use Test::PDL; is_pdl $a->filter_ma(2), pdl( '.6 1.2 2 3 4 5 6 7 7.8 8.4'), "filter moving average on $a"; is_pdl $a->filter_exp(.8), pdl('0 0.8 1.76 2.752 3.7504 4.75008 5.750016 6.7500032 7.7500006 8.7500001'), "filter with exponential smoothing on $a"; is_pdl $a->acf(5)->portmanteau($a->nelem), pdl( 11.1753902662994 ), "portmanteau significance test on $a"; + is_pdl $a->acvf(5) / $a->acvf(0), $a->acf(5), "calculate autocorrelation from autocovariance on $a"; + is_pdl $a->acf(0), pdl('1'), "first value of the autocorrelation function is always 1"; my $b = pdl '1 2 3 4 5 6 7 9 9 10'; is_pdl $b->mape($a), pdl( 0.302619047619048 ), "mean absolute percent error between $a and $b"; is_pdl $b->mae($a), pdl( 1.1 ), "mean absolute error between $a and $b";