1 import mir.ndslice.topology : iota; 2 3 // [0, 1, 2] 4 // [3, 4, 5] 5 // iter = p 6 // lengths = [2, 3] 7 // strides = [3, 1] 8 auto x = Tensor!(2, size_t)(2, 3); 9 x.asSlice[] = iota(2, 3); 10 11 // [0, 3] 12 // [1, 4] 13 // [2, 5] 14 // lengths = [3, 2] 15 // strides = [1, 3] 16 auto t = x.transposed; 17 assert(!t.isContiguous); 18 assert(t.lengths[1] == x.lengths[0]); 19 assert(t.lengths[0] == x.lengths[1]); 20 21 assert(t.asSlice[0, 0] == x.asSlice[0, 0]); 22 assert(t.asSlice[0, 1] == x.asSlice[1, 0]); 23 24 assert(t.asSlice[1, 0] == x.asSlice[0, 1]); 25 assert(t.asSlice[1, 1] == x.asSlice[1, 1]); 26 27 assert(t.asSlice[2, 0] == x.asSlice[0, 2]); 28 assert(t.asSlice[2, 1] == x.asSlice[1, 2]); 29 30 assert(t.transposed.asSlice == x.asSlice);
transpose last two dim