Skip to content
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

Small inconsistency between [<- methods for matter_arr and array #6

Closed
PeteHaitch opened this issue Dec 26, 2017 · 3 comments
Closed

Comments

@PeteHaitch
Copy link

PeteHaitch commented Dec 26, 2017

Hi Kylie,

The [<- replacement method seems to work the same for base::matrix and matter_mat objects, but not so for base::array and matter_arr objects. An example is shown below. Is this fixable? I hit this when using programatically constructed indices passed to the [<- method for the matter_arr class via a do.call().

suppressPackageStartupMessages(library(matter))

m <- matrix(1:6, nrow = 2, ncol = 3)
M <- matter_mat(m)
M[]
#>      [,1] [,2] [,3]
#> [1,]    1    3    5
#> [2,]    2    4    6
# works
M[] <- matrix(6:1, nrow = 2, ncol = 3) 
M[]
#>      [,1] [,2] [,3]
#> [1,]    6    4    2
#> [2,]    5    3    1
# works
M[, ] <- matrix(-(1:6), nrow = 2, ncol = 3)
M[]
#>      [,1] [,2] [,3]
#> [1,]   -1   -3   -5
#> [2,]   -2   -4   -6

a <- array(1:8, dim = c(2, 2, 2))
A <- matter_arr(a)
A[]
#> , , 1
#> 
#>      [,1] [,2]
#> [1,]    1    3
#> [2,]    2    4
#> 
#> , , 2
#> 
#>      [,1] [,2]
#> [1,]    5    7
#> [2,]    6    8
# works
A[] <- array(8:1, dim = c(2, 2, 2))
A[]
#> , , 1
#> 
#>      [,1] [,2]
#> [1,]    8    6
#> [2,]    7    5
#> 
#> , , 2
#> 
#>      [,1] [,2]
#> [1,]    4    2
#> [2,]    3    1
# errors for matter_arr (whereas works for base::array)
A[, , ] <- array(-(1:8), dim = c(2, 2, 2))
#> Error in `[<-`(`*tmp*`, , , , value = structure(-1:-8, .Dim = c(2L, 2L, : argument is missing, with no default
a[, , ] <- array(-(1:8), dim = c(2, 2, 2))
a
#> , , 1
#> 
#>      [,1] [,2]
#> [1,]   -1   -3
#> [2,]   -2   -4
#> 
#> , , 2
#> 
#>      [,1] [,2]
#> [1,]   -5   -7
#> [2,]   -6   -8
@PeteHaitch
Copy link
Author

Another small inconsistency: the [<- method for base::array supports NULL indices but the method for matter does not:

suppressPackageStartupMessages(library(matter))

array <- array(1:8, dim = c(2, 2, 2))
matter <- matter_arr(array, dim = dim(array))

# base: Returns empty array of appropriate dimension
array[NULL, NULL, NULL]
#> <0 x 0 x 0 array of integer>
#> 
# matter: errors
matter[NULL, NULL, NULL]
#> Error in matter[NULL, NULL, NULL]: incorrect number of dimensions

# base: Returns empty array of appropriate dimension
array[NULL, NULL, 1]
#> <0 x 0 matrix>
# matter: errors
matter[NULL, NULL, 1]
#> Error in matter[NULL, NULL, 1]: incorrect number of dimensions

# base: Returns empty array of appropriate dimension
array[NULL, , NULL]
#> <0 x 2 x 0 array of integer>
#>      [,1] [,2]
# matter: errors
matter[NULL, , NULL]
#> Error in FUN(if (length(d.call) < 2L) newX[, 1] else array(newX[, 1L], : subscript out of bounds
Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                                             
#>  version  R Under development (unstable) (2017-12-12 r73903)
#>  system   x86_64, darwin15.6.0                              
#>  ui       X11                                               
#>  language (EN)                                              
#>  collate  en_AU.UTF-8                                       
#>  tz       Australia/Melbourne                               
#>  date     2017-12-27
#> Packages -----------------------------------------------------------------
#>  package      * version date       source        
#>  backports      1.1.2   2017-12-13 CRAN (R 3.5.0)
#>  base         * 3.5.0   2017-12-13 local         
#>  biglm        * 0.9-1   2013-05-16 CRAN (R 3.5.0)
#>  BiocGenerics   0.25.1  2017-12-17 Bioconductor  
#>  compiler       3.5.0   2017-12-13 local         
#>  datasets     * 3.5.0   2017-12-13 local         
#>  DBI          * 0.7     2017-06-18 CRAN (R 3.5.0)
#>  devtools       1.13.4  2017-11-09 CRAN (R 3.5.0)
#>  digest         0.6.13  2017-12-14 CRAN (R 3.5.0)
#>  evaluate       0.10.1  2017-06-24 CRAN (R 3.5.0)
#>  graphics     * 3.5.0   2017-12-13 local         
#>  grDevices    * 3.5.0   2017-12-13 local         
#>  grid           3.5.0   2017-12-13 local         
#>  htmltools      0.3.6   2017-04-28 CRAN (R 3.5.0)
#>  irlba          2.3.1   2017-10-18 CRAN (R 3.5.0)
#>  knitr          1.17    2017-08-10 CRAN (R 3.5.0)
#>  lattice        0.20-35 2017-03-25 CRAN (R 3.5.0)
#>  magrittr       1.5     2014-11-22 CRAN (R 3.5.0)
#>  Matrix         1.2-12  2017-11-20 CRAN (R 3.5.0)
#>  matter       * 1.5.4   2017-12-04 Bioconductor  
#>  memoise        1.1.0   2017-04-21 CRAN (R 3.5.0)
#>  methods      * 3.5.0   2017-12-13 local         
#>  parallel       3.5.0   2017-12-13 local         
#>  Rcpp           0.12.14 2017-11-23 CRAN (R 3.5.0)
#>  rmarkdown      1.8     2017-11-17 CRAN (R 3.5.0)
#>  rprojroot      1.3-1   2017-12-18 CRAN (R 3.5.0)
#>  stats        * 3.5.0   2017-12-13 local         
#>  stringi        1.1.6   2017-11-17 CRAN (R 3.5.0)
#>  stringr        1.2.0   2017-02-18 CRAN (R 3.5.0)
#>  tools          3.5.0   2017-12-13 local         
#>  utils        * 3.5.0   2017-12-13 local         
#>  withr          2.1.1   2017-12-19 CRAN (R 3.5.0)
#>  yaml           2.1.16  2017-12-12 CRAN (R 3.5.0)

@PeteHaitch
Copy link
Author

Sorry, another corner case: the [<- method for base::array supports integer(0) indices but the method for matter does not:

suppressPackageStartupMessages(library(matter))

array <- array(1:8, dim = c(2, 2, 2))
matter <- matter_arr(array)
# base: Returns an array of appropriate dimension
array[integer(0), integer(0), integer(0)]
#> <0 x 0 x 0 array of integer>
#> 
# matter: errors
matter[integer(0), integer(0), integer()]
#> Error in FUN(if (length(d.call) < 2L) newX[, 1] else array(newX[, 1L], : subscript out of bounds

# base: Returns an array (I don't quite understand the dimensions)
array[integer(0), 1, integer(0)]
#> <0 x 0 matrix>
# matter: errors
matter[1, 1, integer(0)]
#> Error in FUN(if (length(d.call) < 2L) newX[, 1] else array(newX[, 1L], : subscript out of bounds
Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                                             
#>  version  R Under development (unstable) (2017-12-12 r73903)
#>  system   x86_64, darwin15.6.0                              
#>  ui       X11                                               
#>  language (EN)                                              
#>  collate  en_AU.UTF-8                                       
#>  tz       Australia/Melbourne                               
#>  date     2017-12-27
#> Packages -----------------------------------------------------------------
#>  package      * version date       source        
#>  backports      1.1.2   2017-12-13 CRAN (R 3.5.0)
#>  base         * 3.5.0   2017-12-13 local         
#>  biglm        * 0.9-1   2013-05-16 CRAN (R 3.5.0)
#>  BiocGenerics   0.25.1  2017-12-17 Bioconductor  
#>  compiler       3.5.0   2017-12-13 local         
#>  datasets     * 3.5.0   2017-12-13 local         
#>  DBI          * 0.7     2017-06-18 CRAN (R 3.5.0)
#>  devtools       1.13.4  2017-11-09 CRAN (R 3.5.0)
#>  digest         0.6.13  2017-12-14 CRAN (R 3.5.0)
#>  evaluate       0.10.1  2017-06-24 CRAN (R 3.5.0)
#>  graphics     * 3.5.0   2017-12-13 local         
#>  grDevices    * 3.5.0   2017-12-13 local         
#>  grid           3.5.0   2017-12-13 local         
#>  htmltools      0.3.6   2017-04-28 CRAN (R 3.5.0)
#>  irlba          2.3.1   2017-10-18 CRAN (R 3.5.0)
#>  knitr          1.17    2017-08-10 CRAN (R 3.5.0)
#>  lattice        0.20-35 2017-03-25 CRAN (R 3.5.0)
#>  magrittr       1.5     2014-11-22 CRAN (R 3.5.0)
#>  Matrix         1.2-12  2017-11-20 CRAN (R 3.5.0)
#>  matter       * 1.5.4   2017-12-04 Bioconductor  
#>  memoise        1.1.0   2017-04-21 CRAN (R 3.5.0)
#>  methods      * 3.5.0   2017-12-13 local         
#>  parallel       3.5.0   2017-12-13 local         
#>  Rcpp           0.12.14 2017-11-23 CRAN (R 3.5.0)
#>  rmarkdown      1.8     2017-11-17 CRAN (R 3.5.0)
#>  rprojroot      1.3-1   2017-12-18 CRAN (R 3.5.0)
#>  stats        * 3.5.0   2017-12-13 local         
#>  stringi        1.1.6   2017-11-17 CRAN (R 3.5.0)
#>  stringr        1.2.0   2017-02-18 CRAN (R 3.5.0)
#>  tools          3.5.0   2017-12-13 local         
#>  utils        * 3.5.0   2017-12-13 local         
#>  withr          2.1.1   2017-12-19 CRAN (R 3.5.0)
#>  yaml           2.1.16  2017-12-12 CRAN (R 3.5.0)

@kuwisdelu
Copy link
Owner

These should behave more as expected in version >= 1.9.8, with the exception that subsetting a matter_arr always produces an array and never a matrix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants