The OpenD Programming Language

mir_slice.opIndexOpAssign

Op Assignment op= of a value of Slice type to a fully defined slice.

  1. auto ref opIndexOpAssign(T value, size_t[N] _indices)
  2. void opIndexOpAssign(Slice!(RIterator, RN, rkind) value, Slices slices)
    struct mir_slice(Iterator_, size_t N_ = 1, SliceKind kind_ = Contiguous, Labels_...)
    return scope
    static if(isMutable!DeepElement)
    void
    opIndexOpAssign
    (
    string op
    RIterator
    SliceKind rkind
    size_t RN
    Slices...
    )
    (
    Slice!(RIterator, RN, rkind) value
    ,
    Slices slices
    )
    if (
    isFullPureSlice!Slices ||
    isIndexedSlice!Slices
    )
    if (
    0 < N_ &&
    N_ < 255
    &&
    !(
    kind_ == Canonical &&
    N_ == 1
    )
    &&
    Labels_.length <= N_
    &&
    isIterator!Iterator_
    )
  3. void opIndexOpAssign(T[] value, Slices slices)
  4. void opIndexOpAssign(T value, Slices slices)
  5. void opIndexOpAssign(T concatenation, Slices slices)

Examples

import mir.ndslice.allocation;
auto a = slice!int(2, 3);
auto b = [1, 2, 3, 4].sliced(2, 2);

a[0..$, 0..$-1] += b;
assert(a == [[1, 2, 0], [3, 4, 0]]);

a[0..$, 0..$-1] += b[0];
assert(a == [[2, 4, 0], [4, 6, 0]]);

a[1, 0..$-1] += b[1];
assert(a[1] == [7, 10, 0]);

a[1, 0..$-1][] += b[0];
assert(a[1] == [8, 12, 0]);

Left slice is packed

import mir.ndslice.allocation : slice;
import mir.ndslice.topology : blocks, iota;
auto a = slice!size_t(4, 4);
a.blocks(2, 2)[] += iota(2, 2);

assert(a ==
        [[0, 0, 1, 1],
         [0, 0, 1, 1],
         [2, 2, 3, 3],
         [2, 2, 3, 3]]);

Both slices are packed

import mir.ndslice.allocation : slice;
import mir.ndslice.topology : blocks, iota, pack;
auto a = slice!size_t(4, 4);
a.blocks(2, 2)[] += iota(2, 2, 2).pack!1;

assert(a ==
        [[0, 1, 2, 3],
         [0, 1, 2, 3],
         [4, 5, 6, 7],
         [4, 5, 6, 7]]);

Meta