Collapsing n-dimensional array to linear (1 dimensional)

Ilya via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 22 16:28:05 PST 2016


On Friday, 22 January 2016 at 12:07:11 UTC, abad wrote:
> Let's say I have an array like this:
>
> int[][][] array;
>
> And I want to generate a linear int[] based on its data. Is 
> there a standard library method for achieving this, or must I 
> iterate over the array manually?
>
> What I'm thinking of is something like this:
>
> int[] onedim = std.array.collapse(array);

You may want to look at upcoming Multidimensional Random Access 
Ranges, `std.experimental.ndslice` package. They are available 
with DMD 2.070 beta.

Pacakge has `reshape` and `byElement` functions.

Docs: 
http://dlang.org/phobos-prerelease/std_experimental_ndslice.html

Ilya


More information about the Digitalmars-d-learn mailing list