public void Test_ParallelHelper_ForEach_Ref2D(
            int sizeY,
            int sizeX,
            int row,
            int column,
            int height,
            int width)
        {
            int[,]
            data = CreateRandomData2D(sizeY, sizeX),
            copy = (int[, ])data.Clone();

            // Prepare the target data iteratively
            foreach (ref int n in copy.AsSpan2D(row, column, height, width))
            {
                n = unchecked (n * 397);
            }

            Memory2D <int> memory = data.AsMemory2D(row, column, height, width);

            Assert.AreEqual(memory.Length, height * width);
            Assert.AreEqual(memory.Height, height);
            Assert.AreEqual(memory.Width, width);

            // Do the same computation in paralellel, then compare the two arrays
            ParallelHelper.ForEach(memory, new Multiplier(397));

            CollectionAssert.AreEqual(data, copy);
        }
Exemplo n.º 2
0
            static Triangle[] AsTriangles(int[,] grid)
            {
                var span = grid.AsSpan2D();
                var list = new List <Triangle>(span.Height);

                for (var i = 0; i < span.Height; i++)
                {
                    var row = span.GetRowSpan(i);

                    list.Add(new(
                                 row[0],
                                 row[1],
                                 row[2]));
                }

                return(list.ToArray());
            }