void run_mean_bench() { var cycles = Pow2.T12; var samples = Pow2.T14; var src = Numeric.force <long, double>(Random.Span <long>(samples, Interval.closed(-2000L, 2000L))); var ds = Observations.Load(src); var dst = 0.0; var last = 0.0; var sw1 = stopwatch(); for (var i = 0; i < cycles; i++) { last = ds.Mean(ref dst); } sw1.Stop(); var sw2 = stopwatch(); for (var i = 0; i < cycles; i++) { last = src.Avg(); } sw2.Stop(); ReportBenchmark("mkl-ssmean", cycles * samples, sw1.Elapsed); ReportBenchmark("direct", cycles * samples, sw2.Elapsed); }
public void sumvals() { var src = Random.Stream <double>().Take(16000).ToArray(); var expect = src.Sum().Round(4); var actual = Observations.Load(src).Sum()[0].Round(4); Claim.require(gmath.within(expect, actual, .01)); }
public void mean() { var src = Random.Span <long>(Pow2.T14, Interval.closed(-2000L, 2000L)); var expect = gAlg.avg(src); var converted = Numeric.force <long, double>(src); var actual = (long)Observations.Load(converted).Mean()[0]; Claim.eq(expect, actual); }
public void minval() { var samplesize = Pow2.T14; var s1Range = Interval.closed(350.0, 1000.0); var s1 = Random.Array <double>(samplesize, s1Range); var s1Max = Observations.Load(s1).Max()[0]; NumericClaims.neq(s1Max, 0.0); var zeroCount = s1.Count(x => x == 0); Notify($"Found {zeroCount} zeroes"); }
public void CreateMt2203Generators() { var gencount = Pow2.T08; var samplesize = Pow2.T16; var seeds = Random.Array <uint>(gencount); var streams = new MklRng[gencount]; for (var i = 0; i < gencount; i++) { streams[i] = rng.mt2203(seeds[i], i); } var bufferF64 = new double[samplesize]; var bufferU32 = new uint[samplesize]; var bufferI32 = new int[samplesize]; var ufRange = Interval.closed(1.0, 250.0); for (var i = 0; i < gencount; i++) { var stream = streams[i]; sample.uniform(stream, ufRange, bufferF64); Observations.Load(bufferF64, 1).Extrema(); var max = Observations.Load(bufferF64, 1).Max()[0]; NumericClaims.lteq(max, ufRange.Right); NumericClaims.neq(max, 0); sample.bits(stream, bufferU32); sample.bernoulli(stream, .40, bufferI32); for (var j = 0; j < samplesize; j++) { Claim.require(bufferI32[j] == 0 || bufferI32[j] == 1); } sample.gaussian(stream, .75, .75, bufferF64); sample.laplace(stream, .5, .5, bufferF64); } for (var i = 0; i < gencount; i++) { streams[i].Dispose(); } }
public void radixSort() { var obs = Pow2.T10; var dim = Pow2.T08; var range = Interval.closed(-20f, 20f); var src = Random.Array <float>(dim * obs, range); var sample = Observations.Load(src, dim); var sorted = sample.RadixSort(); for (var i = 0; i < obs; i++) { var v = sorted.Observation(i); for (var j = 0; j < dim - 1; j++) { ClaimNumeric.lteq(v[j], v[j + 1]); } } }