@@ -83,6 +83,7 @@ import std.meta;
8383import mir.internal.utility;
8484import mir.ndslice.internal;
8585import mir.ndslice.slice;
86+ import mir.utility;
8687
8788@fastmath:
8889
@@ -330,24 +331,15 @@ Returns:
330331 n-dimensional slice of the same type
331332See_also: $(LREF swapped), $(LREF transposed)
332333+/
333- Slice! (Universal, packs, Iterator) everted(size_t [] packs, Iterator)(Slice! (Universal, packs, Iterator) slice)
334+ Slice! (kind, packs, Iterator) everted(size_t [] packs, SliceKind kind, Iterator)(Slice! (kind, packs, Iterator) slice)
335+ if (kind == Universal || kind == Canonical && packs.length > 1 )
334336{
335- mixin _DefineRet;
336- with (slice)
337+ with (slice) foreach (i; Iota! (packs[0 ] / 2 ))
337338 {
338- foreach (i; Iota! (packs[0 ]))
339- {
340- ret._lengths[N - 1 - i] = _lengths[i];
341- ret._strides[N - 1 - i] = _strides[i];
342- }
343- foreach (i; Iota! (packs[0 ], slice.N))
344- {
345- ret._lengths[i] = _lengths[i];
346- ret._strides[i] = _strides[i];
347- }
348- ret._iterator = _iterator;
349- return ret;
339+ swap(_lengths[i], _lengths[packs[0 ] - i - 1 ]);
340+ swap(_strides[i], _strides[packs[0 ] - i - 1 ]);
350341 }
342+ return slice;
351343}
352344
353345// /
@@ -362,24 +354,21 @@ Slice!(Universal, packs, Iterator) everted(size_t[] packs, Iterator)(Slice!(Univ
362354}
363355
364356private enum _transposedCode = q{
365- mixin _DefineRet;
366- with (slice)
357+ size_t [typeof (return ).N] lengths_;
358+ ptrdiff_t [max(typeof (return ).S, size_t (1 ))] strides_;
359+ with (slice) foreach (i; Iota! (packs[0 ]))
367360 {
368- foreach (i; Iota! (packs[0 ]))
369- {
370- ret._lengths[i] = _lengths[perm[i]];
371- static if (i < ret.S)
372- ret._strides[i] = _strides[perm[i]];
373- }
374- foreach (i; Iota! (packs[0 ], slice.N))
375- {
376- ret._lengths[i] = _lengths[i];
377- static if (i < ret.S)
378- ret._strides[i] = _strides[i];
379- }
380- ret._iterator = _iterator;
381- return ret;
361+ lengths_[i] = _lengths[perm[i]];
362+ static if (i < typeof (return ).S)
363+ strides_[i] = _strides[perm[i]];
364+ }
365+ with (slice) foreach (i; Iota! (packs[0 ], slice.N))
366+ {
367+ lengths_[i] = _lengths[i];
368+ static if (i < typeof (return ).S)
369+ strides_[i] = _strides[i];
382370 }
371+ return typeof (return )(lengths_, strides_[0 .. typeof (return ).S], slice._iterator);
383372};
384373
385374private size_t [N] completeTranspose (size_t N)(size_t [] dimensions)
@@ -536,6 +525,7 @@ Returns:
536525 n-dimensional slice of the same type
537526+/
538527Slice! (kind, packs, Iterator) allReversed(SliceKind kind, size_t [] packs, Iterator)(Slice! (kind, packs, Iterator) slice)
528+ @trusted
539529 if (kind == Universal || kind == Canonical && packs.length > 1 )
540530{
541531 foreach (dimension; Iota! (packs[0 ]))
@@ -571,7 +561,9 @@ template reversed(Dimensions...)
571561 alias reversed = .reversed! (staticMap! (toSize_t, Dimensions));
572562 else
573563 // /
574- @fastmath Slice! (kind, packs, Iterator) reversed(SliceKind kind, size_t [] packs, Iterator)(Slice! (kind, packs, Iterator) slice)
564+ @fastmath Slice! (kind, packs, Iterator)
565+ reversed(SliceKind kind, size_t [] packs, Iterator)(Slice! (kind, packs, Iterator) slice)
566+ @trusted
575567 if (kind == Universal || kind == Canonical)
576568 {
577569 foreach (i, dimension; Dimensions)
@@ -585,6 +577,7 @@ template reversed(Dimensions...)
585577
586578// /ditto
587579Slice! (kind, packs, Iterator) reversed(SliceKind kind, size_t [] packs, Iterator, size_t M)(Slice! (kind, packs, Iterator) slice, size_t [M] dimensions... )
580+ @trusted
588581 if (kind == Universal || kind == Canonical)
589582in
590583{
602595}
603596
604597// /
605- pure nothrow unittest
598+ @safe pure nothrow unittest
606599{
607600 import mir.ndslice.topology: iota, universal;
608601 auto slice = iota([2 , 2 ], 1 ).universal;
@@ -626,7 +619,7 @@ pure nothrow unittest
626619}
627620
628621// /
629- pure nothrow unittest
622+ @safe pure nothrow unittest
630623{
631624 import mir.ndslice.topology: iota, canonical;
632625 auto slice = iota([2 , 2 ], 1 ).canonical;
0 commit comments