Ejemplo n.º 1
0
        public static MatrixMultiplier GetMatrixMultiplier(MultiplicationMethod method)
        {
            MatrixMultiplier multiplier = null;

            switch (method)
            {
            case MultiplicationMethod.Simple:
                multiplier = new SimpleMultiplier();
                break;

            case MultiplicationMethod.Winograd:
                multiplier = new WinogradMultiplier();
                break;
            }

            return(multiplier);
        }
Ejemplo n.º 2
0
        static void TestEnhancedWinograd()
        {
            // Testing even size
            Matrix m1 = new Matrix(4, 4);
            Matrix m2 = new Matrix(4, 4);

            Matrix.GenerateRandom(m1, 0, 16);
            Matrix.GenerateRandom(m2, 0, 16);
            //FillSequentially(m1, 1, 1);
            //FillSequentially(m2, 16, -1);

            Matrix correctResult = new SimpleMultiplier().Multiply(m1, m2);

            Matrix testResult = new EnhancedWinogradMultiplier().Multiply(m1, m2);

            Console.WriteLine("Testing even-sized matrixes");
            Console.WriteLine("\nFirst matrix: ");
            Console.WriteLine(m1);
            Console.WriteLine("\nSecond matrix: ");
            Console.WriteLine(m2);

            Console.WriteLine("\nTest result: ");
            Console.WriteLine(testResult);

            bool correct = correctResult.Equals(testResult);

            Console.WriteLine(correct ? "CORRECT" : "WRONG RESULT!");
            if (!correct)
            {
                Console.WriteLine("\nEstimated result: ");
                Console.WriteLine(correctResult);
            }

            // Testing odd size
            m1 = new Matrix(3, 3);
            m2 = new Matrix(3, 3);
            Matrix.GenerateRandom(m1, 0, 9);
            Matrix.GenerateRandom(m2, 0, 9);
            //FillSequentially(m1, 1, 1);
            //FillSequentially(m2, 9, -1);

            correctResult = new SimpleMultiplier().Multiply(m1, m2);

            EnhancedWinogradMultiplier enhancedWinogradMultiplier = new EnhancedWinogradMultiplier();

            testResult = enhancedWinogradMultiplier.Multiply(m1, m2);

            Console.WriteLine("\nTesting odd-sized matrixes");
            Console.WriteLine("\nFirst matrix: ");
            Console.WriteLine(m1);
            Console.WriteLine("\nSecond matrix: ");
            Console.WriteLine(m2);
            Console.WriteLine("\nTest result: ");
            Console.WriteLine(testResult);

            correct = correctResult.Equals(testResult);
            Console.WriteLine(correct ? "CORRECT" : "WRONG RESULT!");
            if (!correct)
            {
                Console.WriteLine("\nEstimated result: ");
                Console.WriteLine(correctResult);
            }
        }
Ejemplo n.º 3
0
        static bool TestMultipication(Matrix a, Matrix b, Matrix assertedResult)
        {
            Matrix correctResult = new SimpleMultiplier().Multiply(a, b);

            return(correctResult.Equals(assertedResult));
        }