@@ -12,6 +12,45 @@ module mir.qualifier;
1212import std.traits ;
1313import 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+/
1756template LightConstOf (T)
0 commit comments