From: Art Owen <owen_at_stanford.edu>

Date: Tue, 18 Dec 2007 16:58:08 -0800

else {

else x)/n

}

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 19 Dec 2007 - 01:02:46 GMT

Date: Tue, 18 Dec 2007 16:58:08 -0800

> for( i in 11:20 )print( system.time(convolve(1:2^i,1:2^i,type="o")))

user system elapsed

0.002 0.000 0.002

user system elapsed

0.373 0.002 0.375

user system elapsed

0.014 0.001 0.016

user system elapsed

0.031 0.002 0.034

user system elapsed

0.126 0.004 0.130

user system elapsed

194.095 0.013 194.185

user system elapsed

0.345 0.011 0.356

> convolve

function (x, y, conj = TRUE, type = c("circular", "open", "filter"))
{

type <- match.arg(type)

n <- length(x)

ny <- length(y)

Real <- is.numeric(x) && is.numeric(y)
if (type == "circular") {

if (ny != n) stop("length mismatch in convolution")}

else {

n1 <- ny - 1 x <- c(rep.int(0, n1), x) n <- length(y <- c(y, rep.int(0, n - 1)))}

x <- fft(fft(x) * (if (conj) Conj(fft(y)) else fft(y)), inv = TRUE) if (type == "filter") (if (Real) Re(x) else x)[-c(1:n1, (n - n1 + 1):n)]/n else (if (Real) Re(x)

else x)/n

}

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 19 Dec 2007 - 01:02:46 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Wed 19 Dec 2007 - 07:30:19 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*