Skip to content

Commit 152fee5

Browse files
committed
add ndslice.mutation module
1 parent b0e55f7 commit 152fee5

File tree

5 files changed

+97
-3
lines changed

5 files changed

+97
-3
lines changed

doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ MIR_PACKAGES = mir mir/ndslice mir/internal mir/math mir/math/func mir/array
2929

3030
PACKAGE_mir = bitmanip conv functional primitives utility
3131
PACKAGE_mir_array = primitives
32-
PACKAGE_mir_ndslice = package algorithm allocation dynamic field ndfield iterator package slice sorting concatenation topology
32+
PACKAGE_mir_ndslice = package algorithm allocation dynamic field ndfield mutation iterator package slice sorting concatenation topology
3333
PACKAGE_mir_math = constant common sum
3434
PACKAGE_mir_math_func = expdigamma
3535
PACKAGE_mir_internal = utility

index.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ $(BOOKTABLE ,
2727
$(TDNW $(MREF mir,ndslice,topology))
2828
$(TD Advanced constructors, SliceKind conversion utilities)
2929
)
30+
$(TR
31+
$(TDNW $(MREF mir,ndslice,mutation))
32+
$(TD Mutation algorithms)
33+
)
3034
$(TR
3135
$(TDNW $(MREF mir,ndslice,algorithm))
3236
$(TD Loop free programming)

source/mir/ndslice/algorithm.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/++
2-
This is a submodule of $(MREF mir,ndslice).
2+
$(H2 Multidimensional iteration algorithms)
33
4-
It contains basic multidimensional iteration algorithms.
4+
This is a submodule of $(MREF mir,ndslice).
55
66
$(BOOKTABLE $(H2 Function),
77
$(TR $(TH Function Name) $(TH Description))

source/mir/ndslice/mutation.d

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
}

source/mir/ndslice/package.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ $(TR $(TDNW $(SUBMODULE topology) $(BR)
150150
)
151151
)
152152
153+
$(TR $(TDNW $(SUBMODULE mutation)
154+
$(BR) $(SMALL mutation algorithms))
155+
$(TD
156+
$(SUBREF mutation, transposeInPlace)
157+
)
158+
)
159+
153160
$(TR $(TDNW $(SUBMODULE algorithm)
154161
$(BR) $(SMALL Loop free programming))
155162
$(TD
@@ -419,6 +426,7 @@ public import mir.ndslice.concatenation;
419426
public import mir.ndslice.dynamic;
420427
public import mir.ndslice.field;
421428
public import mir.ndslice.iterator;
429+
public import mir.ndslice.mutation;
422430
public import mir.ndslice.ndfield;
423431
public import mir.ndslice.slice;
424432
public import mir.ndslice.topology;

0 commit comments

Comments
 (0)