The OpenD Programming Language

concatenation

Creates a Concatenation view of multiple slices.

Can be used in combination with itself, until, slice, and Slice assignment.

concatenation
(
size_t dim = 0
Slices...
)
(
Slices slices
)

Parameters

slices Slices

tuple of slices and/or concatenations.

Return Value

Type: auto

Examples

Concatenation of slices with different dimmensions.

import mir.ndslice.allocation: slice;
import mir.ndslice.topology: repeat, iota;

// 0 0 0
auto vector = size_t.init.repeat([3]);

// 1 2 3
// 4 5 6
auto matrix = iota([2, 3], 1);

auto c0 = concatenation(vector, matrix);

assert(c0.slice == [
    [0, 0, 0],
    [1, 2, 3],
    [4, 5, 6],
]);

vector.popFront;
auto c1 = concatenation!1(vector, matrix);
assert(c1.slice == [
    [0, 1, 2, 3],
    [0, 4, 5, 6],
]);

auto opIndexCompiles0 = c0[];
auto opIndexCompiles1 = c1[];

auto opIndexCompilesForConst0 = (cast(const)c0)[];
auto opIndexCompilesForConst1 = (cast(const)c1)[];

Multidimensional

import mir.ndslice.allocation: slice;
import mir.ndslice.topology: iota;
import mir.ndslice.slice : slicedNdField;

// 0, 1, 2
// 3, 4, 5
auto a = iota(2, 3);
// 0, 1
// 2, 3
auto b = iota(2, 2);
// 0, 1, 2, 3, 4
auto c = iota(1, 5);

// 0, 1, 2,   0, 1
// 3, 4, 5,   2, 3
// 
// 0, 1, 2, 3, 4
// construction phase
auto s = concatenation(concatenation!1(a, b), c);

// allocation phase
auto d = s.slice;
assert(d == [
    [0, 1, 2, 0, 1],
    [3, 4, 5, 2, 3],
    [0, 1, 2, 3, 4],
    ]);

// optimal fragmentation for output/writing/buffering
auto testData = [
    [0, 1, 2], [0, 1],
    [3, 4, 5], [2, 3],
    [0, 1, 2, 3, 4],
];
size_t i;
s.forEachFragment!((fragment) {
    pragma(inline, false); //reduces template bloat
    assert(fragment == testData[i++]);
    });
assert(i == testData.length);

// lazy ndslice view
assert(s.slicedNdField == d);

1D

import mir.ndslice.allocation: slice;
import mir.ndslice.topology: iota;
import mir.ndslice.slice : slicedNdField;

size_t i;
auto a = 3.iota;
auto b = iota([6], a.length);
auto s = concatenation(a, b);
assert(s.length == a.length + b.length);
// fast iteration with until
s.until!((elem){ assert(elem == i++); return false; });
// allocation with slice
assert(s.slice == s.length.iota);
// 1D or multidimensional assignment
auto d = slice!double(s.length);
d[] = s;
assert(d == s.length.iota);
d.opIndexOpAssign!"+"(s);
assert(d == iota([s.length], 0, 2));

// lazy ndslice view
assert(s.slicedNdField == s.length.iota);

Meta