iota.
Multidimensional Slice is a structure that consists of lengths, strides, and a iterator (pointer).
FieldIterator shell is used to wrap fields and random access ranges. FieldIterator contains a shift of the current initial element of a multidimensional slice and the field itself.
With the exception of mir.ndslice.allocation module, no functions in this package move or copy data. The operations are only carried out on lengths, strides, and pointers. If a slice is defined over a range, only the shift of the initial element changes instead of the range.
Mir n-dimensional Slices can be one of the three kinds.
Contiguous in memory (or in a user-defined iterator's field) row-major tensor that doesn't store strides because they can be computed on the fly using lengths. The row stride is always equaled 1.
Canonical slice as contiguous in memory (or in a user-defined iterator's field) rows of a row-major tensor, it doesn't store the stride for row dimension because it is always equaled 1. BLAS/LAPACK matrices are Canonical but originally have column-major order. In the same time you can use 2D Canonical Slices with LAPACK assuming that rows are columns and columns are rows.
A row-major tensor that stores the strides for all dimensions. NumPy strides are Universal.
Type definition
Slice!(Iterator, N, Universal)
Schema
Slice!(Iterator, N, Universal) size_t[N] _lengths sizediff_t[N] _strides Iterator _iterator
Definitions
import mir.ndslice; auto a = new double[24]; Slice!(double*, 3, Universal) s = a.sliced(2, 3, 4).universal; Slice!(double*, 3, Universal) t = s.transposed!(1, 2, 0); Slice!(double*, 3, Universal) r = t.reversed!1;
Representation
s________________________ lengths[0] ::= 2 lengths[1] ::= 3 lengths[2] ::= 4 strides[0] ::= 12 strides[1] ::= 4 strides[2] ::= 1 iterator ::= &a[0] t____transposed!(1, 2, 0) lengths[0] ::= 3 lengths[1] ::= 4 lengths[2] ::= 2 strides[0] ::= 4 strides[1] ::= 1 strides[2] ::= 12 iterator ::= &a[0] r______________reversed!1 lengths[0] ::= 2 lengths[1] ::= 3 lengths[2] ::= 4 strides[0] ::= 12 strides[1] ::= -4 strides[2] ::= 1 iterator ::= &a[8] // (old_strides[1] * (lengths[1] - 1)) = 8
Type definition
Slice!(Iterator, N, Canonical)
Schema
Slice!(Iterator, N, Canonical) size_t[N] _lengths sizediff_t[N-1] _strides Iterator _iterator
Type definition
Slice!(Iterator, N)
Schema
Slice!(Iterator, N, Contiguous) size_t[N] _lengths sizediff_t[0] _strides Iterator _iterator
Presents an n-dimensional view over a range.
Definitions
In order to change data in a slice using overloaded operators such as =, +=, ++, a syntactic structure of type <slice to change>[<index and interval sequence...>] must be used. It is worth noting that just like for regular arrays, operations a = b and a[] = b have different meanings. In the first case, after the operation is carried out, a simply points at the same data as b does, and the data which a previously pointed at remains unmodified. Here, а and b must be of the same type. In the second case, a points at the same data as before, but the data itself will be changed. In this instance, the number of dimensions of b may be less than the number of dimensions of а; and b can be a Slice, a regular multidimensional array, or simply a value (e.g. a number).
In the following table you will find the definitions you might come across in comments on operator overloading.
$(STD `2..$-3`, `0..4`)
$(STD `3`, `$-1`)
$(STD `[3]`, `[0..$]`, `[3, 3]`, `[0..$,0..3]`, `[0..$,2]`)
$(STD `[2,3,1]`)
$(STD `[]`, `[3..$,0..3,0..$-1]`, `[2,0..$,1]`)
$(STD `[anNdslice]`, `[$.iota, anNdsliceForCartesian1, $.iota]`)