The OpenD Programming Language

mir.ndslice.dynamic

This is a submodule of mir.ndslice.

Operators only change strides and lengths of a slice. The range of a slice remains unmodified. All operators return slice as the type of the argument, maybe except slice kind.

Transpose operators

Function NameDescription
transposedPermutes dimensions.
iota(3, 4, 5, 6, 7).transposed!(4, 0, 1).shape returns [7, 3, 4, 5, 6].
swappedSwaps dimensions
iota(3, 4, 5).swapped!(1, 2).shape returns [3, 5, 4].
evertedReverses the order of dimensions
iota(3, 4, 5).everted.shape returns [5, 4, 3].

See also evertPack.

Iteration operators

Function NameDescription
stridedMultiplies the stride of a selected dimension by a factor.
iota(13, 40).strided!(0, 1)(2, 5).shape equals to [7, 8].
reversedReverses the direction of iteration for selected dimensions.
slice.reversed!0 returns the slice with reversed direction of iteration for top level dimension.
allReversedReverses the direction of iteration for all dimensions.
iota(4, 5).allReversed equals to 20.iota.retro.sliced(4, 5).

Other operators

Function NameDescription
rotatedRotates two selected dimensions by k*90 degrees.
iota(2, 3).rotated equals to [[2, 5], [1, 4], [0, 3]].
dropToHypercubeReturns maximal multidimensional cube of a slice.
normalizeStructureReverses iteration order for dimensions with negative strides, they become not negative; and sorts dimensions according to the strides, dimensions with larger strides are going first.

Bifacial operators

Some operators are bifacial, i.e. they have two versions: one with template parameters, and another one with function parameters. Versions with template parameters are preferable because they allow compile time checks and can be optimized better.

$(TR $(TDNW $(LREF swapped)) $(TD No) $(TD <tt class="inline-code">slice.swapped!(2, 3)</tt>) $(TD <tt class="inline-code">slice.swapped(2, 3)</tt>)) $(TR $(TDNW $(LREF rotated)) $(TD No) $(TD <tt class="inline-code">slice.rotated!(2, 3)(-1)</tt>) $(TD <tt class="inline-code">slice.rotated(2, 3, -1)</tt>)) $(TR $(TDNW $(LREF strided)) $(TD Yes/No) $(TD <tt class="inline-code">slice.strided!(1, 2)(20, 40)</tt>) $(TD <tt class="inline-code">slice.strided(1, 20).strided(2, 40)</tt>)) $(TR $(TDNW $(LREF transposed)) $(TD Yes) $(TD <tt class="inline-code">slice.transposed!(1, 4, 3)</tt>) $(TD <tt class="inline-code">slice.transposed(1, 4, 3)</tt>)) $(TR $(TDNW $(LREF reversed)) $(TD Yes) $(TD <tt class="inline-code">slice.reversed!(0, 2)</tt>) $(TD <tt class="inline-code">slice.reversed(0, 2)</tt>))

Function NameVariadicTemplateFunction

Bifacial interface of drop, dropBack dropExactly, and dropBackExactly is identical to that of strided.

Bifacial interface of dropOne and dropBackOne is identical to that of reversed.

Members

Functions

allReversed
Slice!(Iterator, N, Universal) allReversed(Slice!(Iterator, N, kind) _slice)

Reverses the direction of iteration for all dimensions.

dropToHypercube
Slice!(Iterator, N, kind) dropToHypercube(Slice!(Iterator, N, kind) slice)
Slice!(Iterator, N, Canonical) dropToHypercube(Slice!(Iterator, N) slice)

Returns maximal multidimensional cube.

everted
auto everted(Slice!(Iterator, N, kind) _slice)

Reverses the order of dimensions.

normalizeStructure
bool normalizeStructure(Slice!(Iterator, N, kind) slice)

Reverses iteration order for dimensions with negative strides, they become not negative; and sorts dimensions according to the strides, dimensions with larger strides are going first.

reversed
Slice!(Iterator, N, Universal) reversed(Slice!(Iterator, N, kind) _slice, size_t[M] dimensions)
auto reversed(Slice!(Iterator, N, kind) slice)

Reverses the direction of iteration for selected dimensions.

rotated
auto rotated(Slice!(Iterator, N, kind) _slice, size_t dimensionA, size_t dimensionB, sizediff_t k)
Slice!(Iterator, 2, Universal) rotated(Slice!(Iterator, 2, kind) slice, sizediff_t k)

Rotates two selected dimensions by k*90 degrees. The order of dimensions is important. If the slice has two dimensions, the default direction is counterclockwise.

strided
auto strided(Slice!(Iterator, N, kind) slice, ptrdiff_t factor)
Slice!(Iterator, N, Universal) strided(Slice!(Iterator, N, kind) _slice, size_t dimension, ptrdiff_t factor)

Multiplies the stride of the selected dimension by a factor.

swapped
auto swapped(Slice!(Iterator, N, kind) _slice, size_t dimensionA, size_t dimensionB)
Slice!(Iterator, 2, Universal) swapped(Slice!(Iterator, 2, kind) slice)

Swaps two dimensions.

transposed
auto transposed(Slice!(Iterator, N, kind) _slice, size_t[M] dimensions)
Slice!(Iterator, 2, Universal) transposed(Slice!(Iterator, 2, kind) slice)

N-dimensional transpose operator. Brings selected dimensions to the first position.

Templates

reversed
template reversed(Dimensions...)

Reverses the direction of iteration for selected dimensions.

rotated
template rotated(size_t dimensionA, size_t dimensionB)

Rotates two selected dimensions by k*90 degrees. The order of dimensions is important. If the slice has two dimensions, the default direction is counterclockwise.

strided
template strided(Dimensions...)

Multiplies the stride of the selected dimension by a factor.

swapped
template swapped(size_t dimensionA, size_t dimensionB)

Swaps two dimensions.

transposed
template transposed(Dimensions...)

N-dimensional transpose operator. Brings selected dimensions to the first position.

Meta

Authors

Ilia Ki