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]);
implementation: could by done by combining transposed and pack.
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: