The OpenD Programming Language

rcfuse

Fuses ndrange r into GC-allocated (fuse) or RC-allocated (rcfuse) ndslice. Can be used to join rows or columns into a matrix.

import mir.ndslice.fuse;
alias rcfuse(Dimensions...) = fuseImpl!(true, void, Dimensions)

Parameters

Dimensions

(optional) indices of dimensions to be brought to the first position

Return Value

ndslice

Examples

import mir.ndslice.fuse;
import mir.ndslice.slice : Contiguous, Slice;
import mir.ndslice.topology: iota, map, as;
import mir.rc.array: RCI;

enum ror = [
        [0, 1, 2, 3],
        [4, 5, 6, 7],
        [8, 9,10,11]];

//  0  1  2  3
//  4  5  6  7
//  8  9 10 11
auto matrix = ror.fuse;

auto rcmatrix = ror.rcfuse; // nogc version

assert(matrix == [3, 4].iota);
assert(rcmatrix == [3, 4].iota);
static assert(ror.fuse == [3, 4].iota); // CTFE-able

// matrix is contiguos
static assert(is(typeof(matrix) == Slice!(int*, 2)));
static assert(is(typeof(rcmatrix) == Slice!(RCI!int, 2)));

/// also works with strings
auto strMatrix = ror.map!(as!string).fuse;
static assert(is(typeof(strMatrix) == Slice!(string*, 2)));
assert(strMatrix.as!int == matrix);

Transposed

import mir.ndslice.fuse;
import mir.ndslice.topology: iota;
import mir.ndslice.dynamic: transposed;
import mir.ndslice.slice : Contiguous, Slice;

enum ror = [
    [0, 1, 2, 3],
    [4, 5, 6, 7],
    [8, 9,10,11]];

//  0  4  8
//  1  5  9
//  2  6 10
//  3  7 11

// `!1` brings dimensions under index 1 to the front (0 index).
auto matrix = ror.fuse!1;

assert(matrix == [3, 4].iota.transposed!1);
// TODO: CTFE
// static assert(ror.fuse!1 == [3, 4].iota.transposed!1); // CTFE-able
// matrix is contiguos
static assert(is(typeof(matrix) == Slice!(int*, 2)));

3D

import mir.ndslice.fuse;
import mir.ndslice.topology: iota;
import mir.ndslice.dynamic: transposed;

auto ror =
  [[[ 0, 1, 2, 3],
    [ 4, 5, 6, 7]],
   [[ 8, 9,10,11],
    [12,13,14,15]]];

auto nd = [2, 2, 4].iota;

assert(ror.fuse == nd);
assert(ror.fuse!2 == nd.transposed!2);
assert(ror.fuse!(1, 2) == nd.transposed!(1, 2));
assert(ror.fuse!(2, 1) == nd.transposed!(2, 1));

Work with RC Arrays of RC Arrays

import mir.ndslice.fuse;
import mir.ndslice.slice;
import mir.ndslice.topology: map;
import mir.rc.array;

Slice!(const(double)*, 2) conv(RCArray!(const RCArray!(const double)) a)
{
    return a[].map!"a[]".fuse;
}

Meta