import mir.ndslice.topology: universal; import mir.ndslice.allocation: slice; auto sl = slice!double(5, 8); sl[] = [[0, 2, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 4], [0, 0, 0, 0, 0, 0, 0, 0], [6, 0, 0, 0, 0, 0, 0, 9], [0, 0, 0, 0, 0, 0, 0, 5]]; auto crs = sl.compress; // assert(crs.iterator._field == CompressedField!(double, uint, uint)( // 8, // [2, 1, 4, 6, 9, 5], // [1, 7, 7, 0, 7, 7], // [0, 2, 3, 3, 5, 6])); import mir.ndslice.dynamic: reversed; auto rec = crs.reversed.recompress!real; auto rev = sl.universal.reversed.compressWithType!real; assert(rev.structure == rec.structure); // assert(rev.iterator._field.values == rec.iterator._field.values); // assert(rev.iterator._field.indeces == rec.iterator._field.indeces); // assert(rev.iterator._field.pointers == rec.iterator._field.pointers);
Re-compresses a compressed tensor. Makes all values, indeces and pointers consequent in memory.
Sparse slice is iterated twice. The first tine it is iterated to get length of each sparse row, the second time - to copy the data.
Note: allocates using GC.