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.
License:
Authors:
Ilya Yaroshenko
See Also:
concatenation submodule.
- template
fuse
(Dimensions...)
templatercfuse
(Dimensions...) - Fuses ndrange r into GC-allocated (fuse) or RC-allocated (rcfuse) ndslice. Can be used to join rows or columns into a matrix.Parameters:
Dimensions (optional) indices of dimensions to be brought to the first position Returns:ndsliceExamples:import mir.ndslice.fuse; import mir.ndslice.slice : Contiguous, Slice; import mir.ndslice.topology: iota; import mir.rc.array: RCI; 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; auto rcmatrix = ror.rcfuse; // nogc version assert(matrix == [3, 4].iota); assert(rcmatrix == [3, 4].iota); static assert(ror.fuse == [3, 4].iota); // CTFE-able // matrix is contiguos static assert(is(typeof(matrix) == Slice!(int*, 2))); static assert(is(typeof(rcmatrix) == Slice!(RCI!int, 2)));
Examples:Transposedimport 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:3Dimport 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));
Examples:Work with RC Arrays of RC Arraysimport mir.ndslice.fuse; import mir.ndslice.slice; import mir.ndslice.topology: map; import mir.rc.array; Slice!(const(double)*, 2) conv(RCArray!(const RCArray!(const double)) a) { return a[].map!"a[]".fuse; }
- template
fuseAs
(T, Dimensions...)
templatercfuseAs
(T, Dimensions...) - Fuses ndrange r into GC-allocated (fuseAs) or RC-allocated (rcfuseAs) ndslice. Can be used to join rows or columns into a matrix.Parameters:
T output type of ndslice elements Dimensions (optional) indices of dimensions to be brought to the first position Returns:ndsliceExamples:import mir.ndslice.fuse; import mir.ndslice.slice : Contiguous, Slice; import mir.ndslice.topology: iota; import mir.rc.array: RCI; 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.fuseAs!double; auto rcmatrix = ror.rcfuseAs!double; // nogc version assert(matrix == [3, 4].iota); assert(rcmatrix == [3, 4].iota); static assert(ror.fuseAs!double == [3, 4].iota); // CTFE-able // matrix is contiguos static assert(is(typeof(matrix) == Slice!(double*, 2))); static assert(is(typeof(rcmatrix) == Slice!(RCI!double, 2)));
- template
fuseImpl
(bool RC, T_, Dimensions...) -
- auto
fuseImpl
(NDRange)(NDRanger
)
if (hasShape!NDRange); - Parameters:
NDRange r
parallelotope (ndrange) with length/shape and input range primitives.
- auto
fuseCells
(S)(Scells
); - 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:1Dimport 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:2Dimport mir.ndslice.topology: iota; import mir.ndslice.chunks; auto sl = iota(11, 17); assert(sl.chunks!(0, 1)(3, 4).fuseCells == sl);
Copyright © 2016-2022 by Ilya Yaroshenko | Page generated by
Ddoc on Tue Jan 11 06:37:10 2022