Skip to content

Commit 0815ebe

Browse files
committed
Merge branch 'master' of https://github.com/jmh530/mir-algorithm
2 parents c12d549 + b476262 commit 0815ebe

File tree

12 files changed

+128
-43
lines changed

12 files changed

+128
-43
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,3 @@ void main()
8585
```
8686

8787
[![Open on run.dlang.io](https://img.shields.io/badge/run.dlang.io-open-blue.svg)](https://run.dlang.io/is/67Gi6X)
88-
89-
### Our sponsors
90-
91-
[<img src="https://raw.githubusercontent.com/libmir/mir-algorithm/master/images/symmetry.png" height="80" />](http://symmetryinvestments.com/) &nbsp; &nbsp; &nbsp; &nbsp;
92-
[<img src="https://raw.githubusercontent.com/libmir/mir-algorithm/master/images/kaleidic.jpeg" height="80" />](https://github.com/kaleidicassociates)
93-

images/symmetry.png

-8.66 KB
Binary file not shown.

source/mir/algorithm/iteration.d

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ $(T2 find, Finds backward index.)
2020
$(T2 findIndex, Finds index.)
2121
$(T2 fold, Accumulates all elements (different parameter order than `reduce`).)
2222
$(T2 isSymmetric, Checks if the matrix is symmetric.)
23+
$(T2 maxElement, Returns the maximum.)
2324
$(T2 maxIndex, Finds index of the maximum.)
2425
$(T2 maxPos, Finds backward index of the maximum.)
26+
$(T2 minElement, Returns the minimum.)
2527
$(T2 minIndex, Finds index of the minimum.)
2628
$(T2 minmaxIndex, Finds indices of the minimum and the maximum.)
2729
$(T2 minmaxPos, Finds backward indices of the minimum and the maximum.)
@@ -119,7 +121,7 @@ private struct BitSliceAccelerator(Field, I = typeof(Field.init[size_t.init]))
119121
import mir.ndslice.field: BitField;
120122

121123
///
122-
alias U = typeof(I + 1u);
124+
alias U = typeof(I.init + 1u);
123125
/// body bits chunks
124126
static if (isIterator!Field)
125127
Slice!Field bodyChunks;
@@ -4432,3 +4434,86 @@ unittest
44324434
auto z4 = y.minIndex;
44334435
auto z5 = y.maxIndex;
44344436
}
4437+
4438+
/++
4439+
Returns the minimal(maximal) element of a multidimensional slice.
4440+
4441+
Params:
4442+
pred = A predicate.
4443+
4444+
See_also:
4445+
$(LREF minIndex),
4446+
$(LREF maxElement),
4447+
$(LREF maxIndex),
4448+
$(LREF maxPos).
4449+
+/
4450+
template minElement(alias pred = "a < b")
4451+
{
4452+
import mir.functional: naryFun;
4453+
static if (__traits(isSame, naryFun!pred, pred))
4454+
/++
4455+
Params:
4456+
slice = ndslice.
4457+
Returns:
4458+
Minimal(maximal) element of a multidimensional slice
4459+
+/
4460+
@fmamath DeepElementType!(Slice!(Iterator, N, kind)) minElement(Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind) slice)
4461+
{
4462+
return slice[slice.minIndex!pred];
4463+
}
4464+
else
4465+
alias minElement = .minElement!(naryFun!pred);
4466+
}
4467+
4468+
/// ditto
4469+
template maxElement(alias pred = "a < b")
4470+
{
4471+
import mir.functional: naryFun, reverseArgs;
4472+
alias maxElement = minElement!(reverseArgs!(naryFun!pred));
4473+
}
4474+
4475+
///
4476+
@safe pure nothrow
4477+
version(mir_test)
4478+
unittest
4479+
{
4480+
import mir.ndslice.slice: sliced;
4481+
auto s = [
4482+
2, 6, 4, -3,
4483+
0, -4, -3, 3,
4484+
-3, -2, 7, 8,
4485+
].sliced(3, 4);
4486+
4487+
assert(s.minElement == -4);
4488+
assert(s.maxElement == 8);
4489+
}
4490+
4491+
///
4492+
@safe pure nothrow
4493+
version(mir_test)
4494+
unittest
4495+
{
4496+
import mir.ndslice.slice: sliced;
4497+
auto s = [
4498+
-8, 6, 4, -3,
4499+
0, -4, -3, 3,
4500+
-3, -2, 7, 8,
4501+
].sliced(3, 4);
4502+
4503+
assert(s.minElement == -8);
4504+
}
4505+
4506+
@safe pure nothrow
4507+
version(mir_test)
4508+
unittest
4509+
{
4510+
import mir.ndslice.slice: sliced;
4511+
auto s = [
4512+
0, 1, 2, 3,
4513+
4, 5, 6, 7,
4514+
8, 9, 10, 11
4515+
].sliced(3, 4);
4516+
4517+
assert(s.minElement == 0);
4518+
assert(s.maxElement == 11);
4519+
}

source/mir/bignum/decimal.d

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ struct Decimal(uint size64)
3838
void toString(C = char, W)(ref scope W w, NumericSpec spec = NumericSpec.init) const scope
3939
if(isSomeChar!C && isMutable!C)
4040
{
41+
scope C[] _buffer;
42+
if (false) w.put(_buffer);
43+
() @trusted {
4144
assert(spec.format == NumericSpec.Format.exponent || spec.format == NumericSpec.Format.human);
4245
import mir.utility: _expect;
4346
// handle special values
@@ -212,6 +215,7 @@ struct Decimal(uint size64)
212215
auto expLength = printSignedToTail(exponent, buffer0[$ - N - 16 .. $ - 16], '+');
213216
buffer[$ - ++expLength] = spec.exponentChar;
214217
w.put(buffer[$ - expLength .. $]);
218+
} ();
215219
}
216220

217221
@safe:
@@ -422,7 +426,7 @@ struct Decimal(uint size64)
422426
}
423427

424428
///
425-
ref opOpAssign(string op, size_t rhsMaxSize64)(ref const Decimal!rhsMaxSize64 rhs) @safe pure return
429+
ref opOpAssign(string op, size_t rhsMaxSize64)(ref const Decimal!rhsMaxSize64 rhs) @trusted pure return
426430
if (op == "+" || op == "-")
427431
{
428432
import mir.utility: max;
@@ -450,7 +454,7 @@ struct Decimal(uint size64)
450454

451455
///
452456
version(mir_bignum_test)
453-
@safe pure nothrow @nogc
457+
@trusted pure nothrow @nogc
454458
unittest
455459
{
456460
import mir.test: should;

source/mir/bignum/fixed.d

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ UInt!(size + size_t.sizeof * 8)
963963
extendedMul(size_t size)(UInt!size a, size_t b)
964964
@safe pure nothrow @nogc
965965
{
966-
size_t overflow = a.view *= b;
966+
size_t overflow = a.view.opOpAssign!"*"(b);
967967
auto ret = a.toSize!(size + size_t.sizeof * 8);
968968
ret.data[$ - 1] = overflow;
969969
return ret;
@@ -1060,6 +1060,7 @@ UInt!(size + size_t.sizeof * 8)
10601060
{
10611061
auto ret = extendedMul(a, b);
10621062
auto view = ret.view;
1063-
view.coefficients[$ - 1] += view.topLeastSignificantPart(a.data.length) += c.view;
1063+
view.coefficients[$ - 1] +=
1064+
view.topLeastSignificantPart(a.data.length).opOpAssign!"+"(c.view);
10641065
return ret;
10651066
}

source/mir/bignum/fp.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ struct Fp(uint size)
637637

638638
///
639639
Fp!(coefficientizeA + coefficientizeB) extendedMul(bool noSpecial = false, uint coefficientizeA, uint coefficientizeB)(Fp!coefficientizeA a, Fp!coefficientizeB b)
640-
@safe pure nothrow @nogc
640+
@trusted pure nothrow @nogc
641641
{
642642
import mir.bignum.fixed: extendedMul;
643643
import mir.checkedint: adds;

source/mir/bignum/integer.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ struct BigInt(uint size64)
263263
}
264264

265265
///
266-
BigInt copy() @property
266+
BigInt copy() @property @trusted
267267
{
268268
BigInt ret = void;
269269
ret.sign = sign;
@@ -479,7 +479,7 @@ struct BigInt(uint size64)
479479

480480
///ditto
481481
ref powMod()(scope BigUIntView!(const size_t) exponent, scope ref const BigInt modulus)
482-
@safe pure nothrow @nogc return scope
482+
@trusted pure nothrow @nogc return scope
483483
{
484484
pragma(inline, false);
485485

@@ -654,7 +654,7 @@ struct BigInt(uint size64)
654654
remainder or quotient from the truncated division
655655
+/
656656
ref opOpAssign(string op : "*", size_t rhsSize64)(scope const ref BigInt!rhsSize64 rhs)
657-
@safe pure nothrow @nogc return
657+
@trusted pure nothrow @nogc return
658658
{
659659
BigInt!(size64 + rhsSize64) c = void;
660660
c.multiply(this, rhs);

source/mir/bignum/internal/dec2float.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ private template bigSize(T)
288288
}
289289
}
290290

291-
@optStrategy("minsize")
291+
@optStrategy("minsize") @trusted
292292
private T algorithmM(T)(scope const size_t[] coefficients, long exponent)
293293
if ((is(T == float) || is(T == double) || is(T == real)))
294294
in (coefficients.length)

source/mir/format.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ unittest
8888
}
8989

9090
/// Concatenated string results
91-
string text(string separator = "", Args...)(auto scope ref const Args args)
91+
string text(string separator = "", Args...)(auto ref scope const Args args)
9292
if (Args.length > 0)
9393
{
9494
import mir.utility: _expect;
@@ -607,7 +607,7 @@ void printElement(C = char, EscapeFormat escapeFormat = EscapeFormat.ion, W, T)(
607607
/++
608608
Multiargument overload.
609609
+/
610-
void print(C = char, W, Args...)(scope ref W w, auto scope ref const Args args)
610+
void print(C = char, W, Args...)(scope ref W w, auto ref scope const Args args)
611611
if (isSomeChar!C && Args.length > 1)
612612
{
613613
foreach(i, ref c; args)

source/mir/interpolate/spline.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ struct Spline(F, size_t N = 1, X = F)
843843
this._data = shape.rcslice!(F[2 ^^ N]);
844844
}
845845

846-
package static auto pickDataSubslice(D)(auto scope ref D data, size_t index) @trusted
846+
package static auto pickDataSubslice(D)(auto ref scope D data, size_t index) @trusted
847847
{
848848
auto strides = data.strides;
849849
foreach (i; Iota!(strides.length))

0 commit comments

Comments
 (0)