array/map along>=3 changes order of axes
mschubert opened this issue · comments
ar = import('array')
l = letters
id = function(x) x
a = array(1:2*3*4*5, dim=c(2,3,4,5),dimnames=list(l[1:2],l[3:5],l[6:9],l[10:14]))
dim(apply(a, c(2,3,4), id))
dim(ar$map_simple(a, along=1, id)) # $map fails, why?
dim(apply(a, c(1,3,4), id)) # 3 2 4 5
dim(ar$map_simple(a, along=2, id)) # 2 3 4 5 -> this is right
dim(apply(a, c(1,2,4), id)) # 4 2 3 5
dim(ar$map_simple(a, along=3, id)) # 3 4 2 5 -> WRONG
dim(apply(a, c(1,2,3), id)) # 5 2 3 4
dim(ar$map_simple(a, along=4, id)) # 4 5 2 3 -> WRONG
can be fixed by using
aperm(Y, match(seq_along(dim(Y)), c(along, preserveAxes)))
but related issues remain:
fx = function(x) sum(x)
dim(apply(a, c(2,3,4), fx)) # 3 4 5; how to not drop dims?
dim(apply(a, c(1,2,4), fx)) # 2 3 5
dim(apply(a, c(1,2,3), fx)) # 2 3 4