|
| 1 | +/++ |
| 2 | +$(H2 Multidimensional mutation algorithms) |
| 3 | +
|
| 4 | +This is a submodule of $(MREF mir,ndslice). |
| 5 | +
|
| 6 | +$(BOOKTABLE $(H2 Function), |
| 7 | +$(TR $(TH Function Name) $(TH Description)) |
| 8 | +$(T2 all, Checks if all elements satisfy to a predicate.) |
| 9 | +$(T2 any, Checks if at least one element satisfy to a predicate.) |
| 10 | +$(T2 cmp, Compares two slices.) |
| 11 | +$(T2 count, Counts elements in a slices according to a predicate.) |
| 12 | +$(T2 each, Iterates all elements.) |
| 13 | +$(T2 equal, Compares two slices for equality.) |
| 14 | +$(T2 find, Finds backward index.) |
| 15 | +$(T2 findIndex, Finds index.) |
| 16 | +$(T2 minmaxIndex, Finds indexes of the minimum and the maximum.) |
| 17 | +$(T2 minmaxPos, Finds backward indexes of the minimum and the maximum.) |
| 18 | +$(T2 minIndex, Finds index of the minimum.) |
| 19 | +$(T2 maxIndex, Finds index of the maximum.) |
| 20 | +$(T2 minPos, Finds backward index of the minimum.) |
| 21 | +$(T2 maxPos, Finds backward index of the maximum.) |
| 22 | +$(T2 reduce, Accumulates all elements.) |
| 23 | +) |
| 24 | +
|
| 25 | +License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). |
| 26 | +Copyright: Copyright © 2016-, Ilya Yaroshenko |
| 27 | +Authors: Ilya Yaroshenko |
| 28 | +
|
| 29 | +Macros: |
| 30 | +SUBREF = $(REF_ALTTEXT $(TT $2), $2, mir, ndslice, $1)$(NBSP) |
| 31 | +T2=$(TR $(TDNW $(LREF $1)) $(TD $+)) |
| 32 | ++/ |
| 33 | +module mir.ndslice.mutation; |
| 34 | + |
| 35 | +import mir.ndslice.slice; |
| 36 | + |
| 37 | +/++ |
| 38 | +Transposes square matrix in place. |
| 39 | +
|
| 40 | +Params: |
| 41 | + matrix = square matrix |
| 42 | ++/ |
| 43 | +void transposeInPlace(SliceKind kind, Iterator)(Slice!(kind, [2], Iterator) matrix) |
| 44 | +in |
| 45 | +{ |
| 46 | + assert(matrix.length!0 == matrix.length!1); |
| 47 | +} |
| 48 | +body |
| 49 | +{ |
| 50 | + static if (kind == Contiguous) |
| 51 | + { |
| 52 | + import mir.ndslice.topology: canonical; |
| 53 | + .transposeInPlace(matrix.canonical); |
| 54 | + } |
| 55 | + else |
| 56 | + { |
| 57 | + if (!matrix.empty) |
| 58 | + do |
| 59 | + { |
| 60 | + import mir.ndslice.algorithm: eachImpl; |
| 61 | + import mir.utility: swap; |
| 62 | + eachImpl!swap(matrix.front!1, matrix.front!0); |
| 63 | + matrix.popFront!1; |
| 64 | + matrix.popFront!0; |
| 65 | + } |
| 66 | + while (matrix.length); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +/// |
| 71 | +unittest |
| 72 | +{ |
| 73 | + import mir.ndslice.allocation: slice; |
| 74 | + import mir.ndslice.topology: iota, universal; |
| 75 | + import mir.ndslice.dynamic: transposed; |
| 76 | + |
| 77 | + auto m = iota(4, 4).slice; |
| 78 | + |
| 79 | + m.transposeInPlace; |
| 80 | + |
| 81 | + assert(m == iota(4, 4).universal.transposed); |
| 82 | +} |
0 commit comments