From 8c59db1661aadc56724238ed35792bf6a43ca4b5 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Wed, 10 May 2023 15:41:10 +0100 Subject: [PATCH] optional head/tail --- inst/stan/functions/convolve.stan | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/stan/functions/convolve.stan b/inst/stan/functions/convolve.stan index 746f2ae90..73aafc3b5 100644 --- a/inst/stan/functions/convolve.stan +++ b/inst/stan/functions/convolve.stan @@ -8,8 +8,8 @@ vector convolve_with_rev_pmf(vector x, vector y, int len) { vector[len] z; for (s in 1:len) { z[s] = dot_product( - x[max(1, (s - ylen + 1)):min(s, xlen)], - y[max(1, ylen - s + 1):min(ylen, ylen + xlen - s)] + s < ylen ? head(x, min(s, xlen)) : x[(s - ylen + 1):min(s, xlen)], + s < xlen ? tail(y, min(s, ylen)) : y[max(1, ylen - s + 1):(ylen + xlen - s)] ); } return(z);