Ejemplo n.º 1
0
        public void TestUtilities()
        {
            double[,] matrix3 = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };

            //TransposeMatrix
            Transpose transposeMatrix = new Transpose();

            double[,] matrixT = transposeMatrix.TransposeMatrix(matrix3);

            double[,] actualTransMatrix = { { 1, 4, 7 }, { 2, 5, 8 }, { 3, 6, 9 } };

            Assert.Equal(actualTransMatrix, matrixT);
        }
Ejemplo n.º 2
0
        public void TestMultiplication()
        {
            ///Arrange
            ///
            double[,] matrix1 = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
            double[] vector1 = { 2, 4, 5 };

            //DenseMatrix
            DenseMatrix denseMatrix = new DenseMatrix(matrix1);

            //CSR
            CompressedSparseRows csr = new CompressedSparseRows(matrix1);

            //TransposeMatrix
            Transpose transposeMatrix = new Transpose();

            double[,] matrixT = transposeMatrix.TransposeMatrix(matrix1);

            //COOrdinateListRowMajor
            COOrdinateListRowMajor rowCOO = new COOrdinateListRowMajor(matrix1);

            ///Act
            ///
            double[] expectedProduct1 = denseMatrix.Multiplication(vector1);
            double[] expectedProduct2 = csr.MultiplicationAx(vector1);
            double[] expectedProduct3 = csr.MultiplicationATx(vector1);
            double[] expectedProduct4 = rowCOO.Multiplication(vector1);

            ///
            double[] actualResult = new double[] { 25, 58, 91 };
            double[] actualTransMatrixMultiplic = new double[] { 53, 64, 75 };

            ///Assert
            ///
            for (int i = 0; i < vector1.Length; i++)
            {
                Assert.Equal(actualResult[i], expectedProduct1[i]);
            }

            Assert.Equal(actualResult, expectedProduct2);
            Assert.Equal(actualTransMatrixMultiplic, expectedProduct3);
            Assert.Equal(actualResult, expectedProduct4);
        }