Skip to content

Commit

Permalink
prerelease fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Feb 18, 2018
1 parent a1c788b commit 0a7269a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
28 changes: 14 additions & 14 deletions source/mir/ndslice/slice.d
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,20 @@ struct Slice(SliceKind kind, size_t[] packs, Iterator)
return (cast(immutable) this).lightImmutable;
}

/// ditto
auto ref opIndex(Indexes...)(Indexes indexes) const @trusted
if (isPureSlice!Indexes || isIndexedSlice!Indexes || isIndexSlice!Indexes)
{
return .lightConst(this)[indexes];
}

/// ditto
auto ref opIndex(Indexes...)(Indexes indexes) immutable @trusted
if (isPureSlice!Indexes || isIndexedSlice!Indexes || isIndexSlice!Indexes)
{
return .lightImmutable(this)[indexes];
}

static if (isPointer!Iterator)
{
private alias ConstThis = Slice!(kind, packs, const(Unqual!(PointerTarget!Iterator))*);
Expand All @@ -792,20 +806,6 @@ struct Slice(SliceKind kind, size_t[] packs, Iterator)
/// ditto
alias toConst this;

/// ditto
auto ref opIndex(Indexes...)(Indexes indexes) const @trusted
if (isPureSlice!Indexes || isIndexedSlice!Indexes || isIndexSlice!Indexes)
{
return lightConst[indexes];
}

/// ditto
auto ref opIndex(Indexes...)(Indexes indexes) immutable @trusted
if (isPureSlice!Indexes || isIndexedSlice!Indexes || isIndexSlice!Indexes)
{
return lightImmutable[indexes];
}

static if (doUnittest)
///
version(mir_test) unittest
Expand Down
39 changes: 39 additions & 0 deletions source/mir/qualifier.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,45 @@ module mir.qualifier;
import std.traits;
import mir.ndslice.slice: SliceKind, Slice, isSlice;

///
version(mir_test) unittest
{
import mir.math.common;
import mir.ndslice; //includes Mir's zip
import mir.qualifier;

//////////////// Native ///////////////

auto a = slice!double(5, 5);
auto b = iota([5, 5]).as!double.slice.lightConst;
auto c = magic(5).as!double.slice.trustedImmutable;

static assert(is(typeof(a) == ContiguousMatrix!double));
static assert(is(typeof(b) == ContiguousMatrix!(const double)));
static assert(is(typeof(c) == ContiguousMatrix!(immutable double)));

auto ac = (cast(const) a)[]; //[] calls lightConst
auto ai = (cast(immutable) a)[]; //[] calls lightImmutable

static assert(is(typeof(ac) == ContiguousMatrix!(const double)));
static assert(is(typeof(ai) == ContiguousMatrix!(immutable double)));


//////////// Incapsulation ////////////

// zip, map, vmap, zip, indexed, pairwise, slide
// and all other functons from ndslice.topology support
// constant propogation
auto abc0 = zip(a, b, c);
const abc1 = abc0;
auto abc2 = abc1[]; //[] calls lightConst

static assert(is(typeof(abc0) == Slice!(cast(SliceKind)2, [2LU], ZipIterator!(
double*, const(double)*, immutable(double)*))));
static assert(is(typeof(abc2) == Slice!(cast(SliceKind)2, [2LU], ZipIterator!(
const(double)*, const(double)*, immutable(double)*))));
}

/++
+/
template LightConstOf(T)
Expand Down

0 comments on commit 0a7269a

Please sign in to comment.