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

Reconsider dcdim default behaviour #17

Open
psolymos opened this issue Oct 31, 2022 · 0 comments
Open

Reconsider dcdim default behaviour #17

psolymos opened this issue Oct 31, 2022 · 0 comments

Comments

@psolymos
Copy link
Contributor

Array works fine:

r$> ## array
    x <- dcdim(array(1:6, c(2, 3, 1)))

r$> x1 <- dclone(x, 1)

r$> x2 <- dclone(x, 2)

r$> x
, , 1

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

attr(,"drop")
[1] TRUE
attr(,"class")
[1] "dcdim" "array"

r$> x1
, , 1

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

attr(,"drop")
[1] TRUE
attr(,"class")
[1] "dcdim" "array"

r$> x2
, , clone.1

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

, , clone.2

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

attr(,"n.clones")
[1] 2
attr(,"n.clones")attr(,"method")
[1] "dim"
attr(,"n.clones")attr(,"method")attr(,"drop")
[1] TRUE

r$> stopifnot(all(dim(x1) == dim(x)))

r$> stopifnot(all(dim(x2) == dim(x)*c(1,1,2)))

Should the matrix case add a 3rd dim when k=1?

r$> ## matrix
    x <- dcdim(matrix(1:6, 2, 3))

r$> x1 <- dclone(x, 1)

r$> x2 <- dclone(x, 2)

r$> x
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
attr(,"drop")
[1] TRUE
attr(,"class")
[1] "dcdim"  "matrix" "array" 

r$> x1
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
attr(,"drop")
[1] TRUE
attr(,"class")
[1] "dcdim"  "matrix" "array" 

r$> x2
, , clone.1

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

, , clone.2

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

attr(,"n.clones")
[1] 2
attr(,"n.clones")attr(,"method")
[1] "dim"
attr(,"n.clones")attr(,"method")attr(,"drop")
[1] TRUE

r$> stopifnot(all(dim(x1) == dim(x)))

r$> stopifnot(all(dim(x2) == dim(x)*c(1,2)))
Error: all(dim(x2) == dim(x) * c(1, 2)) is not TRUE
In addition: Warning message:
In dim(x2) == dim(x) * c(1, 2) :
  longer object length is not a multiple of shorter object length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant