sparse

Sparse tensors represented in Dictionary of Keys (DOK) format.

Sparse!(T, N)
sparse
(
T
size_t N
)
(
size_t[N] lengths...
)

Parameters

N

dimension count

lengths
Type: size_t[N]

list of dimension lengths

Return Value

Type: Sparse!(T, N)

N-dimensional slice composed of indeces

Examples

1 auto slice = sparse!double(2, 3);
2 slice[0][] = 1;
3 slice[0, 1] = 2;
4 --slice[0, 0];
5 slice[1, 2] += 4;
6 
7 assert(slice == [[0, 2, 1], [0, 0, 4]]);
8 
9 import std.range.primitives: isRandomAccessRange;
10 static assert(isRandomAccessRange!(Sparse!(double, 2)));
11 
12 import mir.ndslice.slice: Slice, DeepElementType;
13 static assert(is(Sparse!(double, 2) : Slice!(FieldIterator!(SparseField!double), 2)));
14 static assert(is(DeepElementType!(Sparse!(double, 2)) == double));

See Also

Meta