예제 #1
0
        static void TestCSMultiplySpeed(double[,] A, double[,] B)
        {
            double[,] C = new double[matrixSize, matrixSize];
            Stopwatch watch = Stopwatch.StartNew();

            for (int i = 0; i < testIterations; i++)
            {
                C = MatrixMathCS.MultiplyMatrices(A, B);
            }
            watch.Stop();
            Console.WriteLine("C# multiply test took: " + watch.ElapsedMilliseconds + " ms.");
        }
예제 #2
0
        //Correctness test functions (these are not rigorous tests, just a spot check!)
        static void TestMultiplyCorrectness()
        {
            double[,] ATest = { { 1, 3, 5, 7 }, { 2, 4, 6, 8 } };
            double[,] BTest = { { 1, 4 }, { 2, 5 }, { 3, 6 } };
            EigenWrapper.Matrix AMatTest = new EigenWrapper.Matrix(4, 2);
            EigenWrapper.Matrix BMatTest = new EigenWrapper.Matrix(2, 3);

            //Set the values for the matrix validation tests
            AMatTest[0, 0] = 1;
            AMatTest[0, 1] = 2;
            AMatTest[1, 0] = 3;
            AMatTest[1, 1] = 4;
            AMatTest[2, 0] = 5;
            AMatTest[2, 1] = 6;
            AMatTest[3, 0] = 7;
            AMatTest[3, 1] = 8;
            BMatTest[0, 0] = 1;
            BMatTest[0, 1] = 2;
            BMatTest[0, 2] = 3;
            BMatTest[1, 0] = 4;
            BMatTest[1, 1] = 5;
            BMatTest[1, 2] = 6;

            double[,] C = new double[BTest.GetLength(0), ATest.GetLength(1)];
            double[,] D = new double[BTest.GetLength(0), ATest.GetLength(1)];
            EigenWrapper.Matrix CMat;

            //Testing the C# multiplcation accuracy
            Console.WriteLine("C# multiplication accuracy test:");
            Console.WriteLine("The input matrices are:");
            PrintMatrix(ATest);
            Console.WriteLine("and:");
            PrintMatrix(BTest);
            Console.WriteLine("The result is:");
            double[,] Atrans = MatrixMathCS.Transpose(ATest);
            double[,] Btrans = MatrixMathCS.Transpose(BTest);
            C = MatrixMathCS.MultiplyMatrices(Atrans, Btrans);
            double[,] Ctrans = MatrixMathCS.Transpose(C);
            PrintMatrix(Ctrans);
            Console.WriteLine();

            //Test the Eigen multiplication accuracy
            Console.WriteLine("P/Invoke Eigen 2D double array multiplication correctness test:");
            Console.WriteLine("The input matrices are:");
            PrintMatrix(ATest);
            Console.WriteLine("and:");
            PrintMatrix(BTest);
            Console.WriteLine("The result is:");
            D = EigenWrapper.MatrixMath.MultiplyMatrices(ATest, BTest);
            PrintMatrix(D);
            Console.WriteLine();

            //Test the Matrix class multiplication accuracy
            Console.WriteLine("P/Invoke Eigen matrix class multiplication correctness test:");
            Console.WriteLine("The input matrices are:");
            PrintMatrix(AMatTest);
            Console.WriteLine("and:");
            PrintMatrix(BMatTest);
            Console.WriteLine("The result is:");
            CMat = AMatTest * BMatTest;
            PrintMatrix(CMat);
        }