-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ichunk #46
Comments
> it <- itertools2::ichunk(1:5, chunk_size=2)
> nextElem(it)
[[1]]
[1] 1
[[2]]
[1] 2
> nextElem(it)
[[1]]
[1] 3
[[2]]
[1] 4
> nextElem(it)
[[1]]
[1] 5
[[2]]
[1] NA |
I understand how to use Also there 2 notes:
it <- ichunk(1:10, 3)
while(TRUE) {
val = try(nextElem(it), silent = T)
if (class(val) == "try-error") break
} Of course I can check it with devtools::install_github('dselivanov/text2vec@redesign')
# reviews of 25000 movies ~ 30mb
data("movie_review")
it <- ichunk(movie_review[['review']], chunk_size = 1000)
limit <- length(movie_review[['review']]) / 1000
i <- 1
system.time(
# i <= limit because of behavior from #1
while(TRUE && i <= limit) {
val = try(nextElem(it), silent = T)
if (class(val) == "try-error") break
i <- i + 1
}
)
#user system elapsed
#1.141 0.002 1.142
#Now lets check without iterators
chunk <- function(x, n) suppressWarnings(split(x, rep(seq_len(n), each = ceiling(length(x) / n)) ))
ich <- chunk(seq_len(nrow(movie_review)), 25)
system.time(
for(i in ich ) {
tmp<-movie_review[['review']][i]
}
)
#user system elapsed
#0.002 0.000 0.003 As you can see, there is very very big overhead of using iterators here. Can we do something with that? |
I'll take a look at the As for the |
2015-11-05 16:52 GMT+03:00 John Ramey [email protected]:
Regards |
That is good to hear. After you created the issue, I realized the |
I eveluated both
itertools::ichunk
anditertools2::ichunk
, and the first (at least for me) looks more logical while trying to handle objects which length not divisible by chunk_size. For example I have vectorv=1:5
and want to obtainlist(c(1,2), c(3,4), c(5))
, is it possible withitertools2::ichunk
?The text was updated successfully, but these errors were encountered: