@@ -54,7 +54,7 @@ module mir.algorithm.iteration;
54
54
55
55
import mir.functional: naryFun;
56
56
import mir.internal.utility;
57
- import mir.math.common: optmath ;
57
+ import mir.math.common: fmamath ;
58
58
import mir.ndslice.field: BitField;
59
59
import mir.ndslice.internal;
60
60
import mir.ndslice.iterator: FieldIterator, RetroIterator;
@@ -101,7 +101,7 @@ version(mir_test) unittest
101
101
102
102
}
103
103
104
- @optmath :
104
+ @fmamath :
105
105
106
106
/+
107
107
Bitslice representation for accelerated bitwise algorithm.
@@ -130,7 +130,7 @@ private struct BitSliceAccelerator(Field, I = typeof(Field.init[size_t.init]))
130
130
// / tail length
131
131
int tailLength;
132
132
133
- @optmath :
133
+ @fmamath :
134
134
135
135
this (Slice! (FieldIterator! (BitField! (Field , I))) slice)
136
136
{
@@ -458,6 +458,7 @@ scope const:
458
458
459
459
sizediff_t nBitsToCount (size_t count)
460
460
{
461
+ pragma (inline, false );
461
462
size_t ret;
462
463
if (count == 0 )
463
464
return count;
@@ -557,6 +558,22 @@ sizediff_t nBitsToCount(Field, I)(Slice!(RetroIterator!(FieldIterator!(BitField!
557
558
return BitSliceAccelerator! (Field , I)(bitSlice.retro).retroNBitsToCount(count);
558
559
}
559
560
561
+ /+ +
562
+ Сount bits starting from the end until set bit count is reached. Works with ndslices created with $(REF bitwise, mir,ndslice,topology), $(REF bitSlice, mir,ndslice,allocation).
563
+ Returns: bit count if set bit count is reached or `-1` otherwise.
564
+ +/
565
+ sizediff_t retroNBitsToCount (Field , I)(Slice! (FieldIterator! (BitField! (Field , I))) bitSlice, size_t count)
566
+ {
567
+ return BitSliceAccelerator! (Field , I)(bitSlice).retroNBitsToCount(count);
568
+ }
569
+
570
+ // /ditto
571
+ sizediff_t retroNBitsToCount (Field , I)(Slice! (RetroIterator! (FieldIterator! (BitField! (Field , I)))) bitSlice, size_t count)
572
+ {
573
+ import mir.ndslice.topology: retro;
574
+ return BitSliceAccelerator! (Field , I)(bitSlice.retro).nBitsToCount(count);
575
+ }
576
+
560
577
// /
561
578
version (mir_test)
562
579
pure unittest
@@ -604,7 +621,7 @@ package(mir) template allFlattened(args...)
604
621
static if (args.length)
605
622
{
606
623
alias arg = args[0 ];
607
- @optmath @property allFlattenedMod()()
624
+ @fmamath @property allFlattenedMod()()
608
625
{
609
626
import mir.ndslice.topology: flattened;
610
627
return flattened (arg);
@@ -661,11 +678,11 @@ version(Mir_disable_inlining_in_reduce)
661
678
662
679
private template nonInlinedNaryFun (alias fun)
663
680
{
664
- import mir.math.common : optmath ;
681
+ import mir.math.common : fmamath ;
665
682
static if (is (typeof (fun) : string ))
666
683
{
667
684
// / Specialization for string lambdas
668
- @optmath auto ref nonInlinedNaryFun(Args... )(auto ref Args args)
685
+ @fmamath auto ref nonInlinedNaryFun(Args... )(auto ref Args args)
669
686
if (args.length <= 26 )
670
687
{
671
688
pragma (inline,false );
@@ -675,7 +692,7 @@ version(Mir_disable_inlining_in_reduce)
675
692
}
676
693
else static if (is (typeof (fun.opCall ) == function ))
677
694
{
678
- @optmath auto ref nonInlinedNaryFun(Args... )(auto ref Args args)
695
+ @fmamath auto ref nonInlinedNaryFun(Args... )(auto ref Args args)
679
696
if (is (typeof (fun.opCall (args))))
680
697
{
681
698
pragma (inline,false );
@@ -684,7 +701,7 @@ version(Mir_disable_inlining_in_reduce)
684
701
}
685
702
else
686
703
{
687
- @optmath auto ref nonInlinedNaryFun(Args... )(auto ref Args args)
704
+ @fmamath auto ref nonInlinedNaryFun(Args... )(auto ref Args args)
688
705
if (is (typeof (fun(args))))
689
706
{
690
707
pragma (inline,false );
@@ -745,7 +762,7 @@ template reduce(alias fun)
745
762
Returns:
746
763
the accumulated `result`
747
764
+/
748
- @optmath auto reduce(S, Slices... )(S seed, Slices slices)
765
+ @fmamath auto reduce(S, Slices... )(S seed, Slices slices)
749
766
if (Slices.length)
750
767
{
751
768
static if (Slices.length > 1 )
@@ -768,7 +785,7 @@ template reduce(alias fun)
768
785
}
769
786
else version (Mir_disable_inlining_in_reduce)
770
787
// As above, but with inlining disabled.
771
- @optmath auto reduce(S, Slices... )(S seed, Slices slices)
788
+ @fmamath auto reduce(S, Slices... )(S seed, Slices slices)
772
789
if (Slices.length)
773
790
{
774
791
static if (Slices.length > 1 )
@@ -849,9 +866,9 @@ version(mir_test) unittest
849
866
import std.numeric : dotProduct;
850
867
import mir.ndslice.allocation : slice;
851
868
import mir.ndslice.topology : as, iota, zip, universal;
852
- import mir.math.common : optmath ;
869
+ import mir.math.common : fmamath ;
853
870
854
- static @optmath T fmuladd(T, Z)(const T a, Z z)
871
+ static @fmamath T fmuladd(T, Z)(const T a, Z z)
855
872
{
856
873
return a + z.a * z.b;
857
874
}
@@ -879,9 +896,9 @@ unittest
879
896
{
880
897
import mir.ndslice.allocation : slice;
881
898
import mir.ndslice.topology : as, iota;
882
- import mir.math.common : optmath ;
899
+ import mir.math.common : fmamath ;
883
900
884
- static @optmath T fun(T)(const T a, ref T b)
901
+ static @fmamath T fun(T)(const T a, ref T b)
885
902
{
886
903
return a + b++ ;
887
904
}
@@ -1018,7 +1035,7 @@ template eachOnBorder(alias fun)
1018
1035
Params:
1019
1036
slices = One or more slices.
1020
1037
+/
1021
- @optmath void eachOnBorder(Slices... )(Slices slices)
1038
+ @fmamath void eachOnBorder(Slices... )(Slices slices)
1022
1039
if (allSatisfy! (isSlice, Slices))
1023
1040
{
1024
1041
import mir.ndslice.traits: isContiguousSlice;
@@ -1117,7 +1134,7 @@ template each(alias fun)
1117
1134
Params:
1118
1135
slices = One or more slices, ranges, and arrays.
1119
1136
+/
1120
- @optmath auto each(Slices... )(Slices slices)
1137
+ @fmamath auto each(Slices... )(Slices slices)
1121
1138
if (Slices.length && ! is (Slices[0 ] : Chequer))
1122
1139
{
1123
1140
static if (Slices.length > 1 )
@@ -1141,7 +1158,7 @@ template each(alias fun)
1141
1158
color = $(LREF Chequer).
1142
1159
slices = One or more slices.
1143
1160
+/
1144
- @optmath auto each(Slices... )(Chequer color, Slices slices)
1161
+ @fmamath auto each(Slices... )(Chequer color, Slices slices)
1145
1162
if (Slices.length && allSatisfy! (isSlice, Slices))
1146
1163
{
1147
1164
static if (Slices.length > 1 )
@@ -1546,7 +1563,7 @@ template minmaxPos(alias pred = "a < b")
1546
1563
Returns:
1547
1564
2 subslices with minimal and maximal `first` elements.
1548
1565
+/
1549
- @optmath Slice! (Iterator, N, kind == Contiguous && N > 1 ? Canonical : kind)[2 ]
1566
+ @fmamath Slice! (Iterator, N, kind == Contiguous && N > 1 ? Canonical : kind)[2 ]
1550
1567
minmaxPos(Iterator, size_t N, SliceKind kind)(Slice! (Iterator, N, kind) slice)
1551
1568
{
1552
1569
typeof (return ) pret;
@@ -1622,7 +1639,7 @@ template minmaxIndex(alias pred = "a < b")
1622
1639
Returns:
1623
1640
Subslice with minimal (maximal) `first` element.
1624
1641
+/
1625
- @optmath size_t [N][2 ] minmaxIndex(Iterator, size_t N, SliceKind kind)(Slice! (Iterator, N, kind) slice)
1642
+ @fmamath size_t [N][2 ] minmaxIndex(Iterator, size_t N, SliceKind kind)(Slice! (Iterator, N, kind) slice)
1626
1643
{
1627
1644
typeof (return ) pret = size_t .max;
1628
1645
if (! slice.anyEmpty)
@@ -1691,7 +1708,7 @@ template minPos(alias pred = "a < b")
1691
1708
Multidimensional backward index such that element is minimal(maximal).
1692
1709
Backward index equals zeros, if slice is empty.
1693
1710
+/
1694
- @optmath Slice! (Iterator, N, kind == Contiguous && N > 1 ? Canonical : kind)
1711
+ @fmamath Slice! (Iterator, N, kind == Contiguous && N > 1 ? Canonical : kind)
1695
1712
minPos(Iterator, size_t N, SliceKind kind)(Slice! (Iterator, N, kind) slice)
1696
1713
{
1697
1714
typeof (return ) ret;
@@ -1766,7 +1783,7 @@ template minIndex(alias pred = "a < b")
1766
1783
Multidimensional index such that element is minimal(maximal).
1767
1784
Index elements equal to `size_t.max`, if slice is empty.
1768
1785
+/
1769
- @optmath size_t [N] minIndex(Iterator, size_t N, SliceKind kind)(Slice! (Iterator, N, kind) slice)
1786
+ @fmamath size_t [N] minIndex(Iterator, size_t N, SliceKind kind)(Slice! (Iterator, N, kind) slice)
1770
1787
{
1771
1788
size_t [N] ret = size_t .max;
1772
1789
if (! slice.anyEmpty)
@@ -1922,7 +1939,7 @@ template findIndex(alias pred)
1922
1939
Constraints:
1923
1940
All slices must have the same shape.
1924
1941
+/
1925
- @optmath Select! (DimensionCount! (Slices[0 ]) > 1 , size_t [DimensionCount! (Slices[0 ])], size_t ) findIndex(Slices... )(Slices slices)
1942
+ @fmamath Select! (DimensionCount! (Slices[0 ]) > 1 , size_t [DimensionCount! (Slices[0 ])], size_t ) findIndex(Slices... )(Slices slices)
1926
1943
if (Slices.length)
1927
1944
{
1928
1945
static if (Slices.length > 1 )
@@ -2018,7 +2035,7 @@ template find(alias pred)
2018
2035
Constraints:
2019
2036
All slices must have the same shape.
2020
2037
+/
2021
- @optmath Select! (DimensionCount! (Slices[0 ]) > 1 , size_t [DimensionCount! (Slices[0 ])], size_t ) find(Slices... )(Slices slices)
2038
+ @fmamath Select! (DimensionCount! (Slices[0 ]) > 1 , size_t [DimensionCount! (Slices[0 ])], size_t ) find(Slices... )(Slices slices)
2022
2039
if (Slices.length && allSatisfy! (hasShape, Slices))
2023
2040
{
2024
2041
static if (Slices.length > 1 )
@@ -2197,7 +2214,7 @@ template any(alias pred = "a")
2197
2214
Constraints:
2198
2215
All slices must have the same shape.
2199
2216
+/
2200
- @optmath bool any(Slices... )(Slices slices)
2217
+ @fmamath bool any(Slices... )(Slices slices)
2201
2218
if ((Slices.length == 1 || ! __traits(isSame, pred, " a" )) && Slices.length)
2202
2219
{
2203
2220
static if (Slices.length > 1 )
@@ -2357,7 +2374,7 @@ template all(alias pred = "a")
2357
2374
Constraints:
2358
2375
All slices must have the same shape.
2359
2376
+/
2360
- @optmath bool all(Slices... )(Slices slices)
2377
+ @fmamath bool all(Slices... )(Slices slices)
2361
2378
if ((Slices.length == 1 || ! __traits(isSame, pred, " a" )) && Slices.length)
2362
2379
{
2363
2380
static if (Slices.length > 1 )
@@ -2487,7 +2504,7 @@ template count(alias fun)
2487
2504
Constraints:
2488
2505
All slices must have the same shape.
2489
2506
+/
2490
- @optmath size_t count(Slices... )(Slices slices)
2507
+ @fmamath size_t count(Slices... )(Slices slices)
2491
2508
if (Slices.length)
2492
2509
{
2493
2510
static if (Slices.length > 1 )
@@ -4308,7 +4325,7 @@ template fold(alias fun)
4308
4325
Returns:
4309
4326
the accumulated result
4310
4327
+/
4311
- @optmath auto fold(Slice, S)(scope Slice slice, S seed)
4328
+ @fmamath auto fold(Slice, S)(scope Slice slice, S seed)
4312
4329
{
4313
4330
import core.lifetime : move;
4314
4331
return reduce! fun(seed, slice.move);
0 commit comments