resize

Returns a resized n-dimensional slice s with new size. When new size is larger, new slice is padded with 0. When new size is smaller, new slice is just a subslice of s.

pure
resize
(
S
)
(
S s
,
size_t size
)
if (
isSlice!S
)
out (ret) { import mir.algorithm.iteration : all; assert (ret.length == size); if (s.length < size) assert (ret[s.length .. $].all!"a == 0"); }

Parameters

s S

n-dimensional slice

size size_t

new size of s

Return Value

Type: auto

new slice with new length

TODO: support n-dimensional new shape

Examples

import mir.ndslice.fuse : fuse;
import mir.ndslice.slice : sliced;

assert([1,2].sliced.resize(3) == [1, 2, 0]);
assert([1,2].sliced.resize(2) == [1, 2]);
assert([1,2].sliced.resize(1) == [1]);

assert([[1,2],[3,4]].fuse.resize(3) == [[1,2], [3,4], [0,0]]);
assert([[1,2],[3,4]].fuse.resize(2) == [[1,2], [3,4]]);
assert([[1,2],[3,4]].fuse.resize(1) == [[1,2]]);

assert([1,2].sliced.resize(0) == [].sliced!int);
assert([].sliced!int.resize(3) == [0,0,0]);

Meta