示例#1
0
        /// <summary>
        /// Shuffles span content as determined by a permutation
        /// </summary>
        /// <param name="src">The source span</param>
        /// <param name="p">The permutation to apply</param>
        public static Span <T> Permute <T>(this ReadOnlySpan <T> src, Perm p)
        {
            Span <T> dst = new T[src.Length];

            for (var i = 0; i < p.Length; i++)
            {
                dst[i] = src[p[i]];
            }
            return(dst);
        }
示例#2
0
        /// <summary>
        /// Creates the matrix determined by a permutation
        /// </summary>
        /// <param name="src">The source permutation</param>
        public static BitMatrix64 ToBitMatrix(this Perm <N64> src)
        {
            var dst = BitMatrix64.Alloc();

            for (var row = 0; row < src.Length; row++)
            {
                dst[row, src[row]] = Bit.On;
            }
            return(dst);
        }
示例#3
0
        /// <summary>
        /// Maps a permutation on 16 symbols to its canonical scalar representation
        /// </summary>
        /// <param name="src">The source permutation</param>
        public static Perm16 ToEnum(this Perm <N16> src)
        {
            var dst = 0ul;

            for (int i = 0, offset = 0; i < src.Length; i++, offset += 3)
            {
                dst |= (ulong)src[i] << offset;
            }
            return((Perm16)dst);
        }
示例#4
0
        /// <summary>
        /// Shuffles bitstring content as determined by a permutation
        /// </summary>
        /// <param name="src">The source span</param>
        /// <param name="p">The permutation to apply</param>
        public static BitString Permute(this BitString src, Perm p)
        {
            var dst = BitString.Alloc(p.Length);

            for (var i = 0; i < p.Length; i++)
            {
                dst[i] = src[p[i]];
            }
            return(dst);
        }
示例#5
0
        /// <summary>
        /// Maps a permutation on 8 symbols to its canonical scalar representation
        /// </summary>
        /// <param name="src">The source permutation</param>
        public static Perm8Symbol ToScalar(this Perm <N8> src)
        {
            var dst = 0u;

            for (int i = 0, offset = 0; i < src.Length; i++, offset += 3)
            {
                dst |= (uint)src[i] << offset;
            }
            return((Perm8Symbol)dst);
        }
示例#6
0
        /// <summary>
        /// Creates a permutation-defined mask
        /// </summary>
        /// <param name="spec">The permutation</param>
        public static BitVector4 Mask(Perm spec)
        {
            var mask = Alloc();
            var n    = math.min(spec.Length, mask.Length);

            for (var i = 0; i < n; i++)
            {
                mask[spec[i]] = i;
            }
            return(mask);
        }
示例#7
0
        /// <summary>
        /// Reifies a permutation of length 16 from its canonical scalar representative
        /// </summary>
        /// <param name="rep">The representative</param>
        public static Perm <N16> ToPerm(this Perm16 rep)
        {
            uint data = (uint)rep;
            var  dst  = Perm <N16> .Alloc();

            for (int i = 0, offset = 0; i < dst.Length; i++, offset += 4)
            {
                dst[i] = (int)BitMask.between(in data, offset, offset + 3);
            }
            return(dst);
        }
示例#8
0
文件: t_shuffle.cs 项目: 0xCM/arrows
        public void Shuffle1()
        {
            var  src  = Perm.Identity(24);
            Perm dst0 = src;
            Perm dst1 = Random.Shuffle(src.Replicate());
            Perm dst2 = Random.Shuffle(src.Replicate());
            Perm dst3 = Random.Shuffle(src.Replicate());

            Claim.eq(dst1.Length, src.Length);
            Claim.eq(dst2.Length, src.Length);
            Claim.eq(dst3.Length, src.Length);
        }
示例#9
0
文件: tbm_create.cs 项目: 0xCM/arrows
        public void permrev_64x64()
        {
            for(var i= 0; i<SampleSize; i++)
            {
                //Creates an "exchange" matrix            
                var perm = Perm.Identity(n64).Reverse();
                var mat = perm.ToBitMatrix();

                var v1 = Random.BitVector(n64);
                var v2 = mat * v1;
                var v3 = v1.Replicate();
                v3.Reverse();
                Claim.eq(v3,v2);
            }
        }
示例#10
0
文件: t_perm.cs 项目: 0xCM/arrows
        OpTime Shuffle(int n, int count, out int duplicates)
        {
            duplicates = 0;

            var sw = stopwatch();
            var p0 = Perm.Identity(n);
            var p1 = Random.Shuffle(in p0);
            var p2 = Random.Shuffle(in p0);

            for (var i = 0; i < count; i++)
            {
                p1 = Random.Shuffle(in p1);
                p2 = Random.Shuffle(in p2);
                if (p1 == p2)
                {
                    duplicates++;
                }
            }

            return(count, snapshot(sw));
        }
示例#11
0
文件: mask.cs 项目: 0xCM/arrows
 public static ref BitVector64 mask(Perm spec, out BitVector64 mask)
 {
     mask = BitVector64.Mask(spec);
     return(ref mask);
 }
示例#12
0
 /// <summary>
 /// Formats the terms of a permutation
 /// </summary>
 /// <param name="terms">The permutation terms</param>
 /// <param name="colwidth">The width of each column</param>
 /// <typeparam name="T">The term type</typeparam>
 internal static string FormatPerm <T>(this ReadOnlySpan <T> terms, int?colwidth = null)
 => Perm.Format(terms, colwidth);
示例#13
0
 public static Span <T> Permute <T>(this Span <T> src, Perm p)
 => src.ReadOnly().Permute(p);