@@ -41,14 +41,14 @@ template statType(T, bool checkComplex = true)
4141 } else static if (checkComplex) {
4242 import mir.internal.utility: isComplex;
4343 static if (isComplex! T) {
44- import std.traits : Unqual;
45- static if (is (T : cdouble )) {
46- deprecated (" Built-in complex types deprecated in D language version 2.097" ) alias statType = Unqual! T;
47- } else {
44+ static if (__traits(getAliasThis, T).length == 1 )
45+ {
46+ alias statType = .statType! (typeof (__traits(getMember, T, __traits(getAliasThis, T)[0 ])));
47+ }
48+ else
49+ {
4850 alias statType = Unqual! T;
4951 }
50- } else static if (is (T : cdouble )) {
51- deprecated (" Built-in complex types deprecated in D language version 2.097" ) alias statType = cdouble ;
5252 } else {
5353 static assert (0 , " statType: type " ~ T.stringof ~ " must be convertible to a complex floating point type" );
5454 }
@@ -73,15 +73,6 @@ unittest
7373 static assert (is (statType! (immutable (double )) == double ));
7474}
7575
76- version (mir_builtincomplex_test)
77- @safe pure nothrow @nogc
78- unittest
79- {
80- static assert (is (statType! cfloat == cfloat ));
81- static assert (is (statType! cdouble == cdouble ));
82- static assert (is (statType! creal == creal ));
83- }
84-
8576version (mir_test)
8677@safe pure nothrow @nogc
8778unittest
@@ -105,16 +96,17 @@ unittest
10596 static assert (is (statType! Foo == double )); // note: this is not float
10697}
10798
108- version (mir_builtincomplex_test )
99+ version (mir_test )
109100@safe pure nothrow @nogc
110101unittest
111102{
103+ import mir.complex;
112104 static struct Foo {
113- cfloat x;
105+ Complex ! float x;
114106 alias x this ;
115107 }
116108
117- static assert (is (statType! Foo == cdouble )); // note: this is not Complex!float
109+ static assert (is (statType! Foo == Complex! float ));
118110}
119111
120112version (mir_test)
@@ -129,16 +121,17 @@ unittest
129121 static assert (is (statType! Foo == double ));
130122}
131123
132- version (mir_builtincomplex_test )
124+ version (mir_test )
133125@safe pure nothrow @nogc
134126unittest
135127{
128+ import mir.complex;
136129 static struct Foo {
137- cdouble x;
130+ Complex ! double x;
138131 alias x this ;
139132 }
140133
141- static assert (is (statType! Foo == cdouble ));
134+ static assert (is (statType! Foo == Complex ! double ));
142135}
143136
144137version (mir_test)
@@ -153,16 +146,17 @@ unittest
153146 static assert (is (statType! Foo == double )); // note: this is not real
154147}
155148
156- version (mir_builtincomplex_test )
149+ version (mir_test )
157150@safe pure nothrow @nogc
158151unittest
159152{
153+ import mir.complex;
160154 static struct Foo {
161- creal x;
155+ Complex ! real x;
162156 alias x this ;
163157 }
164158
165- static assert (is (statType! Foo == cdouble )); // note: this is not Complex!real
159+ static assert (is (statType! Foo == Complex! real ));
166160}
167161
168162version (mir_test)
@@ -206,11 +200,12 @@ unittest
206200 static assert (is (meanType! (float []) == float ));
207201}
208202
209- version (mir_builtincomplex_test )
203+ version (mir_test )
210204@safe pure nothrow @nogc
211205unittest
212206{
213- static assert (is (meanType! (cfloat []) == cfloat ));
207+ import mir.complex;
208+ static assert (is (meanType! (Complex! float []) == Complex! float ));
214209}
215210
216211version (mir_test)
@@ -225,16 +220,17 @@ unittest
225220 static assert (is (meanType! (Foo []) == float ));
226221}
227222
228- version (mir_builtincomplex_test )
223+ version (mir_test )
229224@safe pure nothrow @nogc
230225unittest
231226{
227+ import mir.complex;
232228 static struct Foo {
233- cfloat x;
229+ Complex ! float x;
234230 alias x this ;
235231 }
236232
237- static assert (is (meanType! (Foo []) == cfloat ));
233+ static assert (is (meanType! (Foo []) == Complex ! float ));
238234}
239235
240236/+ +
@@ -423,9 +419,11 @@ version(mir_test)
423419unittest
424420{
425421 import mir.ndslice.slice: sliced;
422+ import mir.complex;
423+ alias C = Complex! double ;
426424
427425 assert (mean([1.0 , 2 , 3 ]) == 2 );
428- assert (mean([1.0 + 3i, 2 , 3 ]) == 2 + 1i );
426+ assert (mean([C( 1 , 3 ), C( 2 ), C( 3 ) ]) == C( 2 , 1 ) );
429427
430428 assert (mean! float ([0 , 1 , 2 , 3 , 4 , 5 ].sliced(3 , 2 )) == 2.5 );
431429
@@ -539,9 +537,11 @@ unittest
539537{
540538 import mir.math.common: approxEqual;
541539 import mir.ndslice.slice: sliced;
540+ import mir.complex;
541+ alias C = Complex! double ;
542542
543- auto x = [1.0 + 2i, 2 + 3i, 3 + 4i, 4 + 5i ].sliced;
544- assert (x.mean.approxEqual(2.5 + 3. 5i ));
543+ auto x = [C( 1.0 , 2 ), C( 2 , 3 ), C( 3 , 4 ), C( 4 , 5 ) ].sliced;
544+ assert (x.mean.approxEqual(C( 2.5 , 3.5 ) ));
545545}
546546
547547// / Compute mean tensors along specified dimention of tensors
@@ -634,28 +634,30 @@ version(mir_test)
634634@safe pure nothrow @nogc
635635unittest
636636{
637+ import mir.complex;
637638 static assert (is (hmeanType! (int []) == double ));
638639 static assert (is (hmeanType! (double []) == double ));
639640 static assert (is (hmeanType! (float []) == float ));
640- static assert (is (hmeanType! (cfloat []) == cfloat ));
641+ static assert (is (hmeanType! (Complex ! float []) == Complex ! float ));
641642}
642643
643644version (mir_test)
644645@safe pure nothrow @nogc
645646unittest
646647{
648+ import mir.complex;
647649 static struct Foo {
648650 float x;
649651 alias x this ;
650652 }
651653
652654 static struct Bar {
653- cfloat x;
655+ Complex ! float x;
654656 alias x this ;
655657 }
656658
657659 static assert (is (hmeanType! (Foo []) == float ));
658- static assert (is (hmeanType! (Bar []) == cfloat ));
660+ static assert (is (hmeanType! (Bar []) == Complex ! float ));
659661}
660662
661663/+ +
@@ -864,9 +866,11 @@ unittest
864866{
865867 import mir.math.common: approxEqual;
866868 import mir.ndslice.slice: sliced;
869+ import mir.complex;
870+ alias C = Complex! double ;
867871
868- auto x = [1.0 + 2i, 2 + 3i, 3 + 4i, 4 + 5i ].sliced;
869- assert (x.hmean.approxEqual(1.97110904 + 3. 14849332i ));
872+ auto x = [C( 1 , 2 ), C( 2 , 3 ), C( 3 , 4 ), C( 4 , 5 ) ].sliced;
873+ assert (x.hmean.approxEqual(C( 1.97110904 , 3.14849332 ) ));
870874}
871875
872876// / Arbitrary harmonic mean
@@ -2291,21 +2295,6 @@ unittest
22912295 assert (v.variance(PopulationFalseCT).approxEqual(54.76562 / 11 ));
22922296}
22932297
2294- version (mir_builtincomplex_test)
2295- @safe pure nothrow
2296- unittest
2297- {
2298- import mir.math.common: approxEqual;
2299- import mir.ndslice.slice: sliced;
2300-
2301- auto x = [1.0 + 3i, 2 , 3 ].sliced;
2302-
2303- VarianceAccumulator! (cdouble , VarianceAlgo.online, Summation.naive) v;
2304- v.put(x);
2305- assert (v.variance(true ).approxEqual((- 4.0 - 6i) / 3 ));
2306- assert (v.variance(false ).approxEqual((- 4.0 - 6i) / 2 ));
2307- }
2308-
23092298version (mir_test)
23102299@safe pure nothrow
23112300unittest
@@ -2654,22 +2643,6 @@ unittest
26542643 assert (v.variance(PopulationFalseCT).approxEqual(54.76562 / 11 ));
26552644}
26562645
2657- version (mir_builtincomplex_test)
2658- @safe pure nothrow
2659- unittest
2660- {
2661- import mir.math.common: approxEqual;
2662- import mir.ndslice.slice: sliced;
2663-
2664- auto a = [1.0 + 3i, 2 , 3 ].sliced;
2665- auto x = a.center;
2666-
2667- VarianceAccumulator! (cdouble , VarianceAlgo.assumeZeroMean, Summation.naive) v;
2668- v.put(x);
2669- assert (v.variance(true ).approxEqual((- 4.0 - 6i) / 3 ));
2670- assert (v.variance(false ).approxEqual((- 4.0 - 6i) / 2 ));
2671- }
2672-
26732646version (mir_test)
26742647@safe pure nothrow
26752648unittest
@@ -2824,11 +2797,13 @@ unittest
28242797{
28252798 import mir.math.common: approxEqual;
28262799 import mir.ndslice.slice: sliced;
2800+ import mir.complex;
2801+ alias C = Complex! double ;
28272802
28282803 assert (variance([1.0 , 2 , 3 ]).approxEqual(2.0 / 2 ));
28292804 assert (variance([1.0 , 2 , 3 ], true ).approxEqual(2.0 / 3 ));
28302805
2831- assert (variance([1.0 + 3i, 2 , 3 ]).approxEqual((- 4.0 - 6i ) / 2 ));
2806+ assert (variance([C( 1 , 3 ), C( 2 ), C( 3 ) ]).approxEqual(C (- 4 , - 6 ) / 2 ));
28322807
28332808 assert (variance! float ([0 , 1 , 2 , 3 , 4 , 5 ].sliced(3 , 2 )).approxEqual(17.5 / 5 ));
28342809
@@ -2993,9 +2968,11 @@ unittest
29932968{
29942969 import mir.math.common: approxEqual;
29952970 import mir.ndslice.slice: sliced;
2971+ import mir.complex;
2972+ alias C = Complex! double ;
29962973
2997- auto x = [1.0 + 2i, 2 + 3i, 3 + 4i, 4 + 5i ].sliced;
2998- assert (x.variance.approxEqual((0.0 + 10. 0i) / 3 ));
2974+ auto x = [C( 1 , 2 ), C( 2 , 3 ), C( 3 , 4 ), C( 4 , 5 ) ].sliced;
2975+ assert (x.variance.approxEqual((C( 0 , 10 )) / 3 ));
29992976}
30002977
30012978// / Compute variance along specified dimention of tensors
0 commit comments