1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/chunkutil.R
\name{chunks}
\alias{chunks}
\title{Function for chunked range index}
\usage{
chunks(
from = NULL,
to = NULL,
by = NULL,
length.out = NULL,
along.with = NULL,
overlap = 0L,
method = c("bbatch", "seq"),
maxindex = NA
)
}
\arguments{
\item{from}{the starting value of the sequence.}
\item{to}{the (maximal) end value of the sequence.}
\item{by}{increment of the sequence}
\item{length.out}{desired length of the sequence.}
\item{along.with}{take the length from the length of this argument.}
\item{overlap}{number of values to overlap (will lower the starting value of
the sequence, the first range becomes smaller}
\item{method}{default 'bbatch' will try to balance the chunk size, see
\code{\link{bbatch}}, 'seq' will create chunks like \code{\link[base]{seq}}}
\item{maxindex}{passed to \code{\link{ri}}}
}
\value{
returns a named list of \code{\link{ri}} objects
representing chunks of subscripts
}
\description{
creates a sequence of range indexes using a syntax not completely unlike
'seq'
}
\examples{
chunks(1, 100, by=30)
chunks(1, 100, by=30, method="seq")
\dontrun{
require(foreach)
m <- 10000
k <- 1000
n <- m*k
message("Four ways to loop from 1 to n. Slowest foreach to fastest chunk is 1700:1
on a dual core notebook with 3GB RAM\n")
z <- 0L;
print(k*system.time({it <- icount(m); foreach (i = it) \%do\% { z <- i; NULL }}))
z
z <- 0L
print(system.time({i <- 0L; while (i<n) {i <- i + 1L; z <- i}}))
z
z <- 0L
print(system.time(for (i in 1:n) z <- i))
z
z <- 0L; n <- m*k;
print(system.time(for (ch in chunks(1, n, by=m)){for (i in ch[1]:ch[2])z <- i}))
z
message("Seven ways to calculate sum(1:n).
Slowest foreach to fastest chunk is 61000:1 on a dual core notebook with 3GB RAM\n")
print(k*system.time({it <- icount(m); foreach (i = it, .combine="+") \%do\% { i }}))
z <- 0;
print(k*system.time({it <- icount(m); foreach (i = it) \%do\% { z <- z + i; NULL }}))
z
z <- 0; print(system.time({i <- 0L;while (i<n) {i <- i + 1L; z <- z + i}})); z
z <- 0; print(system.time(for (i in 1:n) z <- z + i)); z
print(system.time(sum(as.double(1:n))))
z <- 0; n <- m*k
print(system.time(for (ch in chunks(1, n, by=m)){for (i in ch[1]:ch[2])z <- z + i}))
z
z <- 0; n <- m*k
print(system.time(for (ch in chunks(1, n, by=m)){z <- z+sum(as.double(ch[1]:ch[2]))}))
z
}
}
\seealso{
generic \code{\link{chunk}}, \code{\link{ri}}, \code{\link[base]{seq}}, \code{\link{bbatch}}
}
\author{
Jens Oehlschlägel
}
\keyword{data}
|