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

auto sparse = sparse!double(5, 3);
sparse[] =
    [[0, 2, 1],
     [0, 0, 4],
     [0, 0, 0],
     [6, 0, 9],
     [0, 0, 5]];

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

Sparse tensor compression

auto sparse = sparse!double(5, 8);
sparse[] =
    [[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 = sparse.compressWithType!double;
// 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]));

Dense tensor compression

import mir.ndslice.allocation: slice;

auto sl = slice!double(5, 3);
sl[] =
    [[0, 2, 1],
     [0, 0, 4],
     [0, 0, 0],
     [6, 0, 9],
     [0, 0, 5]];

auto crs = sl.compressWithType!double;

// assert(crs.iterator._field == CompressedField!(double, uint, uint)(
//      3,
//     [2, 1, 4, 6, 9, 5],
//     [1, 2, 2, 0, 2, 2],
//     [0, 2, 3, 3, 5, 6]));

Dense tensor compression

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]));

Meta