Example #1
0
        public void Test_MutableSpan2D_Compacting(int rowId)
        {
            var unused = new byte[1024];
            var array  = new ulong[, ]
            {
                { 1, 2, 3 },
                { 4, 5, 6 }
            };

            Span2D <ulong> span2D = array.AsSpan2D();

            Span <ulong> row = SpanExtensions.GetRow(span2D, rowId);

            for (var i = 0; i < row.Length; i++)
            {
                Assert.AreEqual(array[rowId, i], row[i]);
            }

            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);

            for (var i = 0; i < row.Length; i++)
            {
                Assert.AreEqual(array[rowId, i], row[i]);
            }

            row[2] = 30;
            Assert.AreEqual(30, array[rowId, 2]);
        }
Example #2
0
        /// <summary>
        /// Swaps the rows.
        /// </summary>
        /// <param name="matrix">The matrix.</param>
        /// <param name="rows">The number of rows.</param>
        /// <param name="columns">The number of columns.</param>
        /// <param name="row1">The row1.</param>
        /// <param name="row2">The row2.</param>
        /// <returns></returns>
        /// <acknowledgment>
        /// https://github.com/GeorgiSGeorgiev/ExtendedMatrixCalculator
        /// </acknowledgment>
        public static void SwapRows(Span2D <double> matrix, int rows, int columns, int row1, int row2)
        {
            var temp_row = new double[columns];

            for (var j = 0; j < columns; j++)
            {
                temp_row[j]     = matrix[row1, j];
                matrix[row1, j] = matrix[row2, j];
                matrix[row2, j] = temp_row[j];
            }
        }
Example #3
0
        public static void SwapRows(Span2D <float> matrix, int row1, int row2)
        {
            var columns  = matrix.Width;
            var temp_row = new float[columns];

            for (var j = 0; j < columns; j++)
            {
                temp_row[j]     = matrix[row1, j];
                matrix[row1, j] = matrix[row2, j];
                matrix[row2, j] = temp_row[j];
            }
        }