Skip to content

Commit 0a7269a

Browse files
committed
prerelease fixes
1 parent a1c788b commit 0a7269a

File tree

2 files changed

+53
-14
lines changed

2 files changed

+53
-14
lines changed

source/mir/ndslice/slice.d

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,20 @@ struct Slice(SliceKind kind, size_t[] packs, Iterator)
767767
return (cast(immutable) this).lightImmutable;
768768
}
769769

770+
/// ditto
771+
auto ref opIndex(Indexes...)(Indexes indexes) const @trusted
772+
if (isPureSlice!Indexes || isIndexedSlice!Indexes || isIndexSlice!Indexes)
773+
{
774+
return .lightConst(this)[indexes];
775+
}
776+
777+
/// ditto
778+
auto ref opIndex(Indexes...)(Indexes indexes) immutable @trusted
779+
if (isPureSlice!Indexes || isIndexedSlice!Indexes || isIndexSlice!Indexes)
780+
{
781+
return .lightImmutable(this)[indexes];
782+
}
783+
770784
static if (isPointer!Iterator)
771785
{
772786
private alias ConstThis = Slice!(kind, packs, const(Unqual!(PointerTarget!Iterator))*);
@@ -792,20 +806,6 @@ struct Slice(SliceKind kind, size_t[] packs, Iterator)
792806
/// ditto
793807
alias toConst this;
794808

795-
/// ditto
796-
auto ref opIndex(Indexes...)(Indexes indexes) const @trusted
797-
if (isPureSlice!Indexes || isIndexedSlice!Indexes || isIndexSlice!Indexes)
798-
{
799-
return lightConst[indexes];
800-
}
801-
802-
/// ditto
803-
auto ref opIndex(Indexes...)(Indexes indexes) immutable @trusted
804-
if (isPureSlice!Indexes || isIndexedSlice!Indexes || isIndexSlice!Indexes)
805-
{
806-
return lightImmutable[indexes];
807-
}
808-
809809
static if (doUnittest)
810810
///
811811
version(mir_test) unittest

source/mir/qualifier.d

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,45 @@ module mir.qualifier;
1212
import std.traits;
1313
import mir.ndslice.slice: SliceKind, Slice, isSlice;
1414

15+
///
16+
version(mir_test) unittest
17+
{
18+
import mir.math.common;
19+
import mir.ndslice; //includes Mir's zip
20+
import mir.qualifier;
21+
22+
//////////////// Native ///////////////
23+
24+
auto a = slice!double(5, 5);
25+
auto b = iota([5, 5]).as!double.slice.lightConst;
26+
auto c = magic(5).as!double.slice.trustedImmutable;
27+
28+
static assert(is(typeof(a) == ContiguousMatrix!double));
29+
static assert(is(typeof(b) == ContiguousMatrix!(const double)));
30+
static assert(is(typeof(c) == ContiguousMatrix!(immutable double)));
31+
32+
auto ac = (cast(const) a)[]; //[] calls lightConst
33+
auto ai = (cast(immutable) a)[]; //[] calls lightImmutable
34+
35+
static assert(is(typeof(ac) == ContiguousMatrix!(const double)));
36+
static assert(is(typeof(ai) == ContiguousMatrix!(immutable double)));
37+
38+
39+
//////////// Incapsulation ////////////
40+
41+
// zip, map, vmap, zip, indexed, pairwise, slide
42+
// and all other functons from ndslice.topology support
43+
// constant propogation
44+
auto abc0 = zip(a, b, c);
45+
const abc1 = abc0;
46+
auto abc2 = abc1[]; //[] calls lightConst
47+
48+
static assert(is(typeof(abc0) == Slice!(cast(SliceKind)2, [2LU], ZipIterator!(
49+
double*, const(double)*, immutable(double)*))));
50+
static assert(is(typeof(abc2) == Slice!(cast(SliceKind)2, [2LU], ZipIterator!(
51+
const(double)*, const(double)*, immutable(double)*))));
52+
}
53+
1554
/++
1655
+/
1756
template LightConstOf(T)

0 commit comments

Comments
 (0)