The OpenD Programming Language

mir.ndslice.topology

This is a submodule of mir.ndslice.

Selectors create new views and iteration patterns over the same data, without copying.

Sequence Selectors

Function NameDescription
cycleCycle repeates 1-dimensional field/range/array/slice in a fixed length 1-dimensional slice
iotaContiguous Slice with initial flattened (contiguous) index.
linspaceEvenly spaced numbers over a specified interval.
magicMagic square.
ndiotaContiguous Slice with initial multidimensional index.
repeatSlice with identical values

Shape Selectors

Function NameDescription
blocksn-dimensional slice composed of n-dimensional non-overlapping blocks. If the slice has two dimensions, it is a block matrix.
diagonal1-dimensional slice composed of diagonal elements
dropBordersDrops borders for all dimensions.
reshapeNew slice view with changed dimensions
squeezeNew slice view of an n-dimensional slice with dimension removed
unsqueezeNew slice view of an n-dimensional slice with a dimension added
windowsn-dimensional slice of n-dimensional overlapping windows. If the slice has two dimensions, it is a sliding window.

Members

Aliases

diff
alias diff(size_t lag = 1) = pairwise!(('a' + lag) ~ " - a", lag)

Differences between tensor elements.

pairwise
alias pairwise(alias fun, size_t lag = 1) = slide!(lag + 1, fun)

Pairwise map for tensors.

Enums

ReshapeError
enum ReshapeError

Error codes for reshape.

Functions

antidiagonal
Slice!(Iterator, 1, Universal) antidiagonal(Slice!(Iterator, N, kind) slice)

Returns a 1-dimensional slice over the main antidiagonal of an 2D-dimensional slice. antidiagonal can be generalized with other selectors such as blocks (diagonal blocks) and windows (multi-diagonal slice).

assumeCanonical
Slice!(Iterator, N, Canonical, Labels) assumeCanonical(Slice!(Iterator, N, kind, Labels) slice)

Converts a slice to canonical kind (unsafe).

assumeContiguous
Slice!(Iterator, N, Contiguous, Labels) assumeContiguous(Slice!(Iterator, N, kind, Labels) slice)

Converts a slice to contiguous kind (unsafe).

assumeFieldsHaveZeroShift
auto assumeFieldsHaveZeroShift(Slice!(Iterator, N, kind) slice)
assumeHypercube
void assumeHypercube(Slice!(Iterator, N, kind, Labels) slice)

Helps the compiler to use optimisations related to the shape form

assumeSameShape
void assumeSameShape(T slices)

Helps the compiler to use optimisations related to the shape form

bitpack
auto bitpack(Slice!(Iterator, N, kind) slice)
auto bitpack(T[] array)
auto bitpack(T withAsSlice)

Bitpack slice over an integral slice.

bitwise
auto bitwise(Slice!(Iterator, N, kind) slice)
auto bitwise(T[] array)
auto bitwise(T withAsSlice)

Bitwise slice over an integral slice.

bitwiseField
auto bitwiseField(Field field)

Bitwise field over an integral field.

blocks
Slice!(SliceIterator!(Iterator, N, N == 1 ? Universal : min(kind, Canonical)), N, Universal) blocks(Slice!(Iterator, N, kind) slice, size_t[N] rlengths_)

Returns an n-dimensional slice of n-dimensional non-overlapping blocks. blocks can be generalized with other selectors. For example, blocks in combination with diagonal can be used to get a slice of diagonal blocks. For overlapped blocks, combine windows with strided.

bytegroup
Slice!(BytegroupIterator!(Iterator, group, DestinationType), N, kind) bytegroup(Slice!(Iterator, N, kind) slice)
auto bytegroup(T[] array)
auto bytegroup(T withAsSlice)

Bytegroup slice over an integral slice.

cached
Slice!(CachedIterator!(Iterator, CacheIterator, FlagIterator), N, kind) cached(Slice!(Iterator, N, kind) original, Slice!(CacheIterator, N, kind) caches, Slice!(FlagIterator, N, kind) flags)

Creates a random access cache for lazyly computed elements.

cachedGC
Slice!(CachedIterator!(Iterator, typeof(Iterator.init[0])*, FieldIterator!(BitField!(size_t*))), N) cachedGC(Slice!(Iterator, N) original)
auto cachedGC(Slice!(Iterator, 1, Universal) from)
auto cachedGC(T withAsSlice)

Creates a random access cache for lazyly computed elements.

canonical
Slice!(Iterator, N, N == 1 ? Contiguous : Canonical, Labels) canonical(Slice!(Iterator, N, kind, Labels) slice)

Converts a slice to canonical kind.

cartesian
auto cartesian(NdFields fields)

Cartesian product.

chopped
Slice!(ChopIterator!(Iterator, Sliceable)) chopped(Sliceable sliceable, Slice!Iterator bounds)
auto chopped(Sliceable sliceable, S[] bounds)
auto chopped(Sliceable sliceable, S bounds)

Maps index pairs to subslices.

cycle
auto cycle(Field field, size_t loopLength, size_t length)
auto cycle(Field field, size_t length)
auto cycle(Slice!(Iterator, 1, kind) slice, size_t length)
auto cycle(T[] array, size_t length)
auto cycle(T withAsSlice, size_t length)

Cycle repeates 1-dimensional field/range/array/slice in a fixed length 1-dimensional slice.

diagonal
Slice!(Iterator, 1, N == 1 ? kind : Universal) diagonal(Slice!(Iterator, N, kind) slice)

Returns a 1-dimensional slice over the main diagonal of an n-dimensional slice. diagonal can be generalized with other selectors such as blocks (diagonal blocks) and windows (multi-diagonal slice).

dropBorders
Slice!(Iterator, N, N > 1 && kind == Contiguous ? Canonical : kind, Labels) dropBorders(Slice!(Iterator, N, kind, Labels) slice)

Drops borders for all dimensions.

evertPack
Slice!(SliceIterator!(Iterator, N, outerKind), M, innerKind) evertPack(Slice!(SliceIterator!(Iterator, M, innerKind), N, outerKind) slice)

Reverses the order of dimension packs. This function is used in a functional pipeline with other selectors.

flattened
Slice!(FlattenedIterator!(Iterator, N, kind)) flattened(Slice!(Iterator, N, kind) slice)
Slice!Iterator flattened(Slice!(Iterator, N) slice)
Slice!(StrideIterator!Iterator) flattened(Slice!(Iterator, 1, Universal) slice)

A contiguous 1-dimensional slice of all elements of a slice. flattened iterates existing data. The order of elements is preserved.

indexed
Slice!(IndexIterator!(Iterator, Field), N, kind) indexed(Field source, Slice!(Iterator, N, kind) indices)
auto indexed(Field source, S[] indices)
auto indexed(Field source, S indices)

Takes a field source and a slice indices, and creates a view of source as if its elements were reordered according to indices. indices may include only a subset of the elements of source and may also repeat elements.

iota
Slice!(IotaIterator!I, N) iota(size_t[N] lengths)
Slice!(IotaIterator!sizediff_t, N) iota(size_t[N] lengths, sizediff_t start)
Slice!(StrideIterator!(IotaIterator!sizediff_t), N) iota(size_t[N] lengths, sizediff_t start, size_t stride)
Slice!(IotaIterator!I, N) iota(size_t[N] lengths, I start)
Slice!(StrideIterator!(IotaIterator!I), N) iota(size_t[N] lengths, I start, size_t stride)

Returns a slice, the elements of which are equal to the initial flattened index value.

ipack
Slice!(SliceIterator!(Iterator, N - P, N - P == 1 && kind == Canonical ? Contiguous : kind), P, Universal) ipack(Slice!(Iterator, N, kind) slice)

Creates a packed slice, i.e. slice of slices. Packs the last N - P dimensions. The function does not allocate any data.

linspace
auto linspace(size_t[N] lengths, T[2][N] intervals)

Evenly spaced numbers over a specified interval.

magic
auto magic(size_t length)

Magic square.

ndiota
Slice!(FieldIterator!(ndIotaField!N), N) ndiota(size_t[N] lengths)

Returns a slice, the elements of which are equal to the initial multidimensional index value. For a flattened (contiguous) index, see iota.

pack
Slice!(SliceIterator!(Iterator, P, P == 1 && kind == Canonical ? Contiguous : kind), N - P, Universal) pack(Slice!(Iterator, N, kind) slice)

Creates a packed slice, i.e. slice of slices. Packs the last P dimensions. The function does not allocate any data.

repeat
Slice!(FieldIterator!(RepeatField!T), M, Universal) repeat(T value, size_t[M] lengths)
Slice!(SliceIterator!(Iterator, N, kind), M, Universal) repeat(Slice!(Iterator, N, kind) slice, size_t[M] lengths)

Returns a slice with identical elements. RepeatSlice stores only single value.

reshape
Slice!(Iterator, M, kind) reshape(Slice!(Iterator, N, kind) slice, ptrdiff_t[M] rlengths, int err)

Returns a new slice for the same data with different dimensions.

retro
auto retro(Slice!(Iterator, N, kind) slice)
auto retro(T[] array)
auto retro(T withAsSlice)
auto retro(Range r)

Reverses order of iteration for all dimensions.

stairs
Slice!(StairsIterator!(Iterator, type)) stairs(Slice!Iterator slice, size_t n)
Slice!(StairsIterator!(S*, type)) stairs(S[] slice, size_t n)
auto stairs(S slice, size_t n)

Chops 1D input slice into n chunks with ascending or descending lengths.

stairs
auto stairs(Slice!(Iterator, 2, kind) slice)

Slice composed of rows of lower or upper triangular matrix.

stride
auto stride(Slice!(Iterator, N, kind) slice, ptrdiff_t factor)
auto stride(T[] array, ptrdiff_t factor)
auto stride(T withAsSlice, ptrdiff_t factor)

Strides 1-dimensional slice.

subSlices
Slice!(SubSliceIterator!(Iterator, Sliceable), N, kind) subSlices(Sliceable sliceable, Slice!(Iterator, N, kind) slices)
auto subSlices(Sliceable sliceable, S[] slices)
auto subSlices(Sliceable sliceable, S slices)

Maps index pairs to subslices.

triplets
Slice!(TripletIterator!(Iterator, kind)) triplets(Slice!(Iterator, 1, kind) slice)
Slice!(TripletIterator!(T*)) triplets(T[] slice)
auto triplets(S slice, size_t n)

Constructs a lazy view of triplets with left, center, and right members.

universal
auto universal(Slice!(Iterator, N, kind, Labels) slice)

Converts a slice to universal kind.

unpack
Slice!(Iterator, N + M, min(innerKind, Canonical)) unpack(Slice!(SliceIterator!(Iterator, M, innerKind), N, outerKind) slice)

Unpacks a packed slice.

unsqueeze
Slice!(Iterator, N + 1, kind) unsqueeze(Slice!(Iterator, N, kind) slice, sizediff_t axis)

Constructs a view of an n-dimensional slice with a dimension added at axis. Used to unsqueeze a squeezed slice.

unzip
auto unzip(Slice!(ZipIterator!Iterators, N, kind) slice)

Selects a slice from a zipped slice.

vmap
auto vmap(Slice!(Iterator, N, kind) slice, Callable callable)
auto vmap(T[] array, Callable callable)
auto vmap(T withAsSlice, Callable callable)

Implements the homonym function (also known as transform) present in many languages of functional flavor. The call slice.vmap(fun) returns a slice of which elements are obtained by applying fun for all elements in slice. The original slices are not changed. Evaluation is done lazily.

windows
Slice!(SliceIterator!(Iterator, N, N == 1 ? kind : min(kind, Canonical)), N, Universal) windows(Slice!(Iterator, N, kind) slice, size_t[N] rlengths)

Returns an n-dimensional slice of n-dimensional overlapping windows. windows can be generalized with other selectors. For example, windows in combination with diagonal can be used to get a multi-diagonal slice.

Structs

MapRange
struct MapRange(alias fun, Range)

Implements the homonym function (also known as transform) present in many languages of functional flavor. The call map!(fun)(slice) returns a slice of which elements are obtained by applying fun for all elements in slice. The original slices are not changed. Evaluation is done lazily.

RetroRange
struct RetroRange(Range)

Reverses order of iteration for all dimensions.

Templates

alongDim
template alongDim(SDimensions...)

Returns a slice that can be iterated along dimension. Transposes other dimensions on top and then packs them.

as
template as(T)

Convenience function that creates a lazy view, where each element of the original slice is converted to the type T. It uses map and $(TT to)  composition under the hood.

asKindOf
template asKindOf(SliceKind kind)

Converts a slice to user provided kind.

byDim
template byDim(SDimensions...)

Returns a slice that can be iterated by dimension. Transposes dimensions on top and then packs them.

iota
template iota(I)

Returns a slice, the elements of which are equal to the initial flattened index value.

kronecker
template kronecker(alias fun = product)

Kronecker product.

map
template map(fun...)

Implements the homonym function (also known as transform) present in many languages of functional flavor. The call map!(fun)(slice) returns a slice of which elements are obtained by applying fun for all elements in slice. The original slices are not changed. Evaluation is done lazily.

member
template member(string name)

Field (element's member) projection.

orthogonalReduceField
template orthogonalReduceField(alias fun)

Functional deep-element wise reduce of a slice composed of fields or iterators.

rcmap
template rcmap(fun...)

Implements the homonym function (also known as transform) present in many languages of functional flavor. The call rmap!(fun)(slice) returns an RC array (1D) or RC slice (ND) of which elements are obtained by applying fun for all elements in slice. The original slices are not changed. Evaluation is done eagerly.

slide
template slide(size_t params, alias fun)

Lazy convolution for tensors.

slideAlong
template slideAlong(size_t params, alias fun, SDimensions...)

Lazy convolution for tensors.

squeeze
template squeeze(sizediff_t axis = 0)

Constructs a new view of an n-dimensional slice with dimension axis removed.

stride
template stride(size_t factor = 2)

Strides 1-dimensional slice.

unsqueeze
template unsqueeze(sizediff_t axis = 0)

Constructs a view of an n-dimensional slice with a dimension added at axis. Used to unsqueeze a squeezed slice.

withNeighboursSum
template withNeighboursSum(alias fun = "a + b")

Lazy zip view of elements packed with sum of their neighbours.

zip
template zip(bool sameStrides = false)

Groups slices into a slice of refTuples. The slices must have identical strides or be 1-dimensional.

Detailed Description

Subspace Selectors

Function NameDescription
alongDimReturns a slice that can be iterated along dimension.
byDimReturns a slice that can be iterated by dimension.
packReturns slice of slices.
ipackReturns slice of slices.
unpackMerges two hight dimension packs. See also fuse.
evertPackReverses dimension packs.

SliceKind Selectors

Function NameDescription
asKindOfConverts a slice to a user provied kind SliceKind.
universalConverts a slice to universal SliceKind.
canonicalConverts a slice to canonical SliceKind.
assumeCanonicalConverts a slice to canonical SliceKind. Does only assert checks.
assumeContiguousConverts a slice to contiguous SliceKind. Does only assert checks.
assumeHypercubeHelps the compiler to use optimisations related to the shape form. Does only assert checks.
assumeSameShapeHelps the compiler to use optimisations related to the shape form. Does only assert checks.

Products

Function NameDescription
cartesianCartesian product.
kroneckerKronecker product.

Representation Selectors

Function NameDescription
asConvenience function that creates a lazy view, where each element of the original slice is converted to a type T.
bitpackBitpack slice over an unsigned integral slice.
bitwiseBitwise slice over an unsigned integral slice.
bytegroupGroups existing slice into fixed length chunks and uses them as data store for destination type.
cachedRandom access cache. It is usefull in combiation with map and vmap.
cachedGCRandom access cache auto-allocated in GC heap. It is usefull in combiation with map and vmap.
diffDifferences between vector elements.
flattenedContiguous 1-dimensional slice of all elements of a slice.
mapMultidimensional functional map.
memberField (element's member) projection.
orthogonalReduceFieldFunctional deep-element wise reduce of a slice composed of fields or iterators.
pairwisePairwise map for vectors.
pairwiseMapSubSlicesMaps pairwise index pairs to subslices.
retroReverses order of iteration for all dimensions.
slideLazy convolution for tensors.
slideAlongLazy convolution for tensors.
stairsTwo functions to pack, unpack, and iterate triangular and symmetric matrix storage.
strideStrides 1-dimensional slice.
subSlicesMaps index pairs to subslices.
tripletsConstructs a lazy view of triplets with left, center, and right members. The topology is usefull for Math and Physics.
unzipSelects a slice from a zipped slice.
withNeighboursSumZip view of elements packed with sum of their neighbours.
zipZips slices into a slice of refTuples.

Subspace selectors serve to generalize and combine other selectors easily. For a slice of Slice!(Iterator, N, kind) type slice.pack!K creates a slice of slices of Slice!(kind, [N - K, K], Iterator) type by packing the last K dimensions of the top dimension pack, and the type of element of flattened is Slice!(Iterator, K). Another way to use pack is transposition of dimension packs using evertPack. Examples of use of subspace selectors are available for selectors, Slice.shape, and Slice.elementCount.

Meta

Authors

Ilia Ki, John Michael Hall, Shigeki Karita (original numir code)

Sponsors: Part of this work has been sponsored by Symmetry Investments and Kaleidic Associates.