Mir Slice.shape is not consistent with the actual array shape
jmh530
john.michael.hall at gmail.com
Sun May 24 14:35:33 UTC 2020
On Sunday, 24 May 2020 at 14:21:26 UTC, Pavel Shkadzko wrote:
> [snip]
>
> Sorry for the typo. It should be "auto arrSlice = a.sliced;"
Try using fuse
/+dub.sdl:
dependency "mir-algorithm" version="*"
+/
import std.stdio;
import std.conv;
import std.array: array;
import std.range: chunks;
import mir.ndslice;
int[] getShape(T : int)(T obj, int[] dims = null)
{
return dims;
}
// return arr shape
int[] getShape(T)(T obj, int[] dims = null)
{
dims ~= obj.length.to!int;
return getShape!(typeof(obj[0]))(obj[0], dims);
}
void main() {
int[] arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16];
int[][][] a = arr.chunks(4).array.chunks(2).array;
int err;
writeln(arr);
writeln(a.shape(err));
auto aSlice = a.fuse;
writeln(aSlice);
writeln(aSlice.shape);
}
More information about the Digitalmars-d-learn
mailing list