コード例 #1
0
ファイル: NodeGrid.cs プロジェクト: tp-nscan/NodePad
        public NodeGrid(Sz2 <int> strides, IEnumerable <P1V <int, float> > tuples, int generation, int seed)
        {
            Strides = strides;
            Values  = new float[Strides.Count()];
            foreach (var tup in tuples)
            {
                Values[tup.X] = tup.V;
            }

            Generation = generation;

            Seed = seed;
            var randy = GenV.Twist(Seed);

            Noise    = GenS.NormalSF32(randy, 0.0f, 1.0f).Take(Strides.Count()).ToArray();
            NextSeed = randy.Next();

            var Offhi = new P2 <int>(0, -1);
            var Offlo = new P2 <int>(0, 1);
            var Offlf = new P2 <int>(-1, 0);
            var Offrt = new P2 <int>(1, 0);

            Top    = GridUtil.OffsetIndexes(Strides, Offhi);
            Bottom = GridUtil.OffsetIndexes(Strides, Offlo);
            Left   = GridUtil.OffsetIndexes(Strides, Offlf);
            Right  = GridUtil.OffsetIndexes(Strides, Offrt);
        }
コード例 #2
0
ファイル: NodeProcs.cs プロジェクト: tp-nscan/NodePad
        public static NodeGrid RandNodeGrid(Sz2 <int> bounds, int initSeed, int updateSeed)
        {
            var nodeVals = GenS.SeqOfRandUF32(GenV.Twist(initSeed)).Take(bounds.Count()).ToArray();
            var tuples   = Enumerable.Range(0, bounds.Count()).Select(i => new P1V <int, float>(i, nodeVals[i]));

            return(new NodeGrid(
                       strides: bounds,
                       tuples: tuples,
                       generation: 0,
                       seed: updateSeed
                       ));
        }
コード例 #3
0
        async void RunBatch()
        {
            int Stride      = 32;
            var jobs        = 4;
            var GridStrides = new Sz2 <int>(Stride, Stride);
            var nodeGrid    = NodeProcs.RandNodeGrid(GridStrides, 123, 456);
            var localOrders = ColUtils.SubSeqs(jobs, GridStrides.Count() / jobs)
                              .Select(t => t.ToList())
                              .ToList();
            var trackedTasks = new List <Task <int> >();

            for (var i = 0; i < jobs; i++)
            {
                var i1 = i;
                trackedTasks.Add(Task.Run(() =>
                {
                    Thread.Sleep(2000);
                    return(i1);
                }));
            }
            await Task.WhenAll(trackedTasks);

            var tot = trackedTasks.Sum(tt => tt.Result);
        }
コード例 #4
0
ファイル: NodeProcs.cs プロジェクト: tp-nscan/NodePad
 public static NodeArray RandNodeArray(Sz2 <int> bounds, Random randy)
 {
     return(new NodeArray(Enumerable.Range(0, bounds.Count())
                          .Select(i => randy.NextDouble() * 2 - 1.0)
                          .ToArray()));
 }