Skip to content

Is eye() specific to row major layouts? #90

@DavisVaughan

Description

@DavisVaughan

I can't tell if this is expected behavior of eye() or not. Is there a column major option for it?

I dont really see anything here about row/column major, so I honestly have no idea
https://github.com/QuantStack/xtensor/blob/master/include/xtensor/xbuilder.hpp#L305

// [[Rcpp::depends(xtensorrr)]]
// [[Rcpp::plugins(cpp14)]]

#include <xtensor-r/rarray.hpp>
#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
SEXP rray_eye_cpp(const std::vector<std::size_t> shape, int k = 0) {
  xt::rarray<int> res = xt::eye<int>(shape, k);
  return res;
}
Rcpp::sourceCpp("~/Desktop/test.cpp")

# looks good
rray_eye_cpp(c(2, 2))
#>      [,1] [,2]
#> [1,]    1    0
#> [2,]    0    1

rray_eye_cpp(c(2, 2, 2))
#> , , 1
#> 
#>      [,1] [,2]
#> [1,]    1    0
#> [2,]    1    0
#> 
#> , , 2
#> 
#>      [,1] [,2]
#> [1,]    0    1
#> [2,]    0    1

# I think I would have expected
array(c(1,0,0,1,1,0,0,1), c(2,2,2))
#> , , 1
#> 
#>      [,1] [,2]
#> [1,]    1    0
#> [2,]    0    1
#> 
#> , , 2
#> 
#>      [,1] [,2]
#> [1,]    1    0
#> [2,]    0    1

Created on 2019-01-09 by the reprex package (v0.2.1.9000)

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