The OpenD Programming Language

mir_slice.opIndexAssign

Assignment of a value of Slice type to a fully defined slice.

  1. void opIndexAssign(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
    opIndexAssign
    (
    RIterator
    size_t RN
    SliceKind rkind
    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_
    )
  2. void opIndexAssign(T[] value, Slices slices)
  3. void opIndexAssign(T concatenation, Slices slices)
  4. void opIndexAssign(T value, Slices slices)
  5. auto ref opIndexAssign(T value, size_t[N] _indices)
  6. auto ref opIndexAssign(DeepElement value, size_t[N] _indices)

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

// fills both rows with b[0]
a[0..$, 0..$-1] = b[0];
assert(a == [[1, 2, 0], [1, 2, 0]]);

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

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

Left slice is packed

import mir.ndslice.topology : blocks, iota;
import mir.ndslice.allocation : slice;
auto a = slice!int(4, 4);
a.blocks(2, 2)[] = iota!int(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.topology : blocks, iota, pack;
import mir.ndslice.allocation : slice;
auto a = slice!int(4, 4);
a.blocks(2, 2)[] = iota!int(2, 2, 2).pack!1;

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

Meta