Skip to content

Dimension swap from cube to matrix #299

Open
@mboeck11

Description

@mboeck11

I encountered a bug in RcppArmadillo when saving a row of a cube to a matrix. If one of the remaining dimensions is just of dimension 1, then dimensions are swapped. I'll illustrate the bug with an example

cppFunction("arma::mat test_row(arma::cube Rarray) {
arma::mat test = Rarray.row(0);
return test;
}", depends="RcppArmadillo")
Rarray1 <- array(NA, dim=c(100,1,2))
dim(test_row(Rarray1))
> 1 2
Rarray2 <- array(NA, dim=c(100,2,1))
dim(test_row(Rarray2))
> 1 2

When pulling out the first row and saving it to a matrix, dimensions are not kept in the second example, but swapped. I'll tested also whether this happens also when pulling out the first column or slice, but there everything seems fine. I'll just attach the code

cppFunction("arma::mat test_col(arma::cube Rarray) {
arma::mat test = Rarray.col(0);
return test;
}", depends="RcppArmadillo")
Rarray3 <- array(NA, dim=c(1,100,2))
dim(test_col(Rarray3))
> 1 2
Rarray4 <- array(NA, dim=c(2,100,1))
dim(test_col(Rarray4))
> 2 1

cppFunction("arma::mat test_slice(arma::cube Rarray) {
arma::mat test = Rarray.slice(0);
return test;
}", depends="RcppArmadillo")

Rarray5 <- array(NA, dim=c(1,2,100))
dim(test_slice(Rarray5))
> 1 2
Rarray6 <- array(NA, dim=c(2,1,100))
dim(test_slice(Rarray6))
> 2 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions