コード例 #1
0
        void TestMatrix3On3(IMatricesMultiplier matrixMultiplier)
        {
            if (matrixMultiplier == null)
            {
                throw new ArgumentNullException(nameof(matrixMultiplier));
            }

            var m1 = new Matrix(3, 3);

            m1.SetElement(0, 0, 34);
            m1.SetElement(0, 1, 2);
            m1.SetElement(0, 2, 6);

            m1.SetElement(1, 0, 5);
            m1.SetElement(1, 1, 4);
            m1.SetElement(1, 2, 54);

            m1.SetElement(2, 0, 2);
            m1.SetElement(2, 1, 9);
            m1.SetElement(2, 2, 8);

            var m2 = new Matrix(3, 3);

            m2.SetElement(0, 0, 12);
            m2.SetElement(0, 1, 52);
            m2.SetElement(0, 2, 85);

            m2.SetElement(1, 0, 5);
            m2.SetElement(1, 1, 5);
            m2.SetElement(1, 2, 54);

            m2.SetElement(2, 0, 5);
            m2.SetElement(2, 1, 8);
            m2.SetElement(2, 2, 9);

            var multiplied = matrixMultiplier.Multiply(m1, m2);

            Assert.AreEqual(448, multiplied.GetElement(0, 0));
            Assert.AreEqual(1826, multiplied.GetElement(0, 1));
            Assert.AreEqual(3052, multiplied.GetElement(0, 2));

            Assert.AreEqual(350, multiplied.GetElement(1, 0));
            Assert.AreEqual(712, multiplied.GetElement(1, 1));
            Assert.AreEqual(1127, multiplied.GetElement(1, 2));

            Assert.AreEqual(109, multiplied.GetElement(2, 0));
            Assert.AreEqual(213, multiplied.GetElement(2, 1));
            Assert.AreEqual(728, multiplied.GetElement(2, 2));
        }
コード例 #2
0
        private static long GetTimeSpentOnMatrixMultiplication(IMatricesMultiplier matrixMultiplier, int matrixSize)
        {
            if (matrixMultiplier == null || matrixSize < 1)
            {
                throw new ArgumentException("Argument exception");
            }

            var firstMatrix  = new Matrix(matrixSize, matrixSize, true);
            var secondMatrix = new Matrix(matrixSize, matrixSize, true);
            var stopWatch    = new Stopwatch();

            stopWatch.Start();
            var multiplied = matrixMultiplier.Multiply(firstMatrix, secondMatrix);

            stopWatch.Stop();

            return(stopWatch.ElapsedMilliseconds);
        }
コード例 #3
0
        private long MultiplierExecute(IMatricesMultiplier matrixMultiplier, Matrix m1, Matrix m2)
        {
            if (matrixMultiplier == null)
            {
                throw new ArgumentNullException(nameof(matrixMultiplier));
            }
            if (m1 == null)
            {
                throw new ArgumentNullException(nameof(m1));
            }
            if (m2 == null)
            {
                throw new ArgumentNullException(nameof(m2));
            }

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            IMatrix multiplied = matrixMultiplier.Multiply(m1, m2);

            stopwatch.Stop();

            return(stopwatch.ElapsedMilliseconds);
        }