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.concatenation
This is a submodule of mir.ndslice.
The module contains .concatenation routine.
It construct Concatenation structure that can be
assigned to an ndslice of the same shape with [] =  or [] op= .
slicedNdField  can be used to construct ndslice view on top of Concatenation.
slice  has special overload for Concatenation that can be used to allocate new ndslice.
| Function Name | Description | 
|---|---|
| .concatenation | Creates a Concatenation view of multiple slices. | 
| pad | Pads with a constant value. | 
| padEdge | Pads with the edge values of slice. | 
| padSymmetric | Pads with the reflection of the slice mirrored along the edge of the slice. | 
| padWrap | Pads with the wrap of the slice along the axis. The first values are used to pad the end and the end values are used to pad the beginning. | 
License: 
Authors: 
Ilya Yaroshenko
See Also: 
fuse submodule.
- autoconcatenation(size_t dim = 0, Slices...)(Slicesslices);
- Creates a Concatenation view of multiple slices.Parameters:Slices slicestuple of slices and/or concatenations. Returns:Examples:Concatenation of slices with different dimmensions.import mir.ndslice.allocation: slice; import mir.ndslice.topology: repeat, iota; // 0 0 0 auto vector = size_t.init.repeat([3]); // 1 2 3 // 4 5 6 auto matrix = iota([2, 3], 1); assert(concatenation(vector, matrix).slice == [ [0, 0, 0], [1, 2, 3], [4, 5, 6], ]); vector.popFront; assert(concatenation!1(vector, matrix).slice == [ [0, 1, 2, 3], [0, 4, 5, 6], ]); Examples:Multidimensionalimport mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; import mir.ndslice.slice : slicedNdField; // 0, 1, 2 // 3, 4, 5 auto a = iota(2, 3); // 0, 1 // 2, 3 auto b = iota(2, 2); // 0, 1, 2, 3, 4 auto c = iota(1, 5); // 0, 1, 2, 0, 1 // 3, 4, 5, 2, 3 // // 0, 1, 2, 3, 4 // construction phase auto s = concatenation(concatenation!1(a, b), c); // allocation phase auto d = s.slice; assert(d == [ [0, 1, 2, 0, 1], [3, 4, 5, 2, 3], [0, 1, 2, 3, 4], ]); // optimal fragmentation for output/writing/buffering auto testData = [ [0, 1, 2], [0, 1], [3, 4, 5], [2, 3], [0, 1, 2, 3, 4], ]; size_t i; s.forEachFragment!((fragment) { pragma(inline, false); //reduces template bloat assert(fragment == testData[i++]); }); assert(i == testData.length); // lazy ndslice view assert(s.slicedNdField == d); Examples:1Dimport mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; import mir.ndslice.slice : slicedNdField; size_t i; auto a = 3.iota; auto b = iota([6], a.length); auto s = concatenation(a, b); assert(s.length == a.length + b.length); // fast iteration with until s.until!((elem){ assert(elem == i++); return false; }); // allocation with slice assert(s.slice == s.length.iota); // 1D or multidimensional assignment auto d = slice!double(s.length); d[] = s; assert(d == s.length.iota); d.opIndexOpAssign!"+"(s); assert(d == iota([s.length], 0, 2)); // lazy ndslice view assert(s.slicedNdField == s.length.iota); 
- enum boolisConcatenation(T);
- enum size_tconcatenationDimension(T : Concatenation!(dim, Slices), size_t dim, Slices...);
- structConcatenation(size_t dim, Slices...) if (Slices.length > 1);
- 
- Slices_slices;
- Slices and sub-concatenations
- const @property autolightConst()();
- immutable @property autolightImmutable()();
- const @property size_tlength(size_t d = 0)();
- Length primitive
- const @property size_telementCount()();
- Total elements count in the concatenation.
- const @property size_t[N]shape()();
- Shape of the concatenation.
- const @property boolempty(size_t d = 0)();
 voidpopFront(size_t d = 0)();
 autofront(size_t d = 0)();
- Multidimensional input range primitives
- autoopIndex()(size_t[N]indices...);
- Simplest multidimensional random access primitive
 
- autoapplyFront(size_t d = 0, alias fun, size_t dim, Slices...)(Concatenation!(dim, Slices)st);
- Performs fun(st.front!d).This functions is useful whenst.front!d has not a common type and fails to compile. Can be used instead of .Concatenation.front
- autopad(string direction = "both", S, T, size_t N)(Ss, Tvalue, size_t[N]lengths...)
 if (hasShape!S && (N == (typeof(S.shape)).length));
- Pads with a constant value.Parameters:direction padding direction. Direction can be one of the following values: "both", "pre", and "post". S sSlice or ndField T valueinitial value for padding size_t[N] lengthslist of lengths Returns:See Also:.concatenation examples.Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([3], 1) .pad(0, [2]) .slice; assert(pad == [0, 0, 1, 2, 3, 0, 0]); Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([2, 2], 1) .pad(0, [2, 1]) .slice; assert(pad == [ [0, 0, 0, 0], [0, 0, 0, 0], [0, 1, 2, 0], [0, 3, 4, 0], [0, 0, 0, 0], [0, 0, 0, 0]]); 
- templatepad(size_t[] dimensions, string[] directions) if (dimensions.length && (dimensions.length == directions.length))
- Pads with a constant value.Parameters:dimensions dimensions to pad. directions padding directions. Direction can be one of the following values: "both", "pre", and "post". Returns:See Also:.concatenation examples.Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([2, 2], 1) .pad!([1], ["pre"])(0, [2]) .slice; assert(pad == [ [0, 0, 1, 2], [0, 0, 3, 4]]); Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([2, 2], 1) .pad!([0, 1], ["both", "post"])(0, [2, 1]) .slice; assert(pad == [ [0, 0, 0], [0, 0, 0], [1, 2, 0], [3, 4, 0], [0, 0, 0], [0, 0, 0]]); - autopad(S, T)(Ss, Tvalue, size_t[dimensions.length]lengths...);
- Parameters:S sSlice or ndField T valueinitial value for padding size_t[dimensions.length] lengthslist of lengths Returns:See Also:.concatenation examples.
 
- autopadWrap(string direction = "both", Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind)s, size_t[N]lengths...);
- Pads with the wrap of the slice along the axis. The first values are used to pad the end and the end values are used to pad the beginning.Parameters:direction padding direction. Direction can be one of the following values: "both", "pre", and "post". Slice!(Iterator, N, kind) sSlice size_t[N] lengthslist of lengths for each dimension. Each length must be less or equal to the corresponding slice length. Returns:See Also:.concatenation examples.Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([3], 1) .padWrap([2]) .slice; assert(pad == [2, 3, 1, 2, 3, 1, 2]); Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([2, 2], 1) .padWrap([2, 1]) .slice; assert(pad == [ [2, 1, 2, 1], [4, 3, 4, 3], [2, 1, 2, 1], [4, 3, 4, 3], [2, 1, 2, 1], [4, 3, 4, 3]]); 
- templatepadWrap(size_t[] dimensions, string[] directions) if (dimensions.length && (dimensions.length == directions.length))
- Pads with the wrap of the slice along the axis. The first values are used to pad the end and the end values are used to pad the beginning.Parameters:dimensions dimensions to pad. directions padding directions. Direction can be one of the following values: "both", "pre", and "post". Returns:See Also:.concatenation examples.Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([2, 3], 1) .padWrap!([1], ["pre"])([1]) .slice; assert(pad == [ [3, 1, 2, 3], [6, 4, 5, 6]]); Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([2, 2], 1) .padWrap!([0, 1], ["both", "post"])([2, 1]) .slice; assert(pad == [ [1, 2, 1], [3, 4, 3], [1, 2, 1], [3, 4, 3], [1, 2, 1], [3, 4, 3]]); - autopadWrap(Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind)s, size_t[dimensions.length]lengths...);
- Parameters:Slice!(Iterator, N, kind) sSlice size_t[dimensions.length] lengthslist of lengths for each dimension. Each length must be less or equal to the corresponding slice length. Returns:See Also:.concatenation examples.
 
- autopadSymmetric(string direction = "both", Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind)s, size_t[N]lengths...);
- Pads with the reflection of the slice mirrored along the edge of the slice.Parameters:direction padding direction. Direction can be one of the following values: "both", "pre", and "post". Slice!(Iterator, N, kind) sSlice size_t[N] lengthslist of lengths for each dimension. Each length must be less or equal to the corresponding slice length. Returns:See Also:.concatenation examples.Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([3], 1) .padSymmetric([2]) .slice; assert(pad == [2, 1, 1, 2, 3, 3, 2]); Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([2, 2], 1) .padSymmetric([2, 1]) .slice; assert(pad == [ [3, 3, 4, 4], [1, 1, 2, 2], [1, 1, 2, 2], [3, 3, 4, 4], [3, 3, 4, 4], [1, 1, 2, 2]]); 
- templatepadSymmetric(size_t[] dimensions, string[] directions) if (dimensions.length && (dimensions.length == directions.length))
- Pads with the reflection of the slice mirrored along the edge of the slice.Parameters:dimensions dimensions to pad. directions padding directions. Direction can be one of the following values: "both", "pre", and "post". Returns:See Also:.concatenation examples.Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([2, 3], 1) .padSymmetric!([1], ["pre"])([2]) .slice; assert(pad == [ [2, 1, 1, 2, 3], [5, 4, 4, 5, 6]]); Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([2, 2], 1) .padSymmetric!([0, 1], ["both", "post"])([2, 1]) .slice; assert(pad == [ [3, 4, 4], [1, 2, 2], [1, 2, 2], [3, 4, 4], [3, 4, 4], [1, 2, 2]]); - autopadSymmetric(Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind)s, size_t[dimensions.length]lengths...);
- Parameters:Slice!(Iterator, N, kind) sSlice size_t[dimensions.length] lengthslist of lengths for each dimension. Each length must be less or equal to the corresponding slice length. Returns:See Also:.concatenation examples.
 
- autopadEdge(string direction = "both", Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind)s, size_t[N]lengths...);
- Pads with the edge values of slice.Parameters:direction padding direction. Direction can be one of the following values: "both", "pre", and "post". Slice!(Iterator, N, kind) sSlice size_t[N] lengthslist of lengths for each dimension. Returns:See Also:.concatenation examples.Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([3], 1) .padEdge([2]) .slice; assert(pad == [1, 1, 1, 2, 3, 3, 3]); Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([2, 2], 1) .padEdge([2, 1]) .slice; assert(pad == [ [1, 1, 2, 2], [1, 1, 2, 2], [1, 1, 2, 2], [3, 3, 4, 4], [3, 3, 4, 4], [3, 3, 4, 4]]); 
- templatepadEdge(size_t[] dimensions, string[] directions) if (dimensions.length && (dimensions.length == directions.length))
- Pads with the edge values of slice.Parameters:dimensions dimensions to pad. directions padding directions. Direction can be one of the following values: "both", "pre", and "post". Returns:See Also:.concatenation examples.Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([2, 3], 1) .padEdge!([0], ["pre"])([2]) .slice; assert(pad == [ [1, 2, 3], [1, 2, 3], [1, 2, 3], [4, 5, 6]]); Examples:import mir.ndslice.allocation: slice; import mir.ndslice.topology: iota; auto pad = iota([2, 2], 1) .padEdge!([0, 1], ["both", "post"])([2, 1]) .slice; assert(pad == [ [1, 2, 2], [1, 2, 2], [1, 2, 2], [3, 4, 4], [3, 4, 4], [3, 4, 4]]); - autopadEdge(Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind)s, size_t[dimensions.length]lengths...);
- Parameters:Slice!(Iterator, N, kind) sSlice size_t[dimensions.length] lengthslist of lengths for each dimension. Returns:See Also:.concatenation examples.
 
- templateforEachFragment(alias pred)
- Iterates 1D fragments in Slice or Concatenation in optimal for buffering way.See Also:.concatenation examples.- voidforEachFragment(Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind)sl);
- Specialization for slicesParameters:Slice!(Iterator, N, kind) slSlice 
- voidforEachFragment(size_t dim, Slices...)(Concatenation!(dim, Slices)st);
- Specialization for concatenationsParameters:Concatenation!(dim, Slices) stConcatenation 
 
- templateuntil(alias pred)
- Iterates elements in Slice or Concatenation until pred returns true.Returns:false if pred returned false for all elements and true otherwise.See Also:.concatenation examples.- booluntil(Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind)sl);
- Specialization for slicesParameters:Slice!(Iterator, N, kind) slSlice 
- booluntil(size_t dim, Slices...)(Concatenation!(dim, Slices)st);
- Specialization for concatenationsParameters:Concatenation!(dim, Slices) stConcatenation 
 
Copyright © 2016-2022 by Ilya Yaroshenko | Page generated by
Ddoc on Tue Jan 11 06:37:10 2022