Report a bug
If you spot a problem with this page, click here to create a Github issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.ndslice.fuse

This is a submodule of mir.ndslice.
Allocation routines that construct ndslices from ndranges.
Authors:
Ilya Yaroshenko
See Also:
concatenation submodule.
template fuse(Dimensions...)
Fuses ndrange r into GC-allocated ndslice. Can be used to join rows or columns into a matrix.
Parameters:
Dimensions (optional) indexes of dimensions to be brought to the first position
Returns:
ndslice
Examples:
import mir.ndslice.fuse;
import mir.ndslice.topology: iota;
import mir.ndslice.slice : Contiguous, Slice;

enum ror = [
        [0, 1, 2, 3],
        [4, 5, 6, 7],
        [8, 9,10,11]];

//  0  1  2  3
//  4  5  6  7
//  8  9 10 11
auto matrix = ror.fuse;

assert(matrix == [3, 4].iota);
static assert(ror.fuse == [3, 4].iota); // CTFE-able
// matrix is contiguos
static assert(is(typeof(matrix) == Slice!(int*, 2)));
Examples:
Transposed
import mir.ndslice.fuse;
import mir.ndslice.topology: iota;
import mir.ndslice.dynamic: transposed;
import mir.ndslice.slice : Contiguous, Slice;

enum ror = [
    [0, 1, 2, 3],
    [4, 5, 6, 7],
    [8, 9,10,11]];

//  0  4  8
//  1  5  9
//  2  6 10
//  3  7 11

// `!1` brings dimensions under index 1 to the front (0 index).
auto matrix = ror.fuse!1;

assert(matrix == [3, 4].iota.transposed!1);
// TODO: CTFE
// static assert(ror.fuse!1 == [3, 4].iota.transposed!1); // CTFE-able
// matrix is contiguos
static assert(is(typeof(matrix) == Slice!(int*, 2)));
Examples:
3D
import mir.ndslice.fuse;
import mir.ndslice.topology: iota;
import mir.ndslice.dynamic: transposed;

auto ror =
  [[[ 0, 1, 2, 3],
    [ 4, 5, 6, 7]],
   [[ 8, 9,10,11],
    [12,13,14,15]]];

auto nd = [2, 2, 4].iota;

assert(ror.fuse == nd);
assert(ror.fuse!2 == nd.transposed!2);
assert(ror.fuse!(1, 2) == nd.transposed!(1, 2));
assert(ror.fuse!(2, 1) == nd.transposed!(2, 1));
auto fuseCells(S)(S cells);
Fuses cells into GC-allocated ndslice.
Parameters:
S cells ndrange of ndcells, ndrange and ndcell should have shape and multidimensional input range primivies (front!d, empty!d, popFront!d).
Returns:
ndslice composed of fused cells.
See Also:
Examples:
1D
import mir.ndslice.topology: iota;
enum ar = [[0, 1], [], [2, 3, 4, 5], [6], [7, 8, 9]];
static assert ([[0, 1], [], [2, 3, 4, 5], [6], [7, 8, 9]].fuseCells == 10.iota);
assert (ar.fuseCells == 10.iota);
Examples:
2D
import mir.ndslice.topology: iota;
import mir.ndslice.chunks;

auto sl = iota(11, 17);
assert(sl.chunks!(0, 1)(3, 4).fuseCells == sl);