示例#1
0
        public void TestSuite()
        {
            var dim     = N12.Rep;
            var trials  = Pow2.T16;
            var maxVal  = (ulong)Pow2.T07;
            var maxVec  = BlockVector.Alloc(dim, maxVal);
            var buckets = new ulong[maxVal];


            var suite = Rng.WyHash64Suite(dim);

            for (var i = 0; i < trials; i++)
            {
                var vector     = suite.Next <ulong>();
                var contracted = vector.Contract(maxVec);
                for (var j = 0; j < dim; j++)
                {
                    var x = contracted[j];
                    Claim.lteq(x, maxVal);
                    ++buckets[x];
                }
            }

            var indices      = Random.Array <int>(10, leftopen(0, buckets.Length));
            var bucketSample = buckets.Values(indices);
            var avg          = (double)gmath.avg <ulong>(bucketSample);
            var deltas       = bucketSample.Map(c => (math.abs(1 - ((double)c / avg)).Round(4)));
            var tolerance    = .1;
            var intolerant   = deltas.Where(x => x > tolerance).Count();

            Claim.eq(intolerant, 0);
        }
示例#2
0
文件: and.cs 项目: 0xCM/arrows
        public static BlockVector <N, T> and <N, T>(BlockVector <N, T> lhs, BlockVector <N, T> rhs)
            where N : ITypeNat, new()
            where T : unmanaged
        {
            var dst = BlockVector.Alloc <N, T>();

            gbitspan.and <T>(lhs.Data, rhs.Data, dst);
            return(dst);
        }
示例#3
0
文件: Markov.cs 项目: 0xCM/arrows
        public static BlockVector <N, T> MarkovVec <N, T>(this IPolyrand random)
            where N : ITypeNat, new()
            where T : struct
        {
            var dst = BlockVector.Alloc <N, T>();

            random.MarkovVec(dst.Unsized);
            return(dst);
        }
示例#4
0
        public static BlockVector <N, T> BlockVec <N, T>(this IPolyrand random, N n = default)
            where T : struct
            where N : ITypeNat, new()
        {
            var dst = BlockVector.Alloc <N, T>();

            random.Fill(ref dst);
            return(dst);
        }
示例#5
0
        public BlockVector <N, T> Next <T>(Interval <T> domain)
            where T : struct
        {
            var dst = BlockVector.Alloc <N, T>();

            for (var i = 0; i < n; i++)
            {
                dst[i] = members[i].Next <T>(domain);
            }
            return(dst);
        }
示例#6
0
        public BlockVector <N, T> Next <T>(T min, T max)
            where T : struct
        {
            var dst = BlockVector.Alloc <N, T>();

            for (var i = 0; i < n; i++)
            {
                dst[i] = members[i].Next <T>(min, max);
            }
            return(dst);
        }
示例#7
0
文件: Utilies.cs 项目: 0xCM/arrows
        /// <summary>
        /// Effects a component-wise contraction on the source vector on a source vector of unsigned primal type,
        /// dst[i] = src[i].Contract(max[i])
        /// </summary>
        /// <param name="src">The vector to contract</param>
        /// <param name="max">The upper bound</param>
        /// <typeparam name="N">The length type</typeparam>
        /// <typeparam name="T">The unsigned primal type</typeparam>
        public static BlockVector <T> Contract <T>(this BlockVector <T> src, BlockVector <T> max)
            where T : struct
        {
            var len = src.Length;

            require(len == max.Length);
            var dst = BlockVector.Alloc <T>(len);

            for (var i = 0; i < dst.Length; i++)
            {
                dst[i] = Contractors.Contract(src[i], max[i]);
            }
            return(dst);
        }
示例#8
0
        /// <summary>
        /// Produces a blocked vector
        /// </summary>
        /// <param name="random">The random source</param>
        /// <param name="domain">The domain of the random variable</param>
        /// <typeparam name="T">The vector component type</typeparam>
        public static BlockVector <T> BlockVec <T>(this IPolyrand random, int len, Interval <T>?domain = null)
            where T : struct
        {
            var dst = BlockVector.Alloc <T>(len);

            if (domain != null)
            {
                random.StreamTo(domain.Value, len, ref dst[0]);
            }
            else
            {
                random.StreamTo(len, ref dst[0]);
            }
            return(dst);
        }
示例#9
0
文件: t_markov.cs 项目: 0xCM/arrows
        void MarkovVector <N, T>(int count, N n = default, T rep = default)
            where N : ITypeNat, new()
            where T : struct
        {
            var tol    = .0001;
            var radius = closed(1 - tol, 1 + tol);
            var v      = BlockVector.Alloc <N, T>();

            for (var i = 0; i < count; i++)
            {
                Random.MarkovVec(ref v);
                var sum = convert <T, double>(mathspan.sum(v.Unsized));
                Claim.yea(radius.Contains(sum));
            }
        }
示例#10
0
        void blockv_add_check <N, T>()
            where N : ITypeNat, new()
            where T : unmanaged
        {
            var n  = new N();
            var v4 = BlockVector.Alloc <N, T>();

            for (var i = 0; i < CycleCount; i++)
            {
                var v1 = Random.BlockVec <N, T>();
                var v2 = Random.BlockVec <N, T>();
                var v3 = BlockVector.Load(mathspan.add(v1.Unsized, v2.Unsized), n);
                Linear.add(ref v1, v2);
                Claim.yea(v3 == v1);
            }
        }