compress

Returns compressed tensor. Note: allocates using GC.

compress
(
I = uint
J = size_t
SliceKind kind
size_t N
Iterator
)
(
Slice!(Iterator, N, kind) slice
)
if (
N > 1
)

Examples

Sparse tensor compression

1 auto sparse = sparse!double(5, 3);
2 sparse[] =
3     [[0, 2, 1],
4      [0, 0, 4],
5      [0, 0, 0],
6      [6, 0, 9],
7      [0, 0, 5]];
8 
9 auto crs = sparse.compressWithType!double;
10 // assert(crs.iterator._field == CompressedField!(double, uint, uint)(
11 //      3,
12 //     [2, 1, 4, 6, 9, 5],
13 //     [1, 2, 2, 0, 2, 2],
14 //     [0, 2, 3, 3, 5, 6]));

Sparse tensor compression

1 auto sparse = sparse!double(5, 8);
2 sparse[] =
3     [[0, 2, 0, 0, 0, 0, 0, 1],
4      [0, 0, 0, 0, 0, 0, 0, 4],
5      [0, 0, 0, 0, 0, 0, 0, 0],
6      [6, 0, 0, 0, 0, 0, 0, 9],
7      [0, 0, 0, 0, 0, 0, 0, 5]];
8 
9 auto crs = sparse.compressWithType!double;
10 // assert(crs.iterator._field == CompressedField!(double, uint, uint)(
11 //      8,
12 //     [2, 1, 4, 6, 9, 5],
13 //     [1, 7, 7, 0, 7, 7],
14 //     [0, 2, 3, 3, 5, 6]));

Dense tensor compression

1 import mir.ndslice.allocation: slice;
2 
3 auto sl = slice!double(5, 3);
4 sl[] =
5     [[0, 2, 1],
6      [0, 0, 4],
7      [0, 0, 0],
8      [6, 0, 9],
9      [0, 0, 5]];
10 
11 auto crs = sl.compressWithType!double;
12 
13 // assert(crs.iterator._field == CompressedField!(double, uint, uint)(
14 //      3,
15 //     [2, 1, 4, 6, 9, 5],
16 //     [1, 2, 2, 0, 2, 2],
17 //     [0, 2, 3, 3, 5, 6]));

Dense tensor compression

1 import mir.ndslice.allocation: slice;
2 
3 auto sl = slice!double(5, 8);
4 sl[] =
5     [[0, 2, 0, 0, 0, 0, 0, 1],
6      [0, 0, 0, 0, 0, 0, 0, 4],
7      [0, 0, 0, 0, 0, 0, 0, 0],
8      [6, 0, 0, 0, 0, 0, 0, 9],
9      [0, 0, 0, 0, 0, 0, 0, 5]];
10 
11 auto crs = sl.compress;
12 // assert(crs.iterator._field == CompressedField!(double, uint, uint)(
13 //      8,
14 //     [2, 1, 4, 6, 9, 5],
15 //     [1, 7, 7, 0, 7, 7],
16 //     [0, 2, 3, 3, 5, 6]));

Meta