Skip to content

Commit

Permalink
Fix guess_chunks to prevent infinite loop (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
keller-mark committed Jun 20, 2024
1 parent 3bf3ce4 commit 0825c03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/normalize.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ guess_chunks <- function(shape, typesize) {
break # Element size larger than CHUNK_MAX
}

chunks[idx %% ndims] <- ceiling(chunks[idx %% ndims] / 2.0)
chunks[idx %% ndims + 1] <- ceiling(chunks[idx %% ndims + 1] / 2.0)
idx <- idx + 1
}

Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-chunks.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
library(pizzarr)

test_that("no infinite loop", {
shape <- c(27557749)
dtype <- "<i4"
chunks <- NA

dtype <- normalize_dtype(dtype, object_codec = NA)
shape <- normalize_shape(shape)

dtype_itemsize <- dtype$num_bytes
chunks <- normalize_chunks(chunks, shape, dtype_itemsize)
expect_equal(chunks, c(215295))
})

test_that("can get array that spans multiple chunks", {
a <- array(data=1:100, dim=c(10, 10))
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
Expand Down

0 comments on commit 0825c03

Please sign in to comment.