Esempio n. 1
0
 public Span(Span <T> src)
 {
     require(src.Length == CellCount, $"length(src) = {src.Length} != {CellCount} = SpanLength");
     data            = src;
     colbuffer       = NatSpan.Alloc <M, T>();
     this.Blocked256 = false;
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 public Span(T value)
 {
     this.data = new Span <T>(new T[CellCount]);
     this.data.Fill(value);
     colbuffer       = NatSpan.Alloc <M, T>();
     this.Blocked256 = false;
 }
Esempio n. 4
0
        public Span <N, ulong> Next()
        {
            var dst  = NatSpan.Alloc <N, ulong>();
            var next = Generators.Mapi((index, g) => (index, value: g.Next()));

            foreach (var item in next)
            {
                dst[item.index] = item.value;
            }
            return(dst);
        }
Esempio n. 5
0
        public static Span <N, T> Contract <N, T>(this Span <N, T> src, Span <N, T> max)
            where N : ITypeNat, new()
            where T : struct
        {
            var dst = NatSpan.Alloc <N, T>();

            for (var i = 0; i < dst.Length; i++)
            {
                dst[i] = Contractors.Contract(src[i], max[i]);
            }
            return(dst);
        }
Esempio n. 6
0
        public static Span <T> Map <M, N, S, T>(this Span <M, N, S> src, Func <S, T> f)
            where M : ITypeNat, new()
            where N : ITypeNat, new()
            where S : struct
            where T : struct
        {
            var dst = NatSpan.Alloc <M, N, T>();
            var m   = nfunc.nati <M>();
            var n   = nfunc.nati <N>();

            for (var i = 0; i < m; i++)
            {
                for (var j = 0; j < n; j++)
                {
                    dst[i, j] = f(src[i, j]);
                }
            }
            return(dst);
        }
Esempio n. 7
0
        public static Span <M, P, double> Mul <M, N, P>(Span <M, N, double> lhs, Span <N, P, double> rhs)
            where M : ITypeNat, new()
            where N : ITypeNat, new()
            where P : ITypeNat, new()
        {
            var m   = nati <M>();
            var n   = nati <N>();
            var p   = nati <P>();
            var dst = NatSpan.Alloc <M, P, double>();

            for (var r = 0; r < m; r++)
            {
                for (var c = 0; c < p; c++)
                {
                    for (var i = 0; i < nati <N>(); i++)
                    {
                        dst[r, c] += lhs[r, i] * rhs[i, c];
                    }
                }
            }

            return(dst);
        }
Esempio n. 8
0
 public Span(ref T src)
 {
     data            = MemoryMarshal.CreateSpan(ref src, CellCount);
     colbuffer       = NatSpan.Alloc <M, T>();
     this.Blocked256 = false;
 }