The OpenD Programming Language

multivariateNormalVar

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]`)

Operator OverloadingExamples at N == 3
An interval is a part of a sequence of type i .. j.
An index is a part of a sequence of type i.
A partially defined slice is a sequence composed of intervals and indices with an overall length strictly less than N.
A fully defined index is a sequence composed only of indices with an overall length equal to N.
A fully defined slice is an empty sequence or a sequence composed of indices and at least one interval with an overall length equal to N.
An indexed slice is syntax sugar for indexed and cartesian.
  1. MultivariateNormalVariable!T multivariateNormalVar(Slice!(const(T)*) mu, Slice!(T*, 2) sigma, bool chol)
    static if(is(typeof( )))
    multivariateNormalVar
    (
    T
    )
    (
    Slice!(const(T)*) mu
    ,
    Slice!(T*, 2) sigma
    ,
    bool chol = false
    )
  2. MultivariateNormalVariable!T multivariateNormalVar(Slice!(T*, 2) sigma, bool chol)

See Also

iota.

Internal Binary Representation

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 slice

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

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.

Universal slice

A row-major tensor that stores the strides for all dimensions. NumPy strides are Universal.

Internal Representation for Universal Slices

Type definition

Slice!(Iterator, N, Universal)

Schema

Slice!(Iterator, N, Universal)
    size_t[N]     _lengths
    sizediff_t[N] _strides
    Iterator      _iterator
Example

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

Internal Representation for Canonical Slices

Type definition

Slice!(Iterator, N, Canonical)

Schema

Slice!(Iterator, N, Canonical)
    size_t[N]       _lengths
    sizediff_t[N-1] _strides
    Iterator        _iterator

Internal Representation for Contiguous Slices

Type definition

Slice!(Iterator, N)

Schema

Slice!(Iterator, N, Contiguous)
    size_t[N]     _lengths
    sizediff_t[0] _strides
    Iterator      _iterator

Meta