recompress

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.

Slice!(ChopIterator!(J*, Series!(I*, V*)), N)
recompress
(
V
I = uint
J = size_t
Iterator
size_t N
SliceKind kind
)
(
Slice!(Iterator, N, kind) sparseSlice
)
if (
isSeries!(DeepElementType!(Slice!(Iterator, N, kind)))
)

Examples

1 import mir.ndslice.topology: universal;
2 import mir.ndslice.allocation: slice;
3 
4 auto sl = slice!double(5, 8);
5 sl[] =
6     [[0, 2, 0, 0, 0, 0, 0, 1],
7      [0, 0, 0, 0, 0, 0, 0, 4],
8      [0, 0, 0, 0, 0, 0, 0, 0],
9      [6, 0, 0, 0, 0, 0, 0, 9],
10      [0, 0, 0, 0, 0, 0, 0, 5]];
11 
12 auto crs = sl.compress;
13 // assert(crs.iterator._field == CompressedField!(double, uint, uint)(
14 //      8,
15 //     [2, 1, 4, 6, 9, 5],
16 //     [1, 7, 7, 0, 7, 7],
17 //     [0, 2, 3, 3, 5, 6]));
18 
19 import mir.ndslice.dynamic: reversed;
20 auto rec = crs.reversed.recompress!real;
21 auto rev = sl.universal.reversed.compressWithType!real;
22 assert(rev.structure == rec.structure);
23 // assert(rev.iterator._field.values   == rec.iterator._field.values);
24 // assert(rev.iterator._field.indeces  == rec.iterator._field.indeces);
25 // assert(rev.iterator._field.pointers == rec.iterator._field.pointers);

Meta