Skip to content

Commit 54ffc21

Browse files
committed
update fuse
1 parent e999e67 commit 54ffc21

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

source/mir/ndslice/dynamic.d

+10-10
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,7 @@ See_also: $(LREF swapped), $(LREF everted)
489489
template transposed(Dimensions...)
490490
if (Dimensions.length)
491491
{
492-
static if (!allSatisfy!(isSize_t, Dimensions))
493-
alias transposed = .transposed!(staticMap!(toSize_t, Dimensions));
494-
else
492+
static if (allSatisfy!(isSize_t, Dimensions))
495493
///
496494
@optmath auto transposed(Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind) _slice)
497495
{
@@ -531,6 +529,8 @@ template transposed(Dimensions...)
531529
mixin (_transposedCode);
532530
}
533531
}
532+
else
533+
alias transposed = .transposed!(staticMap!(toSize_t, Dimensions));
534534
}
535535

536536
///ditto
@@ -662,9 +662,7 @@ Returns:
662662
template reversed(Dimensions...)
663663
if (Dimensions.length)
664664
{
665-
static if (!allSatisfy!(isSize_t, Dimensions))
666-
alias reversed = .reversed!(staticMap!(toSize_t, Dimensions));
667-
else
665+
static if (allSatisfy!(isSize_t, Dimensions))
668666
///
669667
@optmath auto reversed(Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind) _slice) @trusted
670668
{
@@ -693,6 +691,8 @@ template reversed(Dimensions...)
693691
}
694692
return slice;
695693
}
694+
else
695+
alias reversed = .reversed!(staticMap!(toSize_t, Dimensions));
696696
}
697697

698698
///ditto
@@ -813,12 +813,10 @@ Returns:
813813
template strided(Dimensions...)
814814
if (Dimensions.length)
815815
{
816-
static if (!allSatisfy!(isSize_t, Dimensions))
817-
alias strided = .strided!(staticMap!(toSize_t, Dimensions));
818-
else
816+
static if (allSatisfy!(isSize_t, Dimensions))
819817
/++
820818
Params:
821-
slice = input slice
819+
_slice = input slice
822820
factors = list of step extension factors
823821
+/
824822
@optmath auto strided(Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind) _slice, Repeat!(Dimensions.length, ptrdiff_t) factors)
@@ -849,6 +847,8 @@ template strided(Dimensions...)
849847
}
850848
return slice;
851849
}
850+
else
851+
alias strided = .strided!(staticMap!(toSize_t, Dimensions));
852852
}
853853

854854
///ditto

source/mir/ndslice/fuse.d

+28-10
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,37 @@ import mir.math.common: optmath;
2828
@optmath:
2929

3030
/++
31-
Fuses ndrange `r` into GC-allocated (`fuse`) or RC-allocated (`rcfuse`) ndslice. Can be used to join rows or columns into a matrix.
31+
Fuses ndrange `r` into GC-allocated ($(LREF fuse)) or RC-allocated ($(LREF rcfuse)) ndslice.
32+
Can be used to join rows or columns into a matrix.
3233
3334
Params:
3435
Dimensions = (optional) indexes of dimensions to be brought to the first position
3536
Returns:
3637
ndslice
3738
+/
38-
///
39-
alias fuse(Dimensions...) = fuseImpl!(false, Dimensions);
40-
///
41-
alias rcfuse(Dimensions...) = fuseImpl!(true, Dimensions);
39+
alias fuse(Dimensions...) = fuseImpl!(false, void, Dimensions);
40+
/// ditto
41+
alias rcfuse(Dimensions...) = fuseImpl!(true, void, Dimensions);
42+
43+
/++
44+
Fuses ndrange `r` into GC-allocated ($(LREF fuseAs)) or RC-allocated ($(LREF rcfuseAs)) ndslice.
45+
Can be used to join rows or columns into a matrix.
46+
47+
Params:
48+
T = output type of ndslice elements
49+
Dimensions = (optional) indexes of dimensions to be brought to the first position
50+
Returns:
51+
ndslice
52+
+/
53+
alias fuseAs(T, Dimensions...) = fuseImpl!(false, T, Dimensions);
4254
/// ditto
43-
template fuseImpl(bool RC, Dimensions...)
55+
alias rcfuseAs(T, Dimensions...) = fuseImpl!(true, T, Dimensions);
56+
57+
///
58+
template fuseImpl(bool RC, T_, Dimensions...)
4459
{
4560
import mir.ndslice.internal: isSize_t, toSize_t;
46-
static if (!allSatisfy!(isSize_t, Dimensions))
47-
alias fuseImpl = .fuseImpl!(RC, staticMap!(toSize_t, Dimensions));
48-
else
61+
static if (allSatisfy!(isSize_t, Dimensions))
4962
/++
5063
Params:
5164
r = parallelotope (ndrange) with length/shape and input range primitives.
@@ -57,7 +70,10 @@ template fuseImpl(bool RC, Dimensions...)
5770
import mir.algorithm.iteration: each;
5871
import mir.ndslice.allocation;
5972
auto shape = fuseShape(r);
60-
alias T = FuseElementType!NDRange;
73+
static if (is(T_ == void))
74+
alias T = FuseElementType!NDRange;
75+
else
76+
alias T = T_;
6177
alias UT = Unqual!T;
6278
static if (RC)
6379
{
@@ -137,6 +153,8 @@ template fuseImpl(bool RC, Dimensions...)
137153
return *(() @trusted => cast(R*)&ret)();
138154
}
139155
}
156+
else
157+
alias fuseImpl = .fuseImpl!(RC, T_, staticMap!(toSize_t, Dimensions));
140158
}
141159

142160
///

source/mir/ndslice/package.d

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ $(TR $(TDNW $(SUBMODULE fuse) $(BR)
188188
))
189189
$(TD
190190
$(SUBREF fuse, fuse)
191+
$(SUBREF fuse, fuseAs)
192+
$(SUBREF fuse, rcfuse)
193+
$(SUBREF fuse, rcfuseAs)
191194
$(SUBREF fuse, fuseCells)
192195
)
193196
)

0 commit comments

Comments
 (0)