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

rij_matrix contains duplicates for large rasters #13

Closed
jeffreyhanson opened this Issue Apr 7, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@jeffreyhanson
Copy link
Contributor

jeffreyhanson commented Apr 7, 2017

The rij_matrix() returns duplicate rows for features when the features cannot be loaded in to memory. This might explain why rij_matrix is really slow for large data sets. The offending code is

        m <- plyr::llply(seq_len(raster::nlayers(y)), .parallel = FALSE,
          function(i) {
            m <- matrix(y[included], ncol = 1)
            m[is.na(m)] <- 0
            m <- methods::as(m, "dgCMatrix")
          })

which basically extracts the entire raster data set multiple times, it should instead be more like this:

        m <- plyr::llply(seq_len(raster::nlayers(y)), .parallel = FALSE,
          function(i) {
            m <- matrix(y[[i]][included], ncol = 1)
            m[is.na(m)] <- 0
            m <- methods::as(m, "dgCMatrix")
          })

@jeffreyhanson jeffreyhanson self-assigned this Apr 7, 2017

@jeffreyhanson

This comment has been minimized.

Copy link
Contributor

jeffreyhanson commented Apr 7, 2017

As per the benchmarks in #12, a better implementation would use something like this for extracting cell values:

m <- y[][included,]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment