Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ this_dep = declare_dependency(
dependencies: required_deps,
)

test_versions = ['mir_test']
test_versions = ['mir_test', 'NOGCEXP']

if has_cpp_headers
install_subdir('include/',
Expand Down
63 changes: 37 additions & 26 deletions source/mir/algorithm/iteration.d
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ private void checkShapesMatch(
(scope ref const Slices slices)
if (Slices.length > 1)
{
enum msg = "all arguments must be slices" ~ tailErrorMessage!(fun, pfun);
enum msgShape = "all slices must have the same shape" ~ tailErrorMessage!(fun, pfun);
enum N = slices[0].shape.length;
foreach (i, Slice; Slices)
Expand Down Expand Up @@ -2399,32 +2398,49 @@ template equal(alias pred = "a == b")
{
import mir.functional: naryFun;
static if (__traits(isSame, naryFun!pred, pred))
/++
Params:
slices = Two or more slices, slices, ranges, and arrays.

Returns:
`true` any of the elements verify `pred` and `false` otherwise.
+/
bool equal(Slices...)(scope Slices slices)
if (Slices.length >= 2)
{
enum msg = "all arguments must be slices" ~ tailErrorMessage!();
enum msgShape = "all slices must have the same dimension count" ~ tailErrorMessage!();
import mir.internal.utility;
foreach (i, Slice; Slices)
/++
Params:
slices = Two or more ndslices, ranges, and arrays.

Returns:
`true` any of the elements verify `pred` and `false` otherwise.
+/
bool equal(Slices...)(scope Slices slices)
if (Slices.length >= 2)
{
// static assert (isSlice!Slice, msg);
static if (i)
import mir.internal.utility;
static if (allSatisfy!(hasShape, Slices))
{
auto shape0 = slices[0].shape;
enum N = DimensionCount!(Slices[0]);
foreach (ref slice; slices[1 .. $])
{
if (slice.shape != shape0)
goto False;
}
return all!pred(allLightScope!slices);
}
else
{
static assert (DimensionCount!(Slices[i]) == DimensionCount!(Slices[0]));
foreach (j; Iota!(DimensionCount!(Slices[0])))
if (slices[i].shape[j] != slices[0].shape[j])
for(;;)
{
auto empty = slices[0].empty;
foreach (ref slice; slices[1 .. $])
{
if (slice.empty != empty)
goto False;
}
if (empty)
return true;
if (!pred(frontOf!slices))
goto False;
foreach (ref slice; slices)
slice.popFront;
}
}
False: return false;
}
return all!pred(allLightScope!slices);
False: return false;
}
else
alias equal = .equal!(naryFun!pred);
Expand Down Expand Up @@ -2466,7 +2482,6 @@ version(mir_test) unittest
@safe pure nothrow @nogc
version(mir_test) unittest
{
import mir.algorithm.iteration: equal;
import mir.math.common: approxEqual;
import mir.ndslice.allocation: rcslice;
import mir.ndslice.topology: as, iota;
Expand Down Expand Up @@ -3563,7 +3578,6 @@ if (isInputRange!Range && is(typeof(naryFun!pred(r.front, r.front)) == bool))
///
@safe version(mir_test) unittest
{
import std.algorithm.comparison : equal;
import std.algorithm.mutation : copy;

int[] arr = [ 1, 2, 2, 2, 2, 3, 4, 4, 4, 5 ];
Expand Down Expand Up @@ -3655,7 +3669,6 @@ struct Uniq(alias pred, Range)
version(none)
@safe version(mir_test) unittest
{
import std.algorithm.comparison : equal;
import std.internal.test.dummyrange;
import std.range;

Expand Down Expand Up @@ -3683,8 +3696,6 @@ version(none)

@safe version(mir_test) unittest // https://issues.dlang.org/show_bug.cgi?id=17264
{
import std.algorithm.comparison : equal;

const(int)[] var = [0, 1, 1, 2];
assert(var.uniq.equal([0, 1, 2]));
}
Expand Down
4 changes: 2 additions & 2 deletions source/mir/algorithm/setops.d
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ MultiwayMerge!(naryFun!less, RangeOfRanges) multiwayMerge
///
@safe nothrow @nogc version(mir_test) unittest
{
import std.algorithm.comparison : equal;
import mir.algorithm.iteration: equal;

static a =
[
Expand Down Expand Up @@ -174,7 +174,7 @@ auto multiwayUnion(alias less = "a < b", RangeOfRanges)(RangeOfRanges ror)
///
@safe version(mir_test) unittest
{
import std.algorithm.comparison : equal;
import mir.algorithm.iteration: equal;

// sets
double[][] a =
Expand Down
2 changes: 1 addition & 1 deletion source/mir/container/binaryheap.d
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ if (isRandomAccessRange!Store || isRandomAccessRange!(typeof(Store.init[])))
{
import mir.utility : min;
import mir.functional : naryFun;
static if (__VERSION__ >= 2085) import core.lifetime: move; else import std.algorithm.mutation: move;
import core.lifetime: move;
import std.algorithm.mutation : swapAt;

static if (isRandomAccessRange!Store)
Expand Down
36 changes: 19 additions & 17 deletions source/mir/exception.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ module mir.exception;

version(D_Exceptions):

version(D_Ddoc)
private enum _version_D_Ddoc = true;
else
private enum _version_D_Ddoc = false;

private enum NOGCEXP = __traits(compiles, (()@nogc {throw new Exception("");})());

///
auto ref enforce(string fmt, string file = __FILE__, int line = __LINE__, Expr)(scope auto return ref Expr arg) @trusted
{
Expand Down Expand Up @@ -35,14 +42,6 @@ version (mir_test) unittest
catch(Exception e) assert(e.msg == "Msg");
}

version(D_Ddoc)
private enum _version_D_Ddoc = true;
else
private enum _version_D_Ddoc = false;

static if (_version_D_Ddoc || __traits(compiles, (()@nogc {throw new Exception("");})()))
{

/++
+/
class MirException : Exception
Expand All @@ -52,17 +51,19 @@ class MirException : Exception
}

/// Generic style
version (mir_test) static if (NOGCEXP)
@safe pure nothrow @nogc
version (mir_test) unittest
unittest
{
import mir.exception;
try throw new MirException("Hi D", 2, "!");
catch(Exception e) assert(e.msg == "Hi D2!");
}

/// C++ style
version (mir_test) static if (NOGCEXP)
@safe pure nothrow @nogc
version (mir_test) unittest
unittest
{
import mir.exception;
import mir.format;
Expand All @@ -71,8 +72,9 @@ version (mir_test) unittest
}

/// Low-level style
version (mir_test) static if (NOGCEXP)
@safe pure nothrow @nogc
version (mir_test) unittest
unittest
{
import mir.exception;
import mir.format;
Expand All @@ -82,8 +84,9 @@ version (mir_test) unittest
}

///
version (mir_test) static if (NOGCEXP)
@safe pure nothrow @nogc
version (mir_test) unittest
unittest
{
@safe pure nothrow @nogc
bool func(scope const(char)[] msg)
Expand Down Expand Up @@ -127,7 +130,7 @@ version (mir_test) unittest

// ///
// @safe pure nothrow @nogc
// version (mir_test) unittest
// version (mir_test) unittest static if (NOGCEXP)
// {
// import mir.exception;
// try enforce(false, "Hi D", 2, "!");
Expand All @@ -154,7 +157,7 @@ version (mir_test) unittest

// ///
// @safe pure nothrow @nogc
// version (mir_test) unittest
// version (mir_test) unittest static if (NOGCEXP)
// {
// import mir.exception;
// try enforce(false, "Msg");
Expand All @@ -172,7 +175,8 @@ class MirError : Error

///
@system pure nothrow @nogc
version (mir_test) unittest
version (mir_test) static if (NOGCEXP)
unittest
{
@system pure nothrow @nogc
bool func(scope const(char)[] msg)
Expand Down Expand Up @@ -294,5 +298,3 @@ private const(char)[] initilizePayload(ref return char[maxMsgLen] payload, scope
(() @trusted => memcpy(payload.ptr, msg.ptr, msg.length))();
return payload[0 .. msg.length];
}

}
1 change: 0 additions & 1 deletion source/mir/format.d
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ pragma(inline, false)
ref W printEscaped(C = char, W)(scope return ref W w, scope const(char)[] str)
{
// TODO: replace with Mir implementation.
import std.uni: isGraphical;
w.put('\"');
foreach (char c; str[])
{
Expand Down
2 changes: 1 addition & 1 deletion source/mir/interpolate/polynomial.d
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct Lagrange(T, uint maxAdditionalFunctions = 0, X = T)
+/
this(Slice!(RCI!(immutable X)) grid, RCArray!T values)
{
static if (__VERSION__ >= 2085) import core.lifetime: move; else import std.algorithm.mutation: move;
import core.lifetime: move;
auto weights = grid.lightScope.inversedBarycentricWeights;
this(grid.move, values.move, weights.move);
}
Expand Down
3 changes: 1 addition & 2 deletions source/mir/ndslice/allocation.d
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,7 @@ version(mir_test)
{
import mir.ndslice.slice;
import mir.ndslice.allocation: slice;

import std.datetime.date;
import mir.date: Date;

auto dataframe = slice!(double, Date, string)(4, 3);
assert(dataframe.length == 4);
Expand Down
50 changes: 25 additions & 25 deletions source/mir/ndslice/dynamic.d
Original file line number Diff line number Diff line change
Expand Up @@ -764,29 +764,29 @@ auto reversed(Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind) slic

@safe @nogc pure nothrow version(mir_test) unittest
{
import mir.algorithm.iteration : equal;
import mir.ndslice.concatenation : concatenation;
import mir.ndslice.slice;
import mir.ndslice.topology;
import std.algorithm.comparison : equal;
import std.range : chain;
auto i0 = iota([4], 0); auto r0 = i0.retro;
auto i1 = iota([4], 4); auto r1 = i1.retro;
auto i2 = iota([4], 8); auto r2 = i2.retro;
auto slice = iota(3, 4).universal;
assert(slice .flattened.equal(chain(i0, i1, i2)));
assert(slice .flattened.equal(concatenation(i0, i1, i2)));
// Template
assert(slice.reversed!(0) .flattened.equal(chain(i2, i1, i0)));
assert(slice.reversed!(1) .flattened.equal(chain(r0, r1, r2)));
assert(slice.reversed!(0, 1) .flattened.equal(chain(r2, r1, r0)));
assert(slice.reversed!(1, 0) .flattened.equal(chain(r2, r1, r0)));
assert(slice.reversed!(1, 1) .flattened.equal(chain(i0, i1, i2)));
assert(slice.reversed!(0, 0, 0).flattened.equal(chain(i2, i1, i0)));
assert(slice.reversed!(0) .flattened.equal(concatenation(i2, i1, i0)));
assert(slice.reversed!(1) .flattened.equal(concatenation(r0, r1, r2)));
assert(slice.reversed!(0, 1) .flattened.equal(concatenation(r2, r1, r0)));
assert(slice.reversed!(1, 0) .flattened.equal(concatenation(r2, r1, r0)));
assert(slice.reversed!(1, 1) .flattened.equal(concatenation(i0, i1, i2)));
assert(slice.reversed!(0, 0, 0).flattened.equal(concatenation(i2, i1, i0)));
// Function
assert(slice.reversed (0) .flattened.equal(chain(i2, i1, i0)));
assert(slice.reversed (1) .flattened.equal(chain(r0, r1, r2)));
assert(slice.reversed (0, 1) .flattened.equal(chain(r2, r1, r0)));
assert(slice.reversed (1, 0) .flattened.equal(chain(r2, r1, r0)));
assert(slice.reversed (1, 1) .flattened.equal(chain(i0, i1, i2)));
assert(slice.reversed (0, 0, 0).flattened.equal(chain(i2, i1, i0)));
assert(slice.reversed (0) .flattened.equal(concatenation(i2, i1, i0)));
assert(slice.reversed (1) .flattened.equal(concatenation(r0, r1, r2)));
assert(slice.reversed (0, 1) .flattened.equal(concatenation(r2, r1, r0)));
assert(slice.reversed (1, 0) .flattened.equal(concatenation(r2, r1, r0)));
assert(slice.reversed (1, 1) .flattened.equal(concatenation(i0, i1, i2)));
assert(slice.reversed (0, 0, 0).flattened.equal(concatenation(i2, i1, i0)));
}

private enum _stridedCode = q{
Expand Down Expand Up @@ -919,23 +919,23 @@ pure nothrow version(mir_test) unittest

@safe @nogc pure nothrow version(mir_test) unittest
{
import mir.ndslice.slice;
import mir.ndslice.topology;
import std.algorithm.comparison : equal;
import mir.ndslice;
import mir.algorithm.iteration : equal;

import std.range : chain;
auto i0 = iota([4], 0); auto s0 = stride(i0, 3);
auto i1 = iota([4], 4); auto s1 = stride(i1, 3);
auto i2 = iota([4], 8); auto s2 = stride(i2, 3);
auto slice = iota(3, 4).universal;
assert(slice .flattened.equal(chain(i0, i1, i2)));
assert(slice .flattened.equal(concatenation(i0, i1, i2)));
// Template
assert(slice.strided!0(2) .flattened.equal(chain(i0, i2)));
assert(slice.strided!1(3) .flattened.equal(chain(s0, s1, s2)));
assert(slice.strided!(0, 1)(2, 3).flattened.equal(chain(s0, s2)));
assert(slice.strided!0(2) .flattened.equal(concatenation(i0, i2)));
assert(slice.strided!1(3) .flattened.equal(concatenation(s0, s1, s2)));
assert(slice.strided!(0, 1)(2, 3).flattened.equal(concatenation(s0, s2)));
// Function
assert(slice.strided(0, 2).flattened.equal(chain(i0, i2)));
assert(slice.strided(1, 3).flattened.equal(chain(s0, s1, s2)));
assert(slice.strided(0, 2).strided(1, 3).flattened.equal(chain(s0, s2)));
assert(slice.strided(0, 2).flattened.equal(concatenation(i0, i2)));
assert(slice.strided(1, 3).flattened.equal(concatenation(s0, s1, s2)));
assert(slice.strided(0, 2).strided(1, 3).flattened.equal(concatenation(s0, s2)));
}

/++
Expand Down
5 changes: 2 additions & 3 deletions source/mir/ndslice/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,7 @@ version(mir_test) unittest

pure nothrow version(mir_test) unittest
{
import std.algorithm.comparison : equal;
import std.range : iota;
import mir.ndslice.topology : iota;
import mir.array.allocation : array;
auto r = 1000.iota.array;

Expand All @@ -634,7 +633,7 @@ pure nothrow version(mir_test) unittest
t1.popBack();
assert(t1.back == 17);

assert(t1.equal(iota(12, 18)));
assert(t1 == iota([6], 12));

t1.front = 13;
assert(t1.front == 13);
Expand Down
10 changes: 5 additions & 5 deletions source/mir/ndslice/topology.d
Original file line number Diff line number Diff line change
Expand Up @@ -2634,13 +2634,13 @@ version(mir_test) unittest
///
pure version(mir_test) unittest
{
import std.algorithm.iteration : sum, reduce;
import mir.utility : max;
import mir.ndslice.dynamic : transposed;
import mir.algorithm.iteration: reduce;
import mir.math.common: fmax;
import mir.math.stat: mean;
import mir.math.sum;
/// Returns maximal column average.
auto maxAvg(S)(S matrix) {
return reduce!max(matrix.universal.transposed.pack!1.map!sum)
/ double(matrix.length);
return reduce!fmax(0.0, matrix.alongDim!1.map!mean);
}
// 1 2
// 3 4
Expand Down
Loading