makeNdarray

Allocates a common n-dimensional array using data from a slice.

@optmath
makeNdarray
(
T
Allocator
Iterator
size_t N
SliceKind kind
)
(
auto ref Allocator alloc
,
Slice!(Iterator, N, kind) slice
)

Parameters

alloc Allocator

allocator (optional)

slice Slice!(Iterator, N, kind)

slice

Return Value

Type: auto

multidimensional D array

Examples

import std.experimental.allocator;
import std.experimental.allocator.mallocator;
import mir.ndslice.topology : iota;

auto slice = iota(3, 4);
auto m = Mallocator.instance.makeNdarray!long(slice);

static assert(is(typeof(m) == long[][]));

static immutable ar = [[0L, 1, 2, 3], [4L, 5, 6, 7], [8L, 9, 10, 11]];
assert(m == ar);

foreach (ref row; m)
    Mallocator.instance.dispose(row);
Mallocator.instance.dispose(m);

Meta