Beispiel #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;
 }
Beispiel #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;
 }
Beispiel #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;
 }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #8
0
 public static Span <M, N, T> Span <M, N, T>(this IPolyrand random, M rows = default, N cols = default)
     where T : struct
     where M : ITypeNat, new()
     where N : ITypeNat, new()
 => NatSpan.Load <M, N, T>(random.Span <T>(nfunc.muli(rows, cols)), rows, cols);
Beispiel #9
0
 public static Span <N, T> Span <N, T>(this IPolyrand random, N length = default, Interval <T>?domain = null, Func <T, bool> filter = null)
     where T : struct
     where N : ITypeNat, new()
 => NatSpan.Load <N, T>(random.Span <T>((int)length.value, domain, filter));
Beispiel #10
0
 public static Span <M, N, T> Span <M, N, T>(this IPolyrand random, M rows, N cols, Interval <T> domain)
     where T : struct
     where M : ITypeNat, new()
     where N : ITypeNat, new()
 => NatSpan.Load <M, N, T>(random.Span <T>(nfunc.muli(rows, cols), domain), rows, cols);
Beispiel #11
0
 public Span(ref T src)
 {
     data            = MemoryMarshal.CreateSpan(ref src, CellCount);
     colbuffer       = NatSpan.Alloc <M, T>();
     this.Blocked256 = false;
 }