repack by a specific dimension: slice.by!2 (has code)
timotheecour opened this issue · 2 comments
timotheecour commented
auto a=sliced!double(2,3,4);
auto by_x=a.by!0;
assert(by_x.shape==[2]);
assert(by_x[0].shape==[3,4]);
auto by_y=a.by!1;
assert(by_y.shape==[3]);
assert(by_y[0].shape==[2,4]);
auto by_z=a.by!2;
assert(by_z.shape==[4]);
assert(by_z[0].shape==[2,3]);
implementation: could by done by combining transposed and pack.
auto by(size_t dim, S)(S s){
return s.transposed!(dim).pack!1;
}
It's sufficiently common that it deserves it's own function IMO (eg byRows, byColumns etc are common in matrix and higher order libs)
Extension:
allow multiple indices:
auto by_xz=a.by!(0,2);
assert(by_xz.shape==[2,4]); //or is it [4,2]?
assert(by_xz[0,0].shape==[3]);
9il commented
Will be added. Thanks!
9il commented
In context of new the new ndslice architecture this addition is less actual.