Пример #1
0
 public Span(Span256 <T> src)
 {
     require(src.Length == CellCount, $"length(src) = {src.Length} != {CellCount} = SpanLength");
     colbuffer       = NatSpan.Alloc <M, T>();
     this.data       = src.Unblocked;
     this.Blocked256 = true;
 }
Пример #2
0
        static Vec256 <T> ClearAlternating()
        {
            var mask = Span256.Alloc <T>(1);
            var chop = PrimalInfo.Get <T>().MaxVal;

            //For the first 128-bit lane
            var half = mask.Length / 2;

            for (byte i = 0; i < half; i++)
            {
                if (i % 2 != 0)
                {
                    mask[i] = chop;
                }
                else
                {
                    mask[i] = convert <byte, T>(i);
                }
            }

            //For the second 128-bit lane
            for (byte i = 0; i < half; i++)
            {
                if (i % 2 != 0)
                {
                    mask[i + half] = chop;
                }
                else
                {
                    mask[i + half] = convert <byte, T>(i);
                }
            }

            return(Vec256.Load(mask));
        }
Пример #3
0
        public static Span256 <T> ToSpan256 <T>(this Vec256 <T> src)
            where T : struct
        {
            var dst = Span256.AllocBlocks <T>(1);

            vstore(src, ref dst[0]);
            return(dst);
        }
Пример #4
0
        public static Span256 <T> ToSpan256 <T>(this Vec512 <T> src)
            where T : struct
        {
            var dst = Span256.AllocBlocks <T>(2);

            vstore(src.lo, ref dst[0]);
            vstore(src.hi, ref dst[32]);
            return(dst);
        }
Пример #5
0
        public static Span256 <T> Load <T>(ref T src, int minlen)
            where T : struct
        {
            var bz  = BlockCount <T>(minlen, out int remainder);
            var bl  = BlockLength <T>();
            var len = remainder == 0 ? bz * bl : (bz + 1) * bl;

            return(Span256 <T> .LoadAligned(ref src, len));
        }
Пример #6
0
 public static Span256 <float> sqrt(Span256 <float> src, Span256 <float> dst)
 {
     for (var block = 0; block < src.BlockCount; block++)
     {
         var x = Vec256.Load(ref src.Block(block));
         vstore(dfp.sqrt(x), ref dst[block]);
     }
     return(dst);
 }
Пример #7
0
        public static Span256 <T> AllocBlocks(int blocks, T?fill = null)
        {
            var dst = new Span256 <T>(new T[blocks * BlockLength]);

            if (fill.HasValue)
            {
                dst.data.Fill(fill.Value);
            }
            return(dst);
        }
Пример #8
0
        public static Span256 <T> Replicate <T>(this Span256 <T> src, bool structureOnly = false)
            where T : struct
        {
            Span <T> dst = new T[src.Length];

            if (!structureOnly)
            {
                src.CopyTo(dst);
            }
            return(Z0.Span256 <T> .LoadAligned(dst));
        }
Пример #9
0
        public static Span256 <T> ToSpan256 <T>(this Vec1024 <T> src)
            where T : struct
        {
            var dst = Span256.AllocBlocks <T>(4);

            vstore(src.v00, ref dst[0]);
            vstore(src.v01, ref dst[32]);
            vstore(src.v10, ref dst[64]);
            vstore(src.v10, ref dst[96]);
            return(dst);
        }
Пример #10
0
        public static Span256 <T> Swap <T>(this Span256 <T> src, params Swap[] swaps)
            where T : struct
        {
            if (swaps.Length == 0)
            {
                return(src);
            }

            src.Unblocked.Swap(swaps);
            return(src);
        }
Пример #11
0
        /// <summary>
        /// Creates a vector populated with component values that alternate between the first operand and the second
        /// </summary>
        /// <param name="a">The first operand</param>
        /// <param name="b">The second operand</param>
        /// <typeparam name="T">The primal component type</typeparam>
        public static Vec256 <T> Alternate <T>(T a, T b)
            where T : unmanaged
        {
            var n   = Vec256 <T> .Length;
            var dst = Span256.AllocBlock <T>();

            for (var i = 0; i < n; i++)
            {
                dst[i] = even(i) ? a : b;
            }
            return(Vec256.Load(ref head(dst)));
        }
Пример #12
0
        static Vec256 <T> CalcUnits()
        {
            var n   = Length;
            var dst = Span256.Alloc <T>(n);
            var one = gmath.one <T>();

            for (var i = 0; i < n; i++)
            {
                dst[i] = one;
            }
            return(Vec256.Load(dst));
        }
Пример #13
0
        /// <summary>
        /// Creates a vector with incrementing components
        /// v[0] = first and v[i+1] = v[i] + 1 for i=1...N-1
        /// </summary>
        /// <param name="first">The value of the first component</param>
        /// <typeparam name="T">The primal component type</typeparam>
        public static Vec256 <T> Increments(T first = default, params Swap[] swaps)
        {
            var n   = Length;
            var dst = Span256.Alloc <T>(n);
            var val = first;

            for (var i = 0; i < n; i++)
            {
                dst[i] = val;
                gmath.inc(ref val);
            }
            return(Vec256.Load(dst.Swap(swaps)));
        }
Пример #14
0
 public static Span256 <T> Alloc <T>(int minlen, T?fill = null)
     where T : struct
 {
     Span256.Alignment <T>(minlen, out int blocklen, out int fullBlocks, out int remainder);
     if (remainder == 0)
     {
         return(AllocBlocks <T>(fullBlocks, fill));
     }
     else
     {
         return(Span256.AllocBlocks <T>(fullBlocks + 1, fill));
     }
 }
Пример #15
0
        public static Span256 <T> Alloc <N, T>(T?fill = null)
            where N : ITypeNat, new()
            where T : struct
        {
            var dataLen = nati <N>();

            Span256.Alignment <T>(dataLen, out int blocklen, out int fullBlocks, out int remainder);
            if (remainder == 0)
            {
                return(AllocBlocks <T>(fullBlocks));
            }
            else
            {
                return(AllocBlocks <T>(fullBlocks + 1));
            }
        }
Пример #16
0
        public static Span256 <T> Load <T>(ReadOnlySpan <T> src)
            where T : struct
        {
            var bz = BlockCount <T>(src.Length, out int remainder);

            if (remainder == 0)
            {
                return(Span256 <T> .LoadAligned(src.Replicate()));
            }
            else
            {
                var dst = AllocBlocks <T>(bz + 1);
                src.CopyTo(dst);
                return(dst);
            }
        }
Пример #17
0
        public static void VerifyBinOp <T>(IPolyrand random, int blocks, Vector256BinOp <T> inXOp, Func <T, T, T> primalOp)
            where T : unmanaged
        {
            var blocklen = Span256 <T> .BlockLength;

            var lhs = random.ReadOnlySpan256 <T>(blocks);

            Claim.eq(blocks * blocklen, lhs.Length);

            var rhs = random.ReadOnlySpan256 <T>(blocks);

            Claim.eq(blocks * blocklen, rhs.Length);

            var expect = Span256.AllocBlocks <T>(blocks);

            Claim.eq(blocks, expect.BlockCount);

            var actual = Span256.AllocBlocks <T>(blocks);

            Claim.eq(blocks, actual.BlockCount);

            var tmp = new T[blocklen];

            for (var block = 0; block < blocks; block++)
            {
                var offset = block * blocklen;
                for (var i = 0; i < blocklen; i++)
                {
                    tmp[i] = primalOp(lhs[offset + i], rhs[offset + i]);
                }

                var vExpect = Vec256.LoadVector <T>(ref tmp[0]);

                var vX      = lhs.LoadVec256(block);
                var vY      = rhs.LoadVec256(block);
                var vActual = inXOp(vX, vY);

                Claim.eq(vExpect, vActual);

                ginx.store(vExpect, ref expect.Block(block));
                ginx.store(vActual, ref actual.Block(block));
            }
            Claim.eq(expect, actual);
        }
Пример #18
0
 public static BlockVector <N, T> LoadAligned(Span256 <T> src)
 => new BlockVector <N, T>(src);
Пример #19
0
 public static Vec256 <T> LoadVec256 <T>(this Span256 <T> src, int block = 0)
     where T : unmanaged
 => Vec256.Load(src, block);
Пример #20
0
 public static BlockMatrix <M, N, T> Load <M, N, T>(Span <T> src, M m = default, N n = default)
     where M : ITypeNat, new()
     where N : ITypeNat, new()
     where T : struct
 => Span256.Load(src);
Пример #21
0
 public static BlockMatrix <N, T> Load <N, T>(Span256 <T> src, N n = default)
     where N : ITypeNat, new()
     where T : struct
 => new BlockMatrix <N, T>(src);
Пример #22
0
 public static BlockVector <N, T> Load <N, T>(Span <T> src, N n = default)
     where N : ITypeNat, new()
     where T : struct
 => BlockVector <N, T> .LoadAligned(Span256.Load(src));
Пример #23
0
 public static BlockVector <N, T> Alloc <N, T>(N n, T fill)
     where N : ITypeNat, new()
     where T : struct
 => BlockVector <N, T> .LoadAligned(Span256.Alloc <N, T>(fill));
Пример #24
0
 public static BlockVector <T> Load <T>(Span <T> src)
     where T : struct
 => Span256.Load(src);
Пример #25
0
 public static BlockVector <T> Alloc <T>(int n, T?fill = null)
     where T : struct
 => Span256.Alloc <T>(n, fill);
Пример #26
0
 public static Span256 <byte> From <T>(Span256 <T> src)
     where T : struct
 => Span256.Load(MemoryMarshal.AsBytes(src.Unblocked));
Пример #27
0
 public static BlockVector <N, T> Load <N, T>(N length, params T[] src)
     where N : ITypeNat, new()
     where T : struct
 => BlockVector <N, T> .LoadAligned(Span256.Load <T>(src));
Пример #28
0
 public static BlockMatrix <M, N, T> Alloc <M, N, T>(M m = default, N n = default, T exemplar = default)
     where M : ITypeNat, new()
     where N : ITypeNat, new()
     where T : struct
 => Span256.Alloc <M, N, T>();
Пример #29
0
 public static BlockVector <N, T> Load <N, T>(Span256 <T> src)
     where N : ITypeNat, new()
     where T : struct
 => BlockVector <N, T> .LoadAligned(src);
Пример #30
0
 public static ReadOnlySpan256 <T> Load(Span256 <T> src)
 => new ReadOnlySpan256 <T>(src);